About Monkey 2 › Forums › Monkey 2 Programming Help › Entity pitch/roll/yaw?
This topic contains 5 replies, has 3 voices, and was last updated by
DruggedBunny
1 year, 4 months ago.
-
AuthorPosts
-
November 30, 2017 at 11:05 pm #12045
How do you get an entity’s pitch/roll/yaw in mojo3d?
The only references I can find are buried in a Mat3<T>, in which the GetPitch, etc, methods seem to be located, but entities’ Matrix properties seem to be an AffineMat4f and er.. I…
Could we have an Entity.Pitch/Roll/Yaw? (Preferably in degrees, ahem… )
I was actually kinda hoping that this would work for resetting a camera to absolute world 0.0, 0.0, 0.0 with default rotation!
Monkey123camera.Position = Null ' This works!camera.Rotation = Null ' Entity.Rotation is not a thing. Boo!Even had a vague attempt at casting, but jeeeez (no go!)…
Monkey1Print Mat3<Float> (camera.Matrix).GetPitch () ' Nuh-uh...December 1, 2017 at 3:04 am #12048Look at monkey2\modules\mojo3d\scene\entityexts.monkey2.
Maybe Rx / Ry / Rz extension properties are what you searching for.
Also Vec3 struct have Yaw and Pitch properties, but suddenly haven’t Roll.
I was actually kinda hoping that this would work for resetting a camera to absolute world 0.0, 0.0, 0.0 with default rotation!
Yes, you can assing null to Vectors…
More correct way is to set vectors:
Monkey123camera.Position=New Vec3f( 0 )camera.Rotation=New Vec3f( 0 )December 1, 2017 at 7:31 pm #12057camera.Rotation = Null ‘ Entity.Rotation is not a thing. Boo!
This should work! I just tested entity.Rotation by adding this at the top of OnRender in (very latest) ducks demo:
Monkey123Local yrot:=_ducks[0].Rotation.y_ducks[0].Rotation=New Vec3f( 0,yrot+1,0 )_ducks[0].Rotation=Null also works here too…
[edit]
Maybe Rx / Ry / Rz extension properties are what you searching for.
Bingo. Just went to add pitch, yaw, roll, and they’re already in there as Rx, Ry, Rz, LocalRx, LocalRy, LocalRz. I may add Pitch, Yaw, Roll equivalents too…will think about it.
Also Vec3 struct have Yaw and Pitch properties, but suddenly haven’t Roll.
Vec3 has never had roll – vectors in general can’t have roll as they are infinitely thin, ie: there is no ‘sideways’ *to* roll! Matrices can though as they really represent an entire ‘space’.
December 2, 2017 at 1:16 am #12065Ah, cool — I don’t think the IDE picks up .Rotation then! It does indeed work, though, thought I’d tried it!
Just added to the scene/model viewer below. Been using various downloaded models, but mainly the .fbx versions of these two from the new Google Poly:
https://poly.google.com/view/bmDjSxceaEE
https://poly.google.com/view/2binsxeOBve(You have to mess about with positioning in-demo to see them properly!)
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195#Import "<std>"#Import "<mojo3d>"#Import "<mojo3d-loaders>"#Import "<assimp>"Using std..Using mojo..Using mojo3d..' ----------------------------------------' Application name...' ----------------------------------------Const FORMATS_3D:String = "fbx, obj, b3d, gltf" ' More available!Global AppName:String = "Viewer 0.0000000000000001... pre-alpha"Function CenterModel:Void (model:Model, scale:Float)' Not bulletproof! 10000 hard-coded, not sure how you get around this...model.Mesh.FitVertices (New Boxf (-10000, 0, -10000, 10000, scale, 10000), True)model.Position = NullEndClass Game Extends WindowConst SHIFT_BOOST:Float = 5.0Field scene:SceneField camera:CameraField light:LightField camera_boost:Float = 1.0Field modelpath:StringField model:ModelField scale:Float = 1.0Field copies:Stack <Model>Method New (title:String, width:Int, height:Int, flags:WindowFlags)Super.New (title, width, height, flags)scene = Scene.GetCurrent ()scene.ClearColor = New Color (0.1, 0.2, 0.75)scene.AmbientLight = New Color (0.5, 0.5, 0.5)camera = New Camera' Camera settings...camera.Near = 0.1camera.FOV = 90LoadModel ()light = New Lightlight.CastsShadow = Truelight.Color = New Color (0.95, 0.975, 1.0)light.Range = 1000light.Move (-500, 500, -500)light.PointAt (model)End' This slightly dirty almost-self-contained utility method loads' directly into model:Model field -- ESC from load requester exits app!Method LoadModel:Void ()Local failed:Bool = FalseRepeatIf failed Then Notify ("NOOOOooooo...", "Failed to load " + StripDir (modelpath), True)modelpath = RequestFile ("Select a model, or Cancel/ESC to exit...", FORMATS_3D, False, CurrentDir ())If Not modelpath Then App.Terminate ()ChangeDir (ExtractDir (modelpath))If model Then model.Destroy ()model = Model.Load (modelpath)If Not model Then failed = TrueUntil modelCenterModel (model, 5)scale = 1.0model.Scale = New Vec3f (scale, scale, scale)camera.Position = Nullcamera.Rotation = NullEndMethod UpdateGame:Void ()model.Scale = New Vec3f (scale, scale, scale)EndMethod ProcessInput:Void ()If Keyboard.KeyHit (Key.Space) Then light.CastsShadow = Not light.CastsShadowIf Keyboard.KeyDown (Key.LeftShift)camera_boost = SHIFT_BOOSTElsecamera_boost = 1.0EndifIf Keyboard.KeyHit (Key.Escape)LoadModel ()EndifIf Keyboard.KeyDown (Key.A)camera.Move (0.0, 0.0, 0.1 * camera_boost)EndifIf Keyboard.KeyDown (Key.Z)camera.Move (0.0, 0.0, -0.1 * camera_boost)EndifIf Keyboard.KeyDown (Key.Left)camera.Rotate (0.0, 1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Right)camera.Rotate (0.0, -1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Up)camera.Rotate (1.0, 0.0, 0.0, True)EndifIf Keyboard.KeyDown (Key.Down)camera.Rotate (-1.0, 0.0, 0.0, true)EndifIf Keyboard.KeyDown (Key.Minus) Or Keyboard.KeyDown (Key.KeypadMinus)scale = scale - 0.1EndifIf Keyboard.KeyDown (Key.Equals) Or Keyboard.KeyDown (Key.KeypadPlus)scale = scale + 0.1EndifEndMethod OnRender (canvas:Canvas) OverrideProcessInput ()UpdateGame ()RequestRender ()scene.Render (canvas, camera)canvas.DrawText ("Camera controls: Cursors, plus A/Z (Shift for boost!)", 20.0, 20.0)canvas.DrawText ("ESC to load new model or exit (close dialog)...", 20.0, 40.0)canvas.DrawText ("Model scale (-/+ to change): " + scale, 20.0, 80.0)EndEndFunction Main ()Local width:Int = 1024Local height:Int = 768Local flags:WindowFlags = WindowFlags.Center' Local width:Int = 1920' Local height:Int = 1080' Local flags:WindowFlags = WindowFlags.FullscreenNew AppInstanceNew Game (AppName, width, height, flags)App.Run ()EndI find with these two models that scaling up to ~10.0 works nicely (see on-screen keys). You may have to ‘back up’ when scaling up!
You can hit ESC to load a new model… seems to work well. ESC/Cancel on the file requester to exit.
December 2, 2017 at 1:17 am #12066Oh, would definitely prefer Pitch/Yaw/Roll methods… Rx/Ry/Rz don’t exactly jump out!
December 2, 2017 at 1:20 am #12067Is there a better/more robust way to implement my <span class=”crayon-v”>CenterModel</span>, by the way?
-
AuthorPosts
You must be logged in to reply to this topic.