Hello to the Forum!
To give you a short introduction of mine - my name is Hansjoerg and I’m from southern Germany , and I’m trying to dig into the basics of 3 D programming with hobby background.
Last month, I built a little ( yes I’m a mechatronics and totally no software guy) model of an industrial handling robot. Now I decided to setup an parallel virtual machine space model using a IK / stacked systems transformation - and as I don’t have any access to commercial tools and mainly for the purpose of learning, I want to do my own program using OPENGL. I already found an example of a rotating pyramid on the web which I used for a first attempt of learning, but since I wanted to change the perspective of view using GLULOOKAT() I got stuck. - The line of code is - after my opinion- placed right in the display routine before any other transformation. But it is just ignored … Could you give me any hint about how to achieve the right behaviour ???
I attached the code sequence below!
Thanks in advance for your help!
Hansjoerg
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix
gluLookAt(50, 50, 50, 0, 0, 0, 0, 1, 0);
//KJ1
glLoadIdentity(); // Reset the model-view matrix
glTranslatef( 0.0f, 0.0f, 0.0f); // Move left and into the screen
glRotatef(AngleJ1, 0.0f, 1.0f, 0.0f); // Rotate about the (1,1,0)-axis [NEW]
glBegin(GL_TRIANGLES); // Begin drawing the pyramid with 4 triangles
// Front KJ1
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( 0.0f, heightKJ1, 0.0f);
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( -edgeKJ1 / 2, 0.0f, edgeKJ1 / 2);
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( edgeKJ1 / 2, 0.0f, edgeKJ1 / 2);
// Right KJ1
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( 0.0f, heightKJ1, 0.0f);
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( edgeKJ1 / 2, 0.0f, edgeKJ1 / 2);
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( edgeKJ1 / 2, 0.0f, -edgeKJ1 / 2);
// Back KJ1
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( 0.0f, heightKJ1, 0.0f);
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( edgeKJ1 / 2, 0.0f, -edgeKJ1 / 2);
glColor3f(0.8f, 0.0f, 0.0f);
glVertex3f( -edgeKJ1 / 2, 0.0f, -edgeKJ1 / 2);
// Left KJ1
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( 0.0f, heightKJ1, 0.0f);
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( -edgeKJ1 / 2, 0.0f, -edgeKJ1 / 2);
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f( -edgeKJ1 / 2, 0.0f, edgeKJ1 / 2);
glEnd(); // Done drawing the pyramid
glutSwapBuffers(); // Swap the front and back frame buffers (double buffering)
// Update the rotational angle after each refresh [NEW]
AngleJ1 += 0.2f;
}