Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

Rotating an object to have a new Y-axis and similar Z-axis?

This topic is 4064 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 wanted to simulate something like Prey's little "planet" thing, where you can walk around it in circles. I have the gravity correctly done, I just can't get the player's orientation right. I have a quaternion representing the player's current orientation. When the new "down" changes, I construct a new quaternion for the new orientation with the Y-axis being [-down], and the X and Z axises being 2 automatically generated perpendicular axises to each other and the Y-axis. Then I simply slerp from the old orientation to the new one. This works perfectly until I want to turn my player to the left or right. What happens is that I now have a forward direction that is not the identity forward direction. When I construct the new quaternion for the new orientation, this direction is ignored. Thus, I'm forced to look straight forward. Now, what I'm asking, is how do I keep the constructed quaternion's forward direction as close to the old quaternion's forward direction as possible? (I'm not good with this math at all, but I'm using a pretty powerful math library with quaternions, matrices, vectors, and pretty much anything you'll need in there) Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by agi_shi
I wanted to simulate something like Prey's little "planet" thing, where you can walk around it in circles.

I have the gravity correctly done, I just can't get the player's orientation right.

I have a quaternion representing the player's current orientation. When the new "down" changes, I construct a new quaternion for the new orientation with the Y-axis being [-down], and the X and Z axises being 2 automatically generated perpendicular axises to each other and the Y-axis. Then I simply slerp from the old orientation to the new one. This works perfectly until I want to turn my player to the left or right.

What happens is that I now have a forward direction that is not the identity forward direction. When I construct the new quaternion for the new orientation, this direction is ignored. Thus, I'm forced to look straight forward.

Now, what I'm asking, is how do I keep the constructed quaternion's forward direction as close to the old quaternion's forward direction as possible?

(I'm not good with this math at all, but I'm using a pretty powerful math library with quaternions, matrices, vectors, and pretty much anything you'll need in there)

Thanks in advance!
1. Construct a quaternion that rotates (over the shortest arc) the player's current up vector into alignment with the target up vector.

2. Multiply this quaternion with your current orientation quaternion to yield your target orientation.

3. Slerp between the current and target orientations as you're doing currently.

Let me know if you need any help with the details.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by agi_shi
I wanted to simulate something like Prey's little "planet" thing, where you can walk around it in circles.

I have the gravity correctly done, I just can't get the player's orientation right.

I have a quaternion representing the player's current orientation. When the new "down" changes, I construct a new quaternion for the new orientation with the Y-axis being [-down], and the X and Z axises being 2 automatically generated perpendicular axises to each other and the Y-axis. Then I simply slerp from the old orientation to the new one. This works perfectly until I want to turn my player to the left or right.

What happens is that I now have a forward direction that is not the identity forward direction. When I construct the new quaternion for the new orientation, this direction is ignored. Thus, I'm forced to look straight forward.

Now, what I'm asking, is how do I keep the constructed quaternion's forward direction as close to the old quaternion's forward direction as possible?

(I'm not good with this math at all, but I'm using a pretty powerful math library with quaternions, matrices, vectors, and pretty much anything you'll need in there)

Thanks in advance!
1. Construct a quaternion that rotates (over the shortest arc) the player's current up vector into alignment with the target up vector.

2. Multiply this quaternion with your current orientation quaternion to yield your target orientation.

3. Slerp between the current and target orientations as you're doing currently.

Let me know if you need any help with the details.


Thanks for the reply bud, you always seem to reply to my questions really fast [smile]! I really appreciate it.

Anyways, on to the problem. I did this:

Ogre::Quaternion alignUp = _oldRot.yAxis().getRotationTo(u);
_destRot = _oldRot * alignUp;

(I'm using Ogre)

I got some really strange results. After turning a bit my player seems randomly flip directions. Sometimes he just randomly starts turning and keeps turning.

Also, when flipping gravity (which involves this, see this google video for a demonstration) to arbitrary directions (the camera's direction in the above video's case), I get really odd results. The down direction (which is technically -up) does not rotate to the desired direction

Ideas?

Share this post


Link to post
Share on other sites
The only thing I can think to suggest is to reverse the order of multiplication, i.e.:
_destRot =  alignUp * _oldRot;
If that doesn't work, then I can only guess at what the problem might be (there are a lot of ways one could get the implementation for this wrong).

I will say that I've implemented exactly what you're describing using this method, and it worked perfectly for me, so I'd recommend sticking with this approach.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
The only thing I can think to suggest is to reverse the order of multiplication, i.e.:
_destRot =  alignUp * _oldRot;
If that doesn't work, then I can only guess at what the problem might be (there are a lot of ways one could get the implementation for this wrong).

I will say that I've implemented exactly what you're describing using this method, and it worked perfectly for me, so I'd recommend sticking with this approach.


WOW, it worked! Switching the order worked! [smile]

Thanks a bunch, man! You're an amazing help to pretty much all of my mathematical problems, I really appreciate it! [smile]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!