Results 1 to 5 of 5

Thread: Multiply current Matrix with the stacked Matrix

  1. #1
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Multiply current Matrix with the stacked Matrix

    Hi there is there anyway to multiply your current matrix with the one on the stack?

    I'm testing out some object oriented coding with multiple cameras
    So I have created a 3D world system
    every object in it have global positions but local rotations
    but to rotate every object locally before i draw them i have to first load an identity matrix then rotate then move it and then

    somehow apply it with the camera-matrix that was pushed on the stack. I guess i could make every object store a local rotation matrix and multiply it with the camera-matrix or i hoped that opengl was smart enought to make a built in "multiply current matrix with top stacked matrix operation", because this probly would be super efficiant rather than storing matrixes some other place.

    so is there one?
    Code :
    glPushMatrix(); //push camera matrix on stack
     
        glLoadIdentity();               //creation of object matrix starts here
        glRotatef(rx,1.0f,0.0f,0.0f);   //apply local rotations
        glRotatef(ry,0.0f,1.0f,0.0f);  
        glRotatef(rz,0.0f,0.0f,1.0f);
     
        //space for my hoped matrix operation //merge camera matrix with object matrix
     
        glTranslatef(px,py,pz);         //apply global position
     
        glBegin(GL_LINES);
            glColor4f(1.0f,0.0f,0.0f,alpha);
            glVertex4f(+scale,0.0f,0.0f,alpha);
            glVertex4f(0.0f,0.0f,0.0f,alpha);
     
            glColor4f(0.0f,1.0f,0.0f,alpha);
            glVertex4f(0.0f,+scale,0.0f,alpha);
            glVertex4f(0.0f,0.0f,0.0f,alpha);
     
            glColor4f(0.0f,0.0f,1.0f,alpha);
            glVertex4f(0.0f,0.0f,+scale,alpha);
            glVertex4f(0.0f,0.0f,0.0f,alpha);
        glEnd();
     
    glPopMatrix(); //pop camera matrix on the stack

  2. #2
    V-man
    Guest

    Re: Multiply current Matrix with the stacked Matri

    Yes, there is glMultMatrixf.
    Personally, I suggest that you don't use these things as they are considered deprecated. Do your own matrix math or use a ready made library. Here is mine
    http://www.geocities.com/vmelkon/glhlibrary.html

    and some examples here
    http://www.geocities.com/vmelkon/gl3_and_glh.html

  3. #3
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Re: Multiply current Matrix with the stacked Matri

    Quote Originally Posted by V-man
    Yes, there is glMultMatrixf.
    Personally, I suggest that you don't use these things as they are considered deprecated. Do your own matrix math or use a ready made library. Here is mine
    http://www.geocities.com/vmelkon/glhlibrary.html

    and some examples here
    http://www.geocities.com/vmelkon/gl3_and_glh.html
    No i dont understand how do you get/use the pushed matrix without using popmatrix? glMultMatrixf( PushedMatrix? )

  4. #4
    V-man
    Guest

    Re: Multiply current Matrix with the stacked Matri

    If you want to get the matrix,
    float mymatrix[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, mymatrix);

    If you want to know how to use push and pop

    glPushMatrix();
    glMultMatrixf(....);
    DrawObject();
    glPopMatrix(); //for every push, there must be a pop

  5. #5
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Re: Multiply current Matrix with the stacked Matri

    Alright so what you are saying is that my function that i'd like to exist doesnt exist. gotcha.

Similar Threads

  1. Matrix multiply order
    By 3DPrgmer in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-01-2017, 07:07 AM
  2. avoid loosing Stacked Transformations on Load identity matrix
    By Phil15 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-22-2015, 07:54 AM
  3. Matrix-Matrix multiply [HELP!]
    By AllanMSouza in forum OpenCL
    Replies: 0
    Last Post: 02-06-2013, 06:36 AM
  4. Multiply Vecor by Matrix??!
    By TheBlob in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-16-2002, 01:09 PM
  5. How to multiply point by Current Matrix?
    By GameMaker in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-24-2001, 03:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean