3D Rotation anhand von Transition bestimmen (Face To)

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • 3D Rotation anhand von Transition bestimmen (Face To)

    Problem:

    Gegeben sind die Koordinaten eines Objekts (x/y/z) in VRML. Dieses [coderwiki]Informationen/Objekt[/coderwiki] soll nun immer in die Richtung eines bestimmten Punktes ausgerichtet werden. Z.B. dem Punkt (0/0/0).

    Mein Lösungsansatz mit PHP:

    Zunächst wird die Euler- Rotation anhand der Koordinaten berechnet.
    Und zwar eine nach der anderen:
    Info: Punkt: ($y/$y/$Z), rotation: $xr, $yr, $zr


    Quellcode

    1. // Y- ROTATION
    2. if (($z == 0) && ($x >= 0)) {
    3. $yr = -90;
    4. } else if(($z == 0) && ($x < 0)) {
    5. $yr = 90;
    6. } else if($z > 0) {
    7. $yr = 180 - atan2($x,$y);
    8. } else if($z < 0) {
    9. $yr = atan2($x,$y);
    10. }
    11. // X- ROTATION
    12. if (($y == 0) && ($z >= 0)) {
    13. $xr = -90;
    14. } else if(($y == 0) && ($z < 0)) {
    15. $xr = 90;
    16. } else if($y > 0) {
    17. $xr = 180 - atan2($z,$y);
    18. } else if($y < 0) {
    19. $xr = atan2($z,$y);
    20. }
    21. // Z- ROTATION
    22. if (($y == 0) && ($x >= 0)) {
    23. $zr = -90;
    24. } else if(($y == 0) && ($x < 0)) {
    25. $zr = 90;
    26. } else if($y > 0) {
    27. $zr = 180 - atan2($x,$y) - 180;
    28. } else if($y < 0) {
    29. $zr = atan2($x,$y) ;
    30. }
    Alles anzeigen



    Dann erfolgt die Umwandlung in ein Quaternion:


    Quellcode

    1. function get_quaternionByEulerRotation($xr,$yr,$zr){
    2. $q1 = cos($xr/2) * cos($yr/2) * cos($zr/2) + sin($xr/2) * sin($yr/2) * sin($zr/2);
    3. $q2 = sin($xr/2) * cos($yr/2) * cos($zr/2) - cos($xr/2) * sin($yr/2) * sin($zr/2);
    4. $q3 = cos($xr/2) * sin($yr/2) * cos($zr/2) + sin($xr/2) * cos($yr/2) * sin($zr/2);
    5. $q4 = cos($xr/2) * cos($yr/2) * sin($zr/2) - sin($xr/2) * sin($yr/2) * cos($zr/2);
    6. return array($q2,$q3,$q4,$q1);
    7. }


    So, irgendwas stimmt da nicht. Obwohl es schon nicht schlecht aussieht.
    Hab ich einen Denkfehler???

    bin mal gespannt ob mir da jemand helfen kann...

    Stefan