www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: javamak on November 24, 2015, 12:35:31 pm

Title: calcMinDistance returns 1.0E12
Post by: javamak on November 24, 2015, 12:35:31 pm
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.

Code: [Select]
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.
Title: Re: calcMinDistance returns 1.0E12
Post by: EgonOlsen on November 24, 2015, 01:12:07 pm
The returned value is the COLLISION_NONE-constant. For this to work, the object has to have a proper collision mode set.

Code: [Select]
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:

Code: [Select]
SimpleVector dir=new SimpleVector(obj.getTransformedCenter());
dir.sub(cam.getPosition());
dir=dir.normalize();
Title: Re: calcMinDistance returns 1.0E12
Post by: javamak on November 24, 2015, 03:34:00 pm
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.
Title: Re: calcMinDistance returns 1.0E12
Post by: EgonOlsen on November 24, 2015, 05:30:10 pm
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.
Title: Re: calcMinDistance returns 1.0E12
Post by: javamak on November 25, 2015, 05:39:10 am
Thank you.  :)