View Full Version : Assemble 2 square and translate

McCorwin

06-22-2016, 06:56 AM

Hi all,

I want to assemble 2 square and after translate them with z-axis :

But I'm beginner and don't remember how to do :

glPushMatrix();

glLoadIdentity();

glPushMatrix();

glTranslatef(0f, 0f, 0f);

draw(gl,iSquare1, 2);

glLoadIdentity();

glPushMatrix();

glTranslatef(1f, 0f, 0f);

draw(gl,iSquare2, 2);

glPopMatrix();

glTranslatef(0f, 0f, -35f);

glPushMatrix();

-> It doesn't work

Agent D

06-23-2016, 09:13 AM

glPushMatrix();

I asssume you push the view&projection matrices here to restore them later and draw something else on the current transformation?

glLoadIdentity();

glPushMatrix();

glTranslatef(0f, 0f, 0f);

draw(gl,iSquare1, 2);

So you load an identity matrix into what exactely? Modelview?

Why do push the view & projection matrices again?

That glTranslatef uses zero on every axis and has no effect.

glLoadIdentity();

glPushMatrix();

glTranslatef(1f, 0f, 0f);

draw(gl,iSquare2, 2);

You load idenitity again and then you push the matrices again. Why?

At this point you called glPushMatrix 3 times.

Are you sure you know how a stack works? (https://en.wikipedia.org/wiki/Stack_(abstract_data_type))

glPopMatrix();

glTranslatef(0f, 0f, -35f);

glPushMatrix();

You restore the previous view & projection matrices by calling glPopMatrix. This includes the one you previously

set to identity using glLoadIdentity() before pushing.

You then apply a transformation along the Z axis. Since I don't know what your current matrix mode is and what

your modelview & projection matrices look like, I cannot predict what effect this has.

If your view & projection matrices are both identity, this transforms whatever you draw next outside the unit cube.

In fact, I don't see you drawing anything. You push your matrices again??

-> It doesn't work

If this is your entire drawing loop, you increase your matrix stack by 3 view-projection matrix pairs every iteration.

Your usage of pushmatrix and popmatrix makes no sense. It would be interesting what your transformation and projection

matrices looked like in the beginning and what you expect to happen.

McCorwin

06-26-2016, 11:50 PM

thanks for your reply :-)

No I'm beginner,

I only want to draw 2 square and paste them, after make a Z translation

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.