Beispiel #1
0
func gatherBuildingsPositions(
	rendererPositions map[world.ModelId]Positions,
	buildings world.Buildings,
	offsetX, offsetY float64,
	defaultR *glm.Matrix4, // Can be nil.
	worldToEye glm.Matrix4,
) {
	for coords, building := range buildings {
		position := glm.Vector3{
			float64(coords.X) + offsetX,
			float64(coords.Y) + offsetY,
			0,
		}.Translation()
		facer, ok := building.(world.Facer)
		if ok {
			// We obey the facing of the buildings that have one.
			r := glm.RotZ(float64(90 * facer.Facing().Value()))
			position = position.Mult(r)
		} else {
			// Buildings without facing receive the provided default facing.
			// It is given as a precalculated rotation matrix `defaultR`.
			position = position.Mult(*defaultR)
		}
		position = worldToEye.Mult(position) // Shaders work in view space.
		rendererID := building.Model()
		positions := rendererPositions[rendererID]
		positions = append(positions, position)
		rendererPositions[rendererID] = positions
	}
}
Beispiel #2
0
func (buffer *CameraBuffer) SetEyeToWld(matrix glm.Matrix4) {
	buffer.data[cameraBufferEyeToWld] = matrix.Gl()
	buffer.bufferdataClean = false
}