# OpenGL: matrix manipulation

Hello everyone, I’m an Italian student, so you have to excuse me if my English is not perfect.
I have some problems using the matrix stack in an application for an exam. In particular, the application implements a model viewer and i have to modify it:

1. positioning just 3 different geometric models in the scene using OpenGl function: glPushMatrix() and glPopMatrix().
2. Permit translation, rotation of the single object respect of the WCS, OCS, VCS reference system. The single objects must be selected by means of ‘1’ ‘2’ ‘3’ key. The trasformations of translation or rotation must me applied by means of key ‘x’ ‘X’ ‘y’ ‘Y’ ‘z’ ‘Z’. The selection of the type of the transformation (translation/rotation) and the reference system must be done with:
• ‘o’ translation respect OCS
• ‘O’ rotation respect OCS
• ‘w’ translation respect WCS
• ‘W’ rotation respect WCS
• ‘v’ translation respect VCS
• ‘V’ rotation respect VCS (with the direction of the rotation axis same of the VCS and pass through the Origin of the VCS).

I ask you some help. I can’t do it and maybe you can provide me some suggestions.

Thank you everyone

If you’re not even gonna try and you say this, I’m sure you’re correct.

But yes you can, if you set your mind to it. This isn’t rocket science or particle physics.

Start here and ask questions as needed.

i have alredy tried, but i was not able to find a solution. I’m desperate

What do you have so far?

excuse for my English.
i have alredy positioned 3 differend object in the scene and i have understand how it is possible to translate and rotate them respect on the WCS. I have some problems with OCS and VCS

If you’re drawing three of the same objects, but positioning them independently in world coordinate space… and then changing your view … does your code resemble something like this?

``````
PushMatrix()
// apply view
transformTo(VCS)

// position object 1
PushMatrix()
transformTo(WCS1)
transformTo(OCS)
drawObject()
PopMatrix()

// position object 2
PushMatrix()
transformTo(WCS2)
transformTo(OCS)
drawObject()
PopMatrix()

// position object 3
PushMatrix()
transformTo(WCS3)
transformTo(OCS)
drawObject()
PopMatrix()

PopMatrix()

``````

yes, it is the same. But…the last part of the exercise requires that i select one of the 3 object with key 1,2,3 and it is done…but how can i manipulate one of the 3 objects when they are all alredy inserted in the sceene? i would like to rotate and traslate a single object whene it is alredy positioned in the scene. Do you understand, even if my English in not well?

In the pseudocode provided above, there are 5 distinct transformations used: VCS, OCS, WCS1, WCS2, WCS3. Adjusting the rotation and translation parameters used to produce the WCS1, WCS2, WCS3 transformations should allow you to independently move each individual object in the scene.

thank you…i have done…thank you very much.
Last problem: and respect the VCS, how can i manipulate a single object?

The VCS will change the position of all objects, as it is a transformation done to the entire scene. If you are attempting to manipulate a single object, you’re probably looking to change one of the WCS transformations.

In the example above:

• VCS affects the entire scene.
• WCS[1,2,3] affects 1 instance of the object.
• OCS affects all instances of the object.

ehm i have to do a translation and a rotation respetct on the VCS coordinate system…for the single objects…

Do you have your own matrix class or are you expected to do everything using OpenGL scales, rotates and translates?

I don’t have my matrix class… i should use only glRotatef and gltranslatef.

There is here the code that i have just written

``````int lista[3] = {listname,listWireCone,listSphere};

int i;
for(i=0;i&lt;3;i++){	//For each object
glPushMatrix();

glRotatef(rWCS[i][0],	tWCS[i][0],0,0 );
glRotatef(rWCS[i][1],    0 , tWCS[i][1], 0);
glRotatef(rWCS[i][2],    0,0,tWCS[i][2]);

glTranslatef(tWCS[i][0],tWCS[i][1],tWCS[i][2]);
drawAxis( 1.0, 0 );

glRotatef(rOCS[i][0],tOCS[i][0],0,0);
glRotatef(rOCS[i][1],0,tOCS[i][1],0);
glRotatef(rOCS[i][2],0,0,tOCS[i][2]);

glTranslatef(tOCS[i][0],tOCS[i][1],tOCS[i][2]);
glCallList(lista[i]);
glPopMatrix();

}
``````

listname,listWireCone,listSphere are the 3 Display List of the 3 different object
rWCS/rOCS represents a triple of float value, corresponding on the rotation respect x,y,z, respect on WCS or OCS.
tWCS/tOCS are the translation vector respect on WCS and OCS

Ah, if I understand you correctly, you need be able to position 3 separate objects in 3 different spaces (VCS, WCS and OCS) meaning each object has it’s own VCS WCS and OCS transformations. Be careful about using your translation values in your rotation axes, since it may produce erroneous results if it ends up returning 0 or a negative value.

``````
int lista[3] = {listname,listWireCone,listSphere};

int i;
for(i=0;i<3;i++){ //For each object
glPushMatrix();

// apply VCS
glRotatef(rVCS[i][0], 1,0,0);
glRotatef(rVCS[i][1], 0,1,0);
glRotatef(rVCS[i][2], 0,0,1);
glTranslatef(tVCS[i][0],tVCS[i][1],tVCS[i][2]);

// apply WCS
glRotatef(rWCS[i][0], 1,0,0);
glRotatef(rWCS[i][1], 0,1,0);
glRotatef(rWCS[i][2], 0,0,1);
glTranslatef(tWCS[i][0],tWCS[i][1],tWCS[i][2]);

drawAxis( 1.0, 0 );

// apply OCS
glRotatef(rOCS[i][0],1,0,0);
glRotatef(rOCS[i][1],0,1,0);
glRotatef(rOCS[i][2],0,0,1);
glTranslatef(tOCS[i][0],tOCS[i][1],tOCS[i][2]);

glCallList(lista[i]);

glPopMatrix();

}
``````

But, the VCS system hasn’t the axis same the WCS…so i have to indicate the axis of the VCS and not 1,0,0 0,1,0 0,0,1
Morevoer, i didn’t understant why i shouldn’t use translation value in the rotation axis.

Do not crosspost to multiple forums.

So… i tried to do a video, to explane you what my application must do: http://www.youtube.com/watch?v=ddW_faoN5lw
in the video i was pressing v button to act a translation on the VCS System:

• the object moves in the directions of the camera (observer), and not in the XYZ of the WCS, so the objects moves towards the observer and X Y axis are the camera axis.
• the object rotates along VCS
How can i act translation and rotation along VCS and not along WCS?