コード例 #1
0
ファイル: gui2d.go プロジェクト: Raven67854/go-ngine
func (me *Gui2D) Setup() (err error) {
	var (
		meshBuf    *ng.MeshBuffer
		quadMeshID int
	)
	sceneID := ng.Core.Libs.Scenes.AddNew()
	scene := &ng.Core.Libs.Scenes[sceneID]
	me.View = SceneCanvas.AddNewView("Scene")
	rts := me.View.Technique_Scene()
	rts.Batch.Enabled, me.Cam = false, &rts.Camera
	me.Cam.Perspective.Enabled = false
	me.View.RenderStates.ClearColor.Set(0.75, 0.25, 0.1, 1)
	me.View.Port.SetAbsolute(8, 8, 64, 64) //SetRel(0.02, 0.04, 0.125, 0.222)
	me.Cam.SetScene(sceneID)
	if meshBuf, err = ng.Core.Mesh.Buffers.AddNew("buf_quad", 6); err != nil {
		return
	}
	if quadMeshID, err = ng.Core.Libs.Meshes.AddNewAndLoad("mesh_quad", ng.Core.Mesh.Desc.Quad); err != nil {
		return
	}
	if err = meshBuf.Add(quadMeshID); err != nil {
		return
	}

	me.DogNodeID = scene.AddNewChildNode(0, quadMeshID)
	dog := scene.Node(me.DogNodeID)
	dog.Render.MatID = LibIDs.Mat["dog"]
	dog.Transform.SetScale(0.85)
	dog.Transform.Rot.Z = unum.DegToRad(90)

	me.CatNodeID = scene.AddNewChildNode(0, quadMeshID)
	cat := scene.Node(me.CatNodeID)
	cat.Render.MatID = LibIDs.Mat["cat"]
	cat.Transform.SetScale(0.85)
	cat.Transform.Rot.Z = unum.DegToRad(90)

	dog.Transform.Pos.Z = 0.1
	cat.Transform.Pos.Z = 0.11
	scene.ApplyNodeTransforms(me.DogNodeID)
	scene.ApplyNodeTransforms(me.CatNodeID)
	return
}
コード例 #2
0
ファイル: main.go プロジェクト: Raven67854/go-ngine
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(155)
	camCtl.EndUpdate()
}