*
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
public class SourceCTransform
|
||||
{
|
||||
public SourceCTransform() { }
|
||||
public SourceCTransform(SourceVector v, SourceQuaternion q)
|
||||
{
|
||||
m_vPosition = v;
|
||||
m_orientation = q;
|
||||
}
|
||||
public SourceCTransform(SourceVector v, SourceQAngle a)
|
||||
{
|
||||
m_vPosition = v;
|
||||
MathUtils.AngleQuaternion(a, ref m_orientation);
|
||||
}
|
||||
|
||||
public SourceVector m_vPosition;
|
||||
public SourceQuaternion m_orientation;
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
//return m_vPosition.IsValid() && m_orientation.IsValid();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static bool operator ==(SourceCTransform c1, SourceCTransform c2) => c1.m_vPosition == c2.m_vPosition && c1.m_orientation == c2.m_orientation; //< exact equality check
|
||||
public static bool operator !=(SourceCTransform c1, SourceCTransform c2) => !(c1 == c2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceCTransform)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
// for API compatibility with matrix3x4_t
|
||||
public void InitFromQAngles(SourceQAngle angles, SourceVector vPosition)
|
||||
{
|
||||
MathUtils.AngleQuaternion(angles, ref m_orientation);
|
||||
m_vPosition = vPosition;
|
||||
}
|
||||
public void InitFromMatrix(SourceMatrix3x4 transform)
|
||||
{
|
||||
m_orientation = MathUtils.MatrixQuaternion(transform);
|
||||
m_vPosition = transform.GetOrigin();
|
||||
}
|
||||
public void InitFromQuaternion(SourceQuaternion orientation, SourceVector vPosition)
|
||||
{
|
||||
m_orientation = orientation;
|
||||
m_vPosition = vPosition;
|
||||
}
|
||||
|
||||
public SourceQuaternion ToQuaternion() => m_orientation;
|
||||
public SourceQAngle ToQAngle()
|
||||
{
|
||||
SourceQAngle angles = new SourceQAngle();
|
||||
MathUtils.QuaternionAngles(m_orientation, ref angles);
|
||||
return angles;
|
||||
}
|
||||
public SourceMatrix3x4 ToMatrix() => MathUtils.TransformMatrix(this);
|
||||
|
||||
public void SetToIdentity()
|
||||
{
|
||||
m_vPosition = SourceVector.Empty;
|
||||
m_orientation = SourceQuaternion.Identity;
|
||||
}
|
||||
|
||||
public void SetOrigin(SourceVector vPos) { m_vPosition = vPos; }
|
||||
public void SetAngles(SourceQAngle vAngles) { MathUtils.AngleQuaternion(vAngles, ref m_orientation); }
|
||||
public SourceVector GetOrigin() { return m_vPosition; }
|
||||
|
||||
public void GetBasisVectorsFLU(ref SourceVector pForward, ref SourceVector pLeft, ref SourceVector pUp)
|
||||
{
|
||||
MathUtils.TransformVectorsFLU(this, ref pForward, ref pLeft, ref pUp);
|
||||
}
|
||||
public SourceVector GetForward()
|
||||
{
|
||||
SourceVector vForward = new SourceVector();
|
||||
MathUtils.TransformVectorsForward(this, ref vForward);
|
||||
return vForward;
|
||||
}
|
||||
public SourceVector TransformVector(SourceVector v0) => MathUtils.TransformPoint(this, v0);
|
||||
public SourceVector RotateVector(SourceVector v0)
|
||||
{
|
||||
SourceVector vOut = new SourceVector();
|
||||
MathUtils.RotatePoint(this, v0, ref vOut);
|
||||
return vOut;
|
||||
}
|
||||
public SourceVector TransformVectorByInverse(SourceVector v0)
|
||||
{
|
||||
SourceVector vOut = new SourceVector();
|
||||
MathUtils.VectorITransform(v0, this, ref vOut);
|
||||
return vOut;
|
||||
}
|
||||
public SourceVector RotateVectorByInverse(SourceVector v0)
|
||||
{
|
||||
SourceVector vOut = new SourceVector();
|
||||
MathUtils.VectorIRotate(v0, this, ref vOut);
|
||||
return vOut;
|
||||
}
|
||||
public SourceVector RotateExtents(SourceVector vBoxExtents) { throw new NotImplementedException(); } // these are extents and must remain positive/symmetric after rotation
|
||||
public void TransformAABB(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
ToMatrix().TransformAABB(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void TransformAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
ToMatrix().TransformAABBByInverse(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void RotateAABB(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
ToMatrix().RotateAABB(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void RotateAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
ToMatrix().RotateAABBByInverse(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
//inline void TransformPlane( const cplane_t &inPlane, cplane_t &outPlane ) const;
|
||||
//inline void InverseTransformPlane( const cplane_t &inPlane, cplane_t &outPlane ) const;
|
||||
|
||||
/// Computes an inverse. Uses the 'TR' naming to be consistent with the same method in matrix3x4_t (which only works with orthonormal matrices)
|
||||
public void InverseTR(ref SourceCTransform _out)
|
||||
{
|
||||
SourceMatrix3x4 xForm = ToMatrix();
|
||||
_out = xForm.InverseTR().ToCTransform();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe3919ba3838be48be45220405d6dcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>Degree Euler angle aligned to axis (NOT ROLL/PITCH/YAW)</summary>
|
||||
public class SourceDegreeEuler
|
||||
{
|
||||
public SourceDegreeEuler() { }
|
||||
public SourceDegreeEuler(float X, float Y, float Z) { x = X; y = Y; z = Z; }
|
||||
public SourceDegreeEuler(SourceQuaternion q)
|
||||
{
|
||||
SourceRadianEuler radians = new SourceRadianEuler(q);
|
||||
Init(MathUtils.RAD2DEG(radians.x), MathUtils.RAD2DEG(radians.y), MathUtils.RAD2DEG(radians.z));
|
||||
}
|
||||
public SourceDegreeEuler(SourceQAngle angles)
|
||||
{
|
||||
Init(angles.z, angles.x, angles.y);
|
||||
}
|
||||
public SourceDegreeEuler(SourceRadianEuler angles)
|
||||
{
|
||||
Init(MathUtils.RAD2DEG(angles.x), MathUtils.RAD2DEG(angles.y), MathUtils.RAD2DEG(angles.z));
|
||||
}
|
||||
|
||||
// Initialization
|
||||
public void Init(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f) { x = ix; y = iy; z = iz; }
|
||||
|
||||
public SourceQAngle ToQAngle() => new SourceQAngle(y, z, x);
|
||||
|
||||
// conversion to qangle
|
||||
public bool IsValid() { throw new NotImplementedException(); }
|
||||
public void Invalidate() { throw new NotImplementedException(); }
|
||||
|
||||
public float Base() { return x; }
|
||||
|
||||
// array access...
|
||||
public float this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
default: throw new Exception("wrong index [0..2]");
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
x = value;
|
||||
break;
|
||||
case 1:
|
||||
y = value;
|
||||
break;
|
||||
case 2:
|
||||
z = value;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("wrong index [0..2]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float x, y, z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14e01e0782293504ebe7b80d0a29eed8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,252 @@
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Matrix 3x4 (float)
|
||||
/// Size: 48 bytes (4 bytes per val)
|
||||
/// </summary>
|
||||
public class SourceMatrix3x4
|
||||
{
|
||||
public SourceMatrix3x4() { }
|
||||
public SourceMatrix3x4(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23)
|
||||
{
|
||||
m_flMatVal[0][0] = m00; m_flMatVal[0][1] = m01; m_flMatVal[0][2] = m02; m_flMatVal[0][3] = m03;
|
||||
m_flMatVal[1][0] = m10; m_flMatVal[1][1] = m11; m_flMatVal[1][2] = m12; m_flMatVal[1][3] = m13;
|
||||
m_flMatVal[2][0] = m20; m_flMatVal[2][1] = m21; m_flMatVal[2][2] = m22; m_flMatVal[2][3] = m23;
|
||||
}
|
||||
|
||||
/// Creates a matrix where the X axis = forward the Y axis = left, and the Z axis = up
|
||||
void InitXYZ(SourceVector xAxis, SourceVector yAxis, SourceVector zAxis, SourceVector vecOrigin)
|
||||
{
|
||||
m_flMatVal[0][0] = xAxis.x; m_flMatVal[0][1] = yAxis.x; m_flMatVal[0][2] = zAxis.x; m_flMatVal[0][3] = vecOrigin.x;
|
||||
m_flMatVal[1][0] = xAxis.y; m_flMatVal[1][1] = yAxis.y; m_flMatVal[1][2] = zAxis.y; m_flMatVal[1][3] = vecOrigin.y;
|
||||
m_flMatVal[2][0] = xAxis.z; m_flMatVal[2][1] = yAxis.z; m_flMatVal[2][2] = zAxis.z; m_flMatVal[2][3] = vecOrigin.z;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a matrix where the X axis = forward
|
||||
// the Y axis = left, and the Z axis = up
|
||||
//-----------------------------------------------------------------------------
|
||||
void Init(SourceVector xAxis, SourceVector yAxis, SourceVector zAxis, SourceVector vecOrigin)
|
||||
{
|
||||
m_flMatVal[0][0] = xAxis.x; m_flMatVal[0][1] = yAxis.x; m_flMatVal[0][2] = zAxis.x; m_flMatVal[0][3] = vecOrigin.x;
|
||||
m_flMatVal[1][0] = xAxis.y; m_flMatVal[1][1] = yAxis.y; m_flMatVal[1][2] = zAxis.y; m_flMatVal[1][3] = vecOrigin.y;
|
||||
m_flMatVal[2][0] = xAxis.z; m_flMatVal[2][1] = yAxis.z; m_flMatVal[2][2] = zAxis.z; m_flMatVal[2][3] = vecOrigin.z;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a matrix where the X axis = forward
|
||||
// the Y axis = left, and the Z axis = up
|
||||
//-----------------------------------------------------------------------------
|
||||
public SourceMatrix3x4(SourceVector xAxis, SourceVector yAxis, SourceVector zAxis, SourceVector vecOrigin)
|
||||
{
|
||||
Init(xAxis, yAxis, zAxis, vecOrigin);
|
||||
}
|
||||
|
||||
public void InitFromQAngles(SourceQAngle angles, SourceVector vPosition)
|
||||
{
|
||||
var t = this;
|
||||
MathUtils.AngleMatrix(angles, vPosition, ref t);
|
||||
this.m_flMatVal = t.m_flMatVal;
|
||||
}
|
||||
public void InitFromQAngles(SourceQAngle angles) { InitFromQAngles(angles, SourceVector.Empty); }
|
||||
public void InitFromRadianEuler(SourceRadianEuler angles, SourceVector vPosition)
|
||||
{
|
||||
var t = this;
|
||||
MathUtils.AngleMatrix(angles, vPosition, ref t);
|
||||
this.m_flMatVal = t.m_flMatVal;
|
||||
}
|
||||
public void InitFromRadianEuler(SourceRadianEuler angles) { InitFromRadianEuler(angles, SourceVector.Empty); }
|
||||
public void InitFromCTransform(SourceCTransform transform)
|
||||
{
|
||||
var t = this;
|
||||
MathUtils.TransformMatrix(transform, ref t);
|
||||
this.m_flMatVal = t.m_flMatVal;
|
||||
}
|
||||
public void InitFromQuaternion(SourceQuaternion orientation, SourceVector vPosition)
|
||||
{
|
||||
var t = this;
|
||||
MathUtils.QuaternionMatrix(orientation, vPosition, ref t);
|
||||
this.m_flMatVal = t.m_flMatVal;
|
||||
}
|
||||
public void InitFromQuaternion(SourceQuaternion orientation) { InitFromQuaternion(orientation, SourceVector.Empty); }
|
||||
public void InitFromDiagonal(SourceVector vDiagonal)
|
||||
{
|
||||
SetToIdentity();
|
||||
m_flMatVal[0][0] = vDiagonal.x;
|
||||
m_flMatVal[1][1] = vDiagonal.y;
|
||||
m_flMatVal[2][2] = vDiagonal.z;
|
||||
}
|
||||
|
||||
public SourceQuaternion ToQuaternion() => MathUtils.MatrixQuaternion(this);
|
||||
public SourceQAngle ToQAngle()
|
||||
{
|
||||
SourceQAngle tmp = new SourceQAngle();
|
||||
MathUtils.MatrixAngles(this, ref tmp);
|
||||
return tmp;
|
||||
}
|
||||
public SourceCTransform ToCTransform() => MathUtils.MatrixTransform(this);
|
||||
|
||||
public void SetToIdentity()
|
||||
{
|
||||
for (int i1 = 0; i1 < m_flMatVal.Length; i1++)
|
||||
for (int i2 = 0; i2 < m_flMatVal[i1].Length; i2++)
|
||||
m_flMatVal[i1][i2] = 0.0f;
|
||||
m_flMatVal[0][0] = 1.0f;
|
||||
m_flMatVal[1][1] = 1.0f;
|
||||
m_flMatVal[2][2] = 1.0f;
|
||||
}
|
||||
|
||||
/// multiply the scale/rot part of the matrix by a constant. This doesn't init the matrix ,
|
||||
/// just scale in place. So if you want to construct a scaling matrix, init to identity and
|
||||
/// then call this.
|
||||
public void ScaleUpper3x3Matrix(float flScale)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
m_flMatVal[i][j] *= flScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// modify the origin
|
||||
public void SetOrigin(SourceVector p)
|
||||
{
|
||||
m_flMatVal[0][3] = p.x;
|
||||
m_flMatVal[1][3] = p.y;
|
||||
m_flMatVal[2][3] = p.z;
|
||||
}
|
||||
|
||||
/// return the origin
|
||||
public SourceVector GetOrigin()
|
||||
{
|
||||
return new SourceVector(m_flMatVal[0][3], m_flMatVal[1][3], m_flMatVal[2][3]);
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
m_flMatVal[i][j] = float.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// check all components for invalid floating point values
|
||||
bool IsValid()
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (m_flMatVal[i][j] == float.NaN)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool operator ==(SourceMatrix3x4 m1, SourceMatrix3x4 m2)
|
||||
{
|
||||
bool equals = true;
|
||||
for (int i1 = 0; i1 < 3; i1++)
|
||||
{
|
||||
if (!equals) break;
|
||||
for (int i2 = 0; i2 < 4; i2++)
|
||||
{
|
||||
if (m1[i1][i2] != m2[i1][i2])
|
||||
{
|
||||
equals = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return equals;
|
||||
}
|
||||
public static bool operator !=(SourceMatrix3x4 m1, SourceMatrix3x4 m2) => !(m1 == m2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceMatrix3x4)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
// bool IsEqualTo( const SourceMatrix3x4 &other, float flTolerance = 1e-5f) const;
|
||||
|
||||
//void GetBasisVectorsFLU(Vector* pForward, Vector* pLeft, Vector* pUp) const;
|
||||
//SourceVector TransformVector( const Vector &v0 ) const;
|
||||
//SourceVector RotateVector( const Vector &v0 ) const;
|
||||
//SourceVector TransformVectorByInverse( const Vector &v0 ) const;
|
||||
//SourceVector RotateVectorByInverse( const Vector &v0 ) const;
|
||||
//SourceVector RotateExtents( const Vector &vBoxExtents ) const; // these are extents and must remain positive/symmetric after rotation
|
||||
public void TransformAABB(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
MathUtils.TransformAABB(this, vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void TransformAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
MathUtils.ITransformAABB(this, vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void RotateAABB(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
MathUtils.RotateAABB(this, vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
public void RotateAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut)
|
||||
{
|
||||
MathUtils.IRotateAABB(this, vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut);
|
||||
}
|
||||
//void TransformPlane( const cplane_t &inPlane, cplane_t &outPlane ) const;
|
||||
//void TransformPlaneByInverse( const cplane_t &inPlane, cplane_t &outPlane ) const;
|
||||
//float GetOrthogonalityError() const;
|
||||
//float GetDeterminant()const;
|
||||
//float GetSylvestersCriterion()const; // for symmetrical matrices only: should be >0 iff it's a positive definite matrix
|
||||
|
||||
//SourceVector GetColumn(MatrixAxisType_t nColumn) const;
|
||||
//void SetColumn( const Vector &vColumn, MatrixAxisType_t nColumn);
|
||||
//SourceVector GetForward() const { return GetColumn(FORWARD_AXIS ); }
|
||||
// SourceVector GetLeft() const { return GetColumn(LEFT_AXIS ); }
|
||||
// SourceVector GetUp() const { return GetColumn(UP_AXIS ); }
|
||||
// SourceVector GetRow(int nRow) const { return * (Vector*) (m_flMatVal[nRow]); }
|
||||
// void SetRow(int nRow, const Vector &vRow ) { m_flMatVal[nRow][0] = vRow.x; m_flMatVal[nRow][1] = vRow.y; m_flMatVal[nRow][2] = vRow.z; }
|
||||
|
||||
public void InverseTR(ref SourceMatrix3x4 _out)
|
||||
{
|
||||
MathUtils.MatrixInvert(this, ref _out);
|
||||
}
|
||||
public SourceMatrix3x4 InverseTR()
|
||||
{
|
||||
SourceMatrix3x4 _out = new SourceMatrix3x4();
|
||||
InverseTR(ref _out);
|
||||
return _out;
|
||||
}
|
||||
|
||||
public float[] this[int i]
|
||||
{
|
||||
get => m_flMatVal[i];
|
||||
set => m_flMatVal[i] = value;
|
||||
}
|
||||
|
||||
public float Base() { return m_flMatVal[0][0]; }
|
||||
|
||||
float[][] _m_flMatVal;
|
||||
public float[][] m_flMatVal//[3][4];
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_m_flMatVal == null)
|
||||
{
|
||||
_m_flMatVal = new float[3][];
|
||||
for (int v = 0; v < 3; v++)
|
||||
_m_flMatVal[v] = new float[4];
|
||||
}
|
||||
return _m_flMatVal;
|
||||
}
|
||||
set
|
||||
{
|
||||
_m_flMatVal = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a4f71b4e3573b54c9258fddae8a25e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y/z (float)
|
||||
/// Size: 12 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceQAngle
|
||||
{
|
||||
// Members
|
||||
public float x, y, z;
|
||||
|
||||
// Initialization
|
||||
public SourceQAngle(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f)
|
||||
{
|
||||
this.x = ix;
|
||||
this.y = iy;
|
||||
this.z = iz;
|
||||
}
|
||||
public static SourceQAngle Random(float minVal, float maxVal)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return new SourceQAngle(
|
||||
ix: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal),
|
||||
iy: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal),
|
||||
iz: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal)
|
||||
);
|
||||
}
|
||||
|
||||
// equality
|
||||
public static bool operator ==(SourceQAngle v1, SourceQAngle v2) => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
|
||||
public static bool operator !=(SourceQAngle v1, SourceQAngle v2) => !(v1 == v2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceQAngle)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
// arithmetic operations
|
||||
public static SourceQAngle operator +(SourceQAngle v1, SourceQAngle v2) => new SourceQAngle(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
public static SourceQAngle operator -(SourceQAngle v1, SourceQAngle v2) => new SourceQAngle(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
public static SourceQAngle operator *(SourceQAngle v, float s) => new SourceQAngle(v.x * s, v.y * s, v.z * s);
|
||||
public static SourceQAngle operator /(SourceQAngle v, float fl)
|
||||
{
|
||||
if (fl == 0.0f)
|
||||
return new SourceQAngle();
|
||||
float oofl = 1.0f / fl;
|
||||
return new SourceQAngle(v.x * oofl, v.y * oofl, v.z * oofl);
|
||||
}
|
||||
|
||||
public float this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
}
|
||||
throw new Exception("wrong index");
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
x = value;
|
||||
break;
|
||||
case 1:
|
||||
y = value;
|
||||
break;
|
||||
case 2:
|
||||
z = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the vector's magnitude.
|
||||
public float Length() => (float)Math.Sqrt(LengthSqr());
|
||||
public float LengthSqr() => x * x + y * y + z * z;
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}; {z}}}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42f5749be91a85846b5abe45d8eab4fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Quaternion x/y/z/w (float)
|
||||
/// Size: 16 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceQuaternion
|
||||
{
|
||||
// same data-layout as engine's vec4_t,
|
||||
// which is a vec_t[4]=float[4]
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
public SourceQuaternion(float ix, float iy, float iz, float iw)
|
||||
{
|
||||
//Init(ix, iy, iz, iw);
|
||||
x = ix; y = iy; z = iz; w = iw;
|
||||
}
|
||||
public SourceQuaternion(SourceRadianEuler angle)
|
||||
{
|
||||
var t = new SourceQuaternion();
|
||||
MathUtils.AngleQuaternion(angle, ref t);
|
||||
this.x = t.x;
|
||||
this.y = t.y;
|
||||
this.z = t.z;
|
||||
this.w = t.w;
|
||||
}
|
||||
public SourceQuaternion(SourceDegreeEuler angle)
|
||||
{
|
||||
SourceRadianEuler radians = new SourceRadianEuler(angle);
|
||||
var t = new SourceQuaternion();
|
||||
MathUtils.AngleQuaternion(radians, ref t);
|
||||
this.x = t.x;
|
||||
this.y = t.y;
|
||||
this.z = t.z;
|
||||
this.w = t.w;
|
||||
}
|
||||
|
||||
void Init(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f, float iw = 0.0f) { x = ix; y = iy; z = iz; w = iw; }
|
||||
void Init(SourceVector vImaginaryPart, float flRealPart) { x = vImaginaryPart.x; y = vImaginaryPart.y; z = vImaginaryPart.z; w = flRealPart; }
|
||||
|
||||
|
||||
public static bool operator ==(SourceQuaternion v1, SourceQuaternion v2) => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
|
||||
public static bool operator !=(SourceQuaternion v1, SourceQuaternion v2) => !(v1 == v2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceQuaternion)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
public SourceQuaternion Conjugate() { return new SourceQuaternion(-x, -y, -z, w); }
|
||||
|
||||
public SourceVector GetForward()
|
||||
{
|
||||
SourceVector vAxisX;
|
||||
vAxisX.x = 1.0f - 2.0f * y * y - 2.0f * z * z;
|
||||
vAxisX.y = 2.0f * x * y + 2.0f * w * z;
|
||||
vAxisX.z = 2.0f * x * z - 2.0f * w * y;
|
||||
return vAxisX;
|
||||
}
|
||||
public SourceVector GetLeft()
|
||||
{
|
||||
SourceVector vAxisY;
|
||||
vAxisY.x = 2.0f * x * y - 2.0f * w * z;
|
||||
vAxisY.y = 1.0f - 2.0f * x * x - 2.0f * z * z;
|
||||
vAxisY.z = 2.0f * y * z + 2.0f * w * x;
|
||||
return vAxisY;
|
||||
}
|
||||
public SourceVector GetUp()
|
||||
{
|
||||
SourceVector vAxisZ;
|
||||
vAxisZ.x = 2.0f * x * z + 2.0f * w * y;
|
||||
vAxisZ.y = 2.0f * y * z - 2.0f * w * x;
|
||||
vAxisZ.z = 1.0f - 2.0f * x * x - 2.0f * y * y;
|
||||
return vAxisZ;
|
||||
}
|
||||
|
||||
|
||||
public float RealPart() { return w; }
|
||||
public SourceQAngle ToQAngle()
|
||||
{
|
||||
SourceQAngle anglesOut = new SourceQAngle();
|
||||
MathUtils.QuaternionAngles(this, ref anglesOut);
|
||||
return anglesOut;
|
||||
}
|
||||
public SourceMatrix3x4 ToMatrix()
|
||||
{
|
||||
SourceMatrix3x4 mat = new SourceMatrix3x4();
|
||||
mat.InitFromQuaternion(this);
|
||||
return mat;
|
||||
}
|
||||
|
||||
// array access...
|
||||
public float this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
case 3: return w;
|
||||
default: throw new Exception("wrong index [0..3]");
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
x = value;
|
||||
break;
|
||||
case 1:
|
||||
y = value;
|
||||
break;
|
||||
case 2:
|
||||
z = value;
|
||||
break;
|
||||
case 3:
|
||||
w = value;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("wrong index [0..3]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SourceQuaternion operator +(SourceQuaternion q1, SourceQuaternion q2) => new SourceQuaternion(q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w);
|
||||
public static SourceQuaternion operator -(SourceQuaternion q1, SourceQuaternion q2) => new SourceQuaternion(q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w);
|
||||
|
||||
public static SourceQuaternion Identity = new SourceQuaternion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f79c37491dea4d847806826d30312f7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// RadianEuler x/y/z (float)
|
||||
/// Size: 12 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public class SourceRadianEuler
|
||||
{
|
||||
public SourceRadianEuler() { }
|
||||
public SourceRadianEuler(float X, float Y, float Z) { x = X; y = Y; z = Z; }
|
||||
public SourceRadianEuler(SourceQuaternion q)
|
||||
{
|
||||
var t = this;
|
||||
MathUtils.QuaternionAngles(q, ref t);
|
||||
this.x = t.x;
|
||||
this.y = t.y;
|
||||
this.z = t.z;
|
||||
}
|
||||
public SourceRadianEuler(SourceQAngle angles)
|
||||
{
|
||||
Init(angles.z * 3.14159265358979323846f / 180.0f,
|
||||
angles.x * 3.14159265358979323846f / 180.0f,
|
||||
angles.y * 3.14159265358979323846f / 180.0f);
|
||||
}
|
||||
public SourceRadianEuler(SourceDegreeEuler angles)
|
||||
{
|
||||
Init(MathUtils.DEG2RAD(angles.x), MathUtils.DEG2RAD(angles.y), MathUtils.DEG2RAD(angles.z));
|
||||
}
|
||||
|
||||
// Initialization
|
||||
public void Init(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f) { x = ix; y = iy; z = iz; }
|
||||
|
||||
// conversion to qangle
|
||||
public SourceQAngle ToQAngle() => new SourceQAngle(MathUtils.DEG2RAD(y), MathUtils.DEG2RAD(z), MathUtils.DEG2RAD(x));
|
||||
public bool IsValid() { throw new NotImplementedException(); }
|
||||
public void Invalidate() { throw new NotImplementedException(); }
|
||||
|
||||
public float Base() { return x; }
|
||||
|
||||
// array access...
|
||||
public float this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
default: throw new Exception("wrong index [0..2]");
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
x = value;
|
||||
break;
|
||||
case 1:
|
||||
y = value;
|
||||
break;
|
||||
case 2:
|
||||
z = value;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("wrong index [0..2]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float x, y, z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b270d4664974df54fb6bd34c1e015b9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y/z (float)
|
||||
/// Size: 12 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceVector
|
||||
{
|
||||
public float x, y, z;
|
||||
|
||||
public SourceVector(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f)
|
||||
{
|
||||
this.x = ix;
|
||||
this.y = iy;
|
||||
this.z = iz;
|
||||
}
|
||||
|
||||
// Initialization methods
|
||||
public static SourceVector Random(float minVal, float maxVal)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return new SourceVector(
|
||||
ix: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal),
|
||||
iy: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal),
|
||||
iz: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal)
|
||||
);
|
||||
}
|
||||
public void Zero() => x = y = z = 0.0f; ///< zero out a vector
|
||||
|
||||
// equality
|
||||
public static bool operator ==(SourceVector v1, SourceVector v2) => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
|
||||
public static bool operator !=(SourceVector v1, SourceVector v2) => !(v1 == v2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceVector)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
// arithmetic operations
|
||||
public static SourceVector operator +(SourceVector v1, SourceVector v2) => new SourceVector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
public static SourceVector operator -(SourceVector v1, SourceVector v2) => new SourceVector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
public static SourceVector operator *(SourceVector v1, SourceVector v2) => new SourceVector(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
public static SourceVector operator *(SourceVector v, float s) => new SourceVector(v.x * s, v.y * s, v.z * s);
|
||||
public static SourceVector operator /(SourceVector v1, SourceVector v2)
|
||||
{
|
||||
return new SourceVector(
|
||||
ix: v2.x != 0.0f ? v1.x / v2.x : 0f,
|
||||
iy: v2.y != 0.0f ? v1.y / v2.y : 0f,
|
||||
iz: v2.z != 0.0f ? v1.z / v2.z : 0f
|
||||
);
|
||||
}
|
||||
public static SourceVector operator /(SourceVector v, float fl)
|
||||
{
|
||||
if (fl == 0.0f)
|
||||
return new SourceVector();
|
||||
float oofl = 1.0f / fl;
|
||||
return new SourceVector(v.x * oofl, v.y * oofl, v.z * oofl);
|
||||
}
|
||||
public static SourceVector operator +(SourceVector v, float s) => new SourceVector(v.x + s, v.y + s, v.z + s); //< broadcast add
|
||||
public static SourceVector operator -(SourceVector v, float s) => new SourceVector(v.x - s, v.y - s, v.z - s); //< broadcast sub
|
||||
|
||||
// negate the vector components
|
||||
public void Negate()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
// Get the vector's magnitude.
|
||||
public float Length() => (float)Math.Sqrt(x * x + y * y + z * z);
|
||||
|
||||
// Get the vector's magnitude squared.
|
||||
public float LengthSqr() => (x * x + y * y + z * z);
|
||||
|
||||
// return true if this vector is (0,0,0) within tolerance
|
||||
public bool IsZero(float tolerance = 0.01f)
|
||||
{
|
||||
return x > -tolerance && x < tolerance &&
|
||||
y > -tolerance && y < tolerance &&
|
||||
z > -tolerance && z < tolerance;
|
||||
}
|
||||
|
||||
public bool IsLengthGreaterThan(float val) => LengthSqr() > val * val;
|
||||
public bool IsLengthLessThan(float val) => LengthSqr() < val * val;
|
||||
|
||||
// check if a vector is within the box defined by two other vectors // check a point against a box
|
||||
public bool WithinAABox(SourceVector boxmin, SourceVector boxmax)
|
||||
{
|
||||
return (x >= boxmin.x) && (x <= boxmax.x) &&
|
||||
(y >= boxmin.y) && (y <= boxmax.y) &&
|
||||
(z >= boxmin.z) && (z <= boxmax.z);
|
||||
}
|
||||
|
||||
// Get the distance from this vector to the other one.
|
||||
public float DistTo(SourceVector vOther)
|
||||
{
|
||||
return new SourceVector(
|
||||
ix: x - vOther.x,
|
||||
iy: y - vOther.y,
|
||||
iz: z - vOther.z
|
||||
).Length();
|
||||
}
|
||||
|
||||
// Get the distance from this vector to the other one squared.
|
||||
// NJS: note, VC wasn't inlining it correctly in several deeply nested inlines due to being an 'out of line' inline.
|
||||
// may be able to tidy this up after switching to VC7
|
||||
public float DistToSqr(SourceVector vOther)
|
||||
{
|
||||
return new SourceVector(
|
||||
ix: x - vOther.x,
|
||||
iy: y - vOther.y,
|
||||
iz: z - vOther.z
|
||||
).LengthSqr();
|
||||
}
|
||||
|
||||
// Multiply, add, and assign to this (ie: *this = a + b * scalar). This
|
||||
// is about 12% faster than the actual vector equation (because it's done per-component
|
||||
// rather than per-vector).
|
||||
public void MulAdd(SourceVector a, SourceVector b, float scalar)
|
||||
{
|
||||
x = a.x + b.x * scalar;
|
||||
y = a.y + b.y * scalar;
|
||||
z = a.z + b.z * scalar;
|
||||
}
|
||||
|
||||
// Dot product.
|
||||
public float Dot(SourceVector vOther) => (x * vOther.x + y * vOther.y + z * vOther.z);
|
||||
|
||||
|
||||
// 2d
|
||||
public float Length2D() => (float)Math.Sqrt(Length2DSqr());
|
||||
public float Length2DSqr() => (x * x + y * y);
|
||||
|
||||
|
||||
// Cross product between two vectors.
|
||||
public SourceVector Cross(SourceVector vOther)
|
||||
{
|
||||
return new SourceVector(
|
||||
ix: y * vOther.z - z * vOther.y,
|
||||
iy: z * vOther.x - x * vOther.z,
|
||||
iz: x * vOther.y - y * vOther.x
|
||||
);
|
||||
}
|
||||
|
||||
// Returns a vector with the min or max in X, Y, and Z.
|
||||
public SourceVector Min(SourceVector vOther)
|
||||
{
|
||||
return new SourceVector(x < vOther.x ? x : vOther.x,
|
||||
y < vOther.y ? y : vOther.y,
|
||||
z < vOther.z ? z : vOther.z);
|
||||
}
|
||||
public SourceVector Max(SourceVector vOther)
|
||||
{
|
||||
return new SourceVector(x > vOther.x ? x : vOther.x,
|
||||
y > vOther.y ? y : vOther.y,
|
||||
z > vOther.z ? z : vOther.z);
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}; {z}}}";
|
||||
|
||||
public static SourceVector Empty => new SourceVector();
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector3 toVector3() => new UnityEngine.Vector3(x, y, z);
|
||||
#else
|
||||
public System.Numerics.Vector3 toVector3() => new System.Numerics.Vector3(x, y, z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb2fb64018589c94bb555489a6bf3de0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y (float)
|
||||
/// Size: 8 bytes (4 bytes per axis).
|
||||
/// Is Vector2D in Source Engine.
|
||||
/// </summary>
|
||||
public struct SourceVector2
|
||||
{
|
||||
public float x, y;
|
||||
|
||||
public SourceVector2(float ix = 0.0f, float iy = 0.0f)
|
||||
{
|
||||
this.x = ix;
|
||||
this.y = iy;
|
||||
}
|
||||
|
||||
// Initialization methods
|
||||
public static SourceVector2 Random(float minVal, float maxVal)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return new SourceVector2(
|
||||
ix: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal),
|
||||
iy: minVal + ((float)rand.NextDouble()) * (float)(maxVal - minVal)
|
||||
);
|
||||
}
|
||||
|
||||
// equality
|
||||
public static bool operator ==(SourceVector2 v1, SourceVector2 v2) => v1.x == v2.x && v1.y == v2.y;
|
||||
public static bool operator !=(SourceVector2 v1, SourceVector2 v2) => !(v1 == v2);
|
||||
|
||||
public override bool Equals(object obj) => this == (SourceVector2)obj;
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
|
||||
// arithmetic operations
|
||||
public static SourceVector2 operator +(SourceVector2 v1, SourceVector2 v2) => new SourceVector2(v1.x + v2.x, v1.y + v2.y);
|
||||
public static SourceVector2 operator -(SourceVector2 v1, SourceVector2 v2) => new SourceVector2(v1.x - v2.x, v1.y - v2.y);
|
||||
public static SourceVector2 operator *(SourceVector2 v1, SourceVector2 v2) => new SourceVector2(v1.x * v2.x, v1.y * v2.y);
|
||||
public static SourceVector2 operator *(SourceVector2 v, float s) => new SourceVector2(v.x * s, v.y * s);
|
||||
public static SourceVector2 operator /(SourceVector2 v1, SourceVector2 v2)
|
||||
{
|
||||
return new SourceVector2(
|
||||
ix: v2.x != 0.0f ? v1.x / v2.x : 0f,
|
||||
iy: v2.y != 0.0f ? v1.y / v2.y : 0f
|
||||
);
|
||||
}
|
||||
public static SourceVector2 operator /(SourceVector2 v, float fl)
|
||||
{
|
||||
if (fl == 0.0f)
|
||||
return new SourceVector2();
|
||||
float oofl = 1.0f / fl;
|
||||
return new SourceVector2(v.x * oofl, v.y * oofl);
|
||||
}
|
||||
|
||||
// negate the Vector2D components
|
||||
public void Negate()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
// Get the Vector2D's magnitude.
|
||||
public float Length() => (float)Math.Sqrt(LengthSqr());
|
||||
|
||||
// Get the Vector2D's magnitude squared.
|
||||
public float LengthSqr() => (x * x + y * y);
|
||||
|
||||
// return true if this vector is (0,0) within tolerance
|
||||
public bool IsZero(float tolerance = 0.01f)
|
||||
{
|
||||
return x > -tolerance && x < tolerance &&
|
||||
y > -tolerance && y < tolerance;
|
||||
}
|
||||
|
||||
// Compare length.
|
||||
public bool IsLengthGreaterThan(float val) => LengthSqr() > val * val;
|
||||
public bool IsLengthLessThan(float val) => LengthSqr() < val * val;
|
||||
|
||||
// Get the distance from this Vector2D to the other one.
|
||||
public float DistTo(SourceVector2 vOther)
|
||||
{
|
||||
return new SourceVector2(
|
||||
ix: x - vOther.x,
|
||||
iy: y - vOther.y
|
||||
).Length();
|
||||
}
|
||||
|
||||
// Get the distance from this Vector2D to the other one squared.
|
||||
public float DistToSqr(SourceVector2 vOther)
|
||||
{
|
||||
return new SourceVector2(
|
||||
ix: x - vOther.x,
|
||||
iy: y - vOther.y
|
||||
).LengthSqr();
|
||||
}
|
||||
|
||||
// Multiply, add, and assign to this (ie: *this = a + b * scalar). This
|
||||
// is about 12% faster than the actual Vector2D equation (because it's done per-component
|
||||
// rather than per-Vector2D).
|
||||
public void MulAdd(SourceVector2 a, SourceVector2 b, float scalar)
|
||||
{
|
||||
x = a.x + b.x * scalar;
|
||||
y = a.y + b.y * scalar;
|
||||
}
|
||||
|
||||
// Dot product.
|
||||
public float Dot(SourceVector2 vOther) => (x * vOther.x + y * vOther.y);
|
||||
|
||||
// Returns a SourceVector2 with the min or max in X, Y, and Z.
|
||||
public SourceVector2 Min(SourceVector2 vOther)
|
||||
{
|
||||
return new SourceVector2(x < vOther.x ? x : vOther.x,
|
||||
y < vOther.y ? y : vOther.y);
|
||||
}
|
||||
public SourceVector2 Max(SourceVector2 vOther)
|
||||
{
|
||||
return new SourceVector2(x > vOther.x ? x : vOther.x,
|
||||
y > vOther.y ? y : vOther.y);
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}}}";
|
||||
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector2 toVector2() => new UnityEngine.Vector2(x, y);
|
||||
#else
|
||||
public System.Numerics.Vector2 toVector2() => new System.Numerics.Vector2(x, y);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01a389a372b218e4badb9aa349210a72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y (int)
|
||||
/// Size: 8 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceVector2Int
|
||||
{
|
||||
public int x, y;
|
||||
|
||||
public SourceVector2Int(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}}}";
|
||||
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector2 toVector2() => new UnityEngine.Vector2(x, y);
|
||||
#else
|
||||
public System.Numerics.Vector2 toVector2() => new System.Numerics.Vector2(x, y);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee4829acf0c1cc741af51994378390ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y (short)
|
||||
/// Size: 4 bytes (2 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceVector2Short
|
||||
{
|
||||
public short x, y;
|
||||
|
||||
public SourceVector2Short(short x, short y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}}}";
|
||||
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector2 toVector2() => new UnityEngine.Vector2(x, y);
|
||||
#else
|
||||
public System.Numerics.Vector2 toVector2() => new System.Numerics.Vector2(x, y);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 885618187896fa349b2d688f7f4e562d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y/z/w (float)
|
||||
/// Size: 16 bytes (4 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceVector4
|
||||
{
|
||||
public float x, y, z, w;
|
||||
|
||||
public SourceVector4(float x, float y, float z, float w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}; {z}; {w}}}";
|
||||
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector4 toVector4() => new UnityEngine.Vector4(x, y, z, w);
|
||||
#else
|
||||
public System.Numerics.Vector4 toVector4() => new System.Numerics.Vector4(x, y, z, w);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90caee6c805baba4c9e44f68259e1f98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace SourceFormatParser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector x/y/z (short)
|
||||
/// Size: 6 bytes (2 bytes per axis)
|
||||
/// </summary>
|
||||
public struct SourceVectorShort
|
||||
{
|
||||
public short x, y, z;
|
||||
|
||||
public SourceVectorShort(short x, short y, short z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{{{x}; {y}; {z}}}";
|
||||
|
||||
#if (UNITY)
|
||||
public UnityEngine.Vector3 toVector3() => new UnityEngine.Vector3(x, y, z);
|
||||
#else
|
||||
public System.Numerics.Vector3 toVector3() => new System.Numerics.Vector3(x, y, z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9246da7cb8798c4db4f0fef0e99ee3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user