Own collision

Started by LiuFeng, September 17, 2007, 08:17:35 AM

Previous topic - Next topic

LiuFeng

i want to write a my own class to check collision betwen camera and big model,

what best algorithm ??
thank for help!

EgonOlsen

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
Maybe that helps as a starting point. Have fun!

LiuFeng

This is maths, i don't know

Can you give some code demo?

EgonOlsen

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.

Hrolf

Am I missing something or won't World.calcMinDistance() do the job? That's what I used in Bloodridge...

EgonOlsen

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.

Hrolf

Nor have I - LiuFeng, what do you want to achieve?

LiuFeng

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?

Hrolf

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'...

EgonOlsen

Plus you can use an octree of the mesh is quite large to optimize performance.

LiuFeng

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

Melssj5

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.
Nada por ahora

EgonOlsen

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.

Melssj5



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).
Nada por ahora