Jump to content
  • Advertisement
Sign in to follow this  

Need help: object-rotation arcball under camera transforms

This topic is 3894 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
Never mind, I managed to figure out a way. I used two gluUnproject calls to get two points for a ray, and then sphere intersection centered on the object center.

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!