-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLS_Sphere.cpp
More file actions
78 lines (57 loc) · 1.8 KB
/
LS_Sphere.cpp
File metadata and controls
78 lines (57 loc) · 1.8 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
#include "LS_Sphere.h"
CLS_Sphere::CLS_Sphere()
{
}
CLS_Sphere::~CLS_Sphere()
{
}
void CLS_Sphere::setScale(float newScale)
{
CLS_Shapes::setScale(newScale);
//Width of the circle is -1.0f to 1.0f which is 2.0f. Wdht and height is the same
this->setCollisionBox(glm::vec3(this->getScale(),this->getScale(), this->getScale()));
}
#ifdef GLUseShader
void CLS_Sphere::draw(GLuint shaderProgram)
{
GLuint modelMatrixLoc = glGetUniformLocation(shaderProgram, "modelMatrix");
GLuint colorLoc = glGetUniformLocation(shaderProgram, "objectColor");
glm::mat4 transMat = glm::translate(glm::mat4(1.0f), glm::vec3(this->getLocation().x, this->getLocation().y, 0.0f));
glm::mat4 scaleMat = glm::scale(glm::mat4(1.0f), glm::vec3(this->getScale(), this->getScale(), this->getScale()));
glm::mat4 rotatMat = glm::rotate(glm::mat4(1.0f), this->currentRotation, glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 medelMat = transMat * scaleMat * rotatMat;
glm::vec4 color;
#ifdef SHOW_COLLISION_HIGHLIGHT
if (this->getIsColliding())
{
color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
}
else
{
color = this->getColor();
}
#else
color = this->getColor();
#endif
glUniform4fv(colorLoc, 1, (GLfloat*)&color);
glUniformMatrix4fv(modelMatrixLoc, 1, GL_FALSE, &medelMat[0][0]);
glBindVertexArray(this->modelVAO);
glDrawElements(GL_TRIANGLE_FAN, this->shapeType, GL_UNSIGNED_INT, (GLvoid*)0);
glBindVertexArray(0);
color = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
glUniform4fv(colorLoc, 1, (GLfloat*)&color);
this->drawCenterCross();
}
#else
void CLS_Sphere::draw()
{
glPushMatrix();
glTranslatef(getLocation().x, getLocation().y, getLocation().z);
glPushMatrix();
glScalef(getScale(), getScale(), getScale());
glColor3f(getColor().x, getColor().y, getColor().z);
glutSolidSphere(0.5f, 20, 20);
glPopMatrix();
glPopMatrix();
}
#endif