stuff-from-scratch/src/base/geometry/Transform.h
2023-02-26 18:23:21 +00:00

79 lines
1.5 KiB
C++

#pragma once
#include "Rotation.h"
struct Scale
{
Scale(double x = 1.0, double y = 1.0, double z = 1.0);
bool isIdentity() const;
bool isEqual(const Scale& scale) const;
void operator*=(const Scale& rhs)
{
mX *= rhs.mX;
mY *= rhs.mY;
mZ *= rhs.mZ;
}
bool operator==(const Scale& rhs) const
{
return isEqual(rhs);
}
bool operator!=(const Scale& rhs) const
{
return !operator==(rhs);
}
double mX{1.0};
double mY{1.0};
double mZ{1.0};
};
class Transform
{
public:
Transform(const Point3& location = {}, const Scale& scale = {}, const Rotation& rotation = {});
Transform(const Point2& location, const Scale& scale = {}, const Rotation& rotation = {});
void applyPre(const Transform& transform);
const Point3& getLocation() const;
const Scale& getScale() const;
const Rotation& getRotation() const;
const SquareMatrix4& getMatrix() const;
bool isEqual(const Transform& transform) const;
bool isIdentityTransform() const;
void setLocation(const Point3& loc);
void setScale(const Scale& scale);
void setRotation(const Rotation& rotation);
bool operator==(const Transform& rhs) const
{
return isEqual(rhs);
}
bool operator!=(const Transform& rhs) const
{
return !operator==(rhs);
}
private:
void updateMatrix();
Point3 mLocation;
Scale mScale;
Rotation mRotation;
SquareMatrix4 mMatrix;
};