forked from WenlinMao/SleepWalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareObject.cpp
More file actions
70 lines (55 loc) · 1.65 KB
/
Copy pathSquareObject.cpp
File metadata and controls
70 lines (55 loc) · 1.65 KB
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
/**
* @ Author: Wenlin Mao
* @ Create Time: 2021-10-30 18:35:37
* @ Modified by: Wenlin Mao
* @ Modified time: 2021-11-30 02:20:14
* @ Description: implementation of square object
*/
#include "load_save_png.hpp"
#include "data_path.hpp"
#include "SquareObject.hpp"
#include "Inivar.hpp"
#include "PlayerStats.hpp"
SquareObject::SquareObject(){
}
SquareObject::SquareObject(float mass, const glm::vec3& pos,
const glm::vec3& vel, bool isFixed, float r,
const std::string& filename, float l):
GameObject(mass, pos, vel, isFixed, filename, l), width(r){
createVerts();
prepareDraw();
}
SquareObject::~SquareObject(){}
void SquareObject::createVerts(){
vertex_positions = vector<glm::vec4>({
glm::vec4(width/2, width/2, 0.0f, 1.0f), // top right
glm::vec4(width/2, -width/2, 0.0f, 1.0f), // bottom right
glm::vec4(-width/2, -width/2, 0.0f, 1.0f), // bottom left
glm::vec4(-width/2, width/2, 0.0f, 1.0f) // top left
});
vertex_texcoords = vector<glm::vec2>({
glm::vec2(1.f,1.f),
glm::vec2(1.f,0.f),
glm::vec2(0.f,0.f),
glm::vec2(0.f,1.f)
});
indices = std::vector<unsigned int>({ 0, 1, 2, 2, 3, 0 });
}
void SquareObject::reset(){
GameObject::reset();
vertex_positions.clear();
}
void SquareObject::setWidth(float r){
width = r;
vertex_positions.clear();
createVerts();
prepareDraw();
}
void SquareObject::fadeOut() {
if (color.w > 0.f)
color.w -= MARKER_FADE_OUT;
}
void SquareObject::show(const glm::vec3& pos) {
position = pos + glm::vec3(0.f, 7.f, 0.f) * PlayerStats::Instance().rotMat;
color.w = 1.f;
}