Exemplo n.º 1
0
func setupScene() {
	var (
		err                    error
		meshFloorID, meshBoxID int
		bufRest                *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": "tex/cobbles.png",
		"dog":     "tex/dog.png",
		"cat":     "tex/cat.png",
		"gopher":  "tex/gopher.png",
		"crate":   "tex/crate.jpeg",
	})
	fxPulseID := ng.Core.Libs.Effects.AddNew()
	apputil.LibIDs.Fx["pulse"] = fxPulseID
	fxPulse := &ng.Core.Libs.Effects[fxPulseID]
	fxPulse.EnableTex2D(0).Tex_SetImageID(apputil.LibIDs.Img2D["crate"])
	fxPulse.EnableTex2D(1).Tex_SetImageID(apputil.LibIDs.Img2D["gopher"]).SetMixWeight(0.5)
	fxPulse.UpdateRoutine()

	dogMat := &ng.Core.Libs.Materials[apputil.LibIDs.Mat["dog"]]
	dogMat.FaceEffects.ByTag["top"] = apputil.LibIDs.Fx["cat"]
	dogMat.FaceEffects.ByTag["front"] = fxPulseID

	//	meshes / models
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 200); err != nil {
		panic(err)
	}
	if meshFloorID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}
	if meshBoxID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_box", ng.Core.Mesh.Desc.Cube); err != nil {
		panic(err)
	}
	bufRest.Add(meshFloorID)
	bufRest.Add(meshBoxID)

	scene := apputil.AddMainScene()
	floor := apputil.AddNode(scene, 0, meshFloorID, apputil.LibIDs.Mat["cobbles"], -1)
	floorID = floor.ID
	floor.Transform.SetScale(100)

	box := apputil.AddNode(scene, 0, meshBoxID, apputil.LibIDs.Mat["dog"], -1)
	boxID = box.ID
	box.Transform.Pos.Y = 2

	scene.ApplyNodeTransforms(0)
	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.Set(-2.5, 2, -7)
	camCtl.TurnRightBy(90)
	camCtl.EndUpdate()
}
Exemplo n.º 2
0
func setupScene() {
	var (
		err                     error
		meshFloorID, meshCubeID int
		bufRest                 *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": "tex/cobbles.png",
		"dog":     "tex/dog.png",
	})

	//	meshes / models
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 200); err != nil {
		panic(err)
	}

	if meshFloorID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}

	if meshCubeID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_cube", ng.Core.Mesh.Desc.Cube); err != nil {
		panic(err)
	}
	bufRest.Add(meshFloorID)
	bufRest.Add(meshCubeID)

	//	scene
	scene := apputil.AddMainScene()
	apputil.AddSkyMesh(scene, meshCubeID)
	floor := apputil.AddNode(scene, 0, meshFloorID, apputil.LibIDs.Mat["cobbles"], -1)
	floorID = floor.ID
	floor.Transform.SetScale(100)

	cubeID = apputil.AddNode(scene, 0, meshCubeID, apputil.LibIDs.Mat["sky"], -1).ID
	dog := apputil.AddNode(scene, 0, meshCubeID, apputil.LibIDs.Mat["dog"], -1)
	dogID = dog.ID
	dog.Transform.Pos.X, dog.Transform.Pos.Z = -2, 2
	scene.ApplyNodeTransforms(0)

	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.Set(-1, 2, -5)
	camCtl.EndUpdate()
}
Exemplo n.º 3
0
func setupExample_01_TriQuad() {
	var (
		err                   error
		meshTriID, meshQuadID int
		meshBuf               *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cat": "tex/cat.png",
		"dog": "tex/dog.png",
	})
	toggleOrange(apputil.LibIDs.Fx["dog"])

	//	meshes / models

	if meshTriID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_tri", ng.Core.Mesh.Desc.Tri); err != nil {
		panic(err)
	}
	if meshQuadID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_quad", ng.Core.Mesh.Desc.Quad); err != nil {
		panic(err)
	}

	if meshBuf, err = ng.Core.Mesh.Buffers.AddNew("meshbuf", 3+6); err != nil {
		panic(err)
	}
	if err = meshBuf.Add(meshTriID); err != nil {
		panic(err)
	}
	if err = meshBuf.Add(meshQuadID); err != nil {
		panic(err)
	}

	//	scene
	scene := apputil.AddMainScene()
	catTri = apputil.AddNode(scene, 0, meshTriID, apputil.LibIDs.Mat["cat"], -1).ID
	dogQuad = apputil.AddNode(scene, 0, meshQuadID, apputil.LibIDs.Mat["dog"], -1).ID
	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.TurnRightBy(90)
	camCtl.EndUpdate()
}
Exemplo n.º 4
0
func setupExample_02_EmptyGround() {
	var (
		err         error
		meshPlaneID int
		bufRest     *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": "tex/cobbles.png",
	})

	//	meshes / models
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 100); err != nil {
		panic(err)
	}
	if meshPlaneID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}

	bufRest.Add(meshPlaneID)

	//	scene
	scene := apputil.AddMainScene()
	floor := apputil.AddNode(scene, 0, meshPlaneID, apputil.LibIDs.Mat["cobbles"], -1)
	floorNodeID = floor.ID
	floor.Transform.SetPos(0.1, 0, -8)
	floor.Transform.SetScale(100)
	scene.ApplyNodeTransforms(floorNodeID)

	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.Y = 1.6
	camCtl.TurnRightBy(90)
	camCtl.EndUpdate()
}
Exemplo n.º 5
0
func setupScene() {
	var (
		err                    error
		meshFloorID, meshPyrID int
		bufRest                *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": "tex/cobbles.png",
		"dog":     "tex/dog.png",
		"cat":     "tex/cat.png",
	})

	fxBlueID := ng.Core.Libs.Effects.AddNew()
	fxBlue := &ng.Core.Libs.Effects[fxBlueID]
	fxBlue.EnableColor(-1).Color_SetRgb(0, 0.33, 0.66)
	fxBlue.EnableTex2D(-1).Tex_SetImageID(apputil.LibIDs.Img2D["dog"]).SetMixWeight(0.33)
	fxBlue.UpdateRoutine()

	fxGreenID := ng.Core.Libs.Effects.AddNew()
	fxGreen := &ng.Core.Libs.Effects[fxGreenID]
	fxGreen.EnableColor(-1).Color_SetRgb(0, 0.66, 0.33)
	fxGreen.UpdateRoutine()

	fxCat := &ng.Core.Libs.Effects[apputil.LibIDs.Fx["cat"]]
	fxCat.EnableOrangify(-1)
	fxCat.UpdateRoutine()

	fxPulseID := ng.Core.Libs.Effects.AddNew()
	apputil.LibIDs.Fx["pulse"] = fxPulseID
	fxPulse := &ng.Core.Libs.Effects[fxPulseID]
	fxPulse.EnableColor(0).Color_SetRgb(0.6, 0, 0)
	fxPulse.EnableColor(1).Color_SetRgb(0.9, 0.7, 0).SetMixWeight(0.25)
	fxPulse.UpdateRoutine()

	dogMat := &ng.Core.Libs.Materials[apputil.LibIDs.Mat["dog"]]
	dogMat.DefaultEffectID = fxBlueID
	dogMat.FaceEffects.ByID["t0"] = apputil.LibIDs.Fx["cat"]
	dogMat.FaceEffects.ByID["t1"] = fxPulseID
	dogMat.FaceEffects.ByID["t2"] = fxGreenID

	//	meshes / models
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 200); err != nil {
		panic(err)
	}
	if meshFloorID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}
	if meshPyrID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_pyr", ng.Core.Mesh.Desc.Pyramid); err != nil {
		panic(err)
	}
	bufRest.Add(meshFloorID)
	bufRest.Add(meshPyrID)

	scene := apputil.AddMainScene()
	apputil.AddSkyMesh(scene, meshPyrID)

	floor := apputil.AddNode(scene, 0, meshFloorID, apputil.LibIDs.Mat["cobbles"], -1)
	floorID = floor.ID
	floor.Transform.SetScale(100)

	pyr := apputil.AddNode(scene, 0, meshPyrID, apputil.LibIDs.Mat["dog"], -1)
	pyrID = pyr.ID
	pyr.Transform.Pos.Y = 2

	scene.ApplyNodeTransforms(0)
	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.Set(-1.5, 2, -4)
	camCtl.TurnRightBy(90)
	camCtl.EndUpdate()
}
Exemplo n.º 6
0
func setupExample_03_PyrCube() {
	var (
		err                                error
		meshPlaneID, meshPyrID, meshCubeID int
		bufFloor, bufRest                  *ng.MeshBuffer
	)

	urlPrefix := "http://dl.dropbox.com/u/136375/go-ngine/assets/"
	urlPrefix = ""

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": urlPrefix + "tex/cobbles.png",
		"crate":   "tex/crate.jpeg",
		"mosaic":  "tex/mosaic.jpeg",
		"gopher":  "tex/gopher.png",
		"dog":     "tex/dog.png",
		"cat":     "tex/cat.png",
	})

	//	meshes
	if bufFloor, err = ng.Core.Mesh.Buffers.AddNew("buf_floor", 6); err != nil {
		panic(err)
	}
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 36+12); err != nil {
		panic(err)
	}
	if meshPlaneID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}
	if meshPyrID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_pyramid", ng.Core.Mesh.Desc.Pyramid); err != nil {
		panic(err)
	}
	if meshCubeID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_cube", ng.Core.Mesh.Desc.Cube); err != nil {
		panic(err)
	}
	bufFloor.Add(meshPlaneID)
	bufRest.Add(meshCubeID)
	bufRest.Add(meshPyrID)

	fx := &ng.Core.Libs.Effects[apputil.LibIDs.Fx["cat"]]
	fx.EnableOrangify(-1).SetMixWeight(0.5)
	fx.UpdateRoutine()
	fx = &ng.Core.Libs.Effects[apputil.LibIDs.Fx["dog"]]
	fx.EnableTex2D(1).Tex_SetImageID(apputil.LibIDs.Img2D["gopher"]).SetMixWeight(0.5)
	fx.UpdateRoutine()
	ng.Core.Libs.Materials[apputil.LibIDs.Mat["crate"]].FaceEffects.ByTag["front"] = apputil.LibIDs.Fx["dog"]
	ng.Core.Libs.Materials[apputil.LibIDs.Mat["mosaic"]].FaceEffects.ByID["t3"] = apputil.LibIDs.Fx["cat"]

	//	scene / nodes
	scene := apputil.AddMainScene()
	apputil.AddSkyMesh(scene, meshCubeID)
	floor := apputil.AddNode(scene, 0, meshPlaneID, apputil.LibIDs.Mat["cobbles"], -1)
	floorNodeID = floor.ID
	floor.Transform.SetPos(0.1, 0, -8)
	floor.Transform.SetScale(1000)
	scene.ApplyNodeTransforms(floorNodeID)

	pyrNodeID = apputil.AddNode(scene, 0, meshPyrID, apputil.LibIDs.Mat["mosaic"], -1).ID
	boxNodeID = apputil.AddNode(scene, 0, meshCubeID, apputil.LibIDs.Mat["crate"], -1).ID
	scene.Node(pyrNodeID).Transform.Pos.Set(-2, 1.5, 2)
	scene.Node(boxNodeID).Transform.Pos.Set(2, 1.5, -2)
	scene.ApplyNodeTransforms(0)

	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.X, camCtl.Pos.Y, camCtl.Pos.Z = 0, 1.7, -10
	camCtl.TurnRightBy(90)
	camCtl.EndUpdate()
	if false {
		ng.Loop.Delay = 100 * time.Millisecond
	}
}
Exemplo n.º 7
0
func setupExample_04_PyrsCubes() {
	var (
		err               error
		meshPlaneID       int
		bufFloor, bufRest *ng.MeshBuffer
	)

	//	textures / materials
	apputil.AddTextureMaterials(map[string]string{
		"cobbles": "tex/cobbles.png",
		"crate":   "tex/crate.jpeg",
		"mosaic":  "tex/mosaic.jpeg",
		"cat":     "tex/cat.png",
		"dog":     "tex/dog.png",
		"gopher":  "tex/gopher.png",
	})

	fx := &ng.Core.Libs.Effects[apputil.LibIDs.Fx["mosaic"]]
	fx.EnableTex2D(1).Tex_SetImageID(apputil.LibIDs.Img2D["gopher"]).SetMixWeight(0.5)
	fx.UpdateRoutine()

	//	meshes / models
	if bufFloor, err = ng.Core.Mesh.Buffers.AddNew("buf_floor", 6); err != nil {
		panic(err)
	}
	if bufRest, err = ng.Core.Mesh.Buffers.AddNew("buf_rest", 36+12); err != nil {
		panic(err)
	}

	if meshPlaneID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_plane", ng.Core.Mesh.Desc.Plane); err != nil {
		panic(err)
	}
	modelPlaneDefaultID := ng.Core.Libs.Models.AddNew()
	ng.Core.Libs.Models[modelPlaneDefaultID].MatID = apputil.LibIDs.Mat["cobbles"]
	ng.Core.Libs.Meshes[meshPlaneID].DefaultModelID = modelPlaneDefaultID

	if meshPyrID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_pyramid", ng.Core.Mesh.Desc.Pyramid); err != nil {
		panic(err)
	}
	modelPyrDefaultID := ng.Core.Libs.Models.AddNew()
	ng.Core.Libs.Models[modelPyrDefaultID].MatID = apputil.LibIDs.Mat["mosaic"]
	ng.Core.Libs.Meshes[meshPyrID].DefaultModelID = modelPyrDefaultID
	modelPyrDogID := ng.Core.Libs.Models.AddNew()
	ng.Core.Libs.Models[modelPyrDogID].MatID = apputil.LibIDs.Mat["dog"]

	if meshCubeID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_cube", ng.Core.Mesh.Desc.Cube); err != nil {
		panic(err)
	}
	modelCubeDefaultID := ng.Core.Libs.Models.AddNew()
	ng.Core.Libs.Models[modelCubeDefaultID].MatID = apputil.LibIDs.Mat["crate"]
	ng.Core.Libs.Meshes[meshCubeID].DefaultModelID = modelCubeDefaultID
	modelCubeCatID = ng.Core.Libs.Models.AddNew()
	ng.Core.Libs.Models[modelCubeCatID].MatID = apputil.LibIDs.Mat["cat"]

	tmpMat := &ng.Core.Libs.Materials[apputil.LibIDs.Mat["crate"]]
	tmpMat.FaceEffects.ByTag["front"] = apputil.LibIDs.Fx["cat"]
	tmpMat.FaceEffects.ByTag["back"] = apputil.LibIDs.Fx["dog"]

	tmpMat = &ng.Core.Libs.Materials[ng.Core.Libs.Materials.AddNew()]
	tmpMat.DefaultEffectID = apputil.LibIDs.Fx["crate"]
	tmpMat.FaceEffects.ByTag["front"], tmpMat.FaceEffects.ByTag["back"] = apputil.LibIDs.Fx["cat"], apputil.LibIDs.Fx["cat"]
	tmpMat.FaceEffects.ByTag["top"], tmpMat.FaceEffects.ByTag["bottom"] = apputil.LibIDs.Fx["dog"], apputil.LibIDs.Fx["dog"]
	tmpMat.FaceEffects.ByTag["left"], tmpMat.FaceEffects.ByTag["right"] = apputil.LibIDs.Fx["gopher"], apputil.LibIDs.Fx["gopher"]
	apputil.LibIDs.Mat["mix"] = tmpMat.ID

	bufFloor.Add(meshPlaneID)
	bufRest.Add(meshCubeID)
	bufRest.Add(meshPyrID)

	//	scene
	scene := apputil.AddMainScene()
	apputil.AddSkyMesh(scene, meshPyrID)
	floor := apputil.AddNode(scene, 0, meshPlaneID, -1, -1)
	floorID = floor.ID
	floor.Transform.SetPos(0.1, 0, -8)
	floor.Transform.SetScale(10000)

	pyrID = apputil.AddNode(scene, 0, meshPyrID, -1, -1).ID
	boxID = apputil.AddNode(scene, 0, meshCubeID, -1, -1).ID
	for i := 0; i < initialCrateAdds; i++ {
		addCrates(scene, 3)
	}
	var f float64
	for i := 0; i < len(pyrIDs); i++ {
		tmpNode = apputil.AddNode(scene, 0, meshPyrID, -1, -1)
		pyrIDs[i] = tmpNode.ID
		if i > 1 {
			tmpNode.Render.ModelID = modelPyrDogID
		}
		f = float64(len(pyrIDs) - i)
		tmpNode.Transform.SetScale((f + 1) * 2)
		tmpNode.Transform.SetPos((f+3)*-4, (f+2)*3, (f+2)*14)
		if i > 1 {
			if i == 2 {
				f = 45
			} else {
				f = 135
			}
			tmpNode.Transform.Rot.Z = unum.DegToRad(f)
		} else {
			if i == 0 {
				f = 180
			} else {
				f = 90
			}
			tmpNode.Transform.Rot.X = unum.DegToRad(f)
		}
		if i == 1 {
			tmpNode.Transform.SetScale(100)
			tmpNode.Transform.Pos.Y += 100
		}
	}

	scene.ApplyNodeTransforms(0)
	apputil.RearView.Setup(scene.ID)
	if err = gui2d.Setup(); err != nil {
		panic(err)
	}

	camCtl := &apputil.SceneCam.Controller
	camCtl.BeginUpdate()
	camCtl.Pos.X, camCtl.Pos.Y, camCtl.Pos.Z = -3.57, 3.63, 19.53
	camCtl.TurnRightBy(-111)
	camCtl.EndUpdate()
}