00001 // Magic Software, Inc. 00002 // http://www.magic-software.com 00003 // Copyright (c) 2000-2003. All Rights Reserved 00004 // 00005 // Source code from Magic Software is supplied under the terms of a license 00006 // agreement and may not be copied or disclosed except in accordance with the 00007 // terms of that agreement. The various license agreements may be found at 00008 // the Magic Software web site. This file is subject to the license 00009 // 00010 // FREE SOURCE CODE 00011 // http://www.magic-software.com/License/free.pdf 00012 00013 #ifndef MGCPLANE_H 00014 #define MGCPLANE_H 00015 00016 #include "MgcVector3.h" 00017 00018 namespace Mgc { 00019 00020 00021 class MAGICFM Plane 00022 { 00023 public: 00024 // The plane is represented as Dot(N,X) = c where N is the plane normal 00025 // vector, not necessarily unit length, c is the plane constant, and X is 00026 // any point on the plane. 00027 00028 // N and c are uninitialized 00029 Plane (); 00030 00031 // N and c are specified 00032 Plane (const Vector3& rkNormal, Real fConstant); 00033 00034 // N is specified, c = Dot(N,P) where P is the input point 00035 Plane (const Vector3& rkNormal, const Vector3& rkPoint); 00036 00037 // N = Cross(P1-P0,P2-P0), c = Dot(N,P0) where P0, P1, P2 are input points 00038 Plane (const Vector3& rkPoint0, const Vector3& rkPoint1, 00039 const Vector3& rkPoint2); 00040 00041 // member access 00042 Vector3& Normal (); 00043 const Vector3& Normal () const; 00044 Real& Constant (); 00045 const Real& Constant () const; 00046 00047 // access plane P as P[0] = N.x, P[1] = N.y, P[2] = N.z, P[3] = c 00048 // 00049 // WARNING. These member functions rely on 00050 // (1) Plane not having virtual functions 00051 // (2) the data packed in a 4*sizeof(Real) memory block 00052 Real& operator[] (int i) const; 00053 operator Real* (); 00054 00055 // The "positive side" of the plane is the half space to which the plane 00056 // normal points. The "negative side" is the other half space. The flag 00057 // "no side" indicates the plane itself. 00058 enum Side 00059 { 00060 NO_SIDE, 00061 POSITIVE_SIDE, 00062 NEGATIVE_SIDE 00063 }; 00064 00065 Side WhichSide (const Vector3& rkPoint) const; 00066 00067 // This is a pseudodistance. The sign of the return value is positive if 00068 // the point is on the positive side of the plane, negative if the point 00069 // is on the negative side, and zero if the point is on the plane. The 00070 // absolute value of the return value is the true distance only when the 00071 // plane normal is a unit length vector. 00072 Real DistanceTo (const Vector3& rkPoint) const; 00073 00074 // If the plane is Dot(N,X) = c, arrange for the normal vector to be 00075 // unit length. The new equation is Dot(N/|N|,X) = c/|N|. 00076 void Normalize (); 00077 00078 protected: 00079 Vector3 m_kNormal; 00080 Real m_fConstant; 00081 }; 00082 00083 #include "MgcPlane.inl" 00084 00085 } // namespace Mgc 00086 00087 #endif 00088 00089 00090