A script to Orbit Camera around a point

This topic seems to come up occasionally, but I couldn't find an existing "Orbit Camera" script, so I've written one (CameraOrbit.dsa) and attached it to this post.  It shows one way to Orbit Camera around a point, via Slider controls.

It lets you control the Longitude, Latitude and Radius of the Orbit.

By default it controls the built-in Perspective Camera of the Viewport, and Orbits around the point [ 0, 100, 0 ], but:
    * If your Scene contains a visible Node labelled "Orbit-Point" then that will be used as the point to Orbit instead.
    * If your Scene contains a visible Camera labelled "Orbit-Camera" then that will be used as the controlled Camera instead.
You can enable/disable this behaviour by simply turning off the Visibility of what you don't want to test.

The guts of it is the maths to convert between Cartesian and Spherical coordinates, as per Wikipedia: Spherical coordinates

Hope you find it useful.

 

 

Comments

  • V3DigitimesV3Digitimes Posts: 3,049

    It is useful, it works like a charm, and can be very easily adapted for more specific needs :)

    Thank you!!!

  • PraxisPraxis Posts: 240

    It is useful, it works like a charm, and can be very easily adapted for more specific needs :)

    Thank you!!!

    You are welcome - I'm glad you like it.

    -P

     

  • V3DigitimesV3Digitimes Posts: 3,049

    I like it.. I changed a lot of things but it was a great base. Amongst other things, I included the fact you can select any node in the scene (via a huuuuuge combo box) and orbit around the middle of its bounding box (otherwise, you have issues with parented items as my tester told me).

  • PraxisPraxis Posts: 240

    ... Amongst other things, I included the fact you can select any node in the scene (via a huuuuuge combo box) and orbit around the middle of its bounding box (otherwise, you have issues with parented items as my tester told me).

    Are you referring to a DzNodeSelectionComboBox?  If not, you should try it.

    There is also a DzPropertySelectionComboBox.

    Both are documented in the  Object Index, and they work well for me.

    They do have a quirk: To Close them you must move the mouse off them - clicking on an item does not close them.

    That's a good idea to orbit around the centroid of a bounding box.

     

     

  • V3DigitimesV3Digitimes Posts: 3,049
    edited May 2016

    Gosh! I had not seen this one!
    Once again thanks! I've adapted my script with the DzNodeSelectionCombobox, which allowed me to remove plenty of lines and have a much more clear result!!! Yes it works very well.

    For the quirk you mention, I'll just write that in the documention. Honnestly, with all the benefit it has on the script, it is a minor issue.

    edit : I just saw another quirk. If you do no change the selection, the only fact on clicking on the "select node" will activate the connected function. Well never mind, a new comment to add in my readMe :)

    In France what I did previously is called "re-invent the powder"... But my powder was wet! This Combobox is great now!

    Post edited by V3Digitimes on
  • TotteTotte Posts: 13,498
    Praxis said:

    This topic seems to come up occasionally, but I couldn't find an existing "Orbit Camera" script, so I've written one (CameraOrbit.dsa) and attached it to this post.  It shows one way to Orbit Camera around a point, via Slider controls.

    It lets you control the Longitude, Latitude and Radius of the Orbit.

    By default it controls the built-in Perspective Camera of the Viewport, and Orbits around the point [ 0, 100, 0 ], but:
        * If your Scene contains a visible Node labelled "Orbit-Point" then that will be used as the point to Orbit instead.
        * If your Scene contains a visible Camera labelled "Orbit-Camera" then that will be used as the controlled Camera instead.
    You can enable/disable this behaviour by simply turning off the Visibility of what you don't want to test.

    The guts of it is the maths to convert between Cartesian and Spherical coordinates, as per Wikipedia: Spherical coordinates

    Hope you find it useful.

     

     

    Hi!

    This was exaclty what I was looking for! I was in need for something like this for a script I'm working on (this is just a small but important UI feature of the script)!
    Thank you for posting this (so I was saved the tedious task of figuring out those calculations .... oh, the horror the horror)

    / Totte

  • PraxisPraxis Posts: 240
    Totte said:
    ...Thank you for posting this (so I was saved the tedious task of figuring out those calculations .... oh, the horror the horror)

    I'm glad it helped you.

    For "figuring out those calculations " I find mCasual's site very useful, e.g.:

    P.

  • MikeDMikeD Posts: 291

    I wish I had seen this script before I developed the Orbital Lights Plug in ... I used the "point at" feature to achieve the lights focus, but I see there is more elegant way to do this.... nice script by the way

Sign In or Register to comment.