forked from nlichtenberg/OpenGL_Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleProtein.h
More file actions
99 lines (84 loc) · 2.67 KB
/
SimpleProtein.h
File metadata and controls
99 lines (84 loc) · 2.67 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//============================================================================
// Distributed under the MIT License. Author: Adrian Derstroff
//============================================================================
#ifndef OPENGL_FRAMEWORK_SIMPLEPROTEIN_H
#define OPENGL_FRAMEWORK_SIMPLEPROTEIN_H
#define FLOAT_MIN std::numeric_limits<float>::min()
#define FLOAT_MAX std::numeric_limits<float>::max()
// external includes
#include <GL/glew.h>
#include <glm/glm.hpp>
// project specific includes
#include "SimpleAtom.h"
class SimpleProtein {
public:
//_____________________________________//
// VARIABLES //
//_____________________________________//
std::string name;
std::vector<SimpleAtom> atoms;
glm::vec3 bbMin;
glm::vec3 bbMax;
//_____________________________________//
// CONSTRUCTOR //
//_____________________________________//
SimpleProtein(std::string name = "Protein") : name(name)
{
bbMin = glm::vec3(0, 0, 0);
bbMax = glm::vec3(0, 0, 0);
}
void setName(std::string name)
{
this->name = name;
}
void move(glm::vec3 offset)
{
for (int i = 0; i < atoms.size(); i++) {
atoms.at(i).pos += offset;
}
bbMin += offset;
bbMax += offset;
}
glm::vec3 getCenterOfGravity()
{
glm::vec3 cog = glm::vec3(0,0,0);
for (int i = 0; i < atoms.size(); i++) {
cog += atoms.at(i).pos;
}
if (atoms.size() > 0) cog /= atoms.size();
return cog;
}
void center()
{
glm::vec3 cog = getCenterOfGravity();
for (int i = 0; i < atoms.size(); i++) {
atoms.at(i).pos -= cog;
}
bbMin -= cog;
bbMax -= cog;
}
void recalculateBB()
{
if (atoms.size() > 0) {
bbMin = glm::vec3(FLOAT_MAX, FLOAT_MAX, FLOAT_MAX);
bbMax = glm::vec3(FLOAT_MIN, FLOAT_MIN, FLOAT_MIN);
for (int i = 0; i < atoms.size(); i++) {
SimpleAtom atom = atoms.at(i);
bbMin.x = glm::min(bbMin.x, atom.pos.x);
bbMin.y = glm::min(bbMin.y, atom.pos.y);
bbMin.z = glm::min(bbMin.z, atom.pos.z);
bbMax.x = glm::max(bbMax.x, atom.pos.x);
bbMax.y = glm::max(bbMax.y, atom.pos.y);
bbMax.z = glm::max(bbMax.z, atom.pos.z);
}
} else {
Logger::instance().print("No atoms to recalculate BB!", Logger::Mode::WARNING);
}
}
glm::vec3 extent()
{
//recalculateBB();
return (bbMax - bbMin);
}
};
#endif //OPENGL_FRAMEWORK_SIMPLEPROTEIN_H