// Start is called once at the start of the demo.
Start is called once at the start of the demo.
// Start is called once at the start of the demo .
func (t *PhysicsSpheres) Start(a *app.App) {
	t.app = a
	a.Subscribe(window.OnKeyRepeat, t.onKey)
	a.Subscribe(window.OnKeyDown, t.onKey)
	axes := helper.NewAxes(1)
	a.Scene().Add(axes)
	pl := light.NewPoint(math32.NewColor("white"), 1.0)
	pl.SetPosition(0, 1, 0)
	a.Scene().Add(pl)
	l2 := light.NewDirectional(&math32.Color{1, 1, 1}, 0.5)
	l2.SetPosition(0, 0.1, 0)
	a.Scene().Add(l2)
	t.sim = physics.NewSimulation(a.Scene())
	t.gravity = physics.NewConstantForceField(&math32.Vector3{0, -0.98, 0})
	t.attractor = physics.NewAttractorForceField(&math32.Vector3{0, 1, 0}, 1)
	t.sim.AddForceField(t.gravity)
	tex2, err := texture.NewTexture2DFromImage(a.DirData() + "/images/smoke30.png")
	if err != nil {
		a.Log().Fatal("Error loading texture: %s", err)
	}
	t.anim = texture.NewAnimator(tex2, 6, 5)
	t.anim.SetDispTime(2 * 16666 * time.Microsecond)
	mat2 := material.NewStandard(&math32.Color{1, 1, 1})
	mat2.AddTexture(tex2)
	mat2.SetOpacity(0.5)
	mat2.SetTransparent(true)
	t.sprite = graphic.NewSprite(2, 2, mat2)
	t.sprite.SetPosition(0, 1, 0)
	t.sprite.SetVisible(false)
	a.Scene().Add(t.sprite)
	t.sphereGeom = geometry.NewSphere(0.1, 16, 8)
	texfileG := a.DirData() + "/images/ground2.jpg"
	texG, err := texture.NewTexture2DFromImage(texfileG)
	texG.SetRepeat(100, 100)
	texG.SetWrapS(gls.REPEAT)
	texG.SetWrapT(gls.REPEAT)
	if err != nil {
		a.Log().Fatal("Error loading texture: %s", err)
	}
	mat := material.NewStandard(&math32.Color{1, 1, 1})
	mat.SetTransparent(true)
	mat.SetOpacity(0.5)
	mat.AddTexture(texG)
	floorGeom := geometry.NewPlane(100, 100)
	floor := graphic.NewMesh(floorGeom, mat)
	floor.SetPosition(0, 0, 0)
	floor.SetRotation(-math32.Pi/2, 0, 0)
	a.Scene().Add(floor)
	floorBody := object.NewBody(floor)
	floorBody.SetShape(shape.NewPlane())
	floorBody.SetBodyType(object.Static)
	t.sim.AddBody(floorBody, "Floor")
	texfile := a.DirData() + "/images/uvgrid.jpg"
	tex3, err := texture.NewTexture2DFromImage(texfile)
	if err != nil {
		a.Log().Fatal("Error loading texture: %s", err)
	}
	t.matSphere = material.NewStandard(&math32.Color{1, 1, 1})
	t.matSphere.AddTexture(tex3)
	sphere2 := graphic.NewMesh(t.sphereGeom, t.matSphere)
	sphere2.SetPosition(0, 1, -0.02)
	a.Scene().Add(sphere2)
	rb2 := object.NewBody(sphere2)
	rb2.SetShape(shape.NewSphere(0.1))
	t.sim.AddBody(rb2, "Sphere2")
	sphere3 := graphic.NewMesh(t.sphereGeom, t.matSphere)
	sphere3.SetPosition(0.05, 1.2, 0.05)
	a.Scene().Add(sphere3)
	rb3 := object.NewBody(sphere3)
	rb3.SetShape(shape.NewSphere(0.1))
	t.sim.AddBody(rb3, "Sphere3")
	sphere4 := graphic.NewMesh(t.sphereGeom, t.matSphere)
	sphere4.SetPosition(-0.05, 1.4, 0)
	a.Scene().Add(sphere4)
	rb4 := object.NewBody(sphere4)
	rb4.SetShape(shape.NewSphere(0.1))
	t.sim.AddBody(rb4, "Sphere4")
}
func ( t * PhysicsSpheres ) Start ( a * app . App ) { t . app = a a . Subscribe ( window . OnKeyRepeat , t . onKey ) a . Subscribe ( window . OnKeyDown , t . onKey ) axes := helper . NewAxes ( 1 ) a . Scene ( ) . Add ( axes ) pl := light . NewPoint ( math32 . NewColor ( " " ) , 1.0 ) pl . SetPosition ( 0 , 1 , 0 ) a . Scene ( ) . Add ( pl ) l2 := light . NewDirectional ( & math32 . Color { 1 , 1 , 1 } , 0.5 ) l2 . SetPosition ( 0 , 0.1 , 0 ) a . Scene ( ) . Add ( l2 ) t . sim = physics . NewSimulation ( a . Scene ( ) ) t . gravity = physics . NewConstantForceField ( & math32 . Vector3 { 0 , - 0.98 , 0 } ) t . attractor = physics . NewAttractorForceField ( & math32 . Vector3 { 0 , 1 , 0 } , 1 ) t . sim . AddForceField ( t . gravity ) tex2 , err := texture . NewTexture2DFromImage ( a . DirData ( ) + " " ) if err != nil { a . Log ( ) . Fatal ( " " , err ) } t . anim = texture . NewAnimator ( tex2 , 6 , 5 ) t . anim . SetDispTime ( 2 * 16666 * time . Microsecond ) mat2 := material . NewStandard ( & math32 . Color { 1 , 1 , 1 } ) mat2 . AddTexture ( tex2 ) mat2 . SetOpacity ( 0.5 ) mat2 . SetTransparent ( true ) t . sprite = graphic . NewSprite ( 2 , 2 , mat2 ) t . sprite . SetPosition ( 0 , 1 , 0 ) t . sprite . SetVisible ( false ) a . Scene ( ) . Add ( t . sprite ) t . sphereGeom = geometry . NewSphere ( 0.1 , 16 , 8 ) texfileG := a . DirData ( ) + " " texG , err := texture . NewTexture2DFromImage ( texfileG ) texG . SetRepeat ( 100 , 100 ) texG . SetWrapS ( gls . REPEAT ) texG . SetWrapT ( gls . REPEAT ) if err != nil { a . Log ( ) . Fatal ( " " , err ) } mat := material . NewStandard ( & math32 . Color { 1 , 1 , 1 } ) mat . SetTransparent ( true ) mat . SetOpacity ( 0.5 ) mat . AddTexture ( texG ) floorGeom := geometry . NewPlane ( 100 , 100 ) floor := graphic . NewMesh ( floorGeom , mat ) floor . SetPosition ( 0 , 0 , 0 ) floor . SetRotation ( - math32 . Pi / 2 , 0 , 0 ) a . Scene ( ) . Add ( floor ) floorBody := object . NewBody ( floor ) floorBody . SetShape ( shape . NewPlane ( ) ) floorBody . SetBodyType ( object . Static ) t . sim . AddBody ( floorBody , " " ) texfile := a . DirData ( ) + " " tex3 , err := texture . NewTexture2DFromImage ( texfile ) if err != nil { a . Log ( ) . Fatal ( " " , err ) } t . matSphere = material . NewStandard ( & math32 . Color { 1 , 1 , 1 } ) t . matSphere . AddTexture ( tex3 ) sphere2 := graphic . NewMesh ( t . sphereGeom , t . matSphere ) sphere2 . SetPosition ( 0 , 1 , - 0.02 ) a . Scene ( ) . Add ( sphere2 ) rb2 := object . NewBody ( sphere2 ) rb2 . SetShape ( shape . NewSphere ( 0.1 ) ) t . sim . AddBody ( rb2 , " " ) sphere3 := graphic . NewMesh ( t . sphereGeom , t . matSphere ) sphere3 . SetPosition ( 0.05 , 1.2 , 0.05 ) a . Scene ( ) . Add ( sphere3 ) rb3 := object . NewBody ( sphere3 ) rb3 . SetShape ( shape . NewSphere ( 0.1 ) ) t . sim . AddBody ( rb3 , " " ) sphere4 := graphic . NewMesh ( t . sphereGeom , t . matSphere ) sphere4 . SetPosition ( - 0.05 , 1.4 , 0 ) a . Scene ( ) . Add ( sphere4 ) rb4 := object . NewBody ( sphere4 ) rb4 . SetShape ( shape . NewSphere ( 0.1 ) ) t . sim . AddBody ( rb4 , " " ) }
Start is called once at the start of the demo.
Start is called once at the start of the demo .
// Subscribe to key events //a.Camera().GetCamera().SetPosition // LookAt // Create axes helper // Add directional light from top // Create simulation and force fields // Create sprite texture and animator // Create sphere geometry // Create sphere texture // Create sphere material