Exemplo n.º 1
0
func (self *TexturedCube) Setup() {
	self.theCube = core.NewEntity()
	self.theCube.Name = "Textured Cube"
	self.theCube.AddComponent(new(components.Visual))

	self.colorCube = core.NewEntity()
	self.colorCube.Name = "Colored Cube"
	self.colorCube.AddComponent(&components.Visual{
		MaterialName: "only_color",
		MeshName:     "ColorIndexCube",
	})

	transform := components.GetTransform(self.theCube)
	transform.Position = math3d.Vector{0, 0, -10}
	transform.Scale = math3d.Vector{2, 2, 2}
	transform.Speed = math3d.Vector{5, 5, 5}

	transform = components.GetTransform(self.colorCube)
	transform.Position = math3d.Vector{0, 0, -5}

	//	transform.MoveRelativeToRotation = true
	//	self.theCube.AddComponent(&components.Input{
	//		Mapping: FPSMapping,
	//	})

	skybox := factories.SkyBox("stevecube", self.game.Camera)

	self.game.RegisterEntity(skybox)
	self.game.RegisterEntity(self.theCube)
	self.game.RegisterEntity(self.colorCube)
}
Exemplo n.º 2
0
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 (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})
}
Exemplo n.º 4
0
func (self *VolumeScene) Setup() {
	skybox := factories.SkyBox("stevecube", self.game.Camera)
	self.game.RegisterEntity(skybox)

	self.game.Camera.AddComponent(FPSInput)

	self.game.Camera.SetSpeed(math3d.Vector{5, 5, 5})
	self.game.Camera.LookAt(math3d.Vector{0, 0, -5})

	self.game.Keyboard.OnKey(input.KeyJ, func(e events.Event) {
		if e.Pressed {
			self.marchingCubeSize -= 0.1

			if self.marchingCubeSize <= 0 {
				self.marchingCubeSize = 0.1
			} else {
				self.rebuildVolume()
			}
		}
	})

	self.game.Keyboard.OnKey(input.KeyK, func(e events.Event) {
		if e.Pressed {
			self.marchingCubeSize += 0.1

			self.rebuildVolume()
		}
	})

	self.cubeVolume = &volume.FunctionVolume{
		// A sphere!
		func(x, y, z float32) float32 {
			// Translate to treat middle of the volume as 0,0,0
			// Basically I want 0,0,0 of the volume to act like -25, -25, -25, so that
			// the center point of the sphere is at 25, 25, 25 in the volume,
			// then check the equation against the radius of the sphere.
			tX := x - 25
			tY := y - 25
			tZ := z - 25

			return -(tX*tX + tY*tY + tZ*tZ - 20)
		},
	}

	self.volumeEntity = core.NewEntity()
	self.volumeEntity.Name = "cube volume"

	self.rebuildVolume()

	// Move the volume into view of the starting camera
	transform := components.GetTransform(self.volumeEntity)
	transform.Position = math3d.Vector{-25, -25, -40}

	self.game.RegisterEntity(self.volumeEntity)
}