I've recently written two quite different implementations of firstperson camera that use Quaternions to perform rotations.
Neither worked, they appeared to suffer a common bug (the results onscreen were identical). The only thing they had in common was a code module providing quaternion math functions that I'd written earlier.
For starters, here is the formula for QuatMultiply (gleaned from the net) apon which I based my code - is it correct?
Now, here is my implementation of the above formula. Is it correct?
Does everything here look right?
TIA, Homer.
Neither worked, they appeared to suffer a common bug (the results onscreen were identical). The only thing they had in common was a code module providing quaternion math functions that I'd written earlier.
For starters, here is the formula for QuatMultiply (gleaned from the net) apon which I based my code - is it correct?
Assuming two input quaternions (A and B), find C = A . B
C.x = | A.w*B.x + A.x*B.w + A.y*B.z - A.z*B.y |
C.y = | A.w*B.y - A.x*B.z + A.y*B.w + A.z*B.x |
C.z = | A.w*B.z + A.x*B.y - A.y*B.x + A.z*B.w |
C.w = | A.w*B.w - A.x*B.x - A.y*B.y - A.z*B.z |
Now, here is my implementation of the above formula. Is it correct?
QuaternionMultiply proc uses esi edi ecx pA, pB, pC
mov esi,pA
mov edi,pB
mov ecx,pC
assume esi:ptr CQuaternion
assume edi:ptr CQuaternion
assume ecx:ptr CQuaternion
;C.x = | A.w*B.x + A.x*B.w + A.y*B.z - A.z*B.y |
fld [esi].fW
fmul [edi].fX
fld [esi].fX
fmul [edi].fW
fadd
fld [esi].fY
fmul [edi].fZ
fadd
fld [esi].fZ
fmul [edi].fY
fsub
fstp [ecx].fX
;C.y = | A.w*B.y - A.x*B.z + A.y*B.w + A.z*B.x |
fld [esi].fW
fmul [edi].fY
fld [esi].fX
fmul [edi].fZ
fsub
fld [esi].fY
fmul [edi].fW
fadd
fld [esi].fZ
fmul [edi].fX
fadd
fstp [ecx].fY
;C.z = | A.w*B.z + A.x*B.y - A.y*B.x + A.z*B.w |
fld [esi].fW
fmul [edi].fZ
fld [esi].fX
fmul [edi].fY
fadd
fld [esi].fY
fmul [edi].fX
fsub
fld [esi].fZ
fmul [edi].fW
fadd
fstp [ecx].fZ
;C.w = | A.w*B.w - A.x*B.x - A.y*B.y - A.z*B.z |
fld [esi].fW
fmul [edi].fW
fld [esi].fX
fmul [edi].fX
fsub
fld [esi].fY
fmul [edi].fY
fsub
fld [esi].fZ
fmul [edi].fZ
fsub
fstp [ecx].fW
assume esi:nothing
assume edi:nothing
assume ecx:nothing
ret
QuaternionMultiply endp
Does everything here look right?
TIA, Homer.