Example #1
0
func (self Dynamic) ModelMat(t uint64) glm.Matrix4 {
	const TAU = 1 * 1000000000 // Nanosecond.
	dt := float64(t - self.T0)
	z := .5 + .2*math.Sin(2*math.Pi*dt/TAU)
	pos := glm.Vector3{1, 0, z}
	return pos.Translation()
}
Example #2
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
	}
}
Example #3
0
func viewMatrix(pos world.Position) (glm.Matrix4, glm.Matrix4) {
	const eyeZ = .5
	Rd := glm.RotZ(float64(-90 * pos.F.Value()))
	Td := glm.Vector3{float64(-pos.X), float64(-pos.Y), -eyeZ}.Translation()
	Ri := glm.RotZ(float64(90 * pos.F.Value()))
	Ti := glm.Vector3{float64(pos.X), float64(pos.Y), eyeZ}.Translation()
	Vd := Rd.Mult(Td) // Direct.
	Vi := Ti.Mult(Ri) // Inverse.
	return Vd, Vi
}
Example #4
0
func MakeVertexXyzNor(pos, nor glm.Vector3) VertexXyzNor {
	px64, py64, pz64 := pos.Xyz()
	nx64, ny64, nz64 := nor.Xyz()
	return VertexXyzNor{
		Px: gl.GLfloat(px64),
		Py: gl.GLfloat(py64),
		Pz: gl.GLfloat(pz64),
		Nx: gl.GLfloat(nx64),
		Ny: gl.GLfloat(ny64),
		Nz: gl.GLfloat(nz64),
	}
}