コード例 #1
0
ファイル: level.go プロジェクト: jasonroelofs/slartibartfast
func (self *Level) Generate() *core.Entity {
	// A square arena with walls
	self.volume = &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.volume, math3d.Vector{50, 10, 50}, 0.5)
	volumeMesh.Name = "Level Mesh"

	self.entity = core.NewEntity()
	self.entity.Name = "Level Geometry"
	self.entity.AddComponent(&components.Visual{
		Mesh:         volumeMesh,
		MaterialName: "only_color",
	})

	transform := components.GetTransform(self.entity)
	transform.Position = math3d.Vector{-25, -10, -25}

	return self.entity
}
コード例 #2
0
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})
}
コード例 #3
0
func (self *VolumeScene) rebuildVolume() {
	log.Println("Marching cube size:", self.marchingCubeSize)

	volumeMesh := volume.MarchingCubes(
		self.cubeVolume, math3d.Vector{50, 50, 50}, self.marchingCubeSize)
	volumeMesh.Name = fmt.Sprintf("CubeVolumeMesh[%.2f]", self.marchingCubeSize)

	log.Printf("[%s] has %d verticies\n", volumeMesh.Name, len(volumeMesh.VertexList))

	self.volumeEntity.RemoveComponent(components.VISUAL)
	self.volumeEntity.AddComponent(&components.Visual{
		Mesh:         volumeMesh,
		MaterialName: "only_color",
	})
}