⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xgeomlib.h

📁 XMathLib是一个通用的3D图形数学库。 其中包含两个部分: XMathLib和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 + -