예제 #1
0
파일: knight.go 프로젝트: floffel03/gohorde
func (app *Application) mainLoop(fps float32) {
	app.curFps = fps
	//fmt.Println(app.curFps)

	app.animTime += 1.0 / app.curFps

	// Do animation blending
	horde3d.SetModelAnimParams(app.knight, 0, app.animTime*24.0, app.weight)
	horde3d.SetModelAnimParams(app.knight, 1, app.animTime*24.0, 1.0-app.weight)

	// Animate particle systems (several emitters in a group node)
	cnt := horde3d.FindNodes(app.particleSys, "", horde3d.NodeTypes_Emitter)
	for i := 0; i < cnt; i++ {
		horde3d.AdvanceEmitterTime(horde3d.GetNodeFindResult(i), 1.0/app.curFps)
	}

	// Set camera parameters
	app.cam.SetTransform(app.x, app.y, app.z, app.rx, app.ry, 0, 1, 1, 1)

	// Show stats
	// Show logo
	ww := float32(app.cam.NodeParamI(horde3d.Camera_ViewportWidthI)) /
		float32(app.cam.NodeParamI(horde3d.Camera_ViewportHeightI))
	ovLogo := []float32{ww - 0.4, 0.8, 0, 1, ww - 0.4, 1, 0, 0, ww, 1, 1, 0, ww, 0.8, 1, 1}
	horde3d.ShowOverlays(ovLogo, 4, 1.0, 1.0, 1.0, 1.0, app.logoMatRes, 0)
	horde3d.ShowText("test", 0.03, 0.24, 0.026, 1, 1, 1, app.fontMatRes)
	// Render scene
	horde3d.Render(app.cam)

	// Finish rendering of frame
	horde3d.FinalizeFrame()

	// Remove all overlays
	horde3d.ClearOverlays()

	// Write all messages to log file
	//horde3d.DumpMessages()
}
예제 #2
0
파일: knight.go 프로젝트: floffel03/gohorde
func (app *Application) init() bool {
	app.title = "Horde3D Knight Sample - Go Implementation"
	app.contentDir = "../content"
	app.keys = make([]bool, 320)
	app.prevKeys = make([]bool, 320)

	app.x = 5
	app.y = 3
	app.z = 19
	app.rx = 7
	app.ry = 15
	app.velocity = 10.0
	app.curFps = 30

	app.animTime = 0
	app.weight = 1.0
	app.cam = 0

	// Initialize engine
	if !horde3d.Init() {
		horde3d.DumpMessages()
		return false
	}

	// Set options
	horde3d.SetOption(horde3d.Options_LoadTextures, 1)
	horde3d.SetOption(horde3d.Options_TexCompression, 0)
	horde3d.SetOption(horde3d.Options_FastAnimation, 0)
	horde3d.SetOption(horde3d.Options_MaxAnisotropy, 4)
	horde3d.SetOption(horde3d.Options_ShadowMapSize, 2048)
	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)

	// Add resources
	// Pipelines
	app.hdrPipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/hdr.pipeline.xml", 0)
	app.forwardPipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/forward.pipeline.xml", 0)
	// Overlays
	app.fontMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/font.material.xml", 0)
	app.panelMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/panel.material.xml", 0)
	app.logoMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/logo.material.xml", 0)
	// Environment
	envRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/sphere/sphere.scene.xml", 0)
	// Knight
	knightRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/knight/knight.scene.xml", 0)
	knightAnim1Res := horde3d.AddResource(horde3d.ResTypes_Animation, "animations/knight_order.anim", 0)
	knightAnim2Res := horde3d.AddResource(horde3d.ResTypes_Animation, "animations/knight_attack.anim", 0)
	// Particle system
	particleSysRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph,
		"particles/particleSys1/particleSys1.scene.xml", 0)
	// Load resources
	horde3d.LoadResourcesFromDisk(app.contentDir)

	// Add scene nodes
	// Add camera
	app.cam = horde3d.RootNode.AddCameraNode("Camera", app.hdrPipeRes)
	app.cam.SetNodeParamI(horde3d.Camera_OccCullingI, 0)
	// Add environment
	env := horde3d.RootNode.AddNodes(envRes)
	env.SetTransform(0, -20, 0, 0, 0, 0, 20, 20, 20)
	// Add knight
	app.knight = horde3d.RootNode.AddNodes(knightRes)
	app.knight.SetTransform(0, 0, 0, 0, 180, 0, 0.1, 0.1, 0.1)
	horde3d.SetupModelAnimStage(app.knight, 0, knightAnim1Res, 0, "", false)
	horde3d.SetupModelAnimStage(app.knight, 1, knightAnim2Res, 0, "", false)
	// Attach particle system to hand joint
	horde3d.FindNodes(app.knight, "Bip01_R_Hand", horde3d.NodeTypes_Joint)
	hand := horde3d.GetNodeFindResult(0)
	app.particleSys = hand.AddNodes(particleSysRes)
	app.particleSys.SetTransform(0, 40, 0, 90, 0, 0, 1, 1, 1)

	// Add light source
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 15, 10, -60, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 30)
	light.SetNodeParamF(horde3d.Light_FovF, 0, 90)
	light.SetNodeParamI(horde3d.Light_ShadowMapCountI, 1)
	light.SetNodeParamF(horde3d.Light_ShadowMapBiasF, 0, 0.01)
	light.SetNodeParamF(horde3d.Light_ColorF3, 0, 1.0)
	light.SetNodeParamF(horde3d.Light_ColorF3, 1, 0.8)
	light.SetNodeParamF(horde3d.Light_ColorF3, 2, 0.7)
	light.SetNodeParamF(horde3d.Light_ColorMultiplierF, 0, 1.0)

	// Customize post processing effects
	matRes := horde3d.FindResource(horde3d.ResTypes_Material, "pipelines/postHDR.material.xml")
	horde3d.SetMaterialUniform(matRes, "hdrExposure", 2.5, 0, 0, 0)
	horde3d.SetMaterialUniform(matRes, "hdrBrightThres", 0.5, 0, 0, 0)
	horde3d.SetMaterialUniform(matRes, "hdrBrightOffset", 0.08, 0, 0, 0)
	return true
}