Results 1 to 4 of 4

Thread: quaternion joy.....not (Resolved)

Threaded View

  1. #1

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Unhappy quaternion joy.....not (Resolved)

    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.

    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;
    }
    I tried to do it from the wiki page about rotation using a Querternion so sorry if it seems odd.

    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.
    Last edited by BodwadUK; Mar 12th, 2010 at 04:03 AM.
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width