• Create Account

## Scale up an object on a plane

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1e-tyrell80  Members

103
Like
0Likes
Like

Posted 20 June 2013 - 05:49 AM

Hi everyone,

I have an OpenGL scene when an object is on a plane.
How can I do  to scale up the object with the glScale() function making he stay on the plane? That is, without the object break through the plane.

Best regards,

Tyrell

Edited by e-tyrell80, 20 June 2013 - 05:51 AM.

### #2__SKYe  Members

1578
Like
2Likes
Like

Posted 20 June 2013 - 08:07 AM

You'll have to scale it and then translate (move) it in the direction of the plane's normal by some amount.

//You must know the distance (for each axis) from the center point of your object (it's origin) and the point that touches the plane
//I'll call this distance, and put some random value
vec3 distance = (0.0f, 3.0f, 0.0f);

//In this example the object is at the center of the world, but move up in the Y axis by 3.0.
//Now do the scaling (remember scaling by 1.0 means staying the same)
//We're just scaling in the Y axis
glScalef(1.0f, 2.0f, 1.0f);

//Calculate the amount to translate the object
vec3 move;

//The <scale.X>, etc are the values passed to glScalef()
//We subtract 1.0f from the scale value, again because 1.0f  is the starting value (identity).
move.x = distance.x * (<scale.x> - 1.0f);
move.y = distance.y * (<scale.y> - 1.0f);
move.z = distance.z * (<scale.z> - 1.0f);

//Translate the object
glTranslatef(move.x, move.y, move.z);


Hope you understand (and that it is correct... i think so),

### #3e-tyrell80  Members

103
Like
0Likes
Like

Posted 21 June 2013 - 12:42 AM

Hi  __SKYe,

I tried your solution, it's perfect for my purpose.

Thank you again.

Best regards,

Tyrell

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.