About Monkey 2 › Forums › Monkey 2 Programming Help › Some letterbox 3d
This topic contains 2 replies, has 2 voices, and was last updated by
Mark Sibly
1 year, 2 months ago.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
January 24, 2018 at 4:13 am #13195Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788Namespace myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Using mojo3d..Const VirtualRes:=New Vec2i( 800,600 )Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _donut:ModelMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )Layout="letterbox"SetConfig( "MOJO3D_RENDERER","forward" )_scene=New Scene_scene.ClearColor=Color.Sky'create camera'_camera=New Camera_camera.Viewport=New Recti( 0,0,VirtualRes )_camera.Move( 0,10,-10 )New FlyBehaviour( _camera )'create light'_light=New Light_light.Rotate( 75,15,0 )'create donut - metallic silver...Local material:=New PbrMaterial( Color.Silver,1,0.5 )'_donut=Model.CreateTorus( 2,.5,48,24,material )_donut=Model.CreateSphere( 1,24,12,material )'Torus( 2,.5,48,24,material )_donut.Move( 0,10,0 )EndMethod OnMeasure:Vec2i() OverrideReturn VirtualResEndMethod OnRender( canvas:Canvas ) OverrideRequestRender()_donut.Rotate( .1,.2,.3 )_scene.Update()_camera.Render( canvas )canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndJanuary 24, 2018 at 4:29 am #13196
This will render stretched…
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160Namespace plane#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"'#Import "source/PlaneControl"'#Import "textures/"'#Import "assets/"'#Import "render/plane_Oc.png"'#Import "models/plane.glb"Using std..Using mojo..Using mojo3d..Class MyWindow Extends WindowField _res :Vec2iField _scene:SceneField _camera:CameraField _light:Light' Field _fog:FogEffectField _water:ModelField _plane:ModelField _pivot:Model 'Needs to be a Model instead of Entity otherwise the plane isn't rendered!Field _camTarget:EntityField test:ModelMethod New()Super.New( "Toy Plane", 1280, 480, WindowFlags.Resizable | WindowFlags.HighDPI )_res = New Vec2i( Width, Height )Print _resLayout = "letterbox"_scene=Scene.GetCurrent()_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )_scene.EnvTexture = _scene.SkyTexture_scene.FogColor = New Color(0.69, 0.78, 0.82, 0.3 )_scene.FogFar = 5000_scene.FogNear = 1'create light_light=New Light_light.Rotate( 45, 45, 0 )_light.CastsShadow = True'create water material' Local waterMaterial:=New WaterMaterial'' waterMaterial.ScaleTextureMatrix( 200,200 )' waterMaterial.ColorFactor=New Color( 0.05, 0.25, 0.3 )' waterMaterial.Roughness=0'' waterMaterial.NormalTextures=New Texture[](' Texture.Load( "asset::water_normal0.png",TextureFlags.WrapST | TextureFlags.FilterMipmap ),' Texture.Load( "asset::water_normal1.png",TextureFlags.WrapST | TextureFlags.FilterMipmap ) )'' waterMaterial.Velocities=New Vec2f[](' New Vec2f( .01,.03 ),' New Vec2f( .02,.05 ) )'create water' _water=Model.CreateBox( New Boxf( -10000,-1,-10000,10000,0,10000 ),1,1,1,waterMaterial )'create bloom' Local _bloom := New BloomEffect( 2 )' _scene.AddPostEffect( _bloom )'create main pivot' _pivot = New Model'create airplane' _plane = Model.LoadBoned( "asset::plane_combined.glb" )' _plane.Animator.Animate( 0 )' _plane.Parent = _pivot' _plane.Position = New Vec3f' Local mat := Cast<PbrMaterial>( _plane.Materi )' Local mat := New PbrMaterial( Color.LightGrey, 0.1, 0.1, True )' Local tex := Texture.Load( "asset::plane_Oc.png", TextureFlags.FilterMipmap )' mat.OcclusionTexture = tex' Print _plane.Materials.Length' Print ( _plane.Material? "true" Else "False" )' _plane.Material = mat'create camera target_camTarget = New Entity( _plane )' _camTarget = Model.CreateSphere( 0.25, 12, 12, New PbrMaterial( Color.Red ) )_camTarget.Parent = _plane_camTarget.Position = New Vec3f( 0, 0, 10 )'create camera_camera=New Camera( _pivot )_camera.Near=.1_camera.Far=10000' _camera.FOV = 60_camera.Move( 0,3,-12 )Print _camera.Aspect'Control component' Local control := _pivot.AddComponent<PlaneControl>()' control.plane = _plane' control.camera = _camera' control.target = _camTarget' _pivot.Position = New Vec3f( 0, 6, 0 )Local ball := Model.CreateSphere( 2, 24, 24, New PbrMaterial( Color.Red, 0.1, 0.25 ) )ball.Move( 0, 4, 0)EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()' _water.Position=New Vec3f( Round(_camera.Position.x/2000)*2000,0,Round(_camera.Position.z/2000)*2000 )_camera.WorldPointAt( _camTarget.Position )' _scene.Update()_camera.Render( canvas )canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )End'Method OnMeasure:Vec2i() OverrideReturn _resEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndClass Entity ExtensionMethod WorldPointAt( target:Vec3f,up:Vec3f=New Vec3f( 0,1,0 ) )Local k:=(target-Position).Normalize()Local i:=up.Cross( k ).Normalize()Local j:=k.Cross( i )Basis=New Mat3f( i,j,k )EndEndJanuary 24, 2018 at 4:39 am #13197Add a ‘_camera.Viewport=Rect’ just after you create camera.
Or better yet, use ‘_camera.View=Self’ instead as this will be able to handle resizable views too.
Cameras currently draw to the entire canvas viewport regardless of what camera viewport is set to (but DO use the camera viewport to calculate projection matrix based on FOV) – this may change when I start messing around with multiple cameras, child views etc.
For now, safest thing to do is to attach view to camera.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.