Sign in to follow this  
Pufftek

Translating one object and not another? Seems simple?

Recommended Posts

Pufftek    108
I'm trying to make it so that the objects rendered in the render method are translated by mouse dragging, while another is not. Where should I place the render method call for the other object? I've tried all over, and it doesn't seem to work anywhere?

[code]while (!Display.isCloseRequested())
{
glClear(GL_COLOR_BUFFER_BIT);
if (Mouse.isButtonDown(0))
glPushMatrix();
glTranslatef(xTrans,yTrans,0); //move according to mouse movement

if (Mouse.isButtonDown(0) && Mouse.getX()>0 && Mouse.getX()<639)
xTrans+=Mouse.getDX();
else
xTrans=0;
if (Mouse.isButtonDown(0) && Mouse.getY()>0 && Mouse.getY()<479)
yTrans-=Mouse.getDY();
else
yTrans=0;
render();

if (Mouse.isButtonDown(0))
glPopMatrix();

update();

Display.update();
Display.sync(framesPerSecond);
}[/code]

Share this post


Link to post
Share on other sites
Dunge    405
You probably need to play with matrix transformation functions in your render() function. You just need to set a different modelview matrix for each object, not globally.

Share this post


Link to post
Share on other sites
Pufftek    108
How would I go about doing that? I'm setting this before entering the main loop:


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,640,480,0,1,-1);
glMatrixMode(GL_MODELVIEW);

Is there some way that I can discard the transformations after the render() method is called without affecting already drawn things?

Share this post


Link to post
Share on other sites
Brother Bob    10344
glPushMatrix and glPopMatrix can localize transformations to selected parts of your code only.
[source]
glPushMatrix();
glTranslate(xTrans,yTrans,0);
DrawAnObject();
glPopMatrix();
glPushMatrix();
glTranslate(...); // whatever transformation you want for this other object...
DrawAnotherObject();
glPopMatrix();
[/source]

Share this post


Link to post
Share on other sites
Pufftek    108
[quote name='Brother Bob' timestamp='1333154849' post='4926829']
glPushMatrix and glPopMatrix can localize transformations to selected parts of your code only.
[source]
glPushMatrix();
glTranslate(xTrans,yTrans,0);
DrawAnObject();
glPopMatrix();
glPushMatrix();
glTranslate(...); // whatever transformation you want for this other object...
DrawAnotherObject();
glPopMatrix();
[/source]
[/quote]

That's what I tried, but when I do it the translate is discarded and the object pops back to where it was before. I want one object to stay in the same spot on the screen (it's a GUI) while the other moves around behind it.

Share this post


Link to post
Share on other sites
Brother Bob    10344
That's what my code does; it isolates the translate calls so that only one object is affected by the translate but not the other. If that doesn't work, then you have other things messing up the translations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this