1
Support / How to implement the movement of the object to the point specified by touch
« on: September 20, 2010, 10:51:16 pm »
hi
I have a plane
addHPolygon (create 2 triangles)
and a some box on that plane
Camera
I want that "box" is moved in the plane of "box2". Move to some point, specified by touch.
I fount thread http://www.jpct.net/forum2/index.php/topic,791.0.html where, as i think, what I need.
i try use that,
on touch event:
But it does not work for me. Maybe you could help me by giving advice or an example of such a problem.
thank you.
I have a plane
Code: [Select]
for (int iz = 1; iz < 11; iz++) {
int z = iz * 12;
for (int i = 0; i < 10; i++) {
int x = i * 12;
addHPolygon(box2, x, x + 12, 0, z, z - 12, 1,
tm.getTextureID("floor2"));
}
}
box2.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
addHPolygon (create 2 triangles)
and a some box on that plane
Code: [Select]
box = Loader.load3DS(res.openRawResource(R.raw.crate), 0.095f)[0];
box.setTexture("box1");
box.translate(4, -10, 0);
box.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
Camera
Code: [Select]
Camera cam = world.getCamera();
cam.setPosition(0, -40, 0);
cam.lookAt(new SimpleVector(0, 0, 0));
I want that "box" is moved in the plane of "box2". Move to some point, specified by touch.
I fount thread http://www.jpct.net/forum2/index.php/topic,791.0.html where, as i think, what I need.
i try use that,
on touch event:
Code: [Select]
SimpleVector ray=Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)xpos, (int)ypos);
distance = world.calcMinDistance(world.getCamera().getPosition(), ray, 10000F);
if (distance!=Object3D.COLLISION_NONE) {
SimpleVector offset=new SimpleVector(ray);
ray.scalarMul(distance);
ray=ray.calcSub(offset);
world.getObjectByName("box").translate(world.getCamera().getPosition());
world.getObjectByName("box").translate(ray);
}
But it does not work for me. Maybe you could help me by giving advice or an example of such a problem.
thank you.