Page 1 of 1
[XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 6:41 pm
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
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 6:48 pm
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.
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 6:55 pm
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?
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 7:08 pm
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.
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 7:24 pm
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? :/
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 7:37 pm
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.
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 8:19 pm
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........

Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 8:53 pm
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?
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 9:17 pm
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.
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 9:22 pm
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

Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 9:30 pm
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.
Re: [XNA] Custom Rendering: Rotation missing?
Posted: Wed Apr 10, 2013 9:56 pm
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

)