Rolling a compound body in direction of the camera forward?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Rolling a compound body in direction of the camera forward?

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling a compound body in direction of the camera forwa

Post 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.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Rolling a compound body in direction of the camera forwa

Post 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?!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling a compound body in direction of the camera forwa

Post 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.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Rolling a compound body in direction of the camera forwa

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling a compound body in direction of the camera forwa

Post 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
expected.jpg (3.22 KiB) Viewed 6536 times
If so, this is expected behavior.

If it looks different, perhaps like this:
unexpected.jpg
unexpected.jpg (3.43 KiB) Viewed 6536 times
then something is wrong.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Rolling a compound body in direction of the camera forwa

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling a compound body in direction of the camera forwa

Post 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.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Rolling a compound body in direction of the camera forwa

Post by Spankenstein »

I'll do that then. Thanks.
Post Reply