Hi guys. I am trying to convert a 3d model format into my own format in c++, I have however hit a problem. The source file uses a Quaternion and I have no idea what I am doing with it. I have been trying all day to understand the logic on websites etc and so far I have come up with this.
I tried to do it from the wiki page about rotation using a Querternion so sorry if it seems odd.Code:COB6Vertex RotateVector(float Quarns[4], COB6Vertex *CurrentVector) { COB6Vertex NewV; float t[9]; //Truespace y and z are reversed t[0] = CurrentVector->Y; CurrentVector->Y = CurrentVector->Z; CurrentVector->Z = t[0]; t[0] = Quarns[0] * Quarns[1]; t[1] = Quarns[0] * Quarns[2]; t[2] = Quarns[0] * Quarns[3]; t[3] = -Quarns[1] * Quarns[1]; t[4] = Quarns[1] * Quarns[2]; t[5] = Quarns[1] * Quarns[3]; t[6] = -Quarns[2] * Quarns[2]; t[7] = Quarns[2] * Quarns[3]; t[8] = -Quarns[3] * Quarns[3]; NewV.X = 2 * ((t[6] + t[8]) * CurrentVector->X + (t[4] - t[2]) * CurrentVector->Y + (t[1] + t[5]) * CurrentVector->Z) + CurrentVector->X; NewV.Y = 2 * ((t[2] + t[4]) * CurrentVector->X + (t[3] + t[8]) * CurrentVector->Y + (t[7] - t[0]) * CurrentVector->Z) + CurrentVector->Y; NewV.Z = 2 * ((t[5] - t[1]) * CurrentVector->X + (t[0] + t[7]) * CurrentVector->Y + (t[3] + t[6]) * CurrentVector->Z) + CurrentVector->Z; //Return New return NewV; }
My results seem very mixed. Sometimes one of the returns will be correct but othertimes 2 seem mixed up and with the wrong signage (aka +/-). Other times its just not right at all.
Can anyone give me some pointers, my brain feels like it might explode
P.s COB6Vertex is just a 3 float variable of x,y and z.





Reply With Quote