openmohaa/code/skeletor/SkelVec3.h

210 lines
3.6 KiB
C
Raw Permalink Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
2023-11-06 17:58:58 +01:00
Copyright (C) 2023 the OpenMoHAA team
2016-03-27 11:49:47 +02:00
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// SkelVec3.h : Skeletor
2023-11-06 17:58:58 +01:00
#pragma once
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
typedef enum {
svX,
svY,
svZ,
svW
} SkelVec_Axis;
typedef enum {
Vec3YAW,
Vec3PITCH,
Vec3ROLL
} YPR_Axes;
2016-03-27 11:49:47 +02:00
#ifdef __cplusplus
2023-11-06 17:58:58 +01:00
class SkelVec3
{
2016-03-27 11:49:47 +02:00
public:
2023-11-06 17:58:58 +01:00
union {
float val[3];
struct {
float x;
float y;
float z;
};
};
2016-03-27 11:49:47 +02:00
protected:
2023-11-06 17:58:58 +01:00
void copy(const SkelVec3& skel);
2016-03-27 11:49:47 +02:00
public:
2023-11-06 17:58:58 +01:00
SkelVec3(float x, float y, float z);
SkelVec3(vec3_t vec);
SkelVec3();
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
operator float *();
operator float *() const;
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
float& operator[](int index);
float operator[](int index) const;
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
const SkelVec3& operator+=(const SkelVec3& a);
const SkelVec3& operator+=(vec3_t a);
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
bool IsZero() const;
bool IsUnit() const;
void set(float x, float y, float z);
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
float Normalize();
void NormalizeFast();
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
void SetZero();
void SetXAxis();
void SetYAxis();
void SetZAxis();
void RotateYaw(float yaw, float deg);
2016-03-27 11:49:47 +02:00
};
2023-11-06 17:58:58 +01:00
inline SkelVec3::SkelVec3(float x, float y, float z)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
set(x, y, z);
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline SkelVec3::SkelVec3(vec3_t vec)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
this->x = vec[0];
this->y = vec[1];
this->z = vec[2];
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline SkelVec3::SkelVec3()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
SetZero();
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline SkelVec3::operator float *()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return val;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline SkelVec3::operator float *() const
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return (float *)val;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline bool SkelVec3::IsZero() const
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return (x == 0.0f) && (y == 0.0f) && (z == 0.0f);
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline bool SkelVec3::IsUnit() const
2016-03-27 11:49:47 +02:00
{
2024-09-18 00:18:08 +02:00
return VectorLength(*this) == 1;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::set(float x, float y, float z)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
this->x = x;
this->y = y;
this->z = z;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline float SkelVec3::Normalize()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return VectorNormalize(val);
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::NormalizeFast()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
VectorNormalizeFast(val);
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::SetZero()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
this->x = 0.0f;
this->y = 0.0f;
this->z = 0.0f;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::SetXAxis()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
x = 0.0f;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::SetYAxis()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
y = 0.0f;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::SetZAxis()
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
z = 0.0f;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline void SkelVec3::RotateYaw(float yaw, float deg)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
// FIXME: stub
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline float& SkelVec3::operator[](int index)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return val[index];
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline float SkelVec3::operator[](int index) const
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
return val[index];
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline const SkelVec3& SkelVec3::operator+=(const SkelVec3& a)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
x += a.x;
y += a.y;
z += a.z;
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
return *this;
2016-03-27 11:49:47 +02:00
}
2023-11-06 17:58:58 +01:00
inline const SkelVec3& SkelVec3::operator+=(vec3_t a)
2016-03-27 11:49:47 +02:00
{
2023-11-06 17:58:58 +01:00
x += a[0];
y += a[1];
z += a[2];
2016-03-27 11:49:47 +02:00
2023-11-06 17:58:58 +01:00
return *this;
2016-03-27 11:49:47 +02:00
}
#else
typedef struct {
2023-11-06 17:58:58 +01:00
union {
float val[3];
struct {
float x;
float y;
float z;
};
};
2016-03-27 11:49:47 +02:00
} SkelVec3;
#endif