func (self *SpinningCubes) Setup() { var box *core.Entity positions := [10]math3d.Vector{ math3d.Vector{0, 0, 0}, math3d.Vector{4, 0, 0}, math3d.Vector{4, 4, 0}, math3d.Vector{4, 4, 4}, math3d.Vector{-4, 0, 0}, math3d.Vector{-4, -4, 0}, math3d.Vector{0, -4, 0}, math3d.Vector{-4, 0, -4}, math3d.Vector{0, 4, 4}, math3d.Vector{0, 0, 4}, } skybox := factories.SkyBox("stevecube", self.game.Camera) self.game.RegisterEntity(skybox) for i := 0; i < 10; i++ { box = core.NewEntityAt(positions[i]) box.AddComponent(new(components.Visual)) self.boxen = append(self.boxen, *box) self.game.RegisterEntity(box) } }
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 (self *TopDownTestScene) Setup() { self.game.RegisterEntity(factories.SkyBox("stevecube", self.game.Camera)) self.levelVolume = &volume.FunctionVolume{ func(x, y, z float32) float32 { if y > 5 && (x > 3 && x < 47) && (z > 3 && z < 47) { return -1 } else { return 1 } }, } volumeMesh := volume.MarchingCubes(self.levelVolume, math3d.Vector{50, 10, 50}, 0.5) volumeMesh.Name = "Level Mesh" self.levelEntity = core.NewEntity() self.levelEntity.Name = "Level Geometry" self.levelEntity.AddComponent(&components.Visual{ Mesh: volumeMesh, MaterialName: "only_color", }) self.game.RegisterEntity(self.levelEntity) self.game.Camera.AddComponent(&components.Input{ Mapping: FPSMapping, }) // Get the camera facing downwards cameraTransform := components.GetTransform(self.game.Camera.Entity) cameraTransform.Position = math3d.Vector{25, 10, 25} cameraTransform.CurrentPitch = 90 cameraTransform.Speed = math3d.Vector{8, 8, 8} cameraTransform.MoveRelativeToRotation = false // Our unit we'll control self.playerCube = core.NewEntityAt(math3d.Vector{25, 6, 25}) self.playerCube.Name = "The Player" self.playerCube.AddComponent(&components.Visual{}) playerTransform := components.GetTransform(self.playerCube) playerTransform.Scale = math3d.Vector{0.25, 0.5, 0.25} playerTransform.Speed = math3d.Vector{3, 3, 3} playerTransform.MoveRelativeToRotation = false self.topDownCamera = NewTopDownCamera(self.game.Camera) self.topDownCamera.SetTrackingHeight(5) self.topDownCamera.TrackEntity(self.playerCube) self.game.RegisterEntity(self.playerCube) self.game.Keyboard.OnKey(input.KeySpace, func(event events.Event) { self.SwapInput(event) }) // Start by controlling the player unit. Game defaults to controlling the camera self.SwapInput(events.Event{Pressed: true}) }
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()) }