public void GetCenter(out Vector3F result) { Vector3F.Add(ref Point1, ref Point2, out result); result.X *= .5f; result.Y *= .5f; result.Z *= .5f; }
public static BoundsF Add(ref Vector3F v, ref BoundsF b) { BoundsF result; Vector3F.Add(ref v, ref b.Minimum, out result.Minimum); Vector3F.Add(ref v, ref b.Maximum, out result.Maximum); return(result); }
//public static Bounds FromTransformedBounds( Bounds bounds, Vec3 origin, Mat3 axis ) //{ // Vec3 center = ( bounds.minimum + bounds.maximum ) * 0.5f; // Vec3 extents = bounds.maximum - center; // Vec3 rotatedExtents = new Vec3( // Math.Abs( extents.x * axis.mat0.x ) + // Math.Abs( extents.y * axis.mat1.x ) + // Math.Abs( extents.z * axis.mat2.x ), // Math.Abs( extents.x * axis.mat0.y ) + // Math.Abs( extents.y * axis.mat1.y ) + // Math.Abs( extents.z * axis.mat2.y ), // Math.Abs( extents.x * axis.mat0.z ) + // Math.Abs( extents.y * axis.mat1.z ) + // Math.Abs( extents.z * axis.mat2.z ) ); // //for( int i = 0; i < 3; i++ ) // //{ // // rotatedExtents[ i ] = // // Math.Abs( extents.x * axis.mat0[ i ] ) + // // Math.Abs( extents.y * axis.mat1[ i ] ) + // // Math.Abs( extents.z * axis.mat2[ i ] ); // //} // center = origin + center * axis; // return new Bounds( center - rotatedExtents, center + rotatedExtents ); //} public static BoundsF operator +(BoundsF b, Vector3F v) { BoundsF result; Vector3F.Add(ref b.Minimum, ref v, out result.Minimum); Vector3F.Add(ref b.Maximum, ref v, out result.Maximum); return(result); }
public Vector3F GetCenter() { Vector3F result; Vector3F.Add(ref Point1, ref Point2, out result); result.X *= .5f; result.Y *= .5f; result.Z *= .5f; return(result); }
internal bool LineIntersection(ref Vector3F start, ref Vector3F end) { //unsafe { Vector3F center; GetCenter(out center); Vector3F extents; Vector3F.Subtract(ref Maximum, ref center, out extents); //Vec3 extents = Maximum - center; Vector3F lineDir; lineDir.X = 0.5f * (end.X - start.X); lineDir.Y = 0.5f * (end.Y - start.Y); lineDir.Z = 0.5f * (end.Z - start.Z); //Vec3 lineDir = 0.5f * ( end - start ); Vector3F lineCenter; Vector3F.Add(ref start, ref lineDir, out lineCenter); //Vec3 lineCenter = start + lineDir; Vector3F dir; Vector3F.Subtract(ref lineCenter, ref center, out dir); //Vec3 dir = lineCenter - center; float ld0, ld1, ld2; ld0 = Math.Abs(lineDir.X); if (Math.Abs(dir.X) > extents.X + ld0) { return(false); } ld1 = Math.Abs(lineDir.Y); if (Math.Abs(dir.Y) > extents.Y + ld1) { return(false); } ld2 = Math.Abs(lineDir.Z); if (Math.Abs(dir.Z) > extents.Z + ld2) { return(false); } Vector3F cross; Vector3F.Cross(ref lineDir, ref dir, out cross); if (Math.Abs(cross.X) > extents.Y * ld2 + extents.Z * ld1) { return(false); } if (Math.Abs(cross.Y) > extents.X * ld2 + extents.Z * ld0) return(false); } if (Math.Abs(cross.Z) > extents.X * ld1 + extents.Y * ld0) return(false); }
public static void Add(ref Vector3F v, ref BoundsF b, out BoundsF result) { Vector3F.Add(ref v, ref b.Minimum, out result.Minimum); Vector3F.Add(ref v, ref b.Maximum, out result.Maximum); }