public SourceVector TransformVectorByInverse(SourceVector v0) { SourceVector vOut = new SourceVector(); MathUtils.VectorITransform(v0, this, ref vOut); return(vOut); }
public static void QuaternionVectorsFLU(SourceQuaternion q, ref SourceVector pForward, ref SourceVector pLeft, ref SourceVector pUp) { // Note: it's pretty much identical to just computing the quaternion matrix and assigning its columns to the vectors pForward = q.GetForward(); pLeft = q.GetLeft(); pUp = q.GetUp(); }
public SourceVector RotateVector(SourceVector v0) { SourceVector vOut = new SourceVector(); MathUtils.RotatePoint(this, v0, ref vOut); return(vOut); }
public SourceVector GetForward() { SourceVector vForward = new SourceVector(); MathUtils.TransformVectorsForward(this, ref vForward); return(vForward); }
public static void IRotateAABB(SourceMatrix3x4 transform, SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut) { throw new NotImplementedException(); //can't find some of methods //SourceVector oldCenter; //VectorAdd(vecMinsIn, vecMaxsIn, oldCenter); //oldCenter *= 0.5f; //SourceVector oldExtents; //VectorSubtract(vecMaxsIn, oldCenter, oldExtents); //SourceVector newCenter; //VectorIRotate(oldCenter, transform, newCenter); //SourceVector newExtents; //newExtents.x = FloatMakePositive(oldExtents.x * transform[0][0]) + // FloatMakePositive(oldExtents.y * transform[1][0]) + // FloatMakePositive(oldExtents.z * transform[2][0]); //newExtents.y = FloatMakePositive(oldExtents.x * transform[0][1]) + // FloatMakePositive(oldExtents.y * transform[1][1]) + // FloatMakePositive(oldExtents.z * transform[2][1]); //newExtents.z = FloatMakePositive(oldExtents.x * transform[0][2]) + // FloatMakePositive(oldExtents.y * transform[1][2]) + // FloatMakePositive(oldExtents.z * transform[2][2]); //VectorSubtract(newCenter, newExtents, vecMinsOut); //VectorAdd(newCenter, newExtents, vecMaxsOut); }
public static void ITransformAABB(SourceMatrix3x4 transform, SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut) { throw new NotImplementedException(); //can't find some of methods // SourceVector worldCenter; // VectorAdd(vecMinsIn, vecMaxsIn, worldCenter ); // worldCenter *= 0.5f; // SourceVector worldExtents; // VectorSubtract(vecMaxsIn, worldCenter, worldExtents ); // Vector localCenter; // VectorITransform(worldCenter, transform, localCenter ); // Vector localExtents; // localExtents.x = FloatMakePositive(worldExtents.x* transform[0][0] ) + //FloatMakePositive(worldExtents.y* transform[1][0] ) + //FloatMakePositive(worldExtents.z* transform[2][0] ); // localExtents.y = FloatMakePositive(worldExtents.x* transform[0][1] ) + //FloatMakePositive(worldExtents.y* transform[1][1] ) + //FloatMakePositive(worldExtents.z* transform[2][1] ); // localExtents.z = FloatMakePositive(worldExtents.x* transform[0][2] ) + //FloatMakePositive(worldExtents.y* transform[1][2] ) + //FloatMakePositive(worldExtents.z* transform[2][2] ); // VectorSubtract(localCenter, localExtents, vecMinsOut ); // VectorAdd(localCenter, localExtents, vecMaxsOut ); }
public SourceVector RotateVectorByInverse(SourceVector v0) { SourceVector vOut = new SourceVector(); MathUtils.VectorIRotate(v0, this, ref vOut); return(vOut); }
public static void VectorIRotate(SourceVector v, SourceCTransform t, ref SourceVector _out) { // FIXME: Make work directly with the transform SourceMatrix3x4 m = new SourceMatrix3x4(); TransformMatrix(t, ref m); VectorIRotate(v, m, ref _out); }
public static SourceVector TransformPoint(SourceCTransform tm, SourceVector p) { return(new SourceVector( tm.m_vPosition.x + (1.0f - 2.0f * tm.m_orientation.y * tm.m_orientation.y - 2.0f * tm.m_orientation.z * tm.m_orientation.z) * p.x + (2.0f * tm.m_orientation.x * tm.m_orientation.y - 2.0f * tm.m_orientation.w * tm.m_orientation.z) * p.y + (2.0f * tm.m_orientation.x * tm.m_orientation.z + 2.0f * tm.m_orientation.w * tm.m_orientation.y) * p.z, tm.m_vPosition.y + (2.0f * tm.m_orientation.x * tm.m_orientation.y + 2.0f * tm.m_orientation.w * tm.m_orientation.z) * p.x + (1.0f - 2.0f * tm.m_orientation.x * tm.m_orientation.x - 2.0f * tm.m_orientation.z * tm.m_orientation.z) * p.y + (2.0f * tm.m_orientation.y * tm.m_orientation.z - 2.0f * tm.m_orientation.w * tm.m_orientation.x) * p.z, tm.m_vPosition.z + (2.0f * tm.m_orientation.x * tm.m_orientation.z - 2.0f * tm.m_orientation.w * tm.m_orientation.y) * p.x + (2.0f * tm.m_orientation.y * tm.m_orientation.z + 2.0f * tm.m_orientation.w * tm.m_orientation.x) * p.y + (1.0f - 2.0f * tm.m_orientation.x * tm.m_orientation.x - 2.0f * tm.m_orientation.y * tm.m_orientation.y) * p.z )); }
// 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()); }
public static void QuaternionMatrix(SourceQuaternion q, SourceVector pos, ref SourceMatrix3x4 matrix) { QuaternionMatrix(q, ref matrix); matrix[0][3] = pos.x; matrix[1][3] = pos.y; matrix[2][3] = pos.z; }
// 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 )); }
public static void RotateAABB(SourceMatrix3x4 transform, SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut) { throw new NotImplementedException(); //can't find some of methods //SourceVector localCenter; //VectorAdd(vecMinsIn, vecMaxsIn, localCenter); //localCenter *= 0.5f; //SourceVector localExtents; //VectorSubtract(vecMaxsIn, localCenter, localExtents); //SourceVector newCenter; //VectorRotate(localCenter, transform, newCenter); //VecSourceVectortor newExtents; //newExtents.x = DotProductAbs(localExtents, transform[0]); //newExtents.y = DotProductAbs(localExtents, transform[1]); //newExtents.z = DotProductAbs(localExtents, transform[2]); //VectorSubtract(newCenter, newExtents, vecMinsOut); //VectorAdd(newCenter, newExtents, vecMaxsOut); }
public void TransformAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut) { ToMatrix().TransformAABBByInverse(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut); }
void Init(SourceVector vImaginaryPart, float flRealPart) { x = vImaginaryPart.x; y = vImaginaryPart.y; z = vImaginaryPart.z; w = flRealPart; }
public void GetBasisVectorsFLU(ref SourceVector pForward, ref SourceVector pLeft, ref SourceVector pUp) { MathUtils.TransformVectorsFLU(this, ref pForward, ref pLeft, ref pUp); }
public void SetOrigin(SourceVector vPos) { m_vPosition = vPos; }
public void SetToIdentity() { m_vPosition = SourceVector.Empty; m_orientation = SourceQuaternion.Identity; }
public void InitFromQuaternion(SourceQuaternion orientation, SourceVector vPosition) { m_orientation = orientation; m_vPosition = vPosition; }
public void InitFromMatrix(SourceMatrix3x4 transform) { m_orientation = MathUtils.MatrixQuaternion(transform); m_vPosition = transform.GetOrigin(); }
public SourceVector TransformVector(SourceVector v0) => MathUtils.TransformPoint(this, v0);
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)); }
// 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; }
public SourceVector RotateExtents(SourceVector vBoxExtents) { throw new NotImplementedException(); } // these are extents and must remain positive/symmetric after rotation
// Dot product. public float Dot(SourceVector vOther) => (x * vOther.x + y * vOther.y + z * vOther.z);
public void RotateAABBByInverse(SourceVector vecMinsIn, SourceVector vecMaxsIn, ref SourceVector vecMinsOut, ref SourceVector vecMaxsOut) { ToMatrix().RotateAABBByInverse(vecMinsIn, vecMaxsIn, ref vecMinsOut, ref vecMaxsOut); }
// 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 SourceCTransform(SourceVector v, SourceQAngle a) { m_vPosition = v; MathUtils.AngleQuaternion(a, ref m_orientation); }
// 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)); }
// for API compatibility with matrix3x4_t public void InitFromQAngles(SourceQAngle angles, SourceVector vPosition) { MathUtils.AngleQuaternion(angles, ref m_orientation); m_vPosition = vPosition; }