// reset our viewport after a window resize func resizeWindow(width, height int) { // protect against a divide by zero if height == 0 { height = 1 } // Setup our viewport gl.Viewport(0, 0, width, height) // change to the projection matrix and set our viewing volume. gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() // aspect ratio aspect := gl.GLdouble(width / height) // Set our perspective. // This code is equivalent to using gluPerspective as in the original tutorial. var fov, near, far gl.GLdouble fov = 45.0 near = 0.1 far = 100.0 top := gl.GLdouble(math.Tan(float64(fov*math.Pi/360.0))) * near bottom := -top left := aspect * bottom right := aspect * top gl.Frustum(float64(left), float64(right), float64(bottom), float64(top), float64(near), float64(far)) // Make sure we're changing the model view and not the projection gl.MatrixMode(gl.MODELVIEW) // Reset the view gl.LoadIdentity() }
/* new window size or exposure */ func reshape(width int, height int) { h := float64(height) / float64(width) gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0.0, 0.0, -40.0) }
func (self *Camera) Setup() { d := self.Distance Angle := self.Angle Angle360 := Angle.Scale(1 / math.Pi * 180) TargetPos := self.Target.Pos gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Viewport(0, 0, 800, 600) gl.Frustum(-1, 1, -1, 1, 4, 1000) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0, 0, -d) gl.Rotatef(Angle360.Y, 1, 0, 0) gl.Rotatef(Angle360.X, 0, 1, 0) gl.Translatef(-TargetPos.X, -TargetPos.Y, -TargetPos.Z) }
func ResizeWindow(w int32, h int32) { // resizeWindow gl.MatrixMode(gl.PROJECTION) gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h)) gl.LoadIdentity() // glu.Perspective( 45.0, ratio, 0.1, 100.0) aspect := gl.GLdouble(w) / gl.GLdouble(h) zNear := gl.GLdouble(0.1) zFar := gl.GLdouble(100.0) gl.Frustum(-NearHeight*aspect, NearHeight*aspect, -NearHeight, NearHeight, zNear, zFar) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() WinW = int(w) WinH = int(h) }