Home » Community » Forums » Math and Physics » Rotating a group of points around a pivot
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Rotating a group of points around a pivot
Post New Topic  Post Reply 
So simple and yet I'm stumped.

I have four points (with x, y, z coordinates) that make up a rectangle. I want to rotate the rectangle around it's own center. How do I do that?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Your coordinates should be relative to the center of the rectangle, placed at the origin (so the 4 points are local coordinates, the pivot of the rectangle - its center in your case - is located at 0,0,0).

Transform each point by using a 4x4 matrix which contains the transformation steps you want to apply to the rectangle, for example:

* rotation around the z axis
* followed by a rotation around the y axis
* followed by a rotation around the x axis
* followed by a translation


 User Rating: 1070   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You have to apply a pivot transformation first.
This would translate your vertices so that its center of rotation will be the pivot.

Assuming you only have a translational pivot point, this goes like:

transformMatrix = TranslationMatrix( -pivotPoint ) * RotationMatrix( rotation ) * Translationmatrix( pivotPoint ) * TranslationMatrix( translation )

Where pivotPoint is the center of rotation, rotation is the rotation of your quad and translation its position. Of course you can optimize this, but it shows the idea.

If you have a 10x10 quad with the lower left corner at 0,0,0 and upper right at 10, 10, 0 then your pivotPoint would be 5,5,0 to make it rotate around the center.

Hope that helps :)

Edit: of course I'm assuming you cannot modify the vertex data here. You can also just translate all vertices so that 0,0,0 is the center of rotation. This is also basically what the transform matrix with pivot support does.

 User Rating: 1141   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Could you write me a practical example of this please?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Moved to 'Maths & Physics' for any further discussion...


Jack Hoxley [ Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]

 User Rating: 1947   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

hey

Basically you define a new coordinate system for the group of points. You would place the origin of the coordniate system at the point of the pivot.

Now incase you don't know, basically a coordinate system defines which way/direction is up/down, which way is left/right, and which way is forwards/backwards.

You will need to have some knowledge of matrices and such also, as coordinate systems are represented with a 4x4 matrix, and are combined (added together) via matrix multiplication. I won't bother going any further into things incase you already know.

So what you do is instead of changing/rotating the points, you just change/rotate each axis of your coordinate system and draw the points relative to it.

I hope this makes some sense.

edit
I quickly put together some pesudo code, I hope it is okay :).

render()
{

	// push current modelview matrix onto stack
	// note, I assume the modelview matrix is already set as expected, whether it be in
	// world space, or transformed into eyespace by the camera or whatever
	glPushMatrix();

	// note, if this was a class then you would probably have this matrix defined inside it, and have
	// functions to alter it, but I just do these things here to make the example easier to read
	CMatrix rectMatrix;
	rectMatrix.location = pivot.position;		// set origin to position of pivot
	rectMatrix.rotate(1, 0, 0, 45.0f);			// rotate 45 degrees around X axis

	// note, the group of points should be defined in object space
	glMultMatrix(rectMatrix.matrix);			// multiply/combine with current opengl modelview matrix
	OnDrawGroupOfPoints();				// draw group of points

	// restore previous modelview matrix from stack
	glPopMatrix();
}


cyas

[Edited by - yosh64 on January 28, 2008 5:57:44 PM]

 User Rating: 1000   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: