-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerupNode.cpp
79 lines (68 loc) · 2.51 KB
/
PowerupNode.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
69
70
71
72
73
74
75
76
77
78
79
#include "PowerupNode.h"
#include "os.h"
#include "ColorSpec.h"
#include "Config.h"
#include "PropSpec.h"
PowerupNode::PowerupNode(const string& id, GLenum lightIndex, const PropSpec& initSpec)
: PropNode(id, initSpec), myRot_(0), myLight_(lightIndex) {
glEnable(myLight_);
}
PowerupNode::~PowerupNode() {
}
void PowerupNode::render() {
if (!myProp_.isActive()) {
glDisable(myLight_);
return;
}
myRot_ += 4;
if (myRot_ > 360) myRot_ = 0;
glPushMatrix();
GLfloat mat_emission[4];
for (int i = 0; i < 4; ++i) mat_emission[i] = 0.0;
// A little hacky, but not horrific...
if (myProp_.getType() == FEAR_POWERUP_PROP) {
Config::FEAR_POWERUP_COLOR->set();
glLightfv(myLight_, GL_AMBIENT, Config::FEAR_POWERUP_AMB);
glLightfv(myLight_, GL_DIFFUSE, Config::FEAR_POWERUP_DIF);
glLightfv(myLight_, GL_SPECULAR, Config::FEAR_POWERUP_SPEC);
mat_emission[0] = 0.9;
}
else if (myProp_.getType() == FREEZE_POWERUP_PROP) {
Config::FREEZE_POWERUP_COLOR->set();
glLightfv(myLight_, GL_AMBIENT, Config::FREEZE_POWERUP_AMB);
glLightfv(myLight_, GL_DIFFUSE, Config::FREEZE_POWERUP_DIF);
glLightfv(myLight_, GL_SPECULAR, Config::FREEZE_POWERUP_SPEC);
mat_emission[2] = 0.9;
}
else {
Config::SPEED_POWERUP_COLOR->set();
glLightfv(myLight_, GL_AMBIENT, Config::SPEED_POWERUP_AMB);
glLightfv(myLight_, GL_DIFFUSE, Config::SPEED_POWERUP_DIF);
glLightfv(myLight_, GL_SPECULAR, Config::SPEED_POWERUP_SPEC);
mat_emission[1] = 0.9;
}
GLfloat myPos_[4];
myPos_[0] = myProp_.getXPos(); myPos_[1] = Config::POWERUP_CENTER_HEIGHT; myPos_[2] = myProp_.getYPos(); myPos_[3] = 1;
glLightfv(myLight_, GL_POSITION, myPos_);
glLightf(myLight_, GL_CONSTANT_ATTENUATION, 0.1);
glLightf(myLight_, GL_QUADRATIC_ATTENUATION, 0.1);
glPushAttrib(GL_LIGHTING_BIT);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glMaterialfv(GL_FRONT, GL_AMBIENT, Config::SHINY_MAT_AMB);
glMaterialfv(GL_FRONT, GL_DIFFUSE, Config::SHINY_MAT_AMB);
glMaterialfv(GL_FRONT, GL_SPECULAR, Config::SHINY_MAT_SPEC);
glMaterialf(GL_FRONT, GL_SHININESS, 75);
glTranslated(myProp_.getXPos(), Config::POWERUP_CENTER_HEIGHT, myProp_.getYPos());
glRotated(myRot_, 0, 1, 0);
glPushMatrix();
glRotated(90, 1, 0, 0);
glutSolidCone(Config::POWERUP_DIM, 2 * Config::POWERUP_DIM, 4, 1);
glPopMatrix();
glPushMatrix();
glRotated(-90, 1, 0, 0);
glutSolidCone(Config::POWERUP_DIM, 2 * Config::POWERUP_DIM, 4, 1);
glPopMatrix();
glPopAttrib();
glPopMatrix();
SceneNode::render();
}