Somewhat working camera
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
using namespace Seele;
|
||||
|
||||
Transform::Transform()
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(Quaternion(0, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ Transform::Transform(Transform &&other)
|
||||
: position(other.position), rotation(other.rotation), scale(other.scale)
|
||||
{
|
||||
other.position = Vector4(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(1, 0, 0, 0);
|
||||
other.scale = Vector4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ Transform::Transform(const Transform &other)
|
||||
}
|
||||
|
||||
Transform::Transform(Vector position)
|
||||
: position(Vector4(position, 0)), rotation(Quaternion(0, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
: position(Vector4(position, 0)), rotation(Quaternion(1, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Vector position, Quaternion rotation)
|
||||
@@ -144,6 +144,19 @@ Vector Transform::getScale() const
|
||||
return Vector(scale);
|
||||
}
|
||||
|
||||
Vector Transform::getForward() const
|
||||
{
|
||||
return Vector(0, 0, 1) * rotation;
|
||||
}
|
||||
Vector Transform::getRight() const
|
||||
{
|
||||
return Vector(1, 0, 0) * rotation;
|
||||
}
|
||||
Vector Transform::getUp() const
|
||||
{
|
||||
return Vector(0, 1, 0) * rotation;
|
||||
}
|
||||
|
||||
bool Transform::equals(const Transform &other, float tolerance)
|
||||
{
|
||||
if (abs(position - other.position).length() > tolerance)
|
||||
@@ -174,6 +187,13 @@ void Transform::multiply(Transform *outTransform, const Transform *a, const Tran
|
||||
outTransform->position = b->rotation * (b->scale * a->position) + b->position;
|
||||
outTransform->scale = b->scale * a->scale;
|
||||
}
|
||||
void Transform::add(Transform *outTransform, const Transform *a, const Transform *b)
|
||||
{
|
||||
outTransform->position = a->position + b->position;
|
||||
outTransform->rotation = a->rotation + b->rotation;
|
||||
outTransform->scale = a->scale + b->scale;
|
||||
}
|
||||
|
||||
|
||||
Transform &Transform::operator=(const Transform &other)
|
||||
{
|
||||
@@ -189,11 +209,18 @@ Transform &Transform::operator=(Transform &&other)
|
||||
rotation = other.rotation;
|
||||
scale = other.scale;
|
||||
other.position = Vector4(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(0, 0, 0, 0);
|
||||
other.rotation = Quaternion(1, 0, 0, 0);
|
||||
other.scale = Vector4(0, 0, 0, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Transform Transform::operator+(const Transform & other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
add(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
}
|
||||
|
||||
Transform Transform::operator*(const Transform &other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
|
||||
@@ -23,12 +23,17 @@ public:
|
||||
Vector getPosition() const;
|
||||
Quaternion getRotation() const;
|
||||
Vector getScale() const;
|
||||
Vector getForward() const;
|
||||
Vector getRight() const;
|
||||
Vector getUp() const;
|
||||
|
||||
bool equals(const Transform &other, float tolerance = 0.000000001f);
|
||||
static void multiply(Transform *outTransform, const Transform *a, const Transform *b);
|
||||
static void add(Transform *outTransform, const Transform *a, const Transform *b);
|
||||
|
||||
Transform &operator=(const Transform &other);
|
||||
Transform &operator=(Transform &&other);
|
||||
Transform operator+(const Transform& other) const;
|
||||
Transform operator*(const Transform &other) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -64,30 +64,6 @@ static inline float normalizeRotatorAxis(float angle)
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline Quaternion toQuaternion(const Vector &other)
|
||||
{
|
||||
Quaternion result;
|
||||
const float DEG_TO_RAD = glm::pi<float>() / (180.f);
|
||||
const float RADS_DIVIDED_BY_2 = DEG_TO_RAD / 2.f;
|
||||
|
||||
const float PitchNoWinding = fmod(other.x, 360.0f);
|
||||
const float YawNoWinding = fmod(other.y, 360.0f);
|
||||
const float RollNoWinding = fmod(other.z, 360.0f);
|
||||
|
||||
const float SP = sin(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SY = sin(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SR = sin(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
|
||||
const float CP = cos(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CY = cos(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CR = cos(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
|
||||
result.x = CR * SP * SY - SR * CP * CY;
|
||||
result.y = -CR * SP * CY - SR * CP * SY;
|
||||
result.z = CR * CP * SY - SR * SP * CY;
|
||||
result.w = CR * CP * CY + SR * SP * SY;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline Vector toRotator(const Quaternion &other)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user