diff --git a/src/gamelogic.cpp b/src/gamelogic.cpp index 5b8c282..4edef5f 100644 --- a/src/gamelogic.cpp +++ b/src/gamelogic.cpp @@ -37,6 +37,7 @@ SceneNode* rootNode; SceneNode* boxNode; SceneNode* ballNode; SceneNode* padNode; +std::vector 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); diff --git a/src/sceneGraph.hpp b/src/sceneGraph.hpp index 66180a1..762f0ad 100644 --- a/src/sceneGraph.hpp +++ b/src/sceneGraph.hpp @@ -8,8 +8,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -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 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. \ No newline at end of file +// For more details, see SceneGraph.cpp.