Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Arcball + translation

This topic is 2865 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


I'm trying to create an arcball without playing with the OpenGL API. It is because later I will use it for other kind of API.

My first problem is that I try to translate my object with the mouse, for this I create a plane from my "camera" X axis and the Y axis. Then I project the mouse last position and the current position on this plane. I got 2 3D points and simply use the "difference" between to do my translation.

The problem is that the point I click on the viewport does not exactly follow the mouse.

Here is my code :

if (e->WheelButtonStatus == Down)
VNCamera* camera = _surface->GetScene()->GetActiveCamera();

//---- Adapt to viewport size
float lastX = startMouse.x / _surface->GetWidth();
float newY = startMouse.y / _surface->GetHeight();
float newX = ((float)e->x) / _surface->GetWidth();
float lastY = ((float)e->y) / _surface->GetHeight();

//---- Compute the 3D axis
Vector3 axisY = camera->GetEyeUp();
Vector3 axisZ = camera->GetEye() - camera->GetEyeAt();
axisZ = Normalize(axisZ);
Vector3 axisX = Cross(axisY, axisZ);

//---- Projection plane = AxisX + AxisY

// Project mouse on plane
Vector3 lastV;
lastV.x = axisX.x * lastX + axisY.x * lastY;
lastV.y = axisX.y * lastX + axisY.y * lastY;
lastV.z = axisX.z * lastX + axisY.z * lastY;

// Project mouse on plane
Vector3 newV;
newV.x = axisX.x * newX + axisY.x * newY;
newV.y = axisX.y * newX + axisY.y * newY;
newV.z = axisX.z * newX + axisY.z * newY;

//---- Delta
Vector3 delta = newV - lastV;

//---- Adapt the depth
float depth = (camera->GetEye() - camera->GetEyeAt()).Length();
delta *= depth;

//---- Set the camera
Vector3 eye = camera->GetEye() - delta;
Vector3 eyeAt = camera->GetEyeAt() - delta;

//---- Record new mouse position
startMouse.x = e->x;
startMouse.y = e->y;


If you have an idea ?

[Edited by - polar01 on December 14, 2010 5:00:49 AM]

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!