Beispiel #1
0
// Get the angle in radians of the rotation around the specified axis. The axis must be normalized.
// param axisX the x component of the normalized axis for which to get the angle
// param axisY the y component of the normalized axis for which to get the angle
// param axisZ the z component of the normalized axis for which to get the angle
// return the angle in radians of the rotation around the specified axis
func (self *Quaternion) GetAngleAroundRad(axisX, axisY, axisZ float32) float32 {
	d := DotV3(self.x, self.y, self.z, axisX, axisY, axisZ)
	l2 := Len2Q(axisX*d, axisY*d, axisZ*d, self.w)
	if utils.IsZero(l2) {
		return 0
	} else {
		return float32((2.0 * math.Acos(float64(utils.ClampFloat32((self.w/float32(math.Sqrt(float64(l2)))), -1, 1)))))
	}
}
Beispiel #2
0
// Intersect a {@link Ray} and a triangle, returning the intersection point in intersection.
// param ray The ray
// param t1 The first vertex of the triangle
// param t2 The second vertex of the triangle
// param t3 The third vertex of the triangle
// param intersection The intersection point (optional)
// return True in case an intersection is present.
func IntersectRayTriangle(ray *Ray, t1, t2, t3, intersection *Vector3) bool {
	edge1 := v0.SetV(t2).SubV(t1)
	edge2 := v1.SetV(t3).SubV(t1)
	pvec := v2.SetV(ray.Direction).CrsV(edge2)
	det := edge1.DotV(pvec)
	if utils.IsZero(det) {
		p.SetP3(t1, t2, t3)
		if p.TestPointV3(ray.Origin) == PlaneOn && IsPointInTriangleV3(ray.Origin, t1, t2, t3) {
			if intersection != nil {
				intersection.SetV(ray.Origin)
			}
			return true
		}
		return false
	}

	det = 1.0 / det

	tvec := i.SetV(ray.Origin).SubV(t1)
	u := tvec.DotV(pvec) * det
	if u < 0.0 || u > 1.0 {
		return false
	}

	qvec := tvec.CrsV(edge1)
	v := ray.Direction.DotV(qvec) * det
	if v < 0.0 || u+v > 1.0 {
		return false
	}

	t := edge2.DotV(qvec) * det
	if t < 0 {
		return false
	}

	if intersection != nil {
		if t <= utils.FLOAT_ROUNDING_ERROR {
			intersection.SetV(ray.Origin)
		} else {
			ray.GetEndPoint(intersection, t)
		}
	}

	return true
}
Beispiel #3
0
func (self *Vector3) IsPerpendicular(vector *Vector3) bool {
	return utils.IsZero(self.DotV(vector))
}
Beispiel #4
-1
// return If this quaternion is an identity Quaternion
func (self *Quaternion) IsIdentity() bool {
	return utils.IsZero(self.x) && utils.IsZero(self.y) && utils.IsZero(self.z) && utils.IsEqual(self.w, 1)
}