• Advertisement
Sign in to follow this  

Transforming rotation

This topic is 1230 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 am trying to allow my camera to have different "focus points" around the scene so that when the user rotates the camera, the camera rotates around that focus point. In "focus mode", when the user clicks on an item in the scene that item is set to the camera's rotation point.

 

To do this I simply made a transform from the position of the clicked item and a quaternion holding the cameras rotation about that item. Basically the clicked item acts as the camera's parent.

 

The transforms are multiplied like this -

 

camQuaternion.getRotationTransposeMatrix() * camPosition.getInverseTranslationMatrix() * mParentTransform.getInverse()

 

Where the parent inverse is just

 

parentQuaternion.getRotationTransposeMatrix() * parentPosition.getInverseTranslationMatrix()

 

When the mode is in "focus mode" I then apply all rotations to the parent rather than the camera..

 

This all works great - but im stuck on one thing..

 

How do I set the camera's local position and rotation when the focus point changes so that the camera does not move at all..

 

or in other words, how do I transform the camera's rotation/translation from the coordinate space of one clicked object to the coordinate space of another clicked object so that the camera does appear to move at all to the user when the focus point has changed?

 

right now when you click on another object the camera jumps so that it is in the same position/rotation with respect to the new focus object as it was with the old focus object

Edited by EarthBanana

Share this post


Link to post
Share on other sites
Advertisement

Is the focused object always at the center of the screen?  If so, it's impossible; instead you will need to translate the camera position gradually to prevent the jump, so that the new focus point is at the center.  You can keep it from becoming disorienting by maintaining the same angle relative to the world space.

 

If the focus point isn't at the center of the screen, this sounds a little disorienting.

 

Can you make some images or videos to explain how you want this to work?

 

If the focus point isn't the center, you can do a bit of trig to get your new camera position the same as the old one... but again, this sounds disorienting, since it could cause your camera to point away from your focus point and you'd be rotating around something you can't find.

Share this post


Link to post
Share on other sites

The focus point is not always at the center of the screen - it is wherever the object is located that the user clicks on. I believe the elder scrolls construction set is an example of a program that uses this focus system for the camera..

 

It might sound a bit disorienting, but you can never click something that is not viewable on screen - and the selected object is always highlighted. If there is no selected object then the rotation is about the camera's axis's.. As in a fps..

 

[attachment=24101:tilesscrn.png]

 

In the picture above all camera rotations, for example, are about the center of the selected tiles, which is the tile that is a bit darker..

 

And now I'm trying to make it so that when another tile is clicked, it is made the center of camera movement without having the camera move at all

Share this post


Link to post
Share on other sites

Just work out a new look at quaternion and interpolate it over a few frames, without changing the position. Then use that as the focus point. You may also want to change the position as well though at the same time so the distance for the camera from the look at point is the same as before.

Share this post


Link to post
Share on other sites

Thanks for the input but I got it working how I wanted to..

 

Basically, as mentioned before I store a parent transform for the camera - the transform is built from rotation and translation matrices just like any thing else except the order of multiplication is reversed and the inverse is taken because it is the camera's POV..

 

IE what is normally

 

finalTForm = parentTForm * translationTForm * rotationTForm

 

for the camera is

 

finalTForm = rotationTFormInverse * translationTFormInverse * parentTFormInverse

 

So when in "focus" mode, the camera has a local transform (which is in respect to the focus point) and a global transform which is obtained by multiplying the local transform by the parent transform. The parent transform is built using the position of the focus point and the orientation which is stored in a quaternion.

 

To change from one focus point to another I do the following...

 

Set the cameras local rotation to the global rotation by multiplying the quaternions in the correct order

cam.localOrientation = cam.localOrientation() * cam.parentOrientation()

 

I then set the parent orientation to a unit quaternion ( i = j = k = 0 and w = 1)

 

Then I set the cameras parent position to the changed focus point (in global coords) and set the cameras local position to the camera's world position minus the parent positon

cam.setParentPosition(focusPointGlobalPos);

cam.setLocalPosition(cam.worldPosition() - cam.parentPosition());

 

With that I now apply all rotations to the parent's rotation quaternion.. The focus point changes without moving the camera's view vector or the camera's position

Share this post


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

  • Advertisement