Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

How to orbit around a plane without affecting the camera Z position?

Started by synthetix Nov 8, 2014 at 7:41 AM 0 replies 1.1k views
Original Post
synthetix
synthetix

I have a simple scene rendered in OpenGL that contains grid plane, same as you'd find in any 3D modeling app. I set the initial lookat position using a lookat matrix to point to the center of the scene (0,0). What I want to do is rotate the entire scene with the ground plane around 0,0 without affecting the Z orientation of the "camera." The way it is now, I detect the mouse position and use that to transform the scene via a rotation matrix. However, depending on the angle, the plane will cant fore/aft and won't stay perfectly level. I'm sure I'm missing some math to correct for the angles based on the eye position. I did some searching and found references to atan2(), which appears to be used to correct the angles but I'm not sure how to implement it. Here's what I have:


//set up lookat matrix once when app initializes to give some nice perspective
glMatrixMode(GL_MODELVIEW);
glMultMatrixf(lookat);

//rotate view around the scene
//x,y,z struct members are from the mouse position
glRotatef(userinput.rot.angle, userinput.rot.x, userinput.rot.y, userinput.rot.z);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.