Jump to content
  • Advertisement
Sign in to follow this  
DeadlyDan

Maintaining Orientation While Rotating

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

Hi there,

I've been having trouble trying to figure out how exactly to achieve this. Basically, i'm my world i have an object that has it's own unique rotation.

I make it so i can pick up this object, and move it around. I'm trying to maintain the orientation of the object (the direction relative to the player's viewport angles at the point of picking it up) while being able to rotate along with the viewport to simulate the effect of for example picking it up, turning left and placing it back down with it still maintaing the same orientation it had to begin with.

Here is a real world example. Say you pick up a tennis racket at the handle with the wide area facing away. You turn to the right, keeping the tennis racket at the same orientation as you picked it up, then place it down.

In psuedo code i'm doing this:


ObjectRotation = GetObjectRotation ( );
EyePosition = GetEyePosition ( );
EyeAngles = GetEyeAngles ( );
ForwardVector = GetForwardVector ( EyeAngles );

SetPosition ( EyePosition + ForwardVector * Distance );
SetRotation ( EyeAngles );


The problem is obviously this complete overwrites the rotation, almost giving the effect i want but it won't retain orientation. Due to the design of the engine i can't access the local rotation either.

I need away to combine "ObjectRotation" and "EyeAngles".

Any help is greatly appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Due to the design of the engine i can't access the local rotation either.
What local rotation can't you access? And what engine is this? Not being able to access the local transform for an object seems like a pretty severe limitation, one that it's hard to believe an API would impose...

Anyway, here's the general idea behind what you want to do. Before the object is picked up, the object has a world transform, and the player has a world transform. When the object is picked up, you want to make the object a 'child object' of the player. This means computing the object's local transform relative to the player transform, which can be done as follows (using column-vector notation):
object_local_transform = inverse(player_world_transform) * object_world_transform;
As the object is being moved, you'll need to update its world transform as the player moves, which can be done as follows:
object_world_transform = player_world_transform * object_local_transform;
When it comes time to set the object down, simply 'unparent' the child object, and assign to it its last computed world transform.

Share this post


Link to post
Share on other sites
Well, the problem is each object is a networked physics object, and i'm using the Source SDK (HL2 Engine).

I'll look into what you said. Thanks.

Share this post


Link to post
Share on other sites
Quote:
[Well, the problem is each object is a networked physics object, and i'm using the Source SDK (HL2 Engine).
Ok, one more idea: if the objects involved are objects in a physics simulation, perhaps you could create the effect of the aforementioned parent-child relationship by creating a temporary joint (most likely a fixed or 'weld' joint) between them.

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!