0

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 :(

enter image description here

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

CaipiDE
  • 93
  • 1
  • 10
  • pls ignore: super.setRotZ(anglearoundplayer / anglez) – CaipiDE Oct 05 '18 at 11:12
  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) so what you want is to have separate matrix for each wheel and the car itself. If the wheel matrices are aligned with your model then you can use simple axis aligned local rotation for all (like turning the wheels, and also main rotation around their axis). Also your car is missing some triangles (have you tried to turn of CULL_FACE? if it helps you have wrong order of point in your mesh) Also the "boxes" should be under wheels I think – Spektre Oct 06 '18 at 06:46
  • First of all thank you for the answer, I‘ll see what I can do... And yes, the car isnt completed yet ;) – CaipiDE Oct 07 '18 at 06:56

0 Answers0