Ola there...
BANano3D
This is also part of my bucket list things... .Now that I'm a little comfortable with the html5 games outlook using BANanoCreateJS, today I thought why not try 3D? This is going to be a long road. ThreeJS is kinda cumbersome but I will do my best to stick to what is quick and enable us to get the job done.
In this example, we just create a block randomly (on website refresh).
I have defined some skeleton classes so far just to talk to this example. This used WebGL and if your browser does not support WEBGL, well, watch this space, will do an example that uses the canvas soon.
So let's take a peek at the code.
Later!
BANano3D
This is also part of my bucket list things...
In this example, we just create a block randomly (on website refresh).
I have defined some skeleton classes so far just to talk to this example. This used WebGL and if your browser does not support WEBGL, well, watch this space, will do an example that uses the canvas soon.
So let's take a peek at the code.
B4X:
Sub Init
Math.Initialize("Math")
'do some webpage body settings
body = BANano.GetElement("#body")
body.SetStyle(BANano.ToJson(CreateMap("margin": "0", "overflow": "hidden")))
body.Empty
'lets get the window inner height and width
WindowInnerWidth = BANano.Window.InnerWidth
WindowInnerHeight = BANano.Window.InnerHeight
' this will hold all elements
scene.Initialize
' camera, what we will see
camera.Initialize(45, WindowInnerWidth / WindowInnerHeight, 0.1, 1000)
'create a renderer, set background and size
renderer.Initialize
renderer.setClearColor("0x000000", 1.0)
renderer.setSize(WindowInnerWidth, WindowInnerHeight)
Dim cubeGeometry As TDBoxGeometry
Dim rnd1 As Double = Math.RunMethod("random", Null)
Dim rnd2 As Double = Math.RunMethod("random", Null)
Dim rnd3 As Double = Math.RunMethod("random", Null)
rnd1 = 10 * rnd1
rnd2 = 10 * rnd2
rnd3 = 10 * rnd3
cubeGeometry.Initialize(rnd1, rnd2, rnd3)
'
Dim cubeMaterial As TDMeshNormalMaterial
cubeMaterial.Initialize
Dim cube As TDMesh
cube.Initialize(cubeGeometry.BoxGeometry, cubeMaterial.MeshNormalMaterial)
scene.add(cube.Mesh)
'
'position and point the camera to the center of the scene
camera.SetPosition(15, 16, 13)
camera.LookAt(scene.GetPosition)
'add the output of the renderer to the html element
body.Append(renderer.GetDomElement)
'render stuff
renderer.render(scene.Scene, camera.PerspectiveCamera)
End Sub
Later!