I have a problem for now quite a long time... In my OpenGL game, you can see in the picture, is a car with a height-terrain.
So to calculate the angle for the car, I created 4 Boxes, which are following around the car, so they always have the same position in relation of the car's rotation. So my algorithm for that works quite well, but when I streer the car, it gets useless, because I'm only rotating around the static X and Z axis of the cartesian-coordinate system. Do someone know how the "move" the solid axis, so I could rotate around like custom axis? Or my second Idea was something about interpulation between Xrotation and zrotation...
Pls help :(
Here my code:
Vector3f x1 = new Vector3f(26, cubex1.getPosition().y, 0);
Vector3f x2 = new Vector3f(0, cubex2.getPosition().y, 0);
Vector3f xdif = new Vector3f(x1.x - x2.x, x1.y - x2.y, x1.z - x2.z);
float anglex = -(float) Math.toDegrees(cubex1.getPosition().angle(xdif, new Vector3f(1, 0, 0)));
if(cubex1.getPosition().y < cubex2.getPosition().y){
super.setRotX(-anglex);
}else{
super.setRotX(anglex);
}
Vector3f z1 = new Vector3f(0, cubez1.getPosition().y, 14);
Vector3f z2 = new Vector3f(0, cubez2.getPosition().y, 0);
Vector3f zdif = new Vector3f(z1.x - z2.x, z1.y - z2.y, z1.z - z2.z);
float anglez = -(float) Math.toDegrees(cubez1.getPosition().angle(zdif, new Vector3f(0, 0, 1)));
super.setRotZ(anglearoundplayer / anglez);
if(cubez1.getPosition().y < cubez2.getPosition().y){
super.setRotZ(-anglez);
}else{
super.setRotZ(anglez);
}
I am using the Vectors of different boxes the get the angle in relation of a flat surface...