OpenGL GLUT

My question is at the end of this topic

1) a) Use your logo you drew within a world coordinate space that has 0,0 at the center. You may choose any width and height for your world coordinate space, glut window and viewport. Be sure that you separate this into a function. You may choose any size for your glut window. Additionally translate your logo so that it’s center is lined up at 0,0 and then uniformly scale down your logo using OpenGL so that it fits within a smaller space of your window. (you can also expand your world coordinate system to achieve this.)

2) Implement keyboard commands for:
•   translation (left arrow= negative translation along x, right arrow=positive translation along x, up arrow= positive translation along y, down arrow= negative translation along y), 
•   rotation (- = negative rotation, + = positive rotation), 
•   scale (x= neg scale along x-axis, y= neg scale along y axis, u= neg uniform scaling, 
X= pos scale along x-axis, Y= pos scale along y axis, U= pos uniform scaling), and 
•   Reset (Key “R” or “r” -> reset to original display – ie. clear the transformation matrix of all transformations) 

All should increment by a value that remains constant, appropriate enough to see the transformation in one key press but not by too much or too little. You may need to experiment with this value a bit and this value may differ among transformation type: ie translation by 1 unit may be sufficient but rotation may need to be rotation by 5 degrees each time, etc. This value will be dependent upon your world coordinate system that you have chosen. 


3) Implement OpenGL commands for translation, rotation, scale, and reset within the scene when the corresponding key is pressed. For Reset: The transformations should build upon one another and should only reset to original display if key “R” or “r” is pressed. HINT: All transformations are stored in the GL_Modelview matrix so setting the current matrix mode to be this and then calling glLoadIdentity() will replace the modelview matrix with the identity matrix which in turn will essentially clear all the transformations you added. 


4) Implement push and pop for all transformations only using OpenGL commands. Keys “Page Down” should execute glPushMatrix(); and “Page Up” should execute glPopMatrix(); properly. 
Optional: you may or may not choose to preserve aspect ratio. 

5) Implement your own transformations using the matrices and multiplying the matrices we discussed. Keys “O” or “o” should switch to OpenGL mode and keys “M” or “m” should switch to your transformations mode. 


6) Be sure to include implementation of a transformation stack similar to the one used for OpenGL. (don’t forget the reset!) No matter which display mode you are in you should, compute both such that when switching between modes, the object remains in the same configuration without change- this will enable you to test that your implementations are correct to how OpenGL is computing the transformations. HINT: just like glLoadIdentity() loads the identity matrix into the currentTransformation matrix, you can also load in any other matrix with void glLoadMatrixf(const GLfloat * m); but all matrix multiplications you will need to program on your own. 

**I am unable to understand 4th point (i have called glpushmatrix and glpopmatrix in it) but how it is going to update my scene

and 6th point
i build own transformation matrices for translation, scaling and rotation
ans used glmultmatrix to multiply
but my sir wants me to not use glmultmatrix and multiply matrix manually
how i am supposed to get current matrix and multiply it with translation or scaling matrix and then load it using glloadmatrix and update scene.

Please i have to submit it tomorrow.
i don't want code i want to do it myself as its my homework
but i want you to guide me

i have multiplied using following code


    GLfloat Matrix[16] = {1,0,0,0,0,1,0,0,0,0,1,0,x,y,0,1};
    glMultMatrixf(Matrix);

Please help**

Recommended Answers

All 5 Replies

C section would be more appropriate for OpenGL.

I am unable to understand 4th point (i have called glpushmatrix and glpopmatrix in it) but how it is going to update my scene

glPush/PopMatrix modifies an internal OpenGL matrices stack. You switch between different stacks with glMatrixMode. glTranslate/Rotate/Scale affect the current modelview (if in GL_MODELVIEW mode) matrix. When you push a matrix onto the stack, your current matrix is duplicated (which means that below the current matrix is a copy of it). When you pop a matrix, the current matrix is removed and replaced by the matrix below it. I think your teacher wanted you to make your app handle more than one modelview matrix, and switch between them using gl Push and Pop functions.

how i am supposed to get current matrix and multiply it with translation or scaling matrix and then load it using glloadmatrix and update scene.

GLfloat Matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);

Will copy the current modelview matrix (top of modelview matrices stack) to Matrix array. To load a matrix (thus replacing the matrix on top of the stack) simply:

glLoadMatrixf(Matrix);

After reading point 6 it looks like you have to implement a system similar to the OpenGL's modelview stack. Good luck.

can you give me a lil guidence about OpenGL modelview stack??

and when i loadmatrix it doesn't update scene

    glGetDoublev(GL_MODELVIEW_MATRIX, matrixd);
    multiplyMatrix(matrixd,Matrix);
    glPushMatrix();
    glLoadMatrixd(m);
    glPopMatrix();

am i doing something wrong??

can you give me a lil guidence about OpenGL modelview stack??

What guidance do you need w.r.t that? Also, it would be much better if you post the entire code here.
Also, regarding the code you have posted, have you done a:

glMatrixMode(GL_MODELVIEW);

before it?

and when i loadmatrix it doesn't update scene

glPushMatrix(); /* you duplicate the current matrix (which from the code you posted I presume is an identity matrix) */
glLoadMatrixd(m); /* you replace the top matrix with the one you made (probably, since I have no idea what is m) */
glPopMatrix(); /* you remove the top matrix (thus removing the one you made) and the current matrix is set to the duplicated identity matrix */

We need more code to help you.

thanks guyz,, sorry for late reply :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.