-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskydome.cpp
76 lines (55 loc) · 2.22 KB
/
skydome.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
#include "skydome.h"
#include "frustum.h"
#include "GL_utilities.h"
#include "LoadTGA.h"
#include "helper.h"
#include "math.h"
#include "cmath"
#include <iostream>
#include <random>
#include <jsoncpp/json/json.h>
Skydome::Skydome(Json::Value& c, const vec3& cameraPosition)
: Object(c["filename"].asString(), cameraPosition, c["scale"].asFloat()) {
object_program = loadShaders(c["shader_vert"].asString().c_str(), c["shader_frag"].asString().c_str());
LoadTGATextureSimple(c["texture"].asString().c_str(), &skyBoxtex);
return;
}
Skydome::Skydome(const std::string& filename, const vec3& cameraPosition, float sc)
: Object(filename, cameraPosition, sc) // Loads model based on filename, positions and scales
{
object_program = loadShaders("shaders/skydome.vert", "shaders/skydome.frag");
printError("Skybox Shader compile error");
LoadTGATextureSimple("textures/new_skybox.tga", &skyBoxtex);
glUniform1i(glGetUniformLocation(object_program, "texUnit"), 0);
printError("Skybox texUnit error");
return;
}
void Skydome::update(int time_elapsed, vec3 cameraPosition, vec3 lookAtPoint, std::map<char, bool> keys_pressed) {
vec3 new_pos = vec3(cameraPosition.x, cameraPosition.y-10, cameraPosition.z);
move(new_pos);
return;
}
void Skydome::display(const GLuint& program, const mat4& world2view, const mat4& projection, vec3 light_int) {
glUseProgram(object_program);
glUniform3f(glGetUniformLocation(object_program, "light_intensity"), light_int.x, light_int.y, light_int.z);
glUniformMatrix4fv(glGetUniformLocation(object_program, "viewMatrix"), 1, GL_TRUE, world2view.m);
glUniformMatrix4fv(glGetUniformLocation(object_program, "in_projectionMatrix"), 1, GL_TRUE, projection.m);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glBindTexture(GL_TEXTURE_2D, skyBoxtex);
upload2shader(object_program);
DrawModel(model, object_program, "in_Position", NULL, "in_TexCoord");
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glUseProgram(program);
return;
}
void Skydome::reset() {
rotationMatrix = IdentityMatrix();
return;
}
Skydome::~Skydome() {
delete model;
glDeleteProgram(object_program);
}