Just A Quicky

Ok this should be a quicky for any seasond maths lover (unfortunatly not me…)

Once i have rotated an object (cube) how can i make it go forward at the angle i rotated it. i.e. if an object is rotated 20deg what translation should i give it to move forward in that direction 10…

I know this is somthing to do with Soh Cah Toa but dispite looking around i cant come up with anything better than:

float MoveSize = 10;

movement = movement.add(FastMath.cos(FastMath.DEG_TO_RAD*cube.getCurrentDegree())*(MoveSize), 0, FastMath.sin(FastMath.DEG_TO_RAD*cube.getCurrentDegree())*(MoveSize));

st.setPosition(0, 0, dancers[1].getDancer().getLocalTranslation());
st.setPosition(0, 5, movement);

that _should_ mode the cube forward 10 in the direction it it currently pointing, i works for 90deg but on most others it just does odd things..

Help appreciated as always,


The common way, I think, is to express the movement as a vector and rotate that:

         Vector3f movement = new Vector3f();
         movement.set( 0, 0, 10 );
         movedObject.getLocalRotation().multLocal( movement );
         movedObject.getLocalTranslation().addLocal( movement );

(Not testet - complain if it's not working ;) )

When you do this often you should declare 'movement' as a field to avoid continuous object creation.

I kninda see where that is comming from however due to the local multiplication it’s actually performing the movement as apposed to simply returning a matrix which i can set as the endposition in a transition. I have messed about with it a little and ended up with:

            System.out.println("Forward: " + MoveSize);

            Vector3f movement = new Vector3f();
            movement.set(0, 0, 10);
            movement = dancers[1].getDancer().getLocalRotation().mult(movement);
            movement = dancers[1].getDancer().getLocalTranslation().add(movement);
            st.setPosition(0, dancers[1].getTotalTime(), dancers[1].getDancer().getLocalTranslation());
            st.setPosition(0,(dancers[1].getTotalTime() + (barLength * MoveSize)), movement);
            dancers[1].setTotalTime(dancers[1].getTotalTime() + (barLength * MoveSize));

            System.out.println("End Add");

which i think should work however it doesn't.. Any clues what i am doing wrong?


Aside from creating some unneccessary objects your code seems quite fine, when I ran it (used a Box instead of dancers :)). Are you sure your ‘Dancers’ do what they are supposed to internally?