Help me fine tune jit.gl.camera to use it like a spaceship in 3D space


    Nov 19 2016 | 3:51 pm
    Hello again,
    Today I'd like to navigate a camera viewpoint through a jitter world like I was controlling a space ship, watching a magnificent space show.
    Thus far I have used jit.gl.camera, and I have made a nice patch that controls its "lookat" and "position" attributes. Positioning manouvring works nice, and the lookat part of the patch works well usually too (turning to the right makes me look to the right), but a problem seems to occur when my I position myself behind the object I'm watching (negative Z value on "positioning"). When I try to look to the right my camera turns left! Things get weird! Help!
    To make my patching goal clearer, I'd like to "move my spaceship nose" with the lookat attribute, so that when I'm starting my engines and put my joystick forwards, I will travel towards the way my nose is pointing.
    TL;DR: Is it possible to turn the camera angle relative to the cameras position in the jitter 3D world?
    As a gift for helping and/or reading, have my spaceship.

    • Nov 21 2016 | 7:19 am
      It occurs to me that you may want your lookat to be set to a point on a circular horizon, rather than any object in the scene or other nearby point that you could possibly pass by. Probably best is a horizon at a distance constant relative to the spaceship's position. Try this formula:
      x = cx + r * cos(a) x = cz + r * sin(a)
      Where: x, z are your lookat x z cx, cz are your ships location a is the angle you are looking (0 north, 90 east, &c...) In this case r is arbitrary, so use 1.
      Alternatively, try setting cx, cz to the center of your scene and r to a very large value (a distant horizon).
    • Nov 21 2016 | 4:50 pm
      hi jonas, make sure you check out the jit.anim.drive -> jit.gl.camera combination, as this will probably be all you need to get the type of camera animation you are looking for. you would simply map your joystick movements to the "move" and "turn" messages.
      jit.gl.camera defaults to @animmode local, which means all animation messages (e.g. move and turn) are applied to the local axes of the camera, which is generally what you want when animating a camera.
      you can test out movement easily using the mouse and keyboard, by enabling @ui_listen on the anim.drive.