Results 1 to 5 of 5

Thread: scale object without translate

  1. #1
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    scale object without translate

    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 ?

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

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: scale object without translate

    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.
    Regards,
    Mobeen

  3. #3
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: scale object without translate

    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:
    Code :
    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.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: scale object without translate

    Try this and let me know if this is what u were looking for.

    Code :
    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();
    }
    Regards,
    Mobeen

  5. #5
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: scale object without translate

    thx

Similar Threads

  1. Translate and scale a rectangle with OpenGL 3+
    By Wah0airo in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-29-2018, 03:57 AM
  2. how to paint, translate and scale a cube
    By andrea84 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-27-2010, 03:47 PM
  3. Translate, Rotate, Scale vs baking my own matrix
    By Adrian P. in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-04-2007, 09:46 AM
  4. translate; scale; translate;
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-25-2004, 03:28 AM
  5. Replies: 1
    Last Post: 10-25-2002, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean