![](smile.gif)
intersection problems
Hi
Hope someone can help with this,
I''m tryng to implement this collision detection algorithm,
http://www.acm.org/jgt/papers/MollerTrumbore97/code.html
It''s the algorithm described in realtimerendering,
well, my problem is, that he is not working
I''m doing the following :
When i press the forward key:
if (keys[VK_UP])
{
// camera position before moving
camera_before[0] = look.x;
camera_before[1] = look.y;
camera_before[2] = look.z;
// Now i move the camera
MoveCamera(heading+180);
// position of the camera after moving
camera_after[0] = look.x;
camera_after[1] = look.y;
camera_after[2] = look.z;
dir[0] = camera_after[0] - camera_before[0];
dir[1] = camera_after[1] - camera_before[1];
dir[2] = camera_after[2] - camera_before[2];
col = Check_Collision(camera_p,dir);
if(col==1)
{
look.x = camera_before[0];
look.y = camera_before[1];
look.z = camera_before[2];
}
My check_collision, is as follows for each triangle,
vtx[0] = Vertex_Array[next_face->start].Vertex.x;
vtx[1] = Vertex_Array[next_face->start].Vertex.y;
vtx[2] = Vertex_Array[next_face->start].Vertex.z;
vtx1[0] = Vertex_Array[next_face->start+1].Vertex.x;
vtx1[1] = Vertex_Array[next_face->start+1].Vertex.y;
vtx1[2] = Vertex_Array[next_face->start+1].Vertex.z;
vtx2[0] = Vertex_Array[next_face->start+2].Vertex.x;
vtx2[1] = Vertex_Array[next_face->start+2].Vertex.y;
vtx2[2] = Vertex_Array[next_face->start+2].Vertex.z;
collide = intersect_triangle(camera_before,dir,vtx,vtx1,vtx2,0,0,0);
Do you guys see anything wrong in here ?
thanks,
Bruno
![](smile.gif)
I have made some comments to this, see below
coords, passed as pointers to float. You have passed null pointers, you will likely crash.
I think that the big problem is that intersect_triangle does not do what you think it does. Given a point and a direction it finds if the _RAY_ (ie. from origin, to infinity) intersects an arbitrary triangle, and if it does, the distance from the origin to that triangle and the "2D" or basically texture coords within that triangle.
You need something like
bool collide(float orig[3],float dir[3],virtex_array va) {
float t,u,v;
// Get v0,v1,v2 for each triangle
if(intersect_triangle(orig,dir,v0,v1,v2,&t,&u,&v) {
if(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2] > t*t)
return true;
}
This is slow, you want to start looking for ways to cluster triangles into bounding boxes or bsp trees.
Edited by - Grib on March 11, 2001 4:07:53 PM
quote:how does MoveCamera change look?
Original post by Bruno
Hi
Hope someone can help with this,
I'm tryng to implement this collision detection algorithm,
http://www.acm.org/jgt/papers/MollerTrumbore97/code.html
It's the algorithm described in realtimerendering,
well, my problem is, that he is not working![]()
I'm doing the following :
When i press the forward key:
if (keys[VK_UP])
{
// camera position before moving
camera_before[0] = look.x;
camera_before[1] = look.y;
camera_before[2] = look.z;
// Now i move the camera
MoveCamera(heading+180);
quote:in the original paper t,u,v are the distance and intersection
// position of the camera after moving
camera_after[0] = look.x;
camera_after[1] = look.y;
camera_after[2] = look.z;
dir[0] = camera_after[0] - camera_before[0];
dir[1] = camera_after[1] - camera_before[1];
dir[2] = camera_after[2] - camera_before[2];
col = Check_Collision(camera_p,dir);
if(col==1)
{
look.x = camera_before[0];
look.y = camera_before[1];
look.z = camera_before[2];
}
My check_collision, is as follows for each triangle,
vtx[0] = Vertex_Array[next_face->start].Vertex.x;
vtx[1] = Vertex_Array[next_face->start].Vertex.y;
vtx[2] = Vertex_Array[next_face->start].Vertex.z;
vtx1[0] = Vertex_Array[next_face->start+1].Vertex.x;
vtx1[1] = Vertex_Array[next_face->start+1].Vertex.y;
vtx1[2] = Vertex_Array[next_face->start+1].Vertex.z;
vtx2[0] = Vertex_Array[next_face->start+2].Vertex.x;
vtx2[1] = Vertex_Array[next_face->start+2].Vertex.y;
vtx2[2] = Vertex_Array[next_face->start+2].Vertex.z;
collide = intersect_triangle(camera_before,dir,vtx,vtx1,vtx2,0,0,0);
coords, passed as pointers to float. You have passed null pointers, you will likely crash.
quote:
Do you guys see anything wrong in here ?
thanks,
Bruno
I think that the big problem is that intersect_triangle does not do what you think it does. Given a point and a direction it finds if the _RAY_ (ie. from origin, to infinity) intersects an arbitrary triangle, and if it does, the distance from the origin to that triangle and the "2D" or basically texture coords within that triangle.
You need something like
bool collide(float orig[3],float dir[3],virtex_array va) {
float t,u,v;
// Get v0,v1,v2 for each triangle
if(intersect_triangle(orig,dir,v0,v1,v2,&t,&u,&v) {
if(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2] > t*t)
return true;
}
This is slow, you want to start looking for ways to cluster triangles into bounding boxes or bsp trees.
Edited by - Grib on March 11, 2001 4:07:53 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement