3DCollision: Problem in my engine(memory&maths programmi
Posted: Mon Jul 26, 2004 9:21 am
Hello,
I wanted to include my collision(viewtopic.php?t=11857) into my engine. Now I have one problem: The check says always there is a collision, but I don't know why. The MeshData is saved in a Buffer:
NormalX.f
NormalY.f
NormalZ.f
X1.f
Y1.f
Z1.f
X2.f
Y2.f
Z2.f
X3.f
Y3.f
Z3.f
NormalX.f
NormalY.f
NormalZ.f
X1.f
Y1.f
Z1.f
X2.f
...
Then I'm checking the collision so:
OBJ() Is the next element and the normal parameters are the privious element data
I wanted to include my collision(viewtopic.php?t=11857) into my engine. Now I have one problem: The check says always there is a collision, but I don't know why. The MeshData is saved in a Buffer:
NormalX.f
NormalY.f
NormalZ.f
X1.f
Y1.f
Z1.f
X2.f
Y2.f
Z2.f
X3.f
Y3.f
Z3.f
NormalX.f
NormalY.f
NormalZ.f
X1.f
Y1.f
Z1.f
X2.f
...
Then I'm checking the collision so:
Code: Select all
Procedure CheckCollision(*Buffer, Size, SizeX.f, SizeY.f, SizeZ.f, X.f, Y.f, Z.f)
While k < Size ;Check the data of the 1st object
CopyMemory(*Buffer+k, @Tri1_Normal.Point3D, 12)
k + 12
CopyMemory(*Buffer+k, @Tri1_1.Point3D, 12)
k + 12
CopyMemory(*Buffer+k, @Tri1_2.Point3D, 12)
k + 12
CopyMemory(*Buffer+k, @Tri1_3.Point3D, 12)
k + 12
Tri1_1\X = Tri1_1\X * SizeX + X
Tri1_1\Y = Tri1_1\Y * SizeY + Y
Tri1_1\Z = Tri1_1\Z * SizeZ + Z
Tri1_2\X = Tri1_2\X * SizeX + X
Tri1_2\Y = Tri1_2\Y * SizeY + Y
Tri1_2\Z = Tri1_2\Z * SizeZ + Z
Tri1_3\X = Tri1_3\X * SizeX + X
Tri1_3\Y = Tri1_3\Y * SizeY + Y
Tri1_3\Z = Tri1_3\Z * SizeZ + Z
If Isnan(Tri1_1\X)
Tri1_1\X = X
EndIf
If Isnan(Tri1_1\Y)
Tri1_1\Y = Y
EndIf
If Isnan(Tri1_1\Z)
Tri1_1\Z = Z
EndIf
If Isnan(Tri1_2\X)
Tri1_2\X = X
EndIf
If Isnan(Tri1_2\Y)
Tri1_2\Y = Y
EndIf
If Isnan(Tri1_2\Z)
Tri1_2\Z = Z
EndIf
If Isnan(Tri1_3\X)
Tri1_3\X = X
EndIf
If Isnan(Tri1_3\Y)
Tri1_3\Y = Y
EndIf
If Isnan(Tri1_3\Z)
Tri1_3\Z = Z
EndIf
j=0
While j < OBJ()\VertBufferSize ;Check the data of the 2nd object
CopyMemory(OBJ()\VertBuffer+j, @Tri2_Normal.Point3D, 12)
j + 12
CopyMemory(OBJ()\VertBuffer+j, @Tri2_1.Point3D, 12)
j + 12
CopyMemory(OBJ()\VertBuffer+j, @Tri2_2.Point3D, 12)
j + 12
CopyMemory(OBJ()\VertBuffer+j, @Tri2_3.Point3D, 12)
j + 12
Tri2_1\X = Tri2_1\X * OBJ()\SizeX + OBJ()\X
Tri2_1\Y = Tri2_1\Y * OBJ()\SizeY + OBJ()\Y
Tri2_1\Z = Tri2_1\Z * OBJ()\SizeZ + OBJ()\Z
Tri2_2\X = Tri2_2\X * OBJ()\SizeX + OBJ()\X
Tri2_2\Y = Tri2_2\Y * OBJ()\SizeY + OBJ()\Y
Tri2_2\Z = Tri2_2\Z * OBJ()\SizeZ + OBJ()\Z
Tri2_3\X = Tri2_3\X * OBJ()\SizeX + OBJ()\X
Tri2_3\Y = Tri2_3\Y * OBJ()\SizeY + OBJ()\Y
Tri2_3\Z = Tri2_3\Z * OBJ()\SizeZ + OBJ()\Z
If Isnan(Tri2_Normal\X)
Tri2_Normal\X = 1
EndIf
If Isnan(Tri2_Normal\Y)
Tri2_Normal\Y = 1
EndIf
If Isnan(Tri2_Normal\Z)
Tri2_Normal\Z = 1
EndIf
If Isnan(Tri2_1\X)
Tri2_1\X = OBJ()\X
EndIf
If Isnan(Tri2_1\Y)
Tri2_1\Y = OBJ()\Y
EndIf
If Isnan(Tri2_1\Z)
Tri2_1\Z = OBJ()\Z
EndIf
If Isnan(Tri2_2\X)
Tri2_2\X = OBJ()\X
EndIf
If Isnan(Tri2_2\Y)
Tri2_2\Y = OBJ()\Y
EndIf
If Isnan(Tri2_2\Z)
Tri2_2\Z = OBJ()\Z
EndIf
If Isnan(Tri2_3\X)
Tri2_3\X = OBJ()\X
EndIf
If Isnan(Tri2_3\Y)
Tri2_3\Y = OBJ()\Y
EndIf
If Isnan(Tri2_3\Z)
Tri2_3\Z = OBJ()\Z
EndIf
If IntersectedPolygon(@Tri1_1.Point3D, @Tri1_2.Point3D, @Tri1_3.Point3D, @Tri2_1.Point3D, @Tri2_2.Point3D, @Tri1_Normal.Point3D) Or IntersectedPolygon(@Tri1_1.Point3D, @Tri1_2.Point3D, @Tri1_3.Point3D, @Tri2_2.Point3D, @Tri2_3.Point3D, @Tri1_Normal.Point3D)
ProcedureReturn 1
ElseIf IntersectedPolygon(@Tri2_1.Point3D, @Tri2_2.Point3D, @Tri2_3.Point3D, @Tri1_1.Point3D, @Tri1_2.Point3D, @Tri2_Normal.Point3D) Or IntersectedPolygon(@Tri2_1.Point3D, @Tri2_2.Point3D, @Tri2_3.Point3D, @Tri1_2.Point3D, @Tri1_3.Point3D, @Tri2_Normal.Point3D)
ProcedureReturn 1
EndIf
Wend
Wend
EndProcedure