From 166696041c4dbb19471ad3a8ffc648c0b6aeff15 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 12 Sep 2024 19:27:30 +0300 Subject: [PATCH] working circular lights around units --- activeGameState.cpp | 4 +++- gameObject.cpp | 1 + map.cpp | 11 +++++++++-- unit.cpp | 19 +++++++++++++------ unit.h | 4 +++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index 383f796..261cdde 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -333,6 +333,7 @@ namespace battleship{ for (Unit *u : units) { if (u->getPlayer() == mainPlayer){ + u->getLosLightNode()->setVisible(true); Vector2 pos = u->getScreenPos(); string guiScreen = u->getGuiScreen(); @@ -349,7 +350,8 @@ namespace battleship{ Vector3 compUnitPos = units[i]->getPos(); compUnitPos.y = 0; float dist = compUnitPos.getDistanceFrom(obsUnitPos); - units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); + units[i]->getNode()->setVisible(true); + //units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); } } } diff --git a/gameObject.cpp b/gameObject.cpp index 0249480..d752e77 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -103,6 +103,7 @@ namespace battleship{ Texture *diffuseTexture = new Texture(f, 1, false); mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("lightingEnabled", true); + mat->addBoolUniform("constLightingEnabled", false); mat->addTexUniform("textures[0]", diffuseTexture, true); } else{ diff --git a/map.cpp b/map.cpp index 7d337e9..3ef0167 100755 --- a/map.cpp +++ b/map.cpp @@ -125,6 +125,10 @@ namespace battleship{ Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("lightingEnabled", true); + mat->addBoolUniform("constLightingEnabled", true); + mat->addBoolUniform("normalMapEnabled", false); + mat->addBoolUniform("specularMapEnabled", false); + mat->addBoolUniform("castShadow", false); string fr[]{texPath}; AssetManager::getSingleton()->load(fr[0]); @@ -297,8 +301,11 @@ namespace battleship{ loadTerrainObject(i); } - Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion(1.57, Vector3::VEC_I)); - lightNode->addLight(new Light(Light::Type::DIRECTIONAL)); + Light *light = new Light(Light::Type::AMBIENT); + light->setColor(Vector3::VEC_IJK * .3); + + Node *lightNode = new Node(); + lightNode->addLight(light); Root::getSingleton()->getRootNode()->attachChild(lightNode); } diff --git a/unit.cpp b/unit.cpp index 751001c..964570c 100755 --- a/unit.cpp +++ b/unit.cpp @@ -410,16 +410,23 @@ namespace battleship{ } void Unit::initLosLight(){ - lightNode = new Node(); Light *light = new Light(Light::Type::POINT); - //light->setAttenuationValues(1, 1, 1); - model->attachChild(lightNode); + light->setAttenuation(Light::Attenuation::NONE); + light->setRadius(lineOfSight); + light->setColor(Vector3::VEC_IJK * .3); + light->setAdditiveLighting(false); + light->setUseAngle(false); + + losLightNode = new Node(Vector3::VEC_J * 5); + losLightNode->addLight(light); + losLightNode->setVisible(true); + model->attachChild(losLightNode); } void Unit::destroyLosLight(){ - model->dettachChild(lightNode); - delete lightNode; - lightNode = nullptr; + model->dettachChild(losLightNode); + delete losLightNode; + losLightNode = nullptr; } void Unit::destroySound(){ diff --git a/unit.h b/unit.h index 04df3be..3c9d9e1 100755 --- a/unit.h +++ b/unit.h @@ -21,6 +21,7 @@ namespace vb01{ class Mesh; class Quad; class Node; + class Light; class Camera; } @@ -156,6 +157,7 @@ namespace battleship{ inline int getNumOrders(){return orders.size();} inline std::string getGuiScreen(){return guiScreen;} inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];} + inline vb01::Node* getLosLightNode(){return losLightNode;} private: void renderOrderLine(bool); void updateScreenCoordinates(); @@ -168,7 +170,7 @@ namespace battleship{ const int orderVecDispLength = 2000, DEATH_HP = 0; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *lightNode = nullptr; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *losLightNode = nullptr; bool vehicle; protected: UnitClass unitClass;