mojo3d – unit of rotation?!

About Monkey 2 Forums Monkey 2 Programming Help mojo3d – unit of rotation?!

This topic contains 11 replies, has 5 voices, and was last updated by  Simon Armstrong 1 year, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #9362

    DruggedBunny
    Participant

    Been trying to get a basic 3d game template set up, but I’m struggling on the simplest of things: I can’t tell if entity rotations are in degrees or radians (as I suspect from some of the tests!)…

    The two attached screenshots show an attempt to simply rotate a cube 45 degrees on its vertical axis.

    One version assumes degrees, the other radians, the latter using a Degrees function to convert, but neither screenshot turns out at 45 degrees!

    I assume the error is at my end, but I’m stumped! Even tried assuming rotations are 0.0 – 1.0, but 0.25 was also wrong…

    Asides:

    1. Not sure if I should be checking for keypresses during OnRender, as that seems wrong going by mx1;
    2. Should RequestRender be at the start of OnRender, or at the end? Does it matter?
    #9365

    DruggedBunny
    Participant

    Aside #3, OT!

    Is it intentional that the forums don’t allow posting via a VPN? It either silently fails, or (as I’ve seen once) gives a message saying “Forbidden. Sender blacklisted”, with a “request number”…

    I can only post here if I specifically disable my VPN 🙁

    #9366

    Hezkore
    Participant

    It uses Radians.
    Your Degree function does it backwards, it should be.

    Oh and my VPN is on while posting this, so it should work.

    #9367

    Mark Sibly
    Keymaster

    Hi,

    It definitely uses radians, where ‘TwoPi’ is 360 degrees, ‘Pi’ is 180 degrees, Pi/2 is 90 degrees etc.

    The way I always remember how to do conversions like these is you first ‘normalize’ the quantity, ie: turn it into a 0…1 value, and then scale it by the ‘output’ range. So degrees/360.0 will give you a normalized 0…1 angle and multiplying by TwoPi will give you radians, ie: radians=degree/360.0*TwoPi. This is the same calculation Hezkore performs above.

    No idea about the VPN issue, perhaps your VPN provider (if there’s such a thing?) is indeed blacklisted?

    #9372

    DruggedBunny
    Participant

    Gah! That’ll teach me to copy/paste — I used http://wasted.nz/codearcs.php?code=510 !

    What’s the main reason for using radians instead of degrees now? I’m vaguely aware it has, er, beneficial properties… mathematically… but is pretty darn impossible to visualise a simple ‘turn by x amount’ from my end, whereas 0-360 is just like a compass. People talk about turning 45 degrees, 90 degrees, etc, in the real world.

    Not a major deal, I suppose, but it seems awkward and inefficient to have to call a function to get what I’m after. I wonder if the C++ compiler optimises the call away? I suppose the conversion has to happen somewhere if the GPU or 3D API is after radians…

    I use PIA for my VPN service (one of the biggest providers out there) and I haven’t run into this anywhere else — assume it’s built into the board software, though. Admittedly, I don’t really post much in general, but it’s a bit of a PITA to have to disable it just to post here — just realised I need to do that now!

    Thanks all!

    #9380

    DruggedBunny
    Participant

    Just  realised my two ‘asides’ got missed!

    1. Not sure if I should be checking for keypresses during OnRender, as that seems wrong going by mx1;
    2. Should RequestRender be at the start of OnRender, or at the end? Does it matter?

    EDIT: Interestingly, VPN wasn’t blocked this time, just realised on hitting Submit that I hadn’t disabled it. Must be particular IPs that are blocked.

    #9393

    Mark Sibly
    Keymaster

    What’s the main reason for using radians instead of degrees now?

    Because it’s what mojo3d and all cpus and fpus and the standard C libs and a ton of equations and algorithms and 3rd party libs and 99% of programing languages and apis etc etc etc  use – suck it up! I’ll probably add some DegreesToRadians style functions to math.monkey2 eventually though.

    For more ‘mathsy’ reaons, google ‘why use radians?’ for eg:

    Why Radian Measure Makes Life Easier In Mathematics And Physics

    Not sure if I should be checking for keypresses during OnRender, as that seems wrong going by mx1;

    It’s fine.

    Should RequestRender be at the start of OnRender, or at the end? Does it matter?

    Doesn’t matter.

    #9396

    Simon Armstrong
    Participant

    Reasons why integral values for rotation could be considered better:

    1. exact precision of degrees, with radians the only angle that can be stated precisely is 0
    2. fractions of Math.Pi are neither human readable, integral or rational
    3. navigation has been using degrees for longitude, latitude, bearing etc. since beginning of modern time
    4. integers rock, floats and doubles don’t
    5. rational numbers rock, irrational numbers don’t

    /opinion

    #9406

    DruggedBunny
    Participant

    it’s what mojo3d and all cpus and fpus and the standard C libs and a ton of equations and algorithms and 3rd party libs and 99% of programing languages and apis etc etc etc use – suck it up!

    Yeah, but apart from that… (Ha ha/ouchie.)

    Is a set of degree variants do-able for people who aren’t actually CPUs/GPUs/math libraries? 😛

    Can be worked around if not, obviously…

    #9450

    cocon
    Participant

    Yeah from what I have experienced if you go for radians you will have to reference the PI a lot, which is not an exactly user friendly way.

    For example
    0
    Pi = 180
    Pi * 2 = 360

    Another way is to have extension methods and have the alternative option of feeding either degrees or radians.
    camera.RotateRadians(Pi, 0, 0)

    #9477

    Mark Sibly
    Keymaster

    Another way is to have extension methods and have the alternative option of feeding either degrees or radians.

    I’m not keen on the ‘write 2 of everything’ approach, esp. giving there are gonna be ton of little methods like rx,ry,rz,worldrx,worldry,worldrz and setters and setrotation and getrotation etc. I’m also not keen on dynamically configurable angular units (eg: UseDegrees/UseRadians) for performance reasons, although, yes, 99% of users don’t need to care about performance anymore (on desktop anyway).

    However, after having talked the issue over with several of the programmers here, I do now agree now that degrees is the better default angular unit for mojo3d and will be changing entity rotation units ASAP.

    But I am going to leave monkey.math and std.geom angular units using radians. I would prefer to have ALL angles in monkey2 expressed in the same angular units (and if I had to pick one it’d still be radians for reasons given above) but maintaining consistency in this case probably isn’t worth scarificing the ease of use degrees gives you.

    #9479

    Simon Armstrong
    Participant

    Darn, I was hoping you were going to declare 65536 was the new order to keep wrap functions and normal packing optimal.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.