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

📄 collisiondetectionmath.h.svn-base

📁 自己做的小游戏
💻 SVN-BASE
字号:
//关于我函数之间的调用关系和层次结构,参见我论文的30,31,32页的3.5节和4.1节。
//关于数据类型和数据结构的相关信息,参见我论文的33,34页的4.2.1节和4.2.2节。

#pragma once
#include "math.h"
#include "CollisionDetectionStructDef.h"
#include "../gamedata/Structs.h"

#define SAME_SIGNS( a, b ) \
(((long) ((unsigned long) a ^ (unsigned long) b)) >= 0 )

 #define EPSILON 0.000001

inline Vertex sub(Vertex v1,Vertex v2)
{
	Vertex v;
	v.x = v1.x - v2.x;
	v.y = v1.y - v2.y;
	v.z = v1.z - v2.z;

	return v;
}

inline Vertex cross(Vertex v1,Vertex v2)
{
	Vertex v;
	v.x = v1.y * v2.z - v1.z * v2.y; 
	v.y = v1.z * v2.x - v1.x * v2.z; 
	v.z = v1.x * v2.y - v1.y * v2.x; 

	return v;
}

inline float dot(Vertex v1,Vertex v2)
{
	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

class CollisionDetectionMath
{
public:
	CollisionDetectionMath();
	virtual ~CollisionDetectionMath();
	//判断线段是否与3D包围盒相交  true:相交,false:不相交
    //bool     IsLineSegmentCutBy3DBoundary(Vertex v1 ,Vertex v2,BOUNDARY_3D boundary);    
    //bool     IsLineSegmentCutBy3DBoundary(Vertex *v1 ,Vertex *v2,BOUNDARY_3D *boundary);  

	//判断线段是否与标准长方形相交  true:相交,false:不相交
    bool static IsLineSegmentCutBydQuad(Vertex v1 ,Vertex* v2,Vertex va,Vertex vb,Vertex vc,Vertex vd);    
	// bool     IsLineSegmentCutBydQuad(Vertex v1 ,Vertex* v2,Vertex *pv); 
	bool static IsLineSegmentCutBydQuadExtendTo3D(Vertex v1 ,Vertex* v2,Vertex va,Vertex vb,Vertex vc,Vertex vd,float height); 

	//判断两个线段是否相交,并求交点
    bool static linesSegmentintersect(Vertex v1,Vertex *v2,Vertex v3,Vertex v4);
	bool static linesSegmentintersectExtendTo3D(Vertex v1,Vertex *v2,Vertex v3,Vertex v4,float height);
	bool static linesSegmentintersectExtendTo3DAdvanced(Vertex v1,Vertex *v2,Vertex v3,Vertex v4,float height,Vertex advancedTest);
	
	//判断线段是否与八边形(圆)相交  true:相交,false:不相交
	bool static IsLineSegmentCutByCircle(Vertex v1,Vertex *v2,Vertex v3,float radius);
	bool static IsLineSegmentCutByCircleExtendTo3D(Vertex v1,Vertex *v2,Vertex v3,float radius,float height);

	//判断线段是否和空间三角形相交,并求交点
	bool static IsLineSegmentCutByTriangle(Vertex v1,Vertex *v2,Vertex va,Vertex vb,Vertex vc);

	//获得直线与平面交点
	void static  GetIntersection(Vertex vertex1,Vertex* vertex2,Vertex va,Vertex vb,Vertex vc);

	//////////由三个顶点获得平面方程
	//PLANE    GetPlaneEquation(Vertex v1,Vertex v2,Vertex v3);
	////////////判断点与平面的关系 -1:在平面后,0:在平面上,1:在平面前
	//int      ClassifyPointPlane(Vertex point,PLANE plane);
	////////////获得直线与平面交点
	//Vertex   GetIntersection(Vertex vertex1,Vertex vertex2,PLANE plane);
	////////////获得两向量的叉积
	//NORMAL   GetTwoNormalProduct(NORMAL normal1,NORMAL normal2);
	// //////////归一标准化
	//NORMAL   Normalization(NORMAL normal);
	//NORMAL   Normalization(double x,double y,double z);

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -