GeoObjects.h

00001 //derived geometric objects.  This is not yet officially part of MPMA, due to the fact that what's here is just random scattered stuff I found useful.
00002 //Luke Lenhart (2005-2008)
00003 //See /docs/License.txt for details on how this code may be used.
00004 
00005 #pragma once
00006 
00007 #include "Geo.h"
00008 
00009 namespace GEO
00010 {
00011     // -- 3D
00012 
00013     //A line or ray.
00014     struct Line
00015     {
00016         Vector3 pos; //position of a point on the line
00017         Vector3 dir; //direction of the line
00018 
00019         //
00020         inline Line() {}
00021         inline Line(const Vector3 &inPos, const Vector3 &inDir)
00022             { pos=inPos; dir=inDir; }
00023     };
00024 
00025     //A plane.
00026     struct Plane
00027     {
00028         float c0,c1,c2,c3; //plane coeffecients
00029 
00030         //
00031         inline Plane() {}
00032         //from a position and a normal
00033         inline Plane(const Vector3 &inPos, const Vector3 &inNormal)
00034         {
00035             Normal()=inNormal;
00036             Renormalize();
00037             c3=-VecDot(inPos,Normal());
00038         }
00039         //from the 4 coeffecients
00040         inline Plane(float inC0,float inC1,float inC2,float inC3): c0(inC0), c1(inC1), c2(inC2), c3(inC3)
00041             { Renormalize(); }
00042 
00043         //gets normal of plane
00044         inline Vector3& Normal() const { return *((Vector3*)this); }
00045 
00046         //normalizes normal of plane
00047         inline void Renormalize() { Normal().Normalize(); }
00048     };
00049 
00050     //A sphere.
00051     struct Sphere
00052     {
00053         Vector3 pos;
00054         float radius;
00055 
00056         //
00057         inline Sphere() {}
00058         inline Sphere(const Vector3 &p, float r)
00059         { pos=p; radius=r; }
00060     };
00061 
00062     //Axis-aligned 3d rectangle.
00063     struct AARectoid
00064     {
00065         Vector3 center;
00066         float xradius;
00067         float yradius;
00068         float zradius;
00069 
00070         //
00071         inline AARectoid() {}
00072         inline AARectoid(Vector3 c, float x, float y, float z)
00073         { center=c; xradius=x; yradius=y; zradius=z; }
00074     };
00075 
00076     //A an unbounded cylendar aligned along the x axis.
00077     struct XAlignedUnboundedCylinder: Line
00078     {
00079         float y;
00080         float z;
00081         float radius;
00082 
00083         //
00084         inline XAlignedUnboundedCylinder() {}
00085         inline XAlignedUnboundedCylinder(float ypos, float zpos, float rad)
00086         { y=ypos; z=zpos; radius=rad; }
00087     };
00088 
00089     //An ellipsoid whose stretch is aligned along the y axis
00090     struct YAlignedEllipsoid: Sphere
00091     {
00092         float ymultiplier;
00093 
00094         //
00095         inline YAlignedEllipsoid() {}
00096         inline YAlignedEllipsoid(const Vector3 &p, float r, float ymod)
00097         { pos=p; radius=r; ymultiplier=ymod; }
00098     };
00099 
00100     // -- 2D
00101 
00102     //a circle
00103     struct Circle
00104     {
00105         Vector2 pos;
00106         float radius;
00107 
00108         inline Circle() {}
00109         inline Circle(GEO::Vector2 position, float rad)
00110         { pos=position; radius=rad; }
00111     };
00112 
00113     //an ellipse aligned to the x and y axis
00114     struct AxisAlignedEllipse
00115     {
00116         Vector2 pos;
00117         float radius;
00118         float xmod;
00119         float ymod;
00120 
00121         inline AxisAlignedEllipse() {}
00122         inline AxisAlignedEllipse(Vector2 position, float rad, float xax, float yax)
00123         { pos=position; radius=rad; xmod=xax; ymod=yax; }
00124     };
00125 
00126 }; //namespace GEO

Generated on Sat Aug 9 15:05:05 2008 for MPMA Framework by  doxygen 1.5.6