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.
-
AuthorPosts
-
July 16, 2017 at 8:44 pm #9362
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…
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Function Degrees:Float (radian:Float)Return radian * (180.0 / Pi)EndClass Game Extends WindowField scene:SceneField camera:CameraField light:LightField cube:ModelField cubemesh:MeshField cubematerial:MaterialMethod New (title:String, width:Int, height:Int, flags:WindowFlags)Super.New (title, width, height, flags)scene = Scene.GetCurrent ()camera = New Cameracamera.Move (0, 0, -2)camera.Rotate (0, 0, 0)light = New Lightlight.Move (-10, 10, -10)light.Rotate (0, -90, 0)cubemesh = Mesh.CreateBox (New Boxf (-0.5, 0.5, 0.5, 0.5, -0.5, -0.5))cubematerial = New PbrMaterial (Color.Red)cube = New Model (cubemesh, cubematerial)cube.Rotate (0.0, Degrees (45), 0.0)EndMethod OnRender (canvas:Canvas) OverrideIf Keyboard.KeyHit (Key.Escape) Then App.Terminate ()If Keyboard.KeyDown (Key.A)camera.Move (0.0, 0.0, 0.1)EndifIf Keyboard.KeyDown (Key.Z)camera.Move (0.0, 0.0, -0.1)Endif'cube.Rotate (0.0, 0.01, 0.0)scene.Render (canvas, camera)RequestRender ()EndEndFunction Main ()Local title:String = "My 3D Game"Local width:Int = 640Local height:Int = 480Local flags:WindowFlags=WindowFlags.Center ' FullscreenNew AppInstanceNew Game (title, width, height, flags)App.Run ()EndAsides:
- Not sure if I should be checking for keypresses during OnRender, as that seems wrong going by mx1;
- Should RequestRender be at the start of OnRender, or at the end? Does it matter?
Attachments:
July 16, 2017 at 8:47 pm #9365Aside #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
July 16, 2017 at 9:37 pm #9366It uses Radians.
Your Degree function does it backwards, it should be.Monkey123Function Degrees:Float (radian:Float)Return radian * (Pi / 180.0)EndOh and my VPN is on while posting this, so it should work.
July 16, 2017 at 9:54 pm #9367Hi,
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?
July 16, 2017 at 10:29 pm #9372Gah! 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!
July 17, 2017 at 12:25 pm #9380Just realised my two ‘asides’ got missed!
- Not sure if I should be checking for keypresses during OnRender, as that seems wrong going by mx1;
- 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.
July 17, 2017 at 9:56 pm #9393What’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.
July 18, 2017 at 1:30 am #9396Reasons why integral values for rotation could be considered better:
- exact precision of degrees, with radians the only angle that can be stated precisely is 0
- fractions of Math.Pi are neither human readable, integral or rational
- navigation has been using degrees for longitude, latitude, bearing etc. since beginning of modern time
- integers rock, floats and doubles don’t
- rational numbers rock, irrational numbers don’t
/opinion
July 18, 2017 at 12:25 pm #9406it’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…
July 20, 2017 at 5:29 pm #9450Yeah 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 = 360Another way is to have extension methods and have the alternative option of feeding either degrees or radians.
camera.RotateRadians(Pi, 0, 0)July 23, 2017 at 1:30 am #9477Another 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.
July 23, 2017 at 2:22 am #9479Darn, I was hoping you were going to declare 65536 was the new order to keep wrap functions and normal packing optimal.
-
AuthorPosts
You must be logged in to reply to this topic.

