FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Local vs. World translations

5 posters

Go down

Local vs. World translations Empty Local vs. World translations

Post  meteors Fri Nov 21, 2008 6:47 am

Hi all,

Can someone please explain to translate an object according to its local axis?



Thanks!! Kind regards,
-joshua
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Fri Nov 21, 2008 5:04 pm

Hum...

_SIO2object->pos->x = ???
_SIO2object->pos->y = ???
_SIO2object->pos->z = ???

sio2ObjectBindMatrix( _SIO2object );
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  ducky Wed Apr 08, 2009 4:56 pm

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.

ducky

Posts : 4
Join date : 2009-04-05

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Wed Apr 08, 2009 5:18 pm

Humm can you be more specific...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  ducky Wed Apr 08, 2009 5:41 pm

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.

ducky

Posts : 4
Join date : 2009-04-05

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Wed Apr 08, 2009 5:46 pm

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...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  ducky Fri Apr 10, 2009 6:29 pm

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;

ducky

Posts : 4
Join date : 2009-04-05

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  andreassilva Sat Apr 11, 2009 11:05 am

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

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Sat Apr 11, 2009 4:28 pm

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...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  ducky Wed Apr 15, 2009 7:40 pm

andreassilva, did you ever get this working using the advice from SIO2?

ducky

Posts : 4
Join date : 2009-04-05

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  andreassilva Thu May 14, 2009 5:42 am

Nop. and you?
Sorry for delay, I just notice your question now.

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Thu May 14, 2009 8:49 am

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
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  sio2interactive Thu May 14, 2009 6:21 pm

Here's the function:

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
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  bugman_2000 Wed Jun 03, 2009 8:44 am

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

bugman_2000

Posts : 14
Join date : 2009-04-30

Back to top Go down

Local vs. World translations Empty Re: Local vs. World translations

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum