Results 1 to 3 of 3

Thread: How to move object relative to origin, not origin and object!?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    29

    How to move object relative to origin, not origin and object!?

    Somebody please correct me if I'm wrong or confirm that it's impossible to move an object's position relative to the origin. The glTranslate function moves the coordinate system origin and the object with it! Example, if I define a GLQUADS in the X-Y plane V1=(4,4,0), V2=(0,4,0), V3=(0,0,0), V4=(4,0,0) I thought I could translate the GLQUAD so that the origin's X and Y axes pass through the center of the GLQUAD. WRONG!! It moved but the origin moved also. NOT GOOD! There is no way I can rotate the GLQUAD about an axis perpendicular (i.e., in the Z-Y plane) to it and running thru point (2,2,0). glRotate only works about vectors from the origin. Very disappointing <sigh>...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: How to move object relative to origin, not origin and object!?

    You can move an object relative to any position you like. You have to think of your 3D geometry in either a global coordinate scheme or a local coordinate scheme (the red book discusses both). I assure you that it's possible to move an object relative to the origin. If you want to rotate an object relative to some other vector, you just have to get your transformations right. Here's a simple test you can do:
    Code :
    GLfloat rotate1(0.0f);
    GLfloat rotate2(0.0f);
     
    void Draw()
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glEnable(GL_DEPTH_TEST);
    	glLoadIdentity();
    	// Translate the "camera" away from the scene.
    	glTranslatef(0.0f, 0.0f, -10.0f);
    	// Set color to blue.
    	glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
    	// Draw a sphere around the origin.
    	glutSolidSphere(0.8f, 20, 20);
    	// Rotate the quad below.
    	glRotatef(rotate1, 0.0f, 1.0f, 0.0f);
    	// Rotate around the point (4, 0, 0).
    	glTranslatef(4.0f, 0.0f, 0.0f);
    	// Translate quad back to where it started.
    	glTranslatef(2.0f, 2.0f, 0.0f);
    	// Rotate quad around its central point.
    	glRotatef(-rotate2, 0.0f, 1.0f, 0.0f);
    	// Translate quad around a local origin.
    	glTranslatef(-2.0f, -2.0f, 0.0f);
    	// Draw the quad.
    	glBegin(GL_QUADS);
    		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
    		glVertex3f( 4.0f,  4.0f, 0.0f);
    		glVertex3f( 0.0f,  4.0f, 0.0f);
    		glVertex3f( 0.0f,  0.0f, 0.0f);
    		glVertex3f( 4.0f,  0.0f, 0.0f);
    	glEnd();
     
    	rotate1 += 0.1f;
    	rotate2 += 0.3f;
    	glutSwapBuffers();
    }
    Run that code and see what it does. I get rotation about the quad's centre and rotation about an arbitrary axis. If you don't use GLUT just swap the glutSolidSphere for another quad or something.

    Hope that helps.

    [This message has been edited by ffish (edited 06-15-2001).]

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    29

    Re: How to move object relative to origin, not origin and object!?

    Thanks for your reply ffish. I finally figured out what glTRanslate and glRotate really mean.

Similar Threads

  1. Having a object move around the origin
    By Slong in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-17-2009, 05:37 PM
  2. Setting the origin of an object in OpenGL
    By ReAKtor in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-20-2003, 04:42 PM
  3. rotations relative to object
    By sharangad in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 10-06-2002, 10:50 PM
  4. Rotating a 3-D object centerd at the origin
    By ELIMT in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-04-2001, 02:25 PM
  5. Move the origin of the scene
    By OnkOver in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-31-2001, 02:24 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