Local vs. World translations
5 posters
Local vs. World translations
Hi all,
Can someone please explain to translate an object according to its local axis?
Thanks!! Kind regards,
-joshua
Can someone please explain to translate an object according to its local axis?
Thanks!! Kind regards,
-joshua
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: Local vs. World translations
Hum...
_SIO2object->pos->x = ???
_SIO2object->pos->y = ???
_SIO2object->pos->z = ???
sio2ObjectBindMatrix( _SIO2object );
_SIO2object->pos->x = ???
_SIO2object->pos->y = ???
_SIO2object->pos->z = ???
sio2ObjectBindMatrix( _SIO2object );
Re: Local vs. World translations
On the contrary, how would one translate (specifically rotate) an object according to world coordinates (world space rather than object space)?
Thanks for any help,
John.
Thanks for any help,
John.
ducky- Posts : 4
Join date : 2009-04-05
Re: Local vs. World translations
Let me explain by describing what I am trying to accomplish...
I have a cube object on the screen that I want to rotate according to how the user swipes it. Swipe left/right to rotate on y axis, up/down on x axis. Now this all works fine on first swipe. Swipe left/right or up/down and the cube moves correctly. But rotate it down 90 degrees and then swipe horizontally and the thing rotates in the z axis. I know, I understand that it's still rotating on the local y axis, but that's not what I want. I just want it so that no matter what the orientation, when I drag up and down, it looks like I'm dragging it that way, and same for left/right.
Let me know if I haven't explained myself well...
John.
I have a cube object on the screen that I want to rotate according to how the user swipes it. Swipe left/right to rotate on y axis, up/down on x axis. Now this all works fine on first swipe. Swipe left/right or up/down and the cube moves correctly. But rotate it down 90 degrees and then swipe horizontally and the thing rotates in the z axis. I know, I understand that it's still rotating on the local y axis, but that's not what I want. I just want it so that no matter what the orientation, when I drag up and down, it looks like I'm dragging it that way, and same for left/right.
Let me know if I haven't explained myself well...
John.
ducky- Posts : 4
Join date : 2009-04-05
Re: Local vs. World translations
I think you got a coordinate problem from screen to world... just use sio2Project/sio2Unproject (depending on the approach that you choose) to calculate the direction vector of the movement in 3D, then adjust your object accordingly...
Re: Local vs. World translations
Not sure I see what you mean. Would those util functions work on rotation axis' or only translations? Someone else suggested doing something similar to the following, but now sure how it would work with SIO2...
glMatrixMode(GL_MODELVIEW);
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
glLoadIdentity();
glRotatef(dx, 1.0f, 0.0f, 0.0f);
glRotatef(dy, 0.0f, 1.0f, 0.0f);
glMultMatrixf(m);
dx = dy = 0.0;
glMatrixMode(GL_MODELVIEW);
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
glLoadIdentity();
glRotatef(dx, 1.0f, 0.0f, 0.0f);
glRotatef(dy, 0.0f, 1.0f, 0.0f);
glMultMatrixf(m);
dx = dy = 0.0;
ducky- Posts : 4
Join date : 2009-04-05
Re: Local vs. World translations
ducky wrote:Let me explain by describing what I am trying to accomplish...
I have a cube object on the screen that I want to rotate according to how the user swipes it. Swipe left/right to rotate on y axis, up/down on x axis. Now this all works fine on first swipe. Swipe left/right or up/down and the cube moves correctly. But rotate it down 90 degrees and then swipe horizontally and the thing rotates in the z axis. I know, I understand that it's still rotating on the local y axis, but that's not what I want. I just want it so that no matter what the orientation, when I drag up and down, it looks like I'm dragging it that way, and same for left/right.
Let me know if I haven't explained myself well...
John.
Man I'm exactly with the same issue.
Please, let me know if you find a solution. My solution was to create a 24 states matrix, so that each state is one of the possible "90º position" I needed for my object. But I don't like it like this...
Thanks
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Local vs. World translations
Just center the vertices around the new pivot point... Every time you transform the object, simply sio2MapBuffer the VBO then for each vertices glMultMatrix all of them... like that your object will always be transformed based on its current pivot point...
Re: Local vs. World translations
andreassilva, did you ever get this working using the advice from SIO2?
ducky- Posts : 4
Join date : 2009-04-05
Re: Local vs. World translations
Nop. and you?
Sorry for delay, I just notice your question now.
Sorry for delay, I just notice your question now.
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Local vs. World translations
I'm currently posting from my iPod, I'll post the code as soon I get on my mac... If I forgot can someone post again on this thread as a reminder...
Cheers
Cheers
Re: Local vs. World translations
Here's the function:
The workflow:
1. Map the array buffer
2. For each vertices pass it to the function as well as the worldspace matrix you want to use
3. Unmap the buffer
Now all your vertices are transformed from object space to worldspace, you can now reset the _SIO2object->_SIO2transform->mat
- Code:
void sio2MatTransformVertex( float *_m,
vec3 *_v1,
vec3 *_v2 )
{
vec3 v = { _v1->x, _v1->y, _v1->z };
_v2->x = v.x * _m[ 0 ] +
v.y * _m[ 4 ] +
v.z * _m[ 8 ] + _m[ 12 ];
_v2->y = v.x * _m[ 1 ] +
v.y * _m[ 5 ] +
v.z * _m[ 9 ] + _m[ 13 ];
_v2->z = v.x * _m[ 2 ] +
v.y * _m[ 6 ] +
v.z * _m[ 10 ] + _m[ 14 ];
}
The workflow:
1. Map the array buffer
2. For each vertices pass it to the function as well as the worldspace matrix you want to use
3. Unmap the buffer
Now all your vertices are transformed from object space to worldspace, you can now reset the _SIO2object->_SIO2transform->mat
Re: Local vs. World translations
I'm also working on something similar to what ducky describes, and I'm not fully understanding this solution. I'm just getting confused between matrices, OpenGL rotation operations, and _SIO2object calls, but if somebody is using this code in context with an _SIO2object to rotate it in world space I'd really like to see the code in context.
Thanks,
T
Thanks,
T
bugman_2000- Posts : 14
Join date : 2009-04-30
Permissions in this forum:
You cannot reply to topics in this forum