rotateObject() changes the coordinate system


  • F

    I need some brain-extension here. I hope you can understand what I am struggling with. Or at least explain me, why it is better like the way it is.
    b25a30ff-83a4-4e48-b8ee-d2fe496b2775-grafik.png

    How can I rotate objects around the x axis and afterwards around the z axis or vice versa and get the same object orientation at the end? For me the sequence of these two operations should not matter. Please explain me why it does, and maybe how to get around it.
    The coordinate system used by placedObject() stays in the initial orientation. If I do rotation calculations to move objects its getting very difficult to still use the rotateObject() function. But I have to, because I cannot extract the coordinates out of a 3D object and redraw it point by point. (code shared)


  • F

    @spikey I might be misinterpreting but are you wanting one object to rotate and move around another object like how planets rotate around the sun?


  • F

    3D rotations are done with transformation matrices. Multiplying by matrix being non-commutative (a * b has a different result than b * a) is just an intrinsic property of the math used.

    So the short answer is, you can't. You always have to perform the rotations in the same order.


  • F

    @Tratax you can absolutely look at it this way. What you are saying is the end target. Just use cubes instead of spheres. So not only the coordinates rotate, but also the cube itself. Therefore the coordinate sytem of both rotations need to have the same orientation. And the example shows that they change.


  • F

    @Mincus you are right. I rechecked. I was wrong. They do not have to be oriented in the same way afterwards. Can you tell me if the rotation matrices are depending on the orientation of the coordinate sytem. Maybe i got matrices for thewrong coord system.


  • F

    I use this rotation matrices:
    0fdb2d21-50a6-437e-8516-0a6f0b277a8b-image.png
    I will provide more details, tonight.


  • F

    This post is deleted!

  • F

    I have two examples of this in my Robo 3D game.

    Basically i took and scaled up the sin/cos demo code and then used the angle variable to control the direction and position of x/y movement, I then set the cameras position behind it and then rotated it around the player object, rotation of the player object was then adjusted so the player would rotate with the camera

    I was thinking about putting an orb spinning around the players position but I'm waiting for the next patch as I suspect we'll have some new 3D functions

    Eitherway, feel free to check the demo out!
    SW-8184-9059-9116


  • F

    @Tratax thank you for your answer, I will check the example. And I came to a similar conclusion according to your orb-idea (would love it): currently its super hard to spin an object in sync with an object in a certain distance, only using the functions we have in 3D. But I thought if I only get the math right, I could achieve it.

    So, I end up that all code I check, FUZE or mine, is correct: e.g.

    • rotateObject() --> axis: OK, rotation: right-handed: OK
    • the matrices above --> right-handed: OK
    • my own matrice multiplcation functions --> checked with online calculator examples: OK
      ..so the only possibilities left is: I still have the math wrong or it is not possible yet. So, I recheck the math, part by part.

  • F

    SW-4464-9632-0709
    My head is rotating. But my customObjects are just swirling. Maybe some one can spot the problem.


  • F

    This post is deleted!

  • F

    @spikey Awesome work! Mind sharing up the code? Curious to see how you've done this


  • F

    @Tratax Yes, its shared, you should have a friend request hanging ;-)
    Actually, its not usefull yet, because I can not find out how to handle the self-rotation axis of the red object. In my cube game, I did this with ifs: if rotx, roty, rotz = 270/180/or what ever then switch rot axis of rotateObject() to {0,1,0} or what ever. But then the complexity blew off the roof when I joined 3D objects. So, I started this test program above to get the maths right first.


  • F

    Isolation of the problem for the blue object (I updated the shared code as well):
    rotation_axis.jpg


    I would like to use the same axis for rotation in C as in A.

    I try now to find out how to rotate my inital axis manually so it fits the axis used by rotateObject(). the other way would be to switch the rotation axis in the parameter of rotateObject().

    I still have no clue, so if you know how to do it, I would be happy for any help.
    Probably its just a small operation, but just cant see it. Thanks.


  • F

    @Tratax thanks for letting me have a look. This was smart to put the cam behind the object, because the objects-axis are always oriented like one is sitting in it. Though I can not use that principle, when having multiple objects. I give it another go. By the way, I like your well-thought-out splash screen and design from pong, as well. Nice style.


  • F

    code updated:
    I could find a bug in the matrix-multiplication and found a way to revert the rotation on the blue rectangular cuboid. So, if I press j.left its left side is moving down (rotating around the old z, even after rotating it first around the y-axis.
    But if I do only a 45° rotation the y-axis it swirls around its length axis. (?) Anyone knows somebody working with robotics?


  • F

    I almost gave up. So, I would like to share that, to shorten your path, if you decide to do some 3D. I found out that there is a local coordinate system and global coordinate system if you program a 3D scene. (If you knew it, don't tell me now ;-))
    If you want to rotate multiple objects you have to track the rotation changes for every object to be able to call the rotateObject() for each object with the appropriate axis.

    It would be very helpful to have a rotateObjectGlobal() function that rotates all objects according to the global coordinate system.


  • Fuze Team

    @spikey This is a truly impressive series of posts, we commend you massively for this, showing your working out - it's awesome to see.

    You're going to love (or maybe hate!) a few new functions coming in the next patch ;)


  • F

    Thank you :) I am glad if this is interesting for others as well. Hey, I can imagine what you mean, haha, but the patch I am gonna love any way.


  • F

    To be able to re-use the code I put it into a rotateCustomObject(customObjectHandle, axis, angle) function. And shared it (SW-4464-9632-0709), if you are interested.
    Maybe I will have to update it, because the movement was not tested yet, and I think also of being able to set a rotation origin :---)
    If you find bugs, thanks for the feedback - if you have a suggested fix, go ahead, thanks.

    rotateCustomObjectCode.jpg

    rotateCustomObject_screen.jpg


Log in to reply