Hello,
I am new to the forum and new to 3D programming as well. Trying to get good understanding of JPCT. What is wrong with the below code.
float distance = world.calcMinDistance(cam.getPosition(), obj.getTransformedCenter(), 10000 );
The obj is a cube and visible on screen.
Cam position = (0.0,0.0,-170.0)
ob center = (-3.973643E-8,0.0,0.0)
Thanks.
The returned value is the COLLISION_NONE-constant. For this to work, the object has to have a proper collision mode set.
obj.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
Then, obj.getTransformedCenter() isn't a direction vector. The actual direction vector is the (normalized) vector from the camera's position to the center, like:
SimpleVector dir=new SimpleVector(obj.getTransformedCenter());
dir.sub(cam.getPosition());
dir=dir.normalize();
Thanks for the quick reply it works. Didn't know subtracting the two vectors gives the direction. Where can I learn such things? any recommendation?
Thanks.
It's basic vector math. Usually, you think about these positions as points in space in this context, but you can also see them as a vector from the origin to that point. Just draw this scene in 2D in paper and you'll see, why the difference vector is the vector from the camera's position to the center of the object. If you normalize it, you have your needed direction vector.
Thank you. :)