Original Post
Resolved, don't negate the W of a Quaternion when inverting. Hey everyone, I've got a problem with my MD5 loader.
I'm guessing its something wrong with my joint orientation. After the orientation for a joint is read, this code is applied on it And my quaternion functions are these The mesh I'm testing with is the pistol, the world_pistol mesh. Does anyone have any idea of what I'm doing wrong? Thanks :) [Edited by - CadeF on June 24, 2006 6:07:00 AM]
I'm guessing its something wrong with my joint orientation.
Public Sub SetupVertexArrays(ByVal Skel As clsMD5Skeleton)
Dim I As Integer = 0
Dim J As Integer = 0
For I = 0 To VertCount - 1
Dim finalVertex As Vector3 = Vector3.Empty
Dim finalNormal As Vector3 = Vector3.Empty
Dim finalTangent As Vector3 = Vector3.Empty
For J = 0 To Vert(I).countWeight - 1
Dim pWeight As clsMD5.MD5_Weight = Weight(Vert(I).startWeight + J)
Dim pJoint As clsMD5.MD5_Joint = Skel.Joint(pWeight.joint)
Dim wv As Vector3 = pWeight.pos
'If I comment out this line below, I get the bottom 2 pictures.
'If not, the top 2 pictures.
Quat_Rotate(wv, pJoint.orient)
finalVertex += (wv + pJoint.pos) * pWeight.bias
Dim wn As Vector3 = pWeight.norm
Quat_Rotate(wn, pJoint.orient)
finalNormal += wn * pWeight.bias
Dim wt As Vector3 = pWeight.tan
Quat_Rotate(wt, pJoint.orient)
finalTangent += wt * pWeight.bias
Next
VertexArray(I) = finalVertex
NormalArray(I) = finalNormal
TangentArray(I) = finalTangent
Next
End Sub
With j.orient
Dim t As Single = 1.0F - (.X * .X) - (.Y * .Y) - (.Z * .Z)
If t < 0 Then
.W = 0
Else
.W = -Sqrt(t)
End If
End With
Public Sub Quat_multVec(ByVal Q As Quaternion, ByVal v As Vector3, ByRef out As Quaternion)
out.W = -(Q.X * v.X) - (Q.Y * v.Y) - (Q.Z * v.Z)
out.X = (Q.W * v.X) + (Q.Y * v.Z) - (Q.Z * v.Y)
out.Y = (Q.W * v.Y) + (Q.Z * v.X) - (Q.X * v.Z)
out.Z = (Q.W * v.Z) + (Q.X * v.Y) - (Q.Y * v.X)
End Sub
Public Sub Quat_multQuat(ByVal qa As Quaternion, ByVal qb As Quaternion, ByRef out As Quaternion)
out.W = (qa.W * qb.W) - (qa.X * qb.X) - (qa.Y * qb.Y) - (qa.Z * qb.Z)
out.X = (qa.X * qb.W) + (qa.W * qb.X) + (qa.Y * qb.Z) - (qa.Z * qb.Y)
out.Y = (qa.Y * qb.W) + (qa.W * qb.Y) + (qa.Z * qb.X) - (qa.X * qb.Z)
out.Z = (qa.Z * qb.W) + (qa.W * qb.Z) + (qa.X * qb.Y) - (qa.Y * qb.X)
End Sub
Public Sub Quat_Rotate(ByRef V As Vector3, ByVal Q As Quaternion)
Dim tmp As Quaternion = Nothing
Dim inv As Quaternion = Nothing
Dim final As Quaternion = Nothing
inv.X = -Q.X
inv.Y = -Q.Y
inv.Z = -Q.Z
inv.W = -Q.W
Q.Normalize()
inv.Normalize()
Quat_multVec(Q, V, tmp)
Quat_multQuat(tmp, inv, final)
V.X = final.X
V.Y = final.Y
V.Z = final.Z
End Sub