i want to write a my own class to check collision betwen camera and big model,
what best algorithm ??
thank for help!
There is no best algorithm for this. If it were, you wouldn't have to think about implementing your own solution. What jPCT does is based on this one: http://www.peroxide.dk/papers/collision/collision.pdf (http://www.peroxide.dk/papers/collision/collision.pdf)
Maybe that helps as a starting point. Have fun!
This is maths, i don't know
Can you give some code demo?
The pdf contains a code example at the end. If you don't understand the math involved, then you won't be able to write your own collision system of that complexity, i'm afraid.
Am I missing something or won't World.calcMinDistance() do the job? That's what I used in Bloodridge...
This highly depends on what you want to do. calcMinDistance() is fine making an entity following a terrain like in bloodridge. I have no idea what LuiFeng wants to achieve.
Nor have I - LiuFeng, what do you want to achieve?
my really problem that : i wondder how to check collision while the world has very much of vertices
First, i think use for loop , and check distance each vertex with camera
But collision detected very slow
Can you help me to explain?
Import or create your model as an Object3D.
Set the Object3D's collision mode to COLLISION_CHECK_OTHERS.
Now when you want to move the camera in direction 'dir' by 'dist' units, first use;
yourWorld.calcMinDistance(cameraPos, dir, dist)
if this returns Object3D.COLLISION_NONE there'd be no collision, otherwise the camera would hit the model 'dist' units along vector 'dir'...
Plus you can use an octree of the mesh is quite large to optimize performance.
I known, but i want to understand the algorithm to check collision while model has much of vertices
, and i think can not use for loop to check each vertex
I guess that an ellipsoid, an sphere or a bounding box can be surrounding your object. and you just check the camera position with the respective math equation. I will try to post some images later about what I am talking about.
Quote from: LiuFeng on September 25, 2007, 02:38:29 PM
, and i think can not use for loop to check each vertex
You can apply some optimizations to this process. The distance between two points in space can never be smaller than the distance along the x,y or z axis. So if the distance exceeds some value for one of those directions, you can discard the vertex without doing any further calculations. If this (and similar optimizations) are not enough, you can use an octree or a quadtree. Google for it for more info. jPCT uses an octree for distance calculations if one has been created.
And keep in mind that checking against the vertices usually isn't enough, because you may collide with the triangle itself but with no vertex of it.
(http://www.soft-ec.com/Archivos/imagenes/jpct/jpct_colli.JPG)
For example now you have surrounded the object with this rentangle prism, sphere or whatever. you can chek if the camera position is inside it. The cheking can be easily done by using the respective equations, or if its a rectangula prism you can just do the checking by using simple IF sentence(s).