Exemplo n.º 1
0
// DrawCircle draws a circle centered at v with a radius of r, with n number of points in color c.
func DrawCircle(c color.Color, r float32, n int, v geometry.Vector2) {
	vectors := make([]geometry.Vector2, n)
	for i := 0; i < n; i++ {
		degInRad := (360 / float32(i)) * math.Pi / 180
		vectors[i] = v.Add(geometry.Vector2{math.Cos(degInRad) * r, math.Sin(degInRad) * r})
	}
	DrawLineLoop(c, vectors...)
}
Exemplo n.º 2
0
// YRotationMatrix returns the y-axis rotation matrix based on angle y.
func YRotationMatrix(y float32) Matrix4 {
	cos := math.Cos(y)
	sin := math.Sin(y)
	return Matrix4{
		cos, 0, sin, 0,
		0, 1, 0, 0,
		-sin, 0, cos, 0,
		0, 0, 0, 1}
}
Exemplo n.º 3
0
// XRotationMatrix returns the x-axis rotation matrix based on angle x.
func XRotationMatrix(x float32) Matrix4 {
	cos := math.Cos(x)
	sin := math.Sin(x)
	return Matrix4{
		1, 0, 0, 0,
		0, cos, -sin, 0,
		0, sin, cos, 0,
		0, 0, 0, 1}
}
Exemplo n.º 4
0
// RotationMatrix returns the rotation matrix based on vec with a amount.
func RotationMatrix(a float32, vec geometry.Vector3) Matrix4 {
	c := math.Cos(a)
	s := math.Sin(a)
	return Matrix4{
		vec.X*vec.X*(1-c) + c, vec.X*vec.Y*(1-c) - vec.Z*s, vec.X*vec.Z*(1-c) + vec.Y*s, 0,
		vec.X*vec.Y*(1-c) + vec.Z*s, vec.Y*vec.Y*(1-c) + c, vec.Y*vec.Z*(1-c) - vec.X*s, 0,
		vec.X*vec.Z*(1-c) - vec.Y*s, vec.Y*vec.Z*(1-c) + vec.X*s, vec.Z*vec.Z*(1-c) + c, 0,
		0, 0, 0, 1,
	}
}
Exemplo n.º 5
0
// Vec returns a's vector representation aligned to the x-axis.
func (a Angle) Vec() Vector2 {
	return Vec2(math.Cos(a.Radians()), math.Sin(a.Radians()))
}