• Advertisement
Sign in to follow this  

Turntable camera functionality

This topic is 2261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I would like to implement in my application functionality similar to turntable camera in Blender. I need to move (strafe) 3D object and rotate it. After move it I would like to rotate scene always around of center of the screen. Actually after move object in any direction of the screen it rotates around its local coordinate system, not around center of the screen. It looks like the rotation center point is moving together with object. I tried to use glTranslate function, but I didn't get expected results.

In the Mouse button down event I read the cursor position:

...
previousX = Mouse.X;
previousY = Mouse.Y;
previousZ = Mouse.Y;

prev_eyeX = (float)Mouse.X;
prev_eyeY = (float)Mouse.Y;
prev_eyeZ = (float)Mouse.Y;
...


In the mouse move event I modify the values of variables depending of the pressed mouse button

...
if (Mouse[MouseButton.Middle])
{
rot_x += (Mouse.Y - previousY);
rot_y += (Mouse.X - previousX);
}

if (Mouse[MouseButton.Right])
{
eyeZ += (Mouse.Y - prev_eyeZ) * 0.05f; // zoom in/out scene
}

if (Mouse[MouseButton.Left])
{
centerX -= (Mouse.X - previousX) * 0.005f; // centerX, centerY, centerZ determine the target point of camera view
centerY += (Mouse.Y - previousY) * 0.005f;
centerZ -= (Mouse.Y - previousZ) * 0.005f;

eyeX -= (Mouse.X - prev_eyeX) * 0.005f; // eyeX, eyeY, eyeZ determine the position of camera
eyeY += (Mouse.Y - prev_eyeY) * 0.005f;

translate_x -= (Mouse.X - previousX) * 0.005f; // translate_x, translate_y determines the object displacement
translate_y += (Mouse.Y - previousY) * 0.005f;
}

previousX = (float)Mouse.X;
previousY = (float)Mouse.Y;
previousZ = (float)Mouse.Y;

prev_eyeX = (float)Mouse.X;
prev_eyeY = (float)Mouse.Y;
prev_eyeZ = (float)Mouse.Y;
...


Main render method:

...
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

double aspect = Width / (float)Height;
GL.MatrixMode(MatrixMode.Projection);
Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)aspect, 0.1f, 100.0f);
GL.LoadMatrix(ref perspective);

GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();

Matrix4 lookat = Matrix4.LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);

GL.Rotate(rot_x, 1.0f, 0.0f, 0.0f);
GL.Rotate(rot_y, 0.0f, 1.0f, 0.0f);
GL.Rotate(rot_z, 0.0f, 0.0f, 1.0f);

GL.Translate(-translate_x, -translate_y, -translate_z);

RenderCube();

this.SwapBuffers();
...


Could you please suggest me how should I modify algorithm to get the expected results?

Thanks in advance for your any suggestions.

--
Regards,
Agarwean

Share this post


Link to post
Share on other sites
Advertisement
edit: I'm sorry if I confused you, I'm not used to the immediate mode :rolleyes:
edit2: could you tell a bit more on how you want the camera and mode to behave? I'm not familiar with blender's view.
What do you mean by rotating around the center of the screen?
What you are doing now, is moving the object along the scenes axes, then rotating the object around the scene's origin and then moving and rotating the scene's origin to match the camera's position and direction.

Share this post


Link to post
Share on other sites
could you tell a bit more on how you want the camera and mode to behave? I'm not familiar with blender's view.[/quote]
At the beginning, in the initial state of camera and object (rendered in 0,0,0 position) it's rotation works fine (object rotate around the axis of coordinate system in point (0,0,0)), but when I change the camera position (e.g. move scene a little bit to the right) I would like that the coordinate system (around which rotation of the scene should be realized) still remains in the point (0, 0, 0) and not moved with the object, as is currently.

What do you mean by rotating around the center of the screen?[/quote]
I mean rotation around the origin translate to the point on which camera looks (centerX, centerY, centerZ).

Perhaps the whole problem is caused by that, because when I move mouse cursor holding LMB I change only point on which camera looks and I not translate correctly origin to that point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement