# Moving a point correctly after rotation

This topic is 3047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on your standard level editor, where you can create a shape and move verticies from that shape around. The problem I am having deals with when a person goes to move a vertex around after an object has moved. Imagine if you opened up Maya (or any 3D content creation software) and move a vertex, it always moves the way you wanted it to because of a reason I am not sure of.

A test case I have is displayed in a graphic below for the behavior that I would like.

When an object is at (0, 0, 0) with no rotation, it will have a identity matrix for its transform. If I go to move a vertex up in the Y direction, I simply move it up one in the y.

However, when an object is rotated with (0, 0, 90) and I want to move the vertex up on the Y, without any modification it will move the vertex along the X axis. To account for this I figured when I moved the vertex on the Y, I would multiply it by the UP vector from the rotation matrix, so in this case it would be (-1, 0, 0). The problem is, that would move the vertex down, rather then up as I wanted it to.

My question is, how could I properly move my vertex after a rotation has been set to the object?

Here is my graphic, the error shows how I want to move the vertex and the math next to it is showing what I am doing (although, it is wrong).

##### Share on other sites
I am not certain how experienced you are, but it sounds like your question concerns the order of transformations, which you can find by searching "matrix rotation translation" on the web.
If you want to translate along the rotated axis, you must rotate the translation vector as well (that is the fourth column in the matrix).
RotMatrix*TranslationMatrix*vec3
Now change the translation, and it will move along the rotated axis.

##### Share on other sites
I am still trying to solve this issue and I read through those posts and had came up with the following idea how this should be done.

All I trying to do is locally rotate this vector. For instance take this example was what I am looking for

Movement = 0, 1, 0
Rotation = 0, 0, 90 (degrees)
Result = 1, 0, 0)

as a result, I thought it should be
Result = Movement * Rotation

However, that does not turn out to be case. Does anyone have a suggestion of what it should be?

##### Share on other sites
It sounds to me like you want to be able to manipulate a local-space vertex of an object in world-space, essentially. It seems this could be done as follows (this may have already been covered in the links haegarr provided):

1. When the vertex is 'grabbed', transform it to world space using the world transform for the object.

2. As long as the vertex is still 'grabbed', move it around in world space in response to user input.

3. When the vertex becomes 'ungrabbed', transform it by the inverse of the object's world transform to yield the new local-space vertex.

If you need to update the mesh visually while the vertex is being moved, you can transform the vertex back to local space with each update so that you always have a local-space copy available.

##### Share on other sites
Quote:
 Original post by jykIt sounds to me like you want to be able to manipulate a local-space vertex of an object in world-space, essentially. It seems this could be done as follows (this may have already been covered in the links haegarr provided):1. When the vertex is 'grabbed', transform it to world space using the world transform for the object.2. As long as the vertex is still 'grabbed', move it around in world space in response to user input.3. When the vertex becomes 'ungrabbed', transform it by the inverse of the object's world transform to yield the new local-space vertex.If you need to update the mesh visually while the vertex is being moved, you can transform the vertex back to local space with each update so that you always have a local-space copy available.

The problem is that when the object becomes rotated, the vertex will not move correctly unless I manipulate the "move vector" by the objects rotation matrix some how.

##### Share on other sites
Quote:
 The problem is that when the object becomes rotated, the vertex will not move correctly unless I manipulate the "move vector" by the objects rotation matrix some how.
The method I proposed is intended to address that problem. If it doesn't, then I guess I must not really understand what you're trying to do.

##### Share on other sites
convert the angle into radians then add the sin and cos of the angle to the x and y.

x+=sin(angle);
y+=cos(angle);

if you move to fast, multiply to the end of the addition.

x+=sin(angle)*0.1;

##### Share on other sites
Quote:
Original post by jyk
Quote:
 The problem is that when the object becomes rotated, the vertex will not move correctly unless I manipulate the "move vector" by the objects rotation matrix some how.
The method I proposed is intended to address that problem. If it doesn't, then I guess I must not really understand what you're trying to do.

Does your way deal with rotation? I don't seem to see where it does.

Quote:
 Original post by dantheman1337convert the angle into radians then add the sin and cos of the angle to the x and y.convert_to_rad(angle);x+=sin(angle);y+=cos(angle);if you move to fast, multiply to the end of the addition.x+=sin(angle)*0.1;

This is for 3D, not 2D.

##### Share on other sites
Quote:
 Does your way deal with rotation? I don't seem to see where it does.
The method I proposed deals with object transforms. The transform for an object will generally incorporate a rotation. So yes, it deals with rotation.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013758
×