Exemple #1
0
func (e *Editor) refreshMap() {
	e.rootMapNode.RemoveAll(true)

	cd := countdown.Countdown{}
	cd.Start(countGeometries(e.currentMap.Root))
	e.openProgressBar()
	e.setProgressBar(0)
	e.setProgressTime("Loading Map...")

	mapLoadChan := loadMapToNode(e.currentMap.Root)

	var loader engine.Updatable
	loader = engine.UpdatableFunc(func(dt float64) {
		select {
		case mapLoadUpdate := <-mapLoadChan:
			if mapLoadUpdate.node == nil {
				cd.Count()
				e.setProgressBar(cd.PercentageComplete() / 5)
				e.setProgressTime(fmt.Sprintf("Loading Map... %v seconds remaining", cd.SecondsRemaining()))
			} else {
				e.rootMapNode.Add(mapLoadUpdate.node)
				e.gameEngine.RemoveUpdatable(loader)
				e.closeProgressBar()
			}
		default:
		}
	})
	e.gameEngine.AddUpdatable(loader)
}
Exemple #2
0
func fetchAssets(gameEngine engine.Engine, complete func()) {
	os.Mkdir("TestAssets", 0777)
	patcher := client.NewClient("TestAssets", "http://walesey.net")
	done := make(chan bool)
	go func() {
		patcher.SyncFiles("TestFiles")
		done <- true
	}()

	progressBar := ui.NewProgressBar("Downloading assets...")
	ui.SetProgressBar(progressBar, 0)
	gameEngine.AddOrtho(progressBar)
	progress := 0
	var loader engine.Updatable
	loader = engine.UpdatableFunc(func(dt float64) {
		select {
		case <-patcher.Complete:
			progress++
			ui.SetProgressBar(progressBar, 1+int((progress*20)/patcher.TotalFiles))
		case <-done:
			gameEngine.RemoveSpatial(progressBar, true)
			gameEngine.RemoveUpdatable(loader)
			gameEngine.RequestAnimationFrame(complete)
		default:
		}
	})
	gameEngine.AddUpdatable(loader)
}
Exemple #3
0
func TriggerTimedParticleGroup(tpg TimedParticleGroup) {
	tpg.TargetNode.Add(tpg.Particles)
	tpg.GameEngine.AddUpdatable(tpg.Particles)
	particleLife := tpg.Life

	var updater engine.Updatable
	updater = engine.UpdatableFunc(func(dt float64) {
		particleLife -= dt
		if particleLife < 0 {
			tpg.Particles.Disable(true)
		}
		if particleLife < -tpg.Cleanup {
			tpg.TargetNode.Remove(tpg.Particles, true)
			tpg.GameEngine.RemoveUpdatable(tpg.Particles)
			tpg.GameEngine.RemoveUpdatable(updater)
		}
	})
	tpg.GameEngine.AddUpdatable(updater)
}
Exemple #4
0
func setupScene(gameEngine engine.Engine, shader *renderer.Shader) {
	camera := gameEngine.Camera()

	transparentNode := renderer.NewNode()
	gameEngine.AddSpatialTransparent(transparentNode)
	transparentNode.RendererParams = &renderer.RendererParams{
		DepthTest:    true,
		Unlit:        true,
		Transparency: renderer.EMISSIVE,
	}

	// Sky cubemap
	skyImg, err := assets.ImportImage("TestAssets/cloudSky.jpg")
	if err == nil {
		skyImg = imaging.AdjustBrightness(skyImg, -30)
		skyImg = imaging.AdjustContrast(skyImg, 30)
		geom := renderer.CreateSkyBox()
		geom.Transform(mgl32.Scale3D(10000, 10000, 10000))
		skyNode := renderer.NewNode()
		skyNode.SetOrientation(mgl32.QuatRotate(1.57, mgl32.Vec3{0, 1, 0}))
		skyNode.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", skyImg, false))
		skyNode.RendererParams = renderer.NewRendererParams()
		skyNode.RendererParams.CullBackface = false
		skyNode.RendererParams.Unlit = true
		skyNode.Add(geom)
		gameEngine.AddSpatial(skyNode)
		// create an environmentMap using the skybox texture
		envCubeMap := renderer.NewCubemap("environmentMap", skyImg, true)
		gameEngine.DefaultCubeMap(envCubeMap)
	}

	// load scene objs
	objs := []string{
		"TestAssets/wellScene/floor.obj",
		"TestAssets/wellScene/frame1.obj",
		"TestAssets/wellScene/frame2.obj",
		"TestAssets/wellScene/well.obj",
		"TestAssets/wellScene/torches.obj",
	}
	for _, objFile := range objs {
		if geom, mat, err := assets.ImportObjCached(objFile); err == nil {
			sceneNode := renderer.NewNode()
			sceneNode.Add(geom)
			sceneNode.Material = mat
			sceneNode.RendererParams = renderer.NewRendererParams()
			sceneNode.RendererParams.CullBackface = false
			gameEngine.AddSpatial(sceneNode)
		}
	}

	for i := 0; i < 2; i++ {
		torchLocation := mgl32.Vec3{0.86, 1.76, 1.05}
		if i == 1 {
			torchLocation = mgl32.Vec3{0.86, 1.76, -1.05}
		}

		fire := fireParticles()
		spark := sparkParticles()
		torchParticles := effects.NewParticleGroup(camera, fire, spark)
		torchParticles.SetTranslation(torchLocation)
		transparentNode.Add(torchParticles)
		gameEngine.AddUpdatable(torchParticles)

		light := renderer.NewLight(renderer.POINT)
		light.SetTranslation(torchLocation.Add(mgl32.Vec3{0, 0.05, 0}))
		gameEngine.AddLight(light)

		var x float64
		gameEngine.AddUpdatable(engine.UpdatableFunc(func(dt float64) {
			x += dt
			mag := float32(math.Abs(0.6*math.Sin(3*x)+0.3*math.Sin(4*x)+0.15*math.Sin(7*x)+0.1*math.Sin(15*x))) + 0.5
			mag *= 0.05
			light.Color = [3]float32{1 * mag, 0.6 * mag, 0.4 * mag}
		}))
	}
}
Exemple #5
0
func (e *Editor) Start() {

	glRenderer := opengl.NewOpenglRenderer("GoEngine Editor", 1800, 900, false)
	e.renderer = glRenderer
	e.gameEngine = engine.NewEngine(e.renderer)

	e.gameEngine.Start(func() {

		shader, err := assets.ImportShader(
			filepath.Join(e.assetDir, "shaders/build/pbr.vert"),
			filepath.Join(e.assetDir, "shaders/build/pbr.frag"),
		)
		if err != nil {
			panic("error importing shader")
		}

		e.gameEngine.DefaultShader(shader)

		// Sky cubemap
		skyImg, err := assets.ImportImage(filepath.Join(e.assetDir, "resources/cubemap.png"))
		if err == nil {
			geom := renderer.CreateSkyBox()
			geom.Transform(mgl32.Scale3D(10000, 10000, 10000))
			skyNode := renderer.NewNode()
			skyNode.SetOrientation(mgl32.QuatRotate(1.57, mgl32.Vec3{0, 1, 0}))
			skyNode.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", skyImg, false))
			skyNode.RendererParams = renderer.NewRendererParams()
			skyNode.RendererParams.CullBackface = false
			skyNode.RendererParams.Unlit = true
			skyNode.Add(geom)
			e.gameEngine.AddSpatial(skyNode)
			// create an environmentMap using the skybox texture
			envCubeMap := renderer.NewCubemap("environmentMap", skyImg, true)
			e.gameEngine.DefaultCubeMap(envCubeMap)
		}

		l := renderer.NewLight(renderer.DIRECTIONAL)
		l.Color = [3]float32{0.7, 0.7, 0.8}
		e.gameEngine.AddLight(l)

		//root node
		e.gameEngine.AddSpatial(e.rootMapNode)

		//input/controller manager
		e.controllerManager = glfwController.NewControllerManager(glRenderer.Window)

		//camera + player
		camera := e.gameEngine.Camera()
		freeMoveActor := actor.NewFreeMoveActor(camera)
		freeMoveActor.MoveSpeed = 20.0
		freeMoveActor.LookSpeed = 0.002
		mainController := controller.NewBasicMovementController(freeMoveActor, true)
		e.controllerManager.AddController(mainController.(glfwController.Controller))
		e.gameEngine.AddUpdatable(freeMoveActor)

		e.initSelectSprite()
		e.gameEngine.AddUpdatable(engine.UpdatableFunc(e.updateSelectSprite))

		//editor controller
		e.controllerManager.AddController(NewEditorController(e).(glfwController.Controller))

		//custom controller
		e.customController = controller.CreateController()
		e.controllerManager.AddController(e.customController.(glfwController.Controller))

		e.setupUI()
	})
}
Exemple #6
0
func main() {

	glRenderer := opengl.NewOpenglRenderer("Simple", 800, 800, false)
	gameEngine := engine.NewEngine(glRenderer)
	gameEngine.InitFpsDial()

	gameEngine.Start(func() {

		if shader, err := assets.ImportShader("shaders/build/basic.vert", "shaders/build/basic.frag"); err == nil {
			gameEngine.DefaultShader(shader)
		}

		// sky cube
		skyImg, err := assets.ImportImage("resources/cubemap.png")
		if err == nil {
			geom := renderer.CreateSkyBox()
			geom.Transform(mgl32.Scale3D(10000, 10000, 10000))
			skyNode := renderer.NewNode()
			skyNode.SetOrientation(mgl32.QuatRotate(1.57, mgl32.Vec3{0, 1, 0}))
			skyNode.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", skyImg, false))
			skyNode.RendererParams = renderer.NewRendererParams()
			skyNode.RendererParams.CullBackface = false
			skyNode.RendererParams.Unlit = true
			skyNode.Add(geom)
			gameEngine.AddSpatial(skyNode)
		}

		// Add some light to the scene
		ambientLight := renderer.NewLight(renderer.AMBIENT)
		ambientLight.Color = [3]float32{0.3, 0.3, 0.3}
		gameEngine.AddLight(ambientLight)

		// Create a red box geometry, attach to a node, add the node to the scenegraph
		boxGeometry := renderer.CreateBox(10, 10)
		boxGeometry.SetColor(color.NRGBA{254, 0, 0, 254})
		boxNode := renderer.NewNode()
		boxNode.RendererParams = renderer.NewRendererParams()
		boxNode.RendererParams.CullBackface = false
		boxNode.Material = renderer.NewMaterial()
		boxNode.SetTranslation(mgl32.Vec3{30, 0})
		boxNode.Add(boxGeometry)
		gameEngine.AddSpatial(boxNode)

		// make the box spin
		var angle float64
		gameEngine.AddUpdatable(engine.UpdatableFunc(func(dt float64) {
			angle += dt
			q := mgl32.QuatRotate(float32(angle), mgl32.Vec3{0, 1, 0})
			boxNode.SetOrientation(q)
		}))

		// input/controller manager
		controllerManager := glfwController.NewControllerManager(glRenderer.Window)

		// camera + wasd controls
		camera := gameEngine.Camera()
		freeMoveActor := actor.NewFreeMoveActor(camera)
		freeMoveActor.Location = mgl32.Vec3{}
		mainController := controller.NewBasicMovementController(freeMoveActor, false)
		controllerManager.AddController(mainController.(glfwController.Controller))
		gameEngine.AddUpdatable(freeMoveActor)

		//lock the cursor
		glRenderer.LockCursor(true)

		// custom key bindings
		customController := controller.CreateController()
		controllerManager.AddController(customController.(glfwController.Controller))

		// close window and exit on escape
		customController.BindKeyAction(func() {
			glRenderer.Window.SetShouldClose(true)
		}, controller.KeyEscape, controller.Press)
	})
}