About Store Forum Documentation Contact



Post Reply 
free-flying box help
Author Message
panz3r Offline
Member

Post: #1
free-flying box help
I am trying to do a free flying box. The rotation and movement in global coordinates works fine. However flying forward accordingly to local box coordinates/direction does not seem to be easy to crack.

This works as expected in global coordinates moving box forward
if(Kb.b(KB_U)) box.kinematicMoveTo( box.pos()+Vec(0, 0, 0.02));
if(Kb.b(KB_J)) box.kinematicMoveTo( box.pos()+Vec(0, 0, -0.02));

Trying to convert local coordinates to global coordinates with matrix arithmetic does not work at all(random movement). (I can;t fly the box forward accordingly to it's rotation).

m=box.matrix();
if(Kb.b(KB_U)) box.kinematicMoveTo( box.pos()+Vec(0, 0, 0.02)*m);
if(Kb.b(KB_J)) box.kinematicMoveTo( box.pos()+Vec(0, 0, -0.02)*m);

Please let me know if you have some hints.
Edit:
This is what i found so far about subject - converting local global coordinates/directions:
http://www.esenthel.com/community/printt...p?tid=6285

I hope there is a solution without sin/cos/atan etc, just with matrix.

Second edit:
This is the solution, i could find and works:
m=box.matrix().orn();
if(Kb.b(KB_U)) box.kinematicMoveTo( box.pos()+Vec(0, 0, 0.02)*m);
if(Kb.b(KB_J)) box.kinematicMoveTo( box.pos()+Vec(0, 0, -0.02)*m);
(This post was last modified: 12-03-2014 01:23 AM by panz3r.)
12-03-2014 01:03 AM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #2
RE: free-flying box help
Hey,

I hope i didn't misread your question so, i haven't dealt with moving objects until now but since the general rule applies everywhere, you might wanna replace "Vec(0, 0, 0.02)" with "box.matrix.orn().z" or something like that.

But you have to add a multiplier to control the speed also like "boxSpeed" and you have to take into consideration how fast you add those values with "Time.d()" to keep your box speed steady no matter the frame cycle times.

So you'll have something like:
box.kinematicMoveTo(box.pos()+box.matrix.orn().z*Time.d()*boxSpeed);

Or even better something like:
box.pos() += box.matrix.orn().z*Time.d()*boxSpeed;

Don't know if this works as it is though but that's the general idea.

This is what i do to move my camera forward in the Z axis in a simple FPS flying mode.

Code:
if(Kb.b(KB_W)) Cam.matrix.pos+=(Cam.matrix.orn().z*Time.d()*camSpeed);

Where:
Cam.matrix.orn().z = Unit vector (length one) in world coordinates aiming towards Cam's local Z axis.
Time.d() = Time in seconds the last frame took (e.x. 0.004 sec), used to keep speed steady no matter the frame update speed.
camSpeed = Multiplier that you should use to affect the speed.

So if you use the method above the speed of your box will be "boxSpeed" WorldDistanceUnits/second and if "boxSpeed = 5" then you'll be moving the box with 5 WorldDistanceUnits/sec, if you decide to call it meters then it's 5 m/sec.
(This post was last modified: 12-03-2014 03:17 AM by georgatos7.)
12-03-2014 03:12 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #3
RE: free-flying box help
It's important to remember the difference between a rotation matrix("matrix.orn()") and a translation matrix("matrix"). Order of operation also matters. When you multiplied the translation matrix against your movement vector, it included the current location into the calculation which gives some wacky results. (I think in your original example, you could achieve the same effect by zeroing out m.pos prior to the math, but this would not be optimal)
georgatos7 is also correct- in other words, matrix.orn().z is the direction something is pointed to, and can be used to skip some of the math in many situations.
I also prefer to use matrix math over Sin/Cos/Tan.
12-03-2014 06:48 AM
Find all posts by this user Quote this message in a reply
panz3r Offline
Member

Post: #4
RE: free-flying box help
Thank you for your answers.
12-03-2014 11:05 AM
Find all posts by this user Quote this message in a reply
Post Reply