Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Problems in collision detection

This topic is 5742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have vertex data stored in array I have BSP,who store vertex by their indexes I have to test 2 surfaces for intersection.. test it for interseption by their shperes.. test by bounding box find point of minimum distance find points in BSP by direction of other`s object point of minmim distance... or points finded propertly... find center of both array of points and their bounding boxes.. test.. so now i can say that this 2 object intersept... now i need to find triangles,where this 2 object intersept.. my algorithm cant do it propertly. algorithm is so... for x:=0 to D1.Info.PointsNum do begin //set Active triangle ActiveTri.v1:=VertexData.VertexInfo[VerAr1[x*3]]; ActiveTri.v2:=VertexData.VertexInfo[VerAr1[x*3+1]]; ActiveTri.v3:=VertexData.VertexInfo[VerAr1[x*3+2]]; //set virtual poly Line1.x:=ActiveTri.v2.x-ActiveTri.v1.x;Line1.y:=ActiveTri.v2.y-ActiveTri.v1.y;Line1.z:=ActiveTri.v2.z-ActiveTri.v1.z; Line2.x:=ActiveTri.v3.x-ActiveTri.v1.x;Line2.y:=ActiveTri.v3.y-ActiveTri.v1.y;Line2.z:=ActiveTri.v3.z-ActiveTri.v1.z; Norm:=CrossProduct(Line1,Line2); vrtTri.A:=Norm.x; vrtTri.B:=Norm.y; vrtTri.C:=Norm.z; vrtTri.D:=ActiveTri.v1.x*Norm.x+ActiveTri.v1.x*Norm.y+ActiveTri.v1.z*Norm.z; RB:=0; for y:=0 to D2.Info.PointsNum do begin if IsTriangleOn(Targ.VertexData.VertexInfo[VerAr2[y*3]],Targ.VertexData.VertexInfo[VerAr2[y*3+1]],Targ.VertexData.VertexInfo[VerAr2[y*3+2]])then begin Inc(RB); if RB>1 then begin Result:=True; Collision.Exists:=True; c3:=Normalize(c3); Collision.Point:=LastCheckPoint; Collision.SourseNormal:=Norm; Collision.DestNormal:=CrossProduct(SubPoint(Targ.VertexData.VertexInfo[VerAr2[y*3]],Targ.VertexData.VertexInfo[VerAr2[y*3+1]]), SubPoint(Targ.VertexData.VertexInfo[VerAr2[y*3]],Targ.VertexData.VertexInfo[VerAr2[y*3+2]])); end; //ConsoleMessage(''objecct pass all''); end; it returns TRUE only in 15% times... isTrinangleOn is... function TVertexInterseptor.IsTriangleOn(v1,v2,v3:TSingle3D):Boolean; begin if IsLineOn(v1,v2) then Result:=True else if IsLineOn(v1,v3) then Result:=True else if IsLineOn(v2,v3) then Result:=True else Result:=False; end; function TVertexInterseptor.IsLineOn(d,s:TSingle3D):Boolean; var VLine:record x0,y0,z0,m,n,p:Single;end; tParam:Single; Point:TSingle3D; begin //create virtual line VLine.x0:=d.x; VLine.y0:=d.y; VLine.z0:=d.z; VLine.m:=s.x-d.x; VLine.n:=s.y-d.y; VLine.p:=s.z-d.z; Result:=False; if (vrtTri.A*VLine.m+vrtTri.B*VLine.n+vrtTri.C*VLine.p)<>0 then tParam:=(vrtTri.A*VLine.x0+vrtTri.B*VLine.y0+vrtTri.C*VLine.z0-vrtTri.D)/ (vrtTri.A*VLine.m+vrtTri.B*VLine.n+vrtTri.C*VLine.p) else exit; with vLine do Point:=MakePoint3D(x0+m*tParam,y0+n*tParam,z0+p*tParam); LastCheckPoint:=Point; Result:=IsPointOn(Point); end; function TVertexInterseptor.IsPointOn(p:TSingle3D):Boolean; var //squares NormalS,N1,N2,N3,TrueS:Single; v0:TSingle3D; triDelta:single; function GetTriSQR:Single; var v1,v2:TSingle3D; begin v1:=ActiveTri.v1; v2:=ActiveTri.v2; Result:=Points.VectorLength(Points.CrossProduct(v1,v2)); end; begin NormalS:=GetTriSQR; TrueS:=0; //_!_ use surface class to init new surface // with geomentric centre at (x,y,z) // and found square of it //get square for 1 v0:=ActiveTri.v1; ActiveTri.v1:=p; TrueS:=TrueS+GetTriSQR; ActiveTri.v1:=v0; //get square for 2 v0:=ActiveTri.v2; ActiveTri.v2:=p; TrueS:=TrueS+GetTriSQR; ActiveTri.v2:=v0; //get square for 3 v0:=ActiveTri.v3; ActiveTri.v3:=p; TrueS:=TrueS+GetTriSQR; ActiveTri.v3:=v0; if TrueS/NormalS<1.1{110%} then Result:=True else Result:=False; end; what i did wrong.. or have anyone same code to compare... Cheers Kashey

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!