Author Topic: Axis problem  (Read 3740 times)

manumoi

  • Guest
Axis problem
« on: June 01, 2005, 12:27:05 am »
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

Offline rolz

  • float
  • ****
  • Posts: 280
  • Technocrat
    • View Profile
Axis problem
« Reply #1 on: June 01, 2005, 08:37:29 am »
Hey Manu,

try this
Code: [Select]

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11965
    • View Profile
    • http://www.jpct.net
Axis problem
« Reply #2 on: June 01, 2005, 08:51:48 am »
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();

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
still not working
« Reply #3 on: June 01, 2005, 11:08:31 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11965
    • View Profile
    • http://www.jpct.net
Re: still not working
« Reply #4 on: June 01, 2005, 11:51:48 pm »
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.

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
OK
« Reply #5 on: June 02, 2005, 01:19:18 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11965
    • View Profile
    • http://www.jpct.net
Axis problem
« Reply #6 on: June 03, 2005, 12:30:25 am »
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.