Nicholas Randall Forystek
unread,Aug 24, 2016, 4:40:22 AM8/24/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Public Declare Function VertexPoint_Behind_TrianglePlane Lib
"maxlandlib.dll" Alias "PointBehindPoly" _
(ByVal VertexPointX As Single, ByVal VertexPointY As
Single, ByVal VertexPointZ As Single, _
ByVal TrianglePlaneNormalX As Single, ByVal
TrianglePlaneNormalY As Single, ByVal TrianglePlaneNormalZ As Single, _
ByVal TriangleSideLength1 As Single, ByVal
TriangleSideLength2 As Single, ByVal TriangleSideLength3 As Single) As
Boolean
Public Sub Main()
Dim v As D3DVECTOR
Dim n As D3DVECTOR
Dim p As D3DVECTOR
Dim t1 As D3DVECTOR
Dim t2 As D3DVECTOR
Dim t3 As D3DVECTOR
'make three points of a triangle
t1.x = 20: t2.y = 0: t3.z = 0
t1.x = 20: t2.y = 20: t3.z = 0
t1.x = -20: t2.y = -20: t3.z = 0
'get plane normal of a triangle
n = GetPlaneNormal(t1, t2, t3)
'get lengths of triangle sides
v.x = Distance(t3, t1)
v.y = Distance(t1, t2)
v.z = Distance(t2, t3)
'make up a point test scenario
p.x = 0: p.y = 0: p.z = 30
'check to see if the point is behind the illogical spun traingular
sphere in back spuns
Debug.Print VertexPoint_Behind_TrianglePlane(p.x, p.y, p.z, n.x, n.y,
n.z, v.x, v.y, v.z)
End Sub
Public Function Distance(ByRef p1 As D3DVECTOR, ByRef p2 As D3DVECTOR) As
Single
Distance = Sqr(((p1.x - p2.x) * (p1.x - p2.x)) + ((p1.y - p2.y) *
(p1.y - p2.y)) + ((p1.z - p2.z) * (p1.z - p2.z)))
End Function
Public Function GetPlaneNormal(ByRef v0 As D3DVECTOR, ByRef v1 As D3DVECTOR,
ByRef v2 As D3DVECTOR) As D3DVECTOR
Dim vector1 As D3DVECTOR
Dim vector2 As D3DVECTOR
Dim vector3 As D3DVECTOR
'/*Calculate the Normal*/
'/*Vector 1*/
vector1 = VectorSubtract(v0, v1)
'/*Vector 2*/
vector2 = VectorSubtract(v1, v2)
'/*Apply the Cross Product*/
vector3 = VectorCrossProduct(vector1, vector2)
'/*Normalize the Vector*/
GetPlaneNormal = VectorNormalize(vector3)
End Function
Public Function VectorCrossProduct(ByRef v As D3DVECTOR, ByRef u As
D3DVECTOR) As D3DVECTOR
VectorCrossProduct.x = v.y * u.z - v.z * u.y
VectorCrossProduct.y = v.z * u.x - v.x * u.z
VectorCrossProduct.z = v.x * u.y - v.y * u.x
End Function
Public Function VectorSubtract(ByRef v As D3DVECTOR, ByRef u As D3DVECTOR)
As D3DVECTOR
VectorSubtract.x = v.x - u.x
VectorSubtract.y = v.y - u.y
VectorSubtract.z = v.z - u.z
End Function
Public Function VectorNormalize(ByRef v As D3DVECTOR) As D3DVECTOR
Dim l As Single
l = Sqr(v.x * v.x + v.y * v.y + v.z * v.z)
If l = 0 Then l = 1
VectorNormalize.x = (v.x / l)
VectorNormalize.y = (v.y / l)
VectorNormalize.z = (v.z / l)
End Function