Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello again guys!

This time...i have a problem drawing multiple objects on one viewport or screen. I would like to draw more then one object on the screen and then choose from them (from number 1 to 10 or using tab or any other keyboard) and then rotate them.

I've managed to draw two objects..

See picture: http://postimage.org/image/kjjxmyky5/[^]

But when i want to rotate one object he will go out of shape, because i dont call this function:

C#
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);


See picture: http://postimage.org/image/kmtwn8g97/[^]

If i DO call it, then the other object dissapears. I've tried to use pushMatrix and popMatrix functions, but as it seems i do not understand them quite good if the solution can be made with them.

I seek help, how to have more objects on screen and using rotate and translate functions seperatly on them, while one is rotating or moving, the others stay, where the are.

Can anyone help me? Thnx
Posted

1 solution

After applying a rotation, current model view matrix will changed with the rotation.
Therefore the second rotation will be applied on the already rotated model view matrix.

After drawing an object with a transformation(rotation,translation,scaling) you have to reset it.
Otherwise next transformation will applied on the transformation applied matrix.
It will provide unexpected object drawing.

C#
glClearColor( 0.5,0.5,0.5,0.5 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode(GL_MODELVIEW_MATRIX);
// Save current matrix
glPushMatrix();

// Apply rotation for first object.
glRotatef( 15,0, 0, 1 ); // Here model view matrix rotated.

// Draw first object with rotation. Object1

// Reset matrix to old state. Therefore rotation on model view matrix is reset.
glPopMatrix();


// Save matrix.
glPushMatrix();

// Apply new rotation for second object.
glRotatef( 45,0, 0, 1 );

// Draw next object with new rotation. Object2

// Reset matrix to old state.
glPopMatrix();

// display
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900