From 0f702ea2593d5ebdbc2a9b334fd7a57aaac9f63e Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 29 Mar 2019 10:12:31 +0100 Subject: [PATCH] Hide trees and grass in the path of the car --- src/renderlogic.cpp | 3 +++ src/scene.cpp | 8 +++++++- src/sceneGraph.hpp | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/renderlogic.cpp b/src/renderlogic.cpp index e9a889b..ad419a0 100644 --- a/src/renderlogic.cpp +++ b/src/renderlogic.cpp @@ -144,6 +144,8 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vectorisHidden) 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, vectorpush_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); diff --git a/src/scene.cpp b/src/scene.cpp index 4817fd4..03799af 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -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; } /* diff --git a/src/sceneGraph.hpp b/src/sceneGraph.hpp index 3c16e55..8667f5e 100644 --- a/src/sceneGraph.hpp +++ b/src/sceneGraph.hpp @@ -99,6 +99,7 @@ struct SceneNode { bool isInverted = false; // rendering + bool isHidden = false; Gloom::Shader* shader = nullptr; mat4 MVP; // MVP mat4 MV; // MV