Axis problem

Started by manumoi, June 01, 2005, 12:27:05 AM

Previous topic - Next topic

manumoi

Hello, I loaded an MD2 model using a code mentionned in this forum... I created an environment, following the "car" model.  Movements of my model in the environment are ok, camera is ok but the problem is that my model is oriented in a wrong direction, i.e.  my camera is on the Z axis and I see a side of my model. When I tell to my model to move forward or backward, it follow the Z axis (it s ok) but since my model is in the wrong direction, it is moving side step. I tried to use rotateY on my model but it doesn't reinit the axis... My question is: how can i rotate my model (90degrees) without modifying its axis, in order that it looks in the direction of the ZAxis. Hope my question is clear... Thanks you :)

Manu

rolz

Hey Manu,

try this

model.rotateZ(z);
model.rotateMesh();
Regards,
Andrei

EgonOlsen

But don't forget to reset the rotation matrix afterwards (setRotationMatrix(new Matrix()); However, you'll have to download the 1.06 preview release (look at the news section for it) to get this working. Versions prior to 1.06 don't affect the animation when calling rotateMesh();

manumoi

It must be something simple but it still doesn't work. Here is my code :

// used to init a model
public void loadModel(){
   model=Loader.loadMD2(PATH+SEP+"models"+SEP+"scarlet"+SEP+"tris.md2", 0.5f);
   model.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
   TextureManager.getInstance().addTexture("alita2", new Texture(PATH+SEP+"models"+SEP+"scarlet"+SEP+"scarlet_dress_red.jpg"));
   model.setTexture("alita2");
   model.rotateY(5f); // not the correct angle... just to see if it works
   model.rotateMesh();
   model.build();
   model.setRotationMatrix(new Matrix());
   placeModel(model);
   theWorld.addObject(model);
   }


// used to place the model in the world (at initialization and in the game loop)
public void placeModel(Object3D model){
   SimpleVector dropDown = new SimpleVector(0,1,0);   
   Matrix rotMat = model.getRotationMatrix();
   rotMat.setIdentity();
   float distanceToGround = terrain.calcMinDistance(model.getTransformedCenter(), dropDown, 4*30);
    model.translate(0,-20,0);
   if (distanceToGround!= Object3D.COLLISION_NONE)
       distanceToGround -=10;
   dropDown.scalarMul(distanceToGround-4);
   model.translate(dropDown);
   model.rotateY(yRot);
   }



and here is a picture of the interface



My camera is well placed and follow the model when it is moving. I would like to rotate my model in order that I see its back (so I need to rotate it around the Y axis) and without interfering with axis.

I tested it with different md2 models... and all of them are looking on the right..

Do you see where my mistake is?

Thanks you

Manu

EgonOlsen

Quote from: "manumoi"
Do you see where my mistake is?
Looks quite ok to me...but...there is a rotateY(...) in placeModel(). Maybe that causes the wrong orientation? If that's not the problem: Are you sure that you are using 1.06pr and not 1.05 of jPCT? The code won't work correct with 1.05.

manumoi

I didn t see that the link in the download section wasn t the one for 1.06. With version 1.06, it rocks. Thanks you very much.

Just another small question.
Currently, my world is loaded with a 3DS file.... and it works. But when I try to replace it by a Primitives.getPlane() call (in order to have a flat world), nothing appear. I think something is missing. What do I need?

Here is my code :

public void loadingTerrain(){
   Object3D[] objs = Loader.load3DS(PATH+SEP+"models"+SEP+"terascene.3ds", 400);
   if (objs.length >0){
       terrain = objs[0];
       terrain.setTexture("rocks");
   }

   // Replacing all the precedent line with the commented line below
//   terrain = Primitives.getPlane(200f);
        //terrain.setTexture("rocks");

   terrain.enableLazyTransformations();
   theWorld.addObject(terrain);
   }


Do I need to use setOrigin or something like that?


Again, thanks for all.

Manu

EgonOlsen

The plane will appear at (0,0,0). Maybe your camera is at (0,0,0) too, so that you can't see it. Try to move back the camera or translate the plane into the screen and see if you can see it. You may also need to rotate it (-)90 degrees around X. Depends on how the terascene is actually build...i can't remember that exactly.