Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotations



Hi,
thank you. Yes I have different angles all the time.
I realized that I really need quaternions. So I am learning and implementing
that. Already I am able to use glMultMatrixf(Matrix) so I don't use
glRotatef anymore. However, even using this method, the rotation works
exactly as with glRotate... Did I miss something?

I did:
--------------------
    [self CreateFromAxisAngle:1.0f y:0.0f z:0.0f degrees:xrot];
    [self CreateFromAxisAngle:0.0f y:1.0f z:0.0f degrees:yrot];
    [self CreateFromAxisAngle:0.0f y:0.0f z:1.0f degrees:zrot];
    
    [self MultiplyQuaternion:qx byQuaternion:qy];
    [self MultiplyQuaternion:q byQuaternion:qz];
    [self CreateMatrix];
    glMultMatrixf(Matrix);
--------------------

where
--------------------
- (void)CreateFromAxisAngle:(GLfloat)xx y:(GLfloat)yy z:(GLfloat)zz
degrees:(GLfloat)degrees
{
    GLfloat angle = (GLfloat)((degrees / 180.0f) * pi);
    GLfloat result = (GLfloat)sin( angle / 2.0f );
    
    if(xx){
        qx.m_w = (GLfloat)cos( angle / 2.0f );
        qx.m_x = xx * result;
        qx.m_y = yy * result;
        qx.m_z = zz * result;
    }
    else if(yy){
        qy.m_w = (GLfloat)cos( angle / 2.0f );
        qy.m_x = xx * result;
        qy.m_y = yy * result;
        qy.m_z = zz * result;
    }
    else{
        qz.m_w = (GLfloat)cos( angle / 2.0f );
        qz.m_x = xx * result;
        qz.m_y = yy * result;
        qz.m_z = zz * result;
    }
}


and where
--------------------
- (void)MultiplyQuaternion:(glQuaternion)a byQuaternion:(glQuaternion)b
{
    q.m_w = (b.m_w * a.m_w) - (b.m_x * a.m_x) - (b.m_y * a.m_y) - (b.m_z *
a.m_z);
    q.m_x = (b.m_w * a.m_x) + (b.m_x * a.m_w) + (b.m_y * a.m_z) - (b.m_z *
a.m_y);
    q.m_y = (b.m_w * a.m_y) + (b.m_y * a.m_w) + (b.m_z * a.m_x) - (b.m_x *
a.m_z);
    q.m_z = (b.m_w * a.m_z) + (b.m_z * a.m_w) + (b.m_x * a.m_y) - (b.m_y *
a.m_x);
}


and where
--------------------
- (void)CreateMatrix
{
    // First row
    Matrix[ 0] = 1.0f - 2.0f * (q.m_y * q.m_y + q.m_z * q.m_z);
    Matrix[ 1] = 2.0f *        (q.m_x * q.m_y + q.m_z * q.m_w);
    Matrix[ 2] = 2.0f *        (q.m_x * q.m_z - q.m_y * q.m_w);
    Matrix[ 3] = 0.0f;
    
    // Second row
    Matrix[ 4] = 2.0f *        (q.m_x * q.m_y - q.m_z * q.m_w);
    Matrix[ 5] = 1.0f - 2.0f * (q.m_x * q.m_x + q.m_z * q.m_z);
    Matrix[ 6] = 2.0f *        (q.m_z * q.m_y + q.m_x * q.m_w);
    Matrix[ 7] = 0.0f;

    // Third row
    Matrix[ 8] = 2.0f *        (q.m_x * q.m_z + q.m_y * q.m_w);
    Matrix[ 9] = 2.0f *        (q.m_y * q.m_z - q.m_x * q.m_w);
    Matrix[10] = 1.0f - 2.0f * (q.m_x * q.m_x + q.m_y * q.m_y);
    Matrix[11] = 0.0f;

    // Fourth row
    Matrix[12] = 0;
    Matrix[13] = 0;
    Matrix[14] = 0;
    Matrix[15] = 1.0f;
}


Best Regards
-- 
Lorenzo
email: email@hidden

> From: email@hidden
> Date: Sun, 19 Sep 2004 15:59:54 -0400 (EDT)
> To: email@hidden
> Subject: Re: Rotations
> 
> 
> In a message dated 9/19/04 4:08:50 AM, email@hidden writes:
> 
>> No sorry,
>> this didn't solve the problem. The object still rotates on the original
>> "X"
>> axis. Instead since I firstly rotated the "Y" axis, now rotating by an
>> "X"
>> angle, should rotate the object on its own current local "X" axis. And
>> this
>> doesn't happen. How to fix this? Any other idea?
> 
> So the Object "local" system are not changing with translatef.
> 
> Do you have the same or different value for xrot and yrot?
> example:
> glRotatef(45,0,0,0);
> glRotatef(90,0,0,0);
> 
> if you don't you could try glRotatef(XYrot,1,1,0);
> 
> And you probably want to send your reply to
> the OpenGL-dev instead of Cocoa-dev this time   :)
> 
> 
> 
>   BinarySpike
> 
> 
> 
> 
> 
> 
> 
> 
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.