/// <summary> /// ConvexPoly2 constructor. /// Assumes input points define a convex region. /// </summary> public ConvexPoly2( Vector2[] points ) { Vector2 center = GameEngine2D.Base.Math._00; Planes = new Plane2[ points.Length ]; for ( int n=points.Length,i=n-1,i_next=0; i_next < n; i=i_next++ ) { Vector2 p1 = points[i]; Vector2 p2 = points[i_next]; Planes[i] = new Plane2( p1, -Math.Perp( p2 - p1 ).Normalize() ); center += p1; } center /= (float)points.Length; float radius = 0.0f; for ( int i = 0; i != points.Length; ++i ) radius = FMath.Max( radius, ( points[i] - center ).Length() ); m_sphere = new Sphere2( center, radius ); }
public void MakeRegular( uint num, float r ) { Planes = new Plane2[ num ]; float a2 = Math.TwicePi * 0.5f / (float)num; for ( uint i = 0; i != num; ++i ) { float a = Math.TwicePi * (float)i / (float)num; Vector2 p = Vector2.Rotation( a + a2 ); Vector2 n = Vector2.Rotation( a ); Planes[i] = new Plane2( p * r, n ); } m_sphere = new Sphere2( GameEngine2D.Base.Math._00, r ); }
public void Translate( Vector2 dx, ConvexPoly2 poly ) { Planes = new Plane2[ poly.Planes.Length ]; for ( int i=0; i != poly.Planes.Length; ++i ) { Planes[i] = poly.Planes[i]; Planes[i].Base += dx; } m_sphere = poly.m_sphere; m_sphere.Center += dx; }
public void MakeBox( Bounds2 bounds ) { Planes = new Plane2[ 4 ]; Planes[0] = new Plane2( bounds.Point00, -Math._10 ); Planes[1] = new Plane2( bounds.Point10, -Math._01 ); Planes[2] = new Plane2( bounds.Point11, Math._10 ); Planes[3] = new Plane2( bounds.Point01, Math._01 ); m_sphere = new Sphere2( bounds.Center, bounds.Size.Length() * 0.5f ); }