Hi All

I spent sometime yesterday mucking with the matrix code
in Clouds3d then something turned on the light :-)

Note that SSG and OpenGL use different representations
of Matrices.  

1) SSG is row major and OpenGL is column major

ie SSG is 

0  1  2  3 
4  5  6  7
8  9  10  11
12 13 14 15

whereas OpenGL is

0  4  8  12
1  5  9   13
2  6  10  14
3  7  11  15

basically just the transpose

2)  SSG uses a Z is up whereas conventionally OpenGL uses
     Z is pointing into the screen
     ie this just requires swapping the Y and the Z axis < columns >
     and negating the new Y column

so to go from SSG representation to conventional OpenGL representation 
in Python one would use the following to make a Look at Matrix

def sgMakeSkyLookAt( sgEye, sgCenter, sgUp ):
    eye = Vec3AxisSwap.mulColVec(sgEye)
    cen = Vec3AxisSwap.mulColVec(sgCenter)
    up  = Vec3AxisSwap.mulColVec(sgUp)
    y = cen - eye
    z = up
    x = y.cross(z)
    z = x.cross(y)
    x = x.normalize()
    y = y.normalize()
    z = z.normalize()
    mat = makeMat([
        [ x[0], z[0], -y[0], SG_ZERO ],
        [ x[1], z[1], -y[1], SG_ZERO ],
        [ x[2], z[2], -y[2], SG_ZERO ],
        [ -eye.dot(x), -eye.dot(z), eye.dot(y), SG_ONE ] ] )


3) Now since SSG eventually calls OpenGL SSG must do this
    for us behind the scenes or else things just wouldn't work 
    so inorder to get Clouds3D to render in the proper location
    we should just need to use the Matrix that SSG uses for a Camera
    Matrix and pass this directly to the Clouds3D Camers

so something like

void SkySceneLoader::Draw(sgMat4 mat)
{
    sgMat4 cameraMatrix;

    // sgCopyMat4(cameraMatrix,mat);    
    // or just 
    ssgGetModelviewMatrix(cameraMatrix);

    glMatrixMode ( GL_MODELVIEW ) ;
    glLoadIdentity () ;
    glLoadMatrixf( (float *) cameraMatrix );
  
    pCam->SetModelviewMatrix( (float *) cameraMatrix );
  
    SceneManager::InstancePtr()->Display(*pCam);
        
    //pLight->Display(); // draw the light position to  debug with sun position

    glMatrixMode ( GL_MODELVIEW ) ;
    glLoadIdentity () ;
}


Try it,  it works :-)

Now I just need to get a GFX card with 64megs of memory and hardware
pbuffers .......

Cheers

Norman


_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to