add a few lights to the scene

This commit is contained in:
2026-01-22 13:53:03 +01:00
parent 997d4d2b9f
commit 071ce35d11
2 changed files with 37 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ SceneNode* rootNode;
SceneNode* boxNode;
SceneNode* ballNode;
SceneNode* padNode;
std::vector<SceneNode*> lightNodes;
double ballRadius = 3.0f;
@@ -127,6 +128,34 @@ void initGame(GLFWwindow* window, CommandLineOptions gameOptions) {
padNode = createSceneNode();
ballNode = createSceneNode();
for (int i = 0; i < 3; i++) {
auto lightNode = new SceneNode();
lightNode->nodeType = POINT_LIGHT;
lightNode->lightIdx = i;
lightNodes.push_back(lightNode);
}
auto ceilingLight = lightNodes.at(0);
auto padLight = lightNodes.at(1);
auto ballLight = lightNodes.at(2);
ceilingLight->position = {
boxDimensions.x / 2,
boxDimensions.y,
boxDimensions.z / 2
};
rootNode->children.push_back(ceilingLight);
padLight->position = {
padPositionX,
50,
padPositionZ
};
padNode->children.push_back(padLight);
ballLight->position = ballPosition;
ballNode->children.push_back(ballLight);
rootNode->children.push_back(boxNode);
rootNode->children.push_back(padNode);
rootNode->children.push_back(ballNode);

View File

@@ -8,8 +8,8 @@
#include <vector>
#include <cstdio>
#include <stdbool.h>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
#include <ctime>
#include <chrono>
#include <fstream>
@@ -29,12 +29,13 @@ struct SceneNode {
nodeType = GEOMETRY;
lightIdx = -1;
}
// A list of all children that belong to this node.
// For instance, in case of the scene graph of a human body shown in the assignment text, the "Upper Torso" node would contain the "Left Arm", "Right Arm", "Head" and "Lower Torso" nodes in its list of children.
std::vector<SceneNode*> children;
// The node's position and rotation relative to its parent
glm::vec3 position;
glm::vec3 rotation;
@@ -52,6 +53,9 @@ struct SceneNode {
// Node type is used to determine how to handle the contents of a node
SceneNodeType nodeType;
// indexes into global array of light nodes
unsigned int lightIdx;
};
SceneNode* createSceneNode();
@@ -59,4 +63,4 @@ void addChild(SceneNode* parent, SceneNode* child);
void printNode(SceneNode* node);
int totalChildren(SceneNode* parent);
// For more details, see SceneGraph.cpp.
// For more details, see SceneGraph.cpp.