// 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 *Earth) Start(a *app.App) {
	t.a = a
	a.AmbLight().SetIntensity(1)
	skybox, err := graphic.NewSkybox(graphic.SkyboxData{
		a.DirData() + "/images/space/dark-s_", "jpg",
		[6]string{"px", "nx", "py", "ny", "pz", "nz"}})
	if err != nil {
		panic(err)
	}
	a.Scene().Add(skybox)
	dir1 := light.NewDirectional(&math32.Color{1, 1, 1}, 0.9)
	dir1.SetPosition(0, 0, 100)
	a.Scene().Add(dir1)
	t.a.Renderer().AddShader("shaderEarthVertex", shaderEarthVertex)
	t.a.Renderer().AddShader("shaderEarthFrag", shaderEarthFrag)
	t.a.Renderer().AddProgram("shaderEarth", "shaderEarthVertex", "shaderEarthFrag")
	newTexture := func(path string) *texture.Texture2D {
		tex, err := texture.NewTexture2DFromImage(path)
		if err != nil {
			a.Log().Fatal("Error loading texture: %s", err)
		}
		tex.SetFlipY(false)
		return tex
	}
	texDay := newTexture(a.DirData() + "/images/earth_clouds_big.jpg")
	texSpecular := newTexture(a.DirData() + "/images/earth_spec_big.jpg")
	texNight := newTexture(a.DirData() + "/images/earth_night_big.jpg")
	matEarth := NewEarthMaterial(&math32.Color{1, 1, 1})
	matEarth.SetShininess(20)
	matEarth.AddTexture(texDay)
	matEarth.AddTexture(texSpecular)
	matEarth.AddTexture(texNight)
	geom := geometry.NewSphere(1, 32, 16)
	t.sphere = graphic.NewMesh(geom, matEarth)
	a.Scene().Add(t.sphere)
	texSun, err := texture.NewTexture2DFromImage(a.DirData() + "/images/lensflare0_alpha.png")
	if err != nil {
		a.Log().Fatal("Error loading texture: %s", err)
	}
	sunMat := material.NewStandard(&math32.Color{1, 1, 1})
	sunMat.AddTexture(texSun)
	sunMat.SetTransparent(true)
	sun := graphic.NewSprite(10, 10, sunMat)
	sun.SetPositionZ(20)
	a.Scene().Add(sun)
	axes := helper.NewAxes(5)
	a.Scene().Add(axes)
}
func ( t * Earth ) Start ( a * app . App ) { t . a = a a . AmbLight ( ) . SetIntensity ( 1 ) skybox , err := graphic . NewSkybox ( graphic . SkyboxData { a . DirData ( ) + " " , " " , [ 6 ] string { " " , " " , " " , " " , " " , " " } } ) if err != nil { panic ( err ) } a . Scene ( ) . Add ( skybox ) dir1 := light . NewDirectional ( & math32 . Color { 1 , 1 , 1 } , 0.9 ) dir1 . SetPosition ( 0 , 0 , 100 ) a . Scene ( ) . Add ( dir1 ) t . a . Renderer ( ) . AddShader ( " " , shaderEarthVertex ) t . a . Renderer ( ) . AddShader ( " " , shaderEarthFrag ) t . a . Renderer ( ) . AddProgram ( " " , " " , " " ) newTexture := func ( path string ) * texture . Texture2D { tex , err := texture . NewTexture2DFromImage ( path ) if err != nil { a . Log ( ) . Fatal ( " " , err ) } tex . SetFlipY ( false ) return tex } texDay := newTexture ( a . DirData ( ) + " " ) texSpecular := newTexture ( a . DirData ( ) + " " ) texNight := newTexture ( a . DirData ( ) + " " ) matEarth := NewEarthMaterial ( & math32 . Color { 1 , 1 , 1 } ) matEarth . SetShininess ( 20 ) matEarth . AddTexture ( texDay ) matEarth . AddTexture ( texSpecular ) matEarth . AddTexture ( texNight ) geom := geometry . NewSphere ( 1 , 32 , 16 ) t . sphere = graphic . NewMesh ( geom , matEarth ) a . Scene ( ) . Add ( t . sphere ) texSun , err := texture . NewTexture2DFromImage ( a . DirData ( ) + " " ) if err != nil { a . Log ( ) . Fatal ( " " , err ) } sunMat := material . NewStandard ( & math32 . Color { 1 , 1 , 1 } ) sunMat . AddTexture ( texSun ) sunMat . SetTransparent ( true ) sun := graphic . NewSprite ( 10 , 10 , sunMat ) sun . SetPositionZ ( 20 ) a . Scene ( ) . Add ( sun ) axes := helper . NewAxes ( 5 ) a . Scene ( ) . Add ( axes ) }
Start is called once at the start of the demo.
Start is called once at the start of the demo .
// Create Skybox // Adds directional front light // Create custom shader // Helper function to load a texture and handle errors // Create earth textures //texBump, err := newTexture(a.DirData() + "/images/earth_bump_big.jpg") // Create custom material using the custom shader //matEarth.SetSpecularColor(&math32.Color{0., 1, 1}) //matEarth.SetColor(&math32.Color{0.8, 0.8, 0.8}) // Create sphere // Create sun sprite // Add axes helper //// Create circular sphere section (uncomment to try it out) //geomRad := geometry.NewSphere(1.001, 32, 32, 0, 2 * math32.Pi, 0, 0.03 * math32.Pi) //mat := material.NewPhong(&math32.Color{1,0,0}) //mat.SetOpacity(0.5) //mat.SetTransparent(true) //mesh := graphic.NewMesh(geomRad, mat) //mesh.SetRotationX(90 * math32.Pi/180) //mesh.SetRotationY(10 * math32.Pi/180) //t.sphere.Add(mesh)