-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.cpp
69 lines (57 loc) · 1.75 KB
/
Rectangle.cpp
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
#include "Rectangle.h"
Rectangle::Rectangle(
const Primitives& primitives,
float width,
float height ) :
primitives( primitives ),
width( width ),
height( height ) {
this->matrix = glm::mat4( 1.0f );
this->translation = glm::vec3( 0.0f, 0.0f, 0.0f );
this->rotation = glm::quat( 1.0f, 0.0f, 0.0f, 0.0f );
this->scale = glm::vec3( 1.0f, 1.0f, 1.0f );
this->pivot = glm::vec3( 0.0f, 0.0f, 0.0f );
this->scale.x = width / 2;
this->scale.y = height / 2;
this->UpdateBounds();
}
void Rectangle::UpdateBounds() {
this->minBound.x = this->translation.x - this->width / 2;
this->minBound.y = this->translation.y - this->height / 2;
this->maxBound.x = this->translation.x + this->width / 2;
this->maxBound.y = this->translation.y + this->height / 2;
}
void Rectangle::SetWidth( float value ) {
this->width = value;
this->scale.x = value / 2;
this->UpdateBounds();
}
void Rectangle::SetHeight( float value ) {
this->height = value;
this->scale.y = value / 2;
this->UpdateBounds();
}
void Rectangle::Draw( Shader& shader, Camera& camera ) {
this->primitives.DrawRectangle(
shader,
camera,
this->matrix,
this->translation,
this->rotation,
this->scale,
this->pivot );
}
void Rectangle::Translate( glm::vec3 displacementVec ) {
this->translation += displacementVec;
this->UpdateBounds();
}
void Rectangle::MoveTo( glm::vec3 newPosition ) {
this->translation = newPosition;
this->UpdateBounds();
}
void Rectangle::Rotate( float angle ) {
glm::vec3 rotVec( 0, 0, angle );
//this->Translate( this->pivot );
this->rotation = glm::quat( rotVec );
//this->Translate( -this->pivot );
}