mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Additional 3d support
This commit is contained in:
parent
70680fdf39
commit
f26df6c86b
32 changed files with 2370 additions and 165 deletions
|
@ -26,11 +26,11 @@ Beefy::Quaternion Beefy::Quaternion::Slerp(float fT, const Quaternion& rkP, cons
|
|||
if ((fabs(fCos) < 1.0f - BF_MS_EPSILON) && (false))
|
||||
{
|
||||
// Standard case (slerp)
|
||||
float fSin = sqrt(1.0f - (fCos * fCos));
|
||||
float fAngle = atan2(fSin, fCos);
|
||||
float fSin = sqrtf(1.0f - (fCos * fCos));
|
||||
float fAngle = atan2f(fSin, fCos);
|
||||
float fInvSin = 1.0f / fSin;
|
||||
float fCoeff0 = sin((1.0f - fT) * fAngle) * fInvSin;
|
||||
float fCoeff1 = sin(fT * fAngle) * fInvSin;
|
||||
float fCoeff0 = sinf((1.0f - fT) * fAngle) * fInvSin;
|
||||
float fCoeff1 = sinf(fT * fAngle) * fInvSin;
|
||||
return fCoeff0 * rkP + fCoeff1 * rkT;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -114,7 +114,7 @@ public:
|
|||
static Quaternion Normalise(const Quaternion& quat)
|
||||
{
|
||||
float len = quat.Norm();
|
||||
float factor = 1.0f / sqrt(len);
|
||||
float factor = 1.0f / sqrtf(len);
|
||||
return quat * factor;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ Vector3::Vector3(float x, float y, float z)
|
|||
|
||||
float Vector3::GetMagnitude() const
|
||||
{
|
||||
return sqrt(mX*mX + mY*mY + mZ*mZ);
|
||||
return sqrtf(mX*mX + mY*mY + mZ*mZ);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Normalize(const Vector3& vec)
|
||||
|
@ -75,4 +75,14 @@ Vector3 Vector3::Transform2(const Vector3& vec, const Quaternion& quat)
|
|||
result.mZ = vec.mZ + z * quat.mW + (quat.mX * y - quat.mY * x);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
Vector4::Vector4(float x, float y, float z, float w)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
mZ = z;
|
||||
mW = w;
|
||||
}
|
|
@ -94,4 +94,64 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class Vector4
|
||||
{
|
||||
public:
|
||||
float mX;
|
||||
float mY;
|
||||
float mZ;
|
||||
float mW;
|
||||
|
||||
public:
|
||||
Vector4(float x = 0, float y = 0, float z = 0, float w = 0);
|
||||
|
||||
bool operator==(const Vector4& check) const
|
||||
{
|
||||
return (mX == check.mX) && (mY == check.mY) && (mZ == check.mZ);
|
||||
}
|
||||
|
||||
bool operator!=(const Vector4& check) const
|
||||
{
|
||||
return (mX != check.mX) || (mY != check.mY) || (mZ != check.mZ);
|
||||
}
|
||||
|
||||
static Vector4 Scale(const Vector4& vec, float scale)
|
||||
{
|
||||
return Vector4(vec.mX * scale, vec.mY * scale, vec.mZ * scale, vec.mW * scale);
|
||||
}
|
||||
|
||||
Vector4 operator +(const Vector4& v2) const
|
||||
{
|
||||
return Vector4(mX + v2.mX, mY + v2.mY, mZ + v2.mZ, mW + v2.mW);
|
||||
}
|
||||
|
||||
Vector4 operator *(const Vector4& v2) const
|
||||
{
|
||||
return Vector4(mX * v2.mX, mY * v2.mY, mZ * v2.mZ, mW * v2.mW);
|
||||
}
|
||||
|
||||
Vector4 operator *(float scale) const
|
||||
{
|
||||
return Vector4(mX * scale, mY * scale, mZ * scale, mW * scale);
|
||||
}
|
||||
|
||||
inline Vector4& operator -= (const Vector4& vec)
|
||||
{
|
||||
mX -= vec.mX;
|
||||
mY -= vec.mY;
|
||||
mZ -= vec.mZ;
|
||||
mW -= vec.mW;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4& operator *= (const Vector4& vec)
|
||||
{
|
||||
mX *= vec.mX;
|
||||
mY *= vec.mY;
|
||||
mZ *= vec.mZ;
|
||||
mW *= vec.mW;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
NS_BF_END;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue