
Where to put GL.Rotate in Windows App?
Posted Thursday, 26 August, 2010 - 21:02 by adityatan inHi there:
I have made a program that works in a Console App. But now, as I try to move the whole thing to a Windows App, my GL.Rotate does not work properly. Please help me in catching the error.
Here's where I set up my GL.Rotate.
private void glControl1_Paint(object sender, PaintEventArgs e) { GL.MatrixMode(MatrixMode.Modelview); GL.Translate(0, 0, -500); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.LoadMatrix(ref cameraMatrix); GL.Rotate(camera_rotationY, 0, 1, 0); // Add the Y-rotation GL.Rotate(camera_rotationZ, 0, 0, 1); // Add the Z-rotation glControl1.SwapBuffers(); } private void glControl1_KeyDown(object sender, KeyEventArgs e) { ... if (e.KeyCode == Keys.Up) { camera_rotationZ -= 5; } if (e.KeyCode == Keys.Down) { camera_rotationZ += 5; } if (e.KeyCode == Keys.Left) { camera_rotationY -= 5; } if (e.KeyCode == Keys.Right) { camera_rotationY += 5; } Vector3 lookatPoint = new Vector3((float)Math.Cos(facing), (float)Math.Sin(pitch / 2), (float)Math.Sin(facing)); cameraMatrix = Matrix4.LookAt(location, location + lookatPoint, up); glControl1.Invalidate(); }
Every single code is a replica of what I've done in the Console App; but again, it does not seem to work here. Any idea why? Am I, maybe, supposed to put "GL.Rotate(camera_rotationY, 0, 1, 0);" somewhere else, such as inside "private void glControl1_Resize(object sender, EventArgs e)," or "private void glControl1_Load(object sender, EventArgs e)?"
Thank you for your help!
Aditya


Comments
Re: Where to put GL.Rotate in Windows App?
Got it! Everything is here: http://www.opentk.com/doc/chapter/2/glcontrol. I wish I had found this site much earlier!
Thanks!
Aditya