PDA

View Full Version : Scaling x,y,z coordinates appropriately



Caspa
08-28-2005, 08:04 PM
Hi all,

I have a square printed on screen (for example, positioned with: glTranslatef(-10.0, 10.5, -40.0) and I want to animate it as it is brought forward from -40 to -10. However, as I have tried this, the x and y coordinates change scale (and results in the image changing its location on screen which I don't want). Is there a simple way to convert the x and y so that i am able to bring this square forward with it staying in its initial x and y position (while leaving all objects on the screen untouched). In other words, I am making this object appear bigger without moving it left or right. Quite new to this so please bear with me!

thanks

mikael_aronsson
08-28-2005, 10:18 PM
Hi !

It is a question on when you scale it, if you scale it before you translate it (and render it around the origin) it will scale equal in all directions, if you translate it before you scale it you will get different movement of each corner.

If you do not render it around the origina you can of course translate it so that it is located at the origin, scale it and then translate it back to where it was.

Mikael

Caspa
08-28-2005, 11:03 PM
Hi,

thanks for the reply. Don't quite understand what you mean - I think i should rephrase my question. I am displaying a square using glTranslatef(-5.5, 5.0, -15), which is x = 15 and y = 559 of my screen. I want to draw another square that is -25 into the screen (instead of -15) but want to draw it directly below that square - at x = 15 and y = 468 of my screen. Is there an easy way to draw it directly below - when I next use glTranslate(x, y, -25) i need to figure out what values to set x and y to (at run-time). If i was drawing the square at the same z, i could just use glTranslatef(-5.5, 4.7, -15), but because i'm changing the z it won't be in the right position.

Hope this makes a bit of sense! :)

mikael_aronsson
08-30-2005, 11:23 PM
Hi !

Don't change Z then.... :D

It is a bit messy to try to calculate the correct value to align it I guess, you could try to use gluProject/gluUnproject to map the first rectangles coordinates to window coordinates and then convert them back to world coordinates with different Z value, but you will have to convert the Z value to get correct results because it is not in world coordinates range.

Mikael