@loki could you please post your variable declarations of your code ?
And could you tell me, how i could handle user input ?
EDIT: OK i manged to get the user Input. This was not very difficult.
But now i has to set the position and rotation of my 3D object by this input and also to handle the animation sequences by input.
Any tips about this?
I cancelded the animation stuff at this point for later implementation.
Now to handle the user input.
I manged to get let him rotate by user. But i need some hints about the correct way. At the moment its just for test purposes:
- Code: Select all
public void createMovement() {
int key = getKeyStates();
// Rotiert den 3D Charakter nach links
if ((key & LEFT_PRESSED) != 0)
{
System.out.println("Left pressed" + key);
gameModel.getTransform(transform);
gameModel.postRotate(5, 0, 1, 0);
}
// Rotiert den 3D Charakter nach rechts
else if ((key & RIGHT_PRESSED) != 0) {
//mesh.changePosition(actor.getX() + 5, mesh.getY());
System.out.println("Right pressed" + key);
gameModel.postRotate(-5, 0, 1, 0);
}
else if ((key & UP_PRESSED) != 0) {
System.out.println("UP pressed" + key);
gameModel.getTransform(transform);
transform.postTranslate(0, 0, 10);
gameModel.setTransform(transform);
}
else if ((key & DOWN_PRESSED) != 0) {
//mesh.changePosition(mesh.getX(), mesh.getY() + 5);
System.out.println("DOWN pressed" + key);
gameModel.getTransform(transform);
transform.postTranslate(0, 0, -10);
gameModel.setTransform(transform);
}
As you can see, i just rotate the model. But if i want to movehim in the facing direction this is not possible by this method. So i need some way to store his facing direction and also a way to move him in this direction. At the moment he is always rotateing around the origin. But i have to move its pivot with his position and rotate around this pivot not the origin. How could i achieve this?