-
Notifications
You must be signed in to change notification settings - Fork 3
/
AbstractShape.h
80 lines (65 loc) · 1.61 KB
/
AbstractShape.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
73
74
75
76
77
78
79
#pragma once
#include <vector>
#include <string>
#include <memory>
#include <array>
#include <DirectXMath.h>
#include "RenderTriangle.h"
#include "Color.h"
using namespace DirectX;
class AbstractShape
{
public:
AbstractShape(Point position, float width, float height, Color color) {
m_position = position;
m_width = width;
m_height = height;
m_color = color;
m_triangles = nullptr;
m_isDirty = true;
m_modelMatrix = {};
}
~AbstractShape() {
delete[] m_triangles;
m_triangles = nullptr;
}
virtual void SetHeight(float) = 0;
virtual void SetWidth(float) = 0;
virtual void SetPosition(Point) = 0;
virtual void SetColor(Color) = 0;
virtual int GetTriangleCount() = 0;
const float& GetHeight() const { return m_height; }
const float& GetWidth() const { return m_width; }
const Point& GetPosition() const { return m_position; }
const Color& GetColor() const { return m_color; }
const RenderTriangle* GetTriangles() {
if (m_isDirty)
{
CalculateRenderData();
m_isDirty = false;
}
return m_triangles;
}
const XMMATRIX* GetModelmatrix() {
if (m_isDirty)
{
CalculateRenderData();
m_modelMatrix = { };
auto scaleMatrix = DirectX::XMMatrixScaling(m_width, m_height, 1);
auto translationMatrix = DirectX::XMMatrixTranslation(m_position.x, m_position.y, 0);
m_modelMatrix = scaleMatrix * translationMatrix;
m_isDirty = false;
}
return &m_modelMatrix;
}
protected:
virtual void CalculateRenderData() = 0;
bool m_isDirty;
Color m_color;
float m_height;
float m_width;
Point m_position;
std::string m_name;
RenderTriangle* m_triangles;
XMMATRIX m_modelMatrix;
};