public bool IntersectsBounds(Bounds_d box) { Vector3_d dirfrac = new Vector3_d { x = 1.0 / direction.x, y = 1.0 / direction.y, z = 1.0 / direction.z }; double t1 = (box.min.x - origin.x) * dirfrac.x; double t2 = (box.max.x - origin.x) * dirfrac.x; double t3 = (box.min.y - origin.y) * dirfrac.y; double t4 = (box.max.y - origin.y) * dirfrac.y; double t5 = (box.min.z - origin.z) * dirfrac.z; double t6 = (box.max.z - origin.z) * dirfrac.z; double tmin = Math_d.Max(Math_d.Max(Math_d.Min(t1, t2), Math_d.Min(t3, t4)), Math_d.Min(t5, t6)); double tmax = Math_d.Min(Math_d.Min(Math_d.Max(t1, t2), Math_d.Max(t3, t4)), Math_d.Max(t5, t6)); // if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us if (tmax < 0) { return(false); } // if tmin <= tmax, ray intersects AABB return(tmin <= tmax); }
public static Vector3_d SmoothDamp( Vector3_d current, Vector3_d target, ref Vector3_d currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { smoothTime = Math_d.Max(0.0001, smoothTime); double num1 = 2.0 / smoothTime; double num2 = num1 * deltaTime; double num3 = (1.0 / (1.0 + num2 + 0.479999989271164 * num2 * num2 + 0.234999999403954 * num2 * num2 * num2)); Vector3_d vector = current - target; Vector3_d vector3_1 = target; double maxLength = maxSpeed * smoothTime; Vector3_d vector3_2 = ClampMagnitude(vector, maxLength); target = current - vector3_2; Vector3_d vector3_3 = (currentVelocity + num1 * vector3_2) * deltaTime; currentVelocity = (currentVelocity - num1 * vector3_3) * num3; Vector3_d vector3_4 = target + (vector3_2 + vector3_3) * num3; if (Dot(vector3_1 - current, vector3_4 - vector3_1) > 0.0) { vector3_4 = vector3_1; currentVelocity = (vector3_4 - vector3_1) / deltaTime; } return(vector3_4); }
public static Vector2_d Max(Vector2_d lhs, Vector2_d rhs) { return(new Vector2_d(Math_d.Max(lhs.x, rhs.x), Math_d.Max(lhs.y, rhs.y))); }