Author Topic: Own collision  (Read 8082 times)

Offline LiuFeng

  • byte
  • *
  • Posts: 20
    • View Profile
Own collision
« on: September 17, 2007, 08:17:35 am »
i want to write a my own class to check collision betwen camera and big model,

what best algorithm ??
thank for help!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Own collision
« Reply #1 on: September 17, 2007, 04:28:04 pm »
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!

Offline LiuFeng

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Own collision
« Reply #2 on: September 22, 2007, 04:27:27 pm »
This is maths, i don't know

Can you give some code demo?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Own collision
« Reply #3 on: September 23, 2007, 10:36:18 am »
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.

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Own collision
« Reply #4 on: September 23, 2007, 04:35:24 pm »
Am I missing something or won't World.calcMinDistance() do the job? That's what I used in Bloodridge...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Own collision
« Reply #5 on: September 23, 2007, 05:40:15 pm »
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.

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Own collision
« Reply #6 on: September 24, 2007, 01:51:45 am »
Nor have I - LiuFeng, what do you want to achieve?

Offline LiuFeng

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Own collision
« Reply #7 on: September 24, 2007, 11:56:15 am »
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?

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Own collision
« Reply #8 on: September 24, 2007, 04:08:54 pm »
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'...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Own collision
« Reply #9 on: September 24, 2007, 05:36:17 pm »
Plus you can use an octree of the mesh is quite large to optimize performance.

Offline LiuFeng

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Own collision
« Reply #10 on: September 25, 2007, 02:38:29 pm »
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

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Own collision
« Reply #11 on: September 25, 2007, 07:30:06 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Own collision
« Reply #12 on: September 25, 2007, 11:11:48 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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Own collision
« Reply #13 on: September 26, 2007, 08:40:56 pm »


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