// AssignEulerRotation assigns Euler angle rotations to the rotation part of the matrix and sets the remaining elements to their ident value. func (mat *T) AssignEulerRotation(yHead, xPitch, zRoll float32) *T { sinH := math.Sin(yHead) cosH := math.Cos(yHead) sinP := math.Sin(xPitch) cosP := math.Cos(xPitch) sinR := math.Sin(zRoll) cosR := math.Cos(zRoll) mat[0][0] = cosR*cosH - sinR*sinP*sinH mat[1][0] = -sinR * cosP mat[2][0] = cosR*sinH + sinR*sinP*cosH mat[3][0] = 0 mat[0][1] = sinR*cosH + cosR*sinP*sinH mat[1][1] = cosR * cosP mat[2][1] = sinR*sinH - cosR*sinP*cosH mat[3][1] = 0 mat[0][2] = -cosP * sinH mat[1][2] = sinP mat[2][2] = cosP * cosH mat[3][2] = 0 mat[0][3] = 0 mat[1][3] = 0 mat[2][3] = 0 mat[3][3] = 1 return mat }
// AssignZRotation assigns a rotation around the z axis to the rotation part of the matrix and sets the remaining elements to their ident value. func (mat *T) AssignZRotation(angle float32) *T { cosine := math.Cos(angle) sine := math.Sin(angle) mat[0][0] = cosine mat[1][0] = -sine mat[2][0] = 0 mat[3][0] = 0 mat[0][1] = sine mat[1][1] = cosine mat[2][1] = 0 mat[3][1] = 0 mat[0][2] = 0 mat[1][2] = 0 mat[2][2] = 1 mat[3][2] = 0 mat[0][3] = 0 mat[1][3] = 0 mat[2][3] = 0 mat[3][3] = 1 return mat }
// Rotated returns a counter-clockwise rotated copy of the vector. func (vec *T) Rotated(angle float32) T { sinus := math.Sin(angle) cosinus := math.Cos(angle) return T{ vec[0]*cosinus - vec[1]*sinus, vec[0]*sinus + vec[1]*cosinus, } }
// FromZAxisAngle returns a quaternion representing a rotation around the z axis. func FromZAxisAngle(angle float32) T { angle *= 0.5 return T{0, 0, math.Sin(angle), math.Cos(angle)} }
// FromAxisAngle returns a quaternion representing a rotation around and axis. func FromAxisAngle(axis *vec3.T, angle float32) T { angle *= 0.5 sin := math.Sin(angle) q := T{axis[0] * sin, axis[1] * sin, axis[2] * sin, math.Cos(angle)} return q.Normalized() }