From 87ca117748139626b1dfc0646c527af013f78610 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Mon, 25 Sep 2017 00:26:17 +0800 Subject: [PATCH] Add brush tool --- data | 2 +- src/application.cpp | 8 ++++++-- src/application.hpp | 3 +++ src/game/tool.cpp | 29 +++++++++++++++++++++++++++++ src/game/tool.hpp | 7 +++++++ src/states/play-state.cpp | 8 ++++++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/data b/data index 4477e2f..251460a 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 4477e2f006acafe4058764a7ccd95694e0f61502 +Subproject commit 251460a52158fbf7e3523257aaf134f66240fab6 diff --git a/src/application.cpp b/src/application.cpp index bc93ba2..9f29c16 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -592,9 +592,10 @@ bool Application::loadModels() nestModel = modelLoader->load("data/models/nest.mdl"); forcepsModel = modelLoader->load("data/models/forceps.mdl"); lensModel = modelLoader->load("data/models/lens.mdl"); + brushModel = modelLoader->load("data/models/brush.mdl"); biomeFloorModel = modelLoader->load("data/models/desert-floor.mdl"); - if (!antModel || !antHillModel || !nestModel || !forcepsModel || !lensModel) + if (!antModel || !antHillModel || !nestModel || !forcepsModel || !lensModel || !brushModel) { return false; } @@ -1068,7 +1069,7 @@ bool Application::loadUI() pieMenu->addOption(arcNorthTexture, toolLensTexture, std::bind(&Application::selectTool, this, lens), std::bind(&Application::deselectTool, this, lens)); pieMenu->addOption(arcEastTexture, toolForcepsTexture, std::bind(&Application::selectTool, this, forceps), std::bind(&Application::deselectTool, this, forceps)); pieMenu->addOption(arcSouthTexture, toolTrowelTexture, std::bind(&Application::selectTool, this, nullptr), std::bind(&Application::deselectTool, this, nullptr)); - pieMenu->addOption(arcWestTexture, toolBrushTexture, std::bind(&Application::selectTool, this, forceps), std::bind(&Application::deselectTool, this, nullptr)); + pieMenu->addOption(arcWestTexture, toolBrushTexture, std::bind(&Application::selectTool, this, brush), std::bind(&Application::deselectTool, this, brush)); uiRootElement->addChild(pieMenu->getContainer()); pieMenu->resize(); pieMenu->getContainer()->setVisible(false); @@ -1414,6 +1415,9 @@ bool Application::loadGame() lens = new Lens(lensModel); lens->setCameraController(surfaceCam); + brush = new Brush(brushModel); + brush->setCameraController(surfaceCam); + return true; } diff --git a/src/application.hpp b/src/application.hpp index 0d73528..a1fb660 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -55,6 +55,7 @@ class PieMenu; class Tool; class Forceps; class Lens; +class Brush; /** * Encapsulates the state of the application. @@ -366,6 +367,7 @@ public: Model* nestModel; Model* forcepsModel; Model* lensModel; + Model* brushModel; Model* biomeFloorModel; // Game variables @@ -392,6 +394,7 @@ public: Tool* currentTool; Forceps* forceps; Lens* lens; + Brush* brush; bool simulationPaused; // Debug diff --git a/src/game/tool.cpp b/src/game/tool.cpp index 7a2cc98..2cc052d 100644 --- a/src/game/tool.cpp +++ b/src/game/tool.cpp @@ -376,3 +376,32 @@ void Lens::update(float dt) modelInstance.setTranslation(translation); modelInstance.setRotation(rotation); } + +Brush::Brush(const Model* model) +{ + // Allocate pose and initialize to bind pose + pose = new Pose(model->getSkeleton()); + pose->reset(); + pose->concatenate(); + + // Setup model instance + modelInstance.setModel(model); + modelInstance.setPose(pose); + + hoverDistance = 0.0f; +} + +Brush::~Brush() +{ + delete pose; +} + +void Brush::update(float dt) +{ + Quaternion alignment = glm::angleAxis(cameraController->getAzimuth(), Vector3(0, 1, 0)); + Quaternion rotation = glm::normalize(alignment); + Vector3 translation = pick + Vector3(0, hoverDistance, 0); + + modelInstance.setTranslation(translation); + modelInstance.setRotation(rotation); +} diff --git a/src/game/tool.hpp b/src/game/tool.hpp index d600f5c..e4234e0 100644 --- a/src/game/tool.hpp +++ b/src/game/tool.hpp @@ -233,7 +233,14 @@ private: class Brush: public Tool { public: + Brush(const Model* model); + ~Brush(); + virtual void update(float dt); + +private: + Pose* pose; + float hoverDistance; }; #endif // TOOL_HPP diff --git a/src/states/play-state.cpp b/src/states/play-state.cpp index e782aeb..f223818 100644 --- a/src/states/play-state.cpp +++ b/src/states/play-state.cpp @@ -25,6 +25,7 @@ #include "../game/ant.hpp" #include "../game/tool.hpp" #include "../ui/toolbar.hpp" +#include "../ui/pie-menu.hpp" #include PlayState::PlayState(Application* application): @@ -52,6 +53,8 @@ void PlayState::enter() // Add tools to scene application->defaultLayer->addObject(application->forceps->getModelInstance()); application->defaultLayer->addObject(application->lens->getModelInstance()); + application->defaultLayer->addObject(application->brush->getModelInstance()); + // Add terrain to scene application->defaultLayer->addObject(&application->currentLevel->terrainSurface); @@ -90,6 +93,11 @@ void PlayState::enter() application->simulationPaused = false; + // Select forceps tool + //application->deselectTool(application->currentTool); + //application->selectTool(application->forceps); + application->pieMenu->select(1); + application->mouse->addMouseButtonObserver(this); }