afPlane.h
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:3k
源码类别:
其他游戏
开发平台:
Visual C++
- #ifndef AF_PLANE
- #define AF_PLANE
- #include "afVec3.h"
- #include "afVec3n.h"
- #include <d3dx9.h>
- /// This class implements a plane
- class afPlane
- {
- public:
- float x, y, z, d;
- afPlane() { x=y=z=d=0.0f; }
- afPlane(float nX, float nY, float nZ, float nD) { x=nX; y=nY; z=nZ; d=nD; normalize(); }
- afPlane(const afPlane& tocopy) { *this = tocopy;}
- afPlane(const float *nVec) { set(nVec); }
- afPlane(const afVec3& nVec1, const afVec3& nVec2, const afVec3& nVec3) { set(nVec1, nVec2, nVec3); }
- afPlane(const afVec3& nPos, const afVec3& nNormal) { x = nNormal.x; y = nNormal.y; z = nNormal.z;
- d = x*nPos.x + y*nPos.y + z*nPos.z; normalize(); }
- afPlane(const afVec3& nPos, const afVec3n& nNormal) { x = nNormal.x; y = nNormal.y; z = nNormal.z;
- d = x*nPos.x + y*nPos.y + z*nPos.z; }
- D3DXPLANE*
- getD3DPlane() { return reinterpret_cast<D3DXPLANE*>(this); }
- const D3DXPLANE*
- getD3DPlane() const { return reinterpret_cast<const D3DXPLANE*>(this); }
- void
- set(D3DXPLANE* nPlane) { *reinterpret_cast<D3DXPLANE*>(this) = *nPlane; }
- void
- set(const float *nVec) { x = nVec[0]; y = nVec[1]; z = nVec[2]; d = nVec[3]; }
- void
- set(float nX, float nY, float nZ, float nD) { x = nX; y = nY; z = nZ; d = nD; normalize(); }
- inline void
- set(const afVec3& nVec1, const afVec3& nVec2, const afVec3& nVec3);
- const float&
- getX() const { return x; }
- const float&
- getY() const { return y; }
- const float&
- getZ() const { return z; }
- const float&
- getD() const { return d; }
- inline void
- normalize();
- inline afPlane&
- operator=(const afPlane&);
- friend inline bool
- operator==(const afPlane& left, const afPlane& right);
- const float&
- operator[](unsigned index) const { return (&x)[index]; }
- float&
- operator[](unsigned index) { return (&x)[index]; }
- };
- inline afPlane& afPlane::operator=(const afPlane& other)
- {
- x = other.x;
- y = other.y;
- z = other.z;
- d = other.d;
- return *this;
- }
- inline void afPlane::normalize()
- {
- float l = x*x + y*y + z*z;
- if(l==1.0f || l==0.0f)
- return;
- l = (float)sqrt(l);
- float il = 1.0f/l;
- x *= il; // normalize without
- y *= il; // moving the plane
- z *= il;
- d *= l;
- }
- inline bool
- operator==(const afPlane& left, const afPlane& right)
- {
- return (left.x==right.x && left.y==right.y && left.z==right.z && left.d==right.d);
- }
- // pass in the vertices clockwise order
- //
- inline void afPlane::set(const afVec3& nVec1, const afVec3& nVec2, const afVec3& nVec3)
- {
- afVec3 v12 = nVec2-nVec1,
- v13 = nVec3-nVec1,
- normal;
- normal.cross(v13, v12);
- normal.normalize();
- x = normal.x;
- y = normal.y;
- z = normal.z;
- d = normal * nVec1;
- }
- #endif