PDA

View Full Version : scale object without translate



alex2
04-07-2011, 04:18 AM
When I scale object it scales in all towards - so the final this object has other x,y,z START coordinates than at the beginning, can I scale object but stay starting coordinates this object ?



glPushMatrix();
glRotatef(90, 0, 0, 1);
glScalef(0.1, 3, 0.1);
glutSolidCube (20);
glPopMatrix();

mobeen
04-07-2011, 04:40 AM
Its quite difficult to understand what u r asking but from the bits and pieces I have understood the object when scaled shifts to a different position. To prevent this, untranslate the object with the amount it is translated (this brings the object at origin), scale at origin and then retranslate with the initial amount.

alex2
04-07-2011, 04:58 AM
For example this image:
1. image: red is start cube, blue is end cube after scale
2. image is that what I want: red is start cube, blue is end cube after scale

http://img25.imageshack.us/i/28506548.jpg/

So I have change code to:


glPushMatrix();
glTranslatef(30, 10, -150);
glRotatef(90, 0, 0, 1);
glTranslatef(-20, -20, -20);
glScalef(0.1, 3, 0.1);
glTranslatef(20, 20, 20);
glutSolidCube (20);
glPopMatrix();


but now cube is in totally different place.

mobeen
04-07-2011, 06:16 AM
Try this and let me know if this is what u were looking for.



void display()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-50,50,-50,50,0,100);

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 70,0,0,0,0,1,0);

glTranslatef(-20,0,0);
glutWireCube(20);
glTranslatef(20,-10,0);
glPushMatrix();
glRotatef(90, 0, 0, 1);
glScalef(0.1, 3, 0.1);
glutSolidCube (20);
glPopMatrix();


glutSwapBuffers();
}

alex2
04-07-2011, 07:38 AM
thx :)