?? xgeomlib.h
字號:
/********************************************************************************
聲明:
這里的代碼版權歸潘李亮所有.你可以自由使用分發這些代碼.但是不得用于商業用途.
如有需要請于作者聯系.
在你使用本代碼時候,請務必保留本聲明
潘李亮 2003-10
Stanly Lee. 2003-10
Email : xheartblue@etang.com
幾何對象操作庫的代碼:
實現圖形學里常用的求交點一類的算法.
線和平面的關系。
線和線的關系。
碰撞檢測。
等等。
*******************************************************************************/
#ifndef _XGEOM_LIB_H_
#define _XGEOM_LIB_H_
#include <vector>
using namespace std;
#include "XMathLib.h"
using namespace XMathLib;
#ifdef _WIN32
# ifndef _XREALENGINE_NONCLIENT_BUILD
# define _GEOM_LIB_EXPORT_ __declspec( dllexport )
# else
# define _GEOM_LIB_EXPORT_ __declspec( dllimport )
# endif
#else
# define _GEOM_LIB_EXPORT_
#endif
#undef _GEOM_LIB_EXPORT_
#define _GEOM_LIB_EXPORT_
namespace XGeomLib
{
class XLine;
class XLineSegment;
class XPlan;
class XTriangle;
class XPolygon;
class XCylinder;
/*
表示一條直線
*/
class _GEOM_LIB_EXPORT_ XLine
{
public:
XLine(XPoint point,XDirection dir){m_Point = point;m_Dir = dir;}
public:
XPoint m_Point;
XDirection m_Dir;
};
/*
有兩個端點的線段
*/
class _GEOM_LIB_EXPORT_ XLineSegment
{
public:
XLineSegment(XPoint start,XPoint end){m_Start = start;m_End = end;};
XLineSegment(XPoint start,XDirection dir,float len);
public:
XPoint m_Start;
XPoint m_End;
};
/*
一個平面對象。
*/
class _GEOM_LIB_EXPORT_ XPlan
{
public:
XPlan(XPoint a,XPoint b,XPoint c);
XPlan(XPoint point,XDirection normal);
XPlan(XVector v){ A = v.x;B = v.y ;C = v.z;D = v.w;};
XPlan(float _A,float _B,float _C,float _D){A = _A;B = _B ;C = _C;D = _D;}
operator XVector(){ return XVector(A,B,C,D); }
float operator*(XPoint& p);
friend float operator*(XPoint& v ,XPlan& p);
public:
float A;
float B;
float C;
float D;
};
/*
*/
class _GEOM_LIB_EXPORT_ XTriangle
{
public:
XVector3D GetNormal()
{
XVector3D a = m_points[2] - m_points[0];
XVector3D b = m_points[1] - m_points[0];
return b.cp(a);
}
public:
XPoint m_points[3];
};
class _GEOM_LIB_EXPORT_ XPolygon
{
public:
vector<XPoint> m_points;
};
class _GEOM_LIB_EXPORT_ XRay
{
public:
XPoint m_Point;
XDirection m_Dir;
};
float operator*(XPoint& v ,XPlan& p);
//線和面的交
bool InterSection(XRay& ray,XPlan& plan,XPoint& point,float & t);
bool InterSection(XRay& ray,XTriangle& tri,XPoint& point,float & t);
bool InterSection(XRay& ray,XTriangle& tri,XPoint& point,float& t, float& u, float& v );
//線段和面的相交
bool InterSection(XLineSegment& lineSeg,XPlan& plan,XPoint& point,float & t);
bool InterSection(XLineSegment& lineSeg,XTriangle& tri,XPoint& point,float & t);
//線和線的相交
float InterSection(XRay& ray1,XRay& ray2,XPoint& point);
float InterSection(XRay& ray,XLineSegment& lineSeg,XPoint& point);
float InterSection(XLineSegment& lineSeg1,XLineSegment& lineSeg2,XPoint& point);
//點是不是在三角形和面上
float InterSection(XPoint& point ,XTriangle& tri);
float InterSection(XPoint& point ,XPolygon& polygon);
//計算三角形和面之間的交線.
float InterSection(XTriangle& tri,XTriangle& tri2,XLineSegment& lineSeg);
float InterSection(XTriangle& tri,XPlan& plan,XLineSegment& lineSeg);
//只檢測不計算.
float InterSection(XTriangle& tri,XTriangle& tri2g);
float InterSection(XTriangle& tri,XPlan& plan);
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -