Hide trees and grass in the path of the car

This commit is contained in:
Peder Bergebakken Sundt 2019-03-29 10:12:31 +01:00
parent 213ef68757
commit 0f702ea259
3 changed files with 11 additions and 1 deletions

View File

@ -144,6 +144,8 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
static Gloom::Shader* s = nullptr; // The currently active shader
static Gloom::Shader* prev_s = nullptr; // The last shader to glDrawElements
if (node->isHidden) return;
// activate the correct shader
Gloom::Shader* node_shader = (node->shader != nullptr)
? node->shader
@ -173,6 +175,7 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
//transparent_nodes->push_back({node, node_shader, glm::length(vec3(node->MVP*vec4(0,0,0,1)))});
}
else if(node->vertexArrayObjectID != -1) {
if (node->opacity <= 0.05) break;
// load uniforms
um4fv(MVP);
um4fv(MV);

View File

@ -244,7 +244,7 @@ void step_scene(double timeDelta) {
vec3 o = carNode->position;
o.x += plainNode->uvOffset.x*1000/3;
o.y += plainNode->uvOffset.y*1000/3;
float t = carNode->rotation.z + 3*3.1415926535/2.0;
float t/*heta*/ = carNode->rotation.z + 3*3.1415926535/2.0;
vec3 fr = o + vec3(60*glm::cos(t), 60*glm::sin(t), 0) + vec3(30*glm::sin(t), -30*glm::cos(t), 0);
vec3 fl = o + vec3(60*glm::cos(t), 60*glm::sin(t), 0) - vec3(30*glm::sin(t), -30*glm::cos(t), 0);
@ -273,6 +273,12 @@ void step_scene(double timeDelta) {
if (node->position.x > 1000.0) node->position.x -= 1000.0;
if (node->position.y > 1000.0) node->position.y -= 1000.0;
//node->position.z = DISPLACEMENT * (t_perlin.at_bilinear(node->position.x*3/1000, node->position.y*3/1000).x * 2 - 1) - 0.5;
// cull objects in the cars path
vec2 PQ = vec2(node->position - carNode->position);
vec2 N = flip(plane_movement)*vec2(1, -1);
float dist_from_path = glm::length(glm::dot(PQ, N)) / glm::length(N);
node->isHidden = dist_from_path < 60;
}
/*

View File

@ -99,6 +99,7 @@ struct SceneNode {
bool isInverted = false;
// rendering
bool isHidden = false;
Gloom::Shader* shader = nullptr;
mat4 MVP; // MVP
mat4 MV; // MV