Results 1 to 6 of 6

Thread: matrixes for objects in a 3D world?

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

    matrixes for objects in a 3D world?

    If i want to make a 3d world with objects that can rotate around their own axises do each of the objects have to have their own private rotation-matrix if i want them to be displayed correctly?

    or is there a simpler way using glRotate?

    correct me if i'm wrong but glRotate only rotates the object around the camera-axises

    and do they all maybee need a position-matrix too?

    i want all my objects to be able to move and rotate around their own x-axis y-axis and z-axis

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: matrixes for objects in a 3D world?

    Look at the 4th NeHe Tutorial, titled 'Rotation'.
    Am I doing your homework for you?

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

    Re: matrixes for objects in a 3D world?

    and in his tutorial they rotate the object around the world axis.

    his tutorials doesn't really cover object space orientations.

    and he has only one object and a camera there

    i want to make 3d world with multiple objects and multiple cameras.

    so whats the easiest way to make an object rotate and move along its own axises?

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

    Re: matrixes for objects in a 3D world?

    hmm i just found out about Quaternion's ill look into that.

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

    Re: matrixes for objects in a 3D world?

    Okay so i made every object with a rotation matrix and a position matrix and it works, without using quarternions. Here some code if anyone is interested. Took me a while to figure this out.

    Code :
    void moveX(float v){ // any object x axis movement
        glPushMatrix();
            glLoadMatrixf(positionMatrix);
            glTranslatef(rotationMatrix[0]*v,rotationMatrix[4]*v,rotationMatrix[8]*v);
            glGetFloatv(GL_MODELVIEW_MATRIX,positionMatrix);
        glPopMatrix();
     
    }
    void rotateX(float v){ //any object x axis rotation
        glPushMatrix();
            glLoadMatrixf(rotationMatrix);
            glRotatef(v,rotationMatrix[0],rotationMatrix[4],rotationMatrix[8]);
            glGetFloatv(GL_MODELVIEW_MATRIX,rotationMatrix);
        glPopMatrix();
    }
     
    void setView(){// camera
        glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
        glLoadMatrixf(rotationMatrix);
        glMultMatrixf(positionMatrix);
        //wrong implementation might have the inverse effect
        //rotate first move second will cause the fps effect
        //move first rotate second will cause the fixed camera effect
        //all other models will/should draw with the camera matrix defaults added to them
    }
     
    void draw(){ // model
            glPushMatrix();
                glMultMatrixf(positionMatrix);
                glMultMatrixf(rotationMatrix);
     
                glColor4f(red,green,blue,alpha);
                glBindTexture(GL_TEXTURE_2D, texture[0]);
     
                glBegin(GL_QUADS);
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,-scale,-scale);
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,-scale,+scale);
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(-scale,+scale,+scale);
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(-scale,+scale,-scale);
     
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(+scale,-scale,-scale);
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(+scale,-scale,+scale);
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,+scale,+scale);
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,+scale,-scale);
     
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,-scale,-scale);
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,-scale,+scale);
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,-scale,+scale);
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,-scale,-scale);
     
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,+scale,-scale);
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,+scale,+scale);
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,+scale,+scale);
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,+scale,-scale);
     
                    glVertex3f(-scale,-scale,-scale);
                    glVertex3f(-scale,+scale,-scale);
                    glVertex3f(+scale,+scale,-scale);
                    glVertex3f(+scale,-scale,-scale);
     
                    glVertex3f(-scale,-scale,+scale);
                    glVertex3f(-scale,+scale,+scale);
                    glVertex3f(+scale,+scale,+scale);
                    glVertex3f(+scale,-scale,+scale);
                glEnd();
     
            glPopMatrix();
        }

    I used opengl built in matrix operations which gives a really bad cpu performance. I'll fix my own matrix operation classes later.
    glGetFloatv(); is the one causing heavy cpu drain.

  6. #6
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: matrixes for objects in a 3D world?

    you could concatenate them directly without glGet. all query functions should be avoided and called only at startup/loading times. best to you use own matrix classes and glLoadMatrix them, which is also the only way for OpenGL 3.0 afaik.

Similar Threads

  1. Replies: 8
    Last Post: 10-23-2017, 01:21 PM
  2. About mouse picking objects in 3D world
    By boblee38 in forum OpenGL: Windows
    Replies: 0
    Last Post: 05-12-2012, 11:05 AM
  3. 3d objects in 2d world.
    By iNsaNEiVaN in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 05-10-2002, 07:41 AM
  4. flying objects in 3d world
    By Starnut coder in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-08-2001, 03:08 AM
  5. Replies: 7
    Last Post: 01-15-2001, 02:30 PM

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