Cannot set orientation of TriangleMeshObject

Feb 3, 2009 at 8:19 PM
When I create a TriangleMeshObject I cannot seem to change its orientation. I can give it a new position using ApplyLocalTransform() but when give an orientation (other than the identity matrix) it does not work. It seems like the collisionSkin still has the identity orientation. Am I doing something wrong or is this a bug. In case of the latter: Can I do anything about it?

Best regards,
Per Rasmussen.
Feb 3, 2009 at 8:41 PM
The way I do this is to set the model's orientation before passing it to the TriangleMeshObject. I have a class that stores my model name (path), position, scale, rotation, etc... Once I have my class built, I simply pass it to the TriangleMeshObject with
TriangleMeshObject myObject = new TriangleMeshObject(this, myModel.Model, myModel.Direction, myModel.Position);

However, I've also been able to change the orientation after it has been added to the Components. To do this, I build my object just like I did above, then I add:
this.Components.Add(myObject);

Then I turn it like so...
myObject.PhysicsBody.Orientation = Matrix.CreateRotationY(80);

You can rotate it on any of the axis or all at the same time, just depends on how you want it turned.

Hope this helps.
Feb 3, 2009 at 8:59 PM
"The way I do this is to set the model's orientation before passing it to the TriangleMeshObject. I have a class that stores my model name (path), position, scale, rotation, etc... Once I have my class built, I simply pass it to the TriangleMeshObject with
TriangleMeshObject myObject = new TriangleMeshObject(this, myModel.Model, myModel.Direction, myModel.Position);"

Hmm, that is highly strange since the last two parameters for the TriangleMeshObject constructor aren't even used! The constructor has the following code:

        public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position)
            : base(game, model)
        {
            body = new Body();
            collision = new CollisionSkin(null);

            triangleMesh = new TriangleMesh();

            List<Vector3> vertexList = new List<Vector3>();
            List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>();

            ExtractData(vertexList, indexList, model);

            triangleMesh.CreateMesh(vertexList,indexList, 4, 1.0f);
            collision.AddPrimitive(triangleMesh,1,new MaterialProperties(0.8f,0.7f,0.6f));
            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);
        }

That makes no sense.


"However, I've also been able to change the orientation after it has been added to the Components. To do this, I build my object just like I did above, then I add:
this.Components.Add(myObject);
Then I turn it like so...
myObject.PhysicsBody.Orientation = Matrix.CreateRotationY(80);"

So what you're saying is that you move the body to which the collisionskin is attached? I have tried that but the collisionskin seemed to stay in the same place. :(

Feb 3, 2009 at 10:25 PM
Sorry. That was suppose to just push you in the right direction. Those are 2 different methods that I've used.

Here is how I added in the code to use the last 2 parameters being passed in. In my TriangleMeshObject, I attach the skin to the body and move it there. So, my TriangleMeshObject looks like this:

public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position)
            : base(game, model)
        {
            body = new Body();
            collision = new CollisionSkin(null);

            TriangleMesh triangleMesh = new TriangleMesh();

            List<Vector3> vertexList = new List<Vector3>();
            List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>();

            ExtractData(vertexList, indexList, model);

            triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);
            collision.AddPrimitive(triangleMesh, 1, new MaterialProperties(0.8f, 0.7f, 0.6f));

            body.CollisionSkin = collision;

            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);

            body.MoveTo(position, orientation);
        }
Feb 9, 2009 at 8:24 PM
Hmm, I've tried that too and the body's orientation does change but it seems that the collision model stays the same.
Feb 10, 2009 at 1:08 AM
Well hell. I dunno then. In my last post, you can actually get rid of the line:

PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);

and add:

body.Enable();

That's how I got all of my stuff working properly. I also had to do it that way because after about a minute, my game starting crawling. It was due to the fact that the non-moving objects were touching, and were still always checking collisions. In the mean time, I'll dig thru some of my other stuff and see if I can find anymore ideas that might be helpful for you.


Feb 10, 2009 at 7:20 AM
By body.Enable(); I assume you mean body.EnableBody();

I tried that and now the mesh actually starts to fall. Apparently it is not static anymore. And my intention was to have it static. Actually, since it is a TriangleMeshObject I do not believe I really have a choice.

If you have some working code laying around I would really appreciate it.