[XNA] Custom Rendering: Rotation missing?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

[XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Hi Guys,
I'm currently integrating BEPU within my project.

After browsing the Board, checking out the Demos and GettingStartet stuff - I still can not figure out why my (custom drawn) Model has got no rotation at all?

In my current test, I'm using a MobileMesh's WorldTransform for the rendering - like this:

Code: Select all

myWorld = this.BoneTransforms[mesh.ParentBone.Index] * this.Entity.WorldTransform;
Where this.Entity clearly is the MobileMesh ^^.

I tried to apply some angular forces but it does not rotate at all.

Any Ideas?

Thanks,
Slap
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by Norbo »

Is the LocalInertiaTensorInverse set to all zeroes anywhere? That would prevent all rotation. If it's a kinematic entity and it's being pushed by forces, it will also not move; kinematic entities have essentially infinite mass.

If that's not the case, then I would recommend checking whether or not the mobile mesh is actually getting rotated. You can test this by looking at its AngularVelocity and Orientation fields. If those are changing, then it's a purely graphical issue; some transform somewhere getting mixed up. If they aren't changing, then there's something stopping the entity from rotating.
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Thanks Norbo,

I added the AngularVelocity to my debug output and I think it's "operating" (value's changing and stuff)

So this must be a matrix multiplication failure or something?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by Norbo »

If the physical object is actually rotating, then it is indeed likely a goof with the graphical transforms somewhere. The matrix multiplication implementation itself is almost certainly not at fault, but some other shenanigans may be afoot.
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

I'm applying Angular and Linear Forces like this:

Code: Select all

            Vector3 angularImpulse = new Vector3(10, 0, 0);
            Vector3 linearImpulse = new Vector3(200, 0, 0);

            // Note: Model is my own Class which (in this case) contains an MobileMesh which is stored like this: "public Entity Entity"
            myModel.Entity.ApplyLinearImpulse(ref linearImpulse);
            myModel.Entity.ApplyAngularImpulse(ref angularImpulse);
I'm outputting the AngularVelocity (ToStringed) and it's value starts at about 3,22; -2,52; 9,26 and keeps changing - after a few seconds it's 1,58; -1,23; 4,54

If the Entity is not null I calculate the Matrix as follows:

Code: Select all

            if (this.Body != null)
                        myWorld =
                            boneTransforms[mesh.ParentBone.Index] * this.Entity.WorldTransform;
I stripped everything down so nothing else happens to the matrix before it finally gets set to my shader?

Any idea? :/
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by Norbo »

All I can recommend is analyzing the values and checking them against your expectations. Dig in with the debugger, step through things line by line, see if anything gets wonky.
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Okay now.

I stepped through and compared the matrix at the calculation with the matrix that actually get's set to the shader - they're equal :/ ..

I even tried to replace the usage of the entitie's WorldTransform with this:

Code: Select all

              Rotation =
                            Matrix.CreateRotationX(this.Body.AngularVelocity.X) *
                            Matrix.CreateRotationY(this.Body.AngularVelocity.Y) *
                            Matrix.CreateRotationZ(this.Body.AngularVelocity.Z);
And strapped out the translation - But nothing happend.

This is very very weired........ :(
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Turns out ApplyAngularImpulse doesnt work while setting the AngularVelocity to eg. new Vector3(2, 0, 0) actually rotates it?

But is that the correct usage?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by Norbo »

If changing AngularVelocity makes the entity rotate while using ApplyAngularImpulse does not, the entity in question is likely kinematic (created without a mass specified and thus given infinite inertia) or was explicitly set to infinite inertia. That would be expected behavior.
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Well that would be weired..

My initialisation of the mobilemesh is as follows:

Code: Select all

= new MobileMesh(
                this.RawVertices,
                this.RawIndices,
                new Physics.MathExtensions.AffineTransform(Vector3.Zero),
                Physics.CollisionShapes.MobileMeshSolidity.DoubleSided,
                1f
                );
So the mass must be one.

Also - would it be affected by gravity if it's Kinetic / has Infinite Mass? Because it is affected by gravity.

Thanks for your patience so far ;)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by Norbo »

It would not be affected by gravity if it was kinematic (and indeed unless you later set it to kinematic, it is not kinematic). If the inertia tensor inverse was set to zero, however, it would still be affected by gravity; the inertia tensor only affects angular movement.
SlapY
Posts: 7
Joined: Tue Oct 23, 2012 10:39 am

Re: [XNA] Custom Rendering: Rotation missing?

Post by SlapY »

Due to the fact that I actually did not knew what Kinematic and InertiaTensorInverse was - I'm pretty sure I did not set/change one of them.

(Also - I checked it ;) )
Post Reply