-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTransform.h
72 lines (57 loc) · 1.5 KB
/
Transform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <ostream>
#include <string>
#include "Libraries/include/box2d/box2d.h"
#include "Interpolator.h"
struct Position
{
float x;
float y;
};
struct Scale
{
float x;
float y;
};
using Rotation = float;
class Transform
{
public:
Transform();
Transform(float xPos, float yPos, float rot, float xScale, float yScale);
Position getPosition() const;
void setPosition(float x, float y);
void translate(float x, float y);
void setPhysicsBody(b2Body* newBody);
b2Body* getPhysicsBody();
Scale getScale() const;
void setScale(float x, float y);
Rotation getRotation();
void setRotation(float r);
void rotate(float rDelta);
glm::mat4 getModelMatrix();
void setInterpolatorX(Interpolator* interpol);
void setInterpolatorY(Interpolator* interpol);
private:
Position position;
Scale scale;
Rotation rotation;
glm::mat4 modelMatrix;
b2Body* body;
Interpolator* interpolX;
Interpolator* interpolY;
// for optimizing matrix creation
// reset after every getModelMatrix()
bool changed;
void generateModelMatrix();
};
// a function that enables transform to be directly printed as a string into cout
inline std::ostream& operator<<(std::ostream& str, Transform const& t)
{
Position p = t.getPosition();
Scale s = t.getScale();
str << "transform pos: " << p.x << ", " << p.y << " scale: " << s.x << ", " << s.y;
return str;
}