- added some utilities

This commit is contained in:
Christoph Oelckers 2022-09-02 23:56:03 +02:00
parent fca2f8c683
commit e361abb96d
2 changed files with 34 additions and 6 deletions

View file

@ -665,6 +665,7 @@ struct TVector3
template<class vec_t>
struct TVector4
{
typedef TVector2<vec_t> Vector2;
typedef TVector3<vec_t> Vector3;
vec_t X, Y, Z, W;
@ -723,6 +724,29 @@ struct TVector4
return X != other.X || Y != other.Y || Z != other.Z || W != other.W;
}
// returns the XY fields as a 2D-vector.
const Vector2& XY() const
{
return *reinterpret_cast<const Vector2*>(this);
}
Vector2& XY()
{
return *reinterpret_cast<Vector2*>(this);
}
// returns the XY fields as a 2D-vector.
const Vector3& XYZ() const
{
return *reinterpret_cast<const Vector3*>(this);
}
Vector3& XYZ()
{
return *reinterpret_cast<Vector3*>(this);
}
// Test for approximate equality
bool ApproximatelyEquals(const TVector4 &other) const
{
@ -838,12 +862,6 @@ struct TVector4
return *this;
}
// returns the XYZ fields as a 3D-vector.
Vector3 XYZ() const
{
return{ X, Y, Z };
}
// Add a 4D vector and a 3D vector.
friend TVector4 operator+ (const TVector4 &v4, const Vector3 &v3)
{

View file

@ -240,6 +240,16 @@ public:
__int_vel = x;
}
void set_float_bvel(DVector3 x)
{
__int_vel = { FloatToFixed(x.X), FloatToFixed(x.Y), FloatToFixed(x.Z) };
}
void set_float_bvel_xy(DVector2 x)
{
__int_vel.XY() = { FloatToFixed(x.X), FloatToFixed(x.Y) };
}
void add_int_bvel_x(int x)
{
__int_vel .X += x;