• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# Rotating Object Points

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.

11 replies to this topic

### #1Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 April 2011 - 03:45 AM

Hello, I am creating a small 3D game with a ship that just flies around a rendered terrain.

I created my ship using dynamic Vertices. To move my ship i simply translate all the vertex points as desired. Walking, and strafing with my ship works fine.

My ship's directional movement is also just fine, by creating a unit vector from the angle of my rotation, i am able to move the ship in any 3D direction.

My problem is when i rotate my ship, my ship stays the exact same, the vertex points do not change. I would like to have the vertex points inside my ship
change as I rotate the ship, so the heading of my ship points to the direction that it is headed. I know that once i shift one point inside my ship I will be able
to shift the rest of the vertexes inside the ship, but I do not know how i am going to shift a point in my desired direction. I think i have to use the angle with
sin or cos and apply it to my point but so far that has yielded bad results, my math is pretty rusty.

I think i may be approaching this problem wrong and I do not have a lot of time to focus on this due to exams, but i really want to figure it out. Is there
anyone who can point me in the right direction? Possibly give me a hint if they know the answer?

Thank you

### #2scgames  Members   -  Reputation: 1900

Like
1Likes
Like

Posted 18 April 2011 - 04:53 AM

Typically you wouldn't manipulate the vertices manually as it sounds like you're doing. Instead, you would store the model in local space, and then transform it when it comes time to render (using the fixed-function pipeline or a vertex program, depending).

Am I understanding that correctly? Are you transforming the vertices 'by hand'? Or are you using a transform matrix?

### #3Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 April 2011 - 01:58 PM

So from what i gather i would store one of points in a transform matrix, and apply the transformations in local space, and then render.

Am i right in assuming i just need to store one point in a transform matrix, and then apply the transformation to all points or would i need
a transformation matrix for each point?

### #4Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 April 2011 - 05:41 PM

Ok i used a transform matrix with a translation matrix and was able to get the object to rotate around the origin.

the problem now is I need my object to rotate around its local axis instead of the origin, so i'll try to figure that out, thanks for the help!

Oh by the way how would i go about storing my object vertices within a local space? Do i have to "manually" figure out the center of my object and use that as the origin?
Or is there a simpler more efficient way?

### #5Burnt_Fyr  Members   -  Reputation: 560

Like
1Likes
Like

Posted 18 April 2011 - 06:57 PM

Ok i used a transform matrix with a translation matrix and was able to get the object to rotate around the origin.

the problem now is I need my object to rotate around its local axis instead of the origin, so i'll try to figure that out, thanks for the help!

Oh by the way how would i go about storing my object vertices within a local space? Do i have to "manually" figure out the center of my object and use that as the origin?
Or is there a simpler more efficient way?

The model is in local space if you say it is The difference between local and global space is the transform used. If you were previously using an Identity matrix, then it just happened to be that the local and global spaces were coincident. You should look into D3DXMatrixRotationAxis() or the XNA equivilent.

### #6Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 19 April 2011 - 01:04 AM

Thanks for the replies, I'm almost there, I can feel it! Burnt_Fyr from your post I just realized I was going about my ship completely wrong, i was hard coding in the ships position into
the world space.

I was wondering for Rotations this is what my logic is right now...

1.) Go into local space, save the current coordinates of the ship inside the world space
2.) return the ship back to object space (0,0,0) origin
3.) Rotate the ship (which i now i have working )
4.) translate the ship back into world space

Also if this is right, do i require a View matrix for my ship to do translations from object to world space?

### #7scgames  Members   -  Reputation: 1900

Like
1Likes
Like

Posted 19 April 2011 - 01:37 AM

I was wondering for Rotations this is what my logic is right now...

1.) Go into local space, save the current coordinates of the ship inside the world space
2.) return the ship back to object space (0,0,0) origin
3.) Rotate the ship (which i now i have working )
4.) translate the ship back into world space

Also if this is right, do i require a View matrix for my ship to do translations from object to world space?

Just to be clear, you shouldn't be modifying the vertices of the ship model at all. Just leave them in local space, and apply a transform via the D3D API to position and orient the ship the way you want it.

### #8Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 19 April 2011 - 02:09 AM

Ok, you may have just shattered my world, ummm let me get this straight

1.) To orient the ship, just apply a transform do not touch vertices
1.1.) This makes sense, but how am I to change the ship's orientation without changing its vertices? Do I move the world instead of the ship?

2.) To move the ship do i just apply another transform, and not touch the vertices in local space as well?

This is because for all of my ships movement, i had been changing the vertices to simulate movement.

Thank you, you may have steered me away from a bad road.

### #9scgames  Members   -  Reputation: 1900

Like
1Likes
Like

Posted 19 April 2011 - 02:21 AM

1.) To orient the ship, just apply a transform do not touch vertices

Right.

2.) To move the ship do i just apply another transform, and not touch the vertices in local space as well?

This is because for all of my ships movement, i had been changing the vertices to simulate movement.

Right, assuming a typical setup, you don't want to touch or modify the model vertices at all. In fact, in many cases you'll just stick them in a static vertex buffer and never touch them again.

To tell the rendering API where to render the ship (essentially), you provide a transform that specifies the object's position and rotation (and any other transforms you might want, such as scale). You can build this transform from separate rotation and translation matrices, or from a quaternion and a position vector, or from a set of Euler angles and a position vector - that's all up to you. But what you actually end up sending to the API will generally be one or more transforms that specifies how the geometry will make its way from local space to clip space. (If you're using the fixed-function pipeline, for example, these will be the world, view, and projection transforms.)

### #10Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 19 April 2011 - 02:43 AM

Oh my god, I have wasted a day and a half using a dynamic vertex buffer as a ship in my game, and now everything has just clicked and it all makes sense.

Thank you JYK, i feel like an idiot haha, thanks for getting me off that road of thought.

This is my last question because i feel bad about asking so many questions when i should be experimenting through example but...

Just making sure i'm supposed to assign this ship a position on the world map, which will also be the origin of the ship correct?
So to move the ship i am technically "Moving the world to adjust to the ships movement" Is that a good way to think of it?

Thanks again!

### #11scgames  Members   -  Reputation: 1900

Like
1Likes
Like

Posted 19 April 2011 - 03:07 AM

Just making sure i'm supposed to assign this ship a position on the world map, which will also be the origin of the ship correct?

I'm not completely sure what you mean, but in general, yes, the position of the object in the world will correspond to the local-space origin of the model. (That is, the world-space position of the model x, y, z will correspond to the local-space origin 0, 0, 0.)

So to move the ship i am technically "Moving the world to adjust to the ships movement" Is that a good way to think of it?

We were just discussing this in another thread :)

Generally speaking, as far as the simulation is concerned, you move the ship and not the world. There are some conceptual issues involved, and there's more than one way to look at things, but when it comes to actually updating the entities in your simulation, you should think of the ship as moving, rather than the world. (In the general case, at least.)

### #12Believe82  Members   -  Reputation: 103

Like
0Likes
Like

Posted 19 April 2011 - 03:13 AM

Thank you for all the help JYK, you are my boy haha

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.

PARTNERS