func Test_TopDownCamera_TracksEntities(t *testing.T) {
	camera := NewTopDownCamera(core.NewCamera())
	entity := core.NewEntity()
	camera.TrackEntity(entity)

	assert.Equal(t, entity, camera.trackingEntity)
}
func Test_NewTopDownCamera(t *testing.T) {
	camera := core.NewCamera()
	tdCam := NewTopDownCamera(camera)

	assert.NotNil(t, tdCam)
	assert.Equal(t, camera, tdCam.camera)
}
func Test_TopDownCamera_CanPauseTracking(t *testing.T) {
	baseCam := core.NewCamera()
	camera := NewTopDownCamera(baseCam)
	camera.TrackEntity(core.NewEntityAt(math3d.Vector{10, 10, 10}))
	camera.PauseTracking()

	camera.UpdatePosition()
	assert.Equal(t, math3d.Vector{0, 0, 0}, baseCam.Position())
}
func Test_TopDownCamera_ResumesTrackingPositionOverTime(t *testing.T) {
	baseCam := core.NewCamera()
	camera := NewTopDownCamera(baseCam)
	camera.TrackEntity(core.NewEntityAt(math3d.Vector{10, 10, 10}))
	camera.SetTrackingHeight(10)

	camera.ResumeTracking()

	assert.NotNil(t, baseCam.Entity.GetComponent(components.ANIMATION))
}
func Test_TopDownCamera_UpdatePositionCanKeepAHeightFromTheEntity(t *testing.T) {
	baseCam := core.NewCamera()
	camera := NewTopDownCamera(baseCam)
	camera.TrackEntity(core.NewEntityAt(math3d.Vector{10, 10, 10}))
	camera.SetTrackingHeight(10)

	camera.UpdatePosition()

	assert.Equal(t, math3d.Vector{10, 20, 10}, baseCam.Position())
}
Ejemplo n.º 6
0
func Test_SkyBox(t *testing.T) {
	camera := core.NewCamera()
	skybox := SkyBox("testMap", camera)

	visual := components.GetVisual(skybox)
	transform := components.GetTransform(skybox)

	assert.Equal(t, "Skybox testMap", skybox.Name)
	assert.Equal(t, "testMap", visual.MaterialName)
	assert.Equal(t, camera.Entity, transform.UsingPositionOf)
}
Ejemplo n.º 7
0
func (self *Game) setupGame() {
	self.camera = core.NewCamera()
	self.camera.Perspective(60.0, self.window.AspectRatio(), 0.1, 100.0)
	self.camera.SetPosition(math3d.Vector{0, 10, 0})
	self.camera.LookAt(math3d.Vector{0, 0, -0.1})
	self.entityDB.RegisterEntity(self.camera.Entity)

	self.player = NewPlayer()
	self.entityDB.RegisterEntity(self.player.GetEntity())

	self.currentLevel = NewLevel()
	self.entityDB.RegisterEntity(self.currentLevel.Generate())
}
Ejemplo n.º 8
0
func Test_Update_ConfiguresQueueWithViewData(t *testing.T) {
	graphical, renderer, _ := getTestGraphical()

	camera := core.NewCamera()
	camera.SetPosition(math3d.Vector{5, 5, 5})
	camera.LookAt(math3d.Vector{1, 2, 3})

	graphical.Update(camera, 0)

	assert.NotNil(t, renderer.queueRendered)

	assert.Equal(t, camera.ProjectionMatrix(), renderer.queueRendered.ProjectionMatrix)
	assert.Equal(t, camera.ViewMatrix(), renderer.queueRendered.ViewMatrix)
}
Ejemplo n.º 9
0
func Test_Update_UsesMeshLinkedToVisualIfExists(t *testing.T) {
	graphical, renderer, entityDb := getTestGraphical()

	mesh := &render.Mesh{}

	entity := core.NewEntity()
	entity.AddComponent(&components.Visual{Mesh: mesh})
	entityDb.RegisterEntity(entity)

	graphical.Update(core.NewCamera(), 0)
	renderOp := renderer.queueRendered.RenderOperations()[0]

	assert.Equal(t, mesh, renderOp.Mesh)
}
Ejemplo n.º 10
0
func (self *Game) initializeScene() {
	self.Camera = core.NewCamera()
	self.Camera.Perspective(60.0, self.window.AspectRatio(), 0.1, 100.0)
	self.Camera.SetPosition(math3d.Vector{0, 0, 0})
	self.Camera.LookAt(math3d.Vector{0, 0, -5})

	// YUCK, must be a better way of doing this?
	// Will probably move camera creation into Graphical so it
	// can take care of situations like this.
	self.RegisterEntity(self.Camera.Entity)

	//	self.currentScene = NewSpinningCubes(self)
	// self.currentScene = NewTexturedCube(self)
	// self.currentScene = NewVolumeScene(self)
	self.currentScene = NewTopDownTestScene(self)

	self.currentScene.Setup()
}
Ejemplo n.º 11
0
func Test_Update_RendersAllVisualEntityMeshesWithMaterials(t *testing.T) {
	graphical, renderer, entityDb := getTestGraphical()

	entity := core.NewEntity()
	entity.AddComponent(new(components.Visual))
	entityDb.RegisterEntity(entity)

	graphical.Update(core.NewCamera(), 0)

	assert.NotNil(t, renderer.queueRendered)

	assert.Equal(t, 1, len(renderer.queueRendered.RenderOperations()))

	renderOp := renderer.queueRendered.RenderOperations()[0]

	assert.Equal(t, render.DefaultMesh, renderOp.Mesh)
	assert.Equal(t, render.DefaultMaterial.Name, renderOp.Material.Name)
	assert.Equal(t, math3d.IdentityMatrix(), renderOp.Transform)
}