Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:33:13+00:00 2026-06-01T02:33:13+00:00

Im trying to translate an object without using glTranslate(). I have searched through web

  • 0

Im trying to translate an object without using glTranslate(). I have searched through web and found a function glMultMatrixf(). I wanted to multiply my translation matrix using this function but I couldn’t accomplished it. I feel like I’m on the correct path logically but is translating an object this way even possible?

I have written the code using opengl and c++. Here is the code:

#include <iostream>
#include <stdlib.h>
#include <math.h>

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

float _angle = 0;

typedef GLfloat Matrix4x4 [4][4];
Matrix4x4 matTransl3D;

/* Construct the 4 x 4 identity matrix. */
void matrix4x4SetIdentity (Matrix4x4 matIdent4x4)
{
    GLint row, col;

    for (row = 0; row < 4; row++)
        for (col = 0; col < 4 ; col++)
            matIdent4x4 [row][col] = (row == col);
}

void translate3D (GLfloat tx, GLfloat ty, GLfloat tz)
{

    /*  Initialize translation matrix to identity.  */
    matrix4x4SetIdentity (matTransl3D);  

    matTransl3D [0][3] = tx;
    matTransl3D [1][3] = ty;
    matTransl3D [2][3] = tz;

}


void handleKeypress(unsigned char key, int x, int y) {
    switch (key) {
        case 27: //Escape key
            exit(0);
    }
}



void initRendering() 
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);

}

void handleResize(int w, int h) 
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
}

void drawScene() 
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);


    glLoadIdentity();

    translate3D(0.0f, 0.0f, -50.0f);
    glMultMatrixf(*matTransl3D);




    glBegin(GL_TRIANGLE_FAN);       // draw triangle

    glColor3f(1.0f,0.0f,0.0f);  // set color to red
    glVertex3f(  0.0f,  3.0f, 0.0f);
    glColor3f(0.0f,1.0f,0.0f);                  // set color to green
    glVertex3f(-5.0f, -5.0f, 5.0f);
    glColor3f(1.0f,1.0f,0.0f);                  // set color to yellow
    glVertex3f( 5.0f, -5.0f, 5.0f);
    glColor3f(0.0f,0.0f,1.0f);                  // set color to blue
    glVertex3f( 5.0f, -5.0f, -5.0f);
    glColor3f(1.0f,1.0f,1.0f);                  // set color to white
    glVertex3f( -5.0f, -5.0f, -5.0f);
    glColor3f(0.0f,1.0f,0.0f);                  // set color to green
    glVertex3f(-5.0f, -5.0f, 5.0f);
    glEnd();

    glBegin(GL_QUADS);     
    glColor3f(0.0f,1.0f,0.0f);                  // set color to green
    glVertex3f(-5.0f, -5.0f, 5.0f);
    glColor3f(1.0f,1.0f,1.0f);                  // set color to white
    glVertex3f( -5.0f, -5.0f, -5.0f);
    glColor3f(0.0f,0.0f,1.0f);                  // set color to blue
    glVertex3f( 5.0f, -5.0f, -5.0f);
    glColor3f(1.0f,1.0f,0.0f);                  // set color to yellow
    glVertex3f( 5.0f, -5.0f, 5.0f);
    glEnd();


    glutSwapBuffers();
}

//Called every 25 milliseconds
void update(int value) {
    _angle += 1.0f;
    if (_angle > 360) {
        _angle -= 360;
    }
    glutPostRedisplay();
    glutTimerFunc(25, update, 0);
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(400, 400);

    glutCreateWindow("Translation 3d");
    initRendering();


    glutDisplayFunc(drawScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);
    glutTimerFunc(25, update, 0);

    glutMainLoop();
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:33:14+00:00Added an answer on June 1, 2026 at 2:33 am

    OpenGL takes matrices as column major, i.e. the indexing is

    0 4 8 c
    1 5 9 d
    2 6 a e
    3 7 b f
    

    However you’re indexing your translation matrix in the order

    0 1 2 3
    4 5 6 7
    8 9 a b
    c d e f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to translate the usage of find function in Matlab to C++ .
I have some jquery code which I am trying to translate to YUI. I
I have spent the afternoon trying to wrap my mind around how to translate
I'm trying to write a simple maze game, without using any deprecated OpenGL API
I am trying to translate an OpenGl object around in a helical pattern. I
I am trying to translate the VBA code found in this link into IronPython.
I have some simple example WinForms code which I am trying to translate into
when trying to translate the confirmation message to Norwegian i get the following error:
I'm trying to translate a Perl script to PHP and I'm having trouble with
I'm trying to translate a grammar from bison to ANTLR. The grammar itself is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.