Sign in to follow this  

Need help: object-rotation arcball under camera transforms

This topic is 3590 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 have an arcball implementation that accumulates rotations as quaternions, and I extract a matrix to apply the transform to the object. That part works fine. However, the arcball needs the click and current drag points. For testing, I was just using a map-to-sphere based on what I found on the web (w and h are half screen width and height:
bool Arcball::MapToSphere(int const mx, int const my, Float3 &res)
{
	float const tx(static_cast<float>(mx - w) * ir), ty(static_cast<float>(my - h) * ir);
	float tmp(tx * tx + ty * ty);
	if (tmp > 1.0f) return false;
	res.x = tx;
	res.y = ty;
	res.z = std::sqrtf(1.0f - tmp);
	return true;
}
This assumes an arcball that is screen-sized and centered. I can use offsets to center it on the object's center, and reduce the size to match a handle on the object, and that works from the default camera view along Z. However, if there's any camera movement, the rotation is messed up. I can provide the click point as gluUnproject minus object center. However, I don't know how to provide the current drag point, since that has to be determined from a virtual sphere around the object, and I can't use gluUnproject since I don't know what the depth would be. How do I do this?

Share this post


Link to post
Share on other sites

This topic is 3590 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this