Page 1 of 1
Rolling a compound body in direction of the camera forward?
Posted: Sun Jul 24, 2011 11:02 pm
by Spankenstein
I would like to roll a compound body relative to the camera.
If I do the following:
Code: Select all
compoundBody.AngularVelocity += activeCamera.Forward * speed * dt_Seconds;
then the body rolls in the wrong direction and not in the direction of the camera's forward vector.
Transforming the vector by the compound body's orientation doesn't work either:
Code: Select all
Vector3 forward = Vector3.Transform(activeCamera.Forward, concaveSphere.CompoundBody.Orientation);
What have I done wrong?
Re: Rolling a compound body in direction of the camera forwa
Posted: Sun Jul 24, 2011 11:24 pm
by Norbo
It could be that the matrix you are getting the Forward vector from is the inverse from the matrix you are intending to use (view vs. world).
Angular velocity causes an object to rotate around the given axis with speed equal to the length of the axis, so as long as the right axis is chosen, it should work fine.
Re: Rolling a compound body in direction of the camera forwa
Posted: Sun Jul 24, 2011 11:40 pm
by Spankenstein
If I invert the camera's view matrix then it makes no difference:
Code: Select all
Matrix invView = Matrix.Invert(activeCamera.ViewMatrix);
concaveSphere.CompoundBody.AngularVelocity += invView.Forward * speed * dt_Seconds;
The direction of the roll is the same for both inverted and non inverted?!
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 12:04 am
by Norbo
I would recommend looking at the actual axis that it's using. Are they the same in both the inverted and non-inverted case? If so, is it erroneously using the identity matrix? Are the speed/dt values computed properly and non-zero?
I also note that the angular velocity property is an incremental add. It may be helpful to strip it down to a pure set for debugging purposes so that the previous state can't interfere with expectations.
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 12:26 am
by Spankenstein
I would recommend looking at the actual axis that it's using.
The camera forward vector is correct as I can draw a ray using the same vector and it points in the same direction with its origin at the camera position. The forward vector is the axis I am using but the resultant compound body motion is in the direction of what looks like a cross product result, i.e. at 90 degrees to the forward axis.
Are they the same in both the inverted and non-inverted case?
Only if I don't move the camera as it looks down the z axis (identity matrix, as you said).
Are the speed/dt values computed properly and non-zero?
Yes. I can use the same values for moving non physics engine objects around in the correct direction.
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 12:34 am
by Norbo
Angular velocity is a very simple and fundamental part of the system, so there exists some external issue.
To verify: if you set (as opposed to add to) the angular velocity to the camera forward vector, does the object appear to rotate like this?

- expected.jpg (3.22 KiB) Viewed 6534 times
If so, this is expected behavior.
If it looks different, perhaps like this:

- unexpected.jpg (3.43 KiB) Viewed 6534 times
then something is wrong.
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 12:48 am
by Spankenstein
I'm getting the expected result.
In which case, how do I get the object to roll "forwards" based on the camera's forward vector? In other words in the direction the camera is facing?
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 12:51 am
by Norbo
The easiest thing to do would be to use the Right/Left or Up/Down vectors of the matrix, depending on what result you want.
Re: Rolling a compound body in direction of the camera forwa
Posted: Mon Jul 25, 2011 1:00 am
by Spankenstein
I'll do that then. Thanks.