Author Topic: Camera position object3D position mismatching  (Read 3928 times)

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Camera position object3D position mismatching
« on: June 14, 2004, 05:51:01 pm »
Hi Egon,

I’ve to implement the following capability: I need to place some objects in the world using custom coordinate. So, for decide where place objects I’ve to move myself in the world (by the camera) and, where I decide to place an object, pressing the right click, my applet has to pass the camera’s coordinate to a html page. I’ve created this feature in this way:

Code: [Select]

if (event.getButton()==MouseEvent.BUTTON3) {
    cameraPosition=camera.getPosition();
    cameraX=(int)cameraPosition.x;
    cameraY=(int)cameraPosition.y;
    cameraZ=(int)cameraPosition.z;
                 clicked=true;
                 rightClick=true;
}


then I’ve created a function that creates and places the object using the camera’s coordinates:

Code: [Select]

public void loadFerito(String name, float x, float y, float z){
     
      texMan=TextureManager.getInstance();
      texMan.addTexture(name+".jpg",new  Texture(getDocumentBase(),"textures/feriti/"+name+".jpg"));
      Object3D[] ferito1Array=Loader.load3DS(getDocumentBase(),"3ds/"+name+".3ds", 20f);
      ferito1=new Object3D(0);
      ferito1=ferito1Array[0];
      ferito1.setCenter(SimpleVector.ORIGIN);
      ferito1.translate (x, y+109, z);
      ferito1.rotateX((float)-Math.PI/2);
      ferito1.rotateMesh();
      ferito1.setRotationMatrix(new Matrix());
     
      ferito1.createTriangleStrips(2);
      ferito1.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
      ferito1.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
     
      ferito1.enableLazyTransformations();
     

  }


My problem is that the object in placed in a different position compared to the camera position where I’ve taken the camera’s coordinates. I guess the resulting camera’s coordinates don’t match the object coordinates method. Exist a way to make a matching?

Bye and thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Camera position object3D position mismatching
« Reply #1 on: June 14, 2004, 06:20:04 pm »
There are some places in your code where things can go wrong. The first thing is: Are you actually calling build() on your loaded object somewhere? Are you adding it to the world? (Obviously you do, because you couldn't even see it otherwise..it's just that i can't spot that place in your code). Anyway, you are rotating the mesh. If you do this without calling build() before, your rotation pivot could be wrong. It will be placed at the origin, which may be correct but it doesn't have to. It depends on your model, so try to call build() before doing this or check if a rotation pivot at the origin is really what you want.
If it still doesn't work, try to figure out in which way your cam's position and the one of the object differ. Maybe that will help to see what's wrong here.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Camera position object3D position mismatching
« Reply #2 on: June 16, 2004, 09:53:46 am »
It’s a problem related to the position of the obj in Maya’s world coordinates: placing the obj in the center on the Maya’s coordinates (0,0,0), it behaves correctly in jPCT’s world.

Bye and thanks again.
 :D