资源简介
实现的gjk算法,同时计算了epa穿插距离,碰撞两点。
放在这里,供大家和自己以后用
代码片段和文件信息
using UnityEngine;
using System.Collections;
public class myGJK : MonoBehaviour {
public struct myVec3
{
public float _xPos;
public float _yPos;
public float _zPos;
public myVec3(float xPos float yPos float zPos)
{
_xPos = xPos;
_yPos = yPos;
_zPos = zPos;
}
public static myVec3 operator - (myVec3 a)
{
return new myVec3 (-a._xPos -a._yPos -a._zPos);
}
public static myVec3 operator - (myVec3 a myVec3 b)
{
return new myVec3 (a._xPos -b._xPos a._yPos - b._yPos a._zPos - b._zPos);
}
public static myVec3 operator + (myVec3 a myVec3 b)
{
return new myVec3 (a._xPos +b._xPos a._yPos + b._yPos a._zPos+ b._zPos);
}
public static myVec3 operator * (float d myVec3 a)
{
return new myVec3 (a._xPos *d a._yPos *d a._zPos*d);
}
public static myVec3 operator / (myVec3 a float d)
{
return new myVec3 (a._xPos /d a._yPos /d a._zPos/d);
}
public static myVec3 Normalize (myVec3 a)
{
float len = a.Dot (a);
return a / Mathf.Sqrt((float)len);
}
public static bool operator == (myVec3 lhs myVec3 rhs)
{
if ((Mathf.Abs ((float)(lhs._xPos - rhs._xPos)) < 1.0E-6)
&& (Mathf.Abs ((float)(lhs._yPos - rhs._yPos)) < 1.0E-6)
&& (Mathf.Abs ((float)(lhs._zPos - rhs._zPos)) < 1.0E-6))
{
return true;
}
return false;
}
public static bool operator != (myVec3 lhs myVec3 rhs)
{
if ((Mathf.Abs ((float)(lhs._xPos - rhs._xPos)) < 1.0E-6)
&& (Mathf.Abs ((float)(lhs._yPos - rhs._yPos)) < 1.0E-6)
&& (Mathf.Abs ((float)(lhs._zPos - rhs._zPos)) < 1.0E-6))
{
return false;
}
return true;
}
public float Dot(myVec3 a)
{
return _xPos*a._xPos + _yPos*a._yPos+_zPos*a._zPos;
}
public static myVec3 Cross (myVec3 lhs myVec3 rhs)
{
return new myVec3 (lhs._yPos * rhs._zPos - lhs._zPos * rhs._yPos -(lhs._xPos * rhs._zPos - lhs._zPos * rhs._xPos) lhs._xPos * rhs._yPos - lhs._yPos * rhs._xPos);
}
public float Lenghsquare()
{
return _xPos*_xPos + _yPos*_yPos+_zPos*_zPos;
}
public float Lengh()
{
return Mathf.Sqrt((float) (_xPos * _xPos + _yPos * _yPos + _zPos * _zPos));
}
public float Dis(myVec3 a)
{
return Mathf.Sqrt((float) ((_xPos-a._xPos)*(_xPos-a._xPos) + (_yPos -a._yPos)* (_yPos -a._yPos) + (_zPos -a._zPos)*(_zPos -a._zPos)));
}
public float Dissquare(myVec3 a)
{
return (_xPos-a._xPos)*(_xPos-a._xPos) + (_yPos -a._yPos)* (_yPos -a._yPos) + (_zPos -a._zPos)*(_zPos -a._zPos);
}
};
public struct myTCSOpoint
{
public myVec3 _Wpos;
public myVec3 _Adir;
public int _Aindex;
public int _Bindex;
public myTCSOpoint(myVec3 Posint Aindexint BindexmyVec3 Adir)
{
_Wpos = Pos;
_Aindex = Aindex;
_Bindex = Bindex;
_Adir = Adir;
}
};
public enum eResultStatus
{
Separated = 0 /* Shapes doesnt penetrate */
Penetrating = 1 /* Shapes are penetrating */
GJK_Failed= 2 /* GJK phase fail no big issue shapes are probably just
- 上一篇:C# Ftp客户端源码
- 下一篇:C#串口助手源码新手
评论
共有 条评论