Browse Source

Add brush tool

master
C. J. Howard 7 years ago
parent
commit
87ca117748
6 changed files with 54 additions and 3 deletions
  1. +1
    -1
      data
  2. +6
    -2
      src/application.cpp
  3. +3
    -0
      src/application.hpp
  4. +29
    -0
      src/game/tool.cpp
  5. +7
    -0
      src/game/tool.hpp
  6. +8
    -0
      src/states/play-state.cpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 4477e2f006acafe4058764a7ccd95694e0f61502
Subproject commit 251460a52158fbf7e3523257aaf134f66240fab6

+ 6
- 2
src/application.cpp View File

@ -592,9 +592,10 @@ bool Application::loadModels()
nestModel = modelLoader->load("data/models/nest.mdl"); nestModel = modelLoader->load("data/models/nest.mdl");
forcepsModel = modelLoader->load("data/models/forceps.mdl"); forcepsModel = modelLoader->load("data/models/forceps.mdl");
lensModel = modelLoader->load("data/models/lens.mdl"); lensModel = modelLoader->load("data/models/lens.mdl");
brushModel = modelLoader->load("data/models/brush.mdl");
biomeFloorModel = modelLoader->load("data/models/desert-floor.mdl"); biomeFloorModel = modelLoader->load("data/models/desert-floor.mdl");
if (!antModel || !antHillModel || !nestModel || !forcepsModel || !lensModel)
if (!antModel || !antHillModel || !nestModel || !forcepsModel || !lensModel || !brushModel)
{ {
return false; 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(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(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(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()); uiRootElement->addChild(pieMenu->getContainer());
pieMenu->resize(); pieMenu->resize();
pieMenu->getContainer()->setVisible(false); pieMenu->getContainer()->setVisible(false);
@ -1414,6 +1415,9 @@ bool Application::loadGame()
lens = new Lens(lensModel); lens = new Lens(lensModel);
lens->setCameraController(surfaceCam); lens->setCameraController(surfaceCam);
brush = new Brush(brushModel);
brush->setCameraController(surfaceCam);
return true; return true;
} }

+ 3
- 0
src/application.hpp View File

@ -55,6 +55,7 @@ class PieMenu;
class Tool; class Tool;
class Forceps; class Forceps;
class Lens; class Lens;
class Brush;
/** /**
* Encapsulates the state of the application. * Encapsulates the state of the application.
@ -366,6 +367,7 @@ public:
Model* nestModel; Model* nestModel;
Model* forcepsModel; Model* forcepsModel;
Model* lensModel; Model* lensModel;
Model* brushModel;
Model* biomeFloorModel; Model* biomeFloorModel;
// Game variables // Game variables
@ -392,6 +394,7 @@ public:
Tool* currentTool; Tool* currentTool;
Forceps* forceps; Forceps* forceps;
Lens* lens; Lens* lens;
Brush* brush;
bool simulationPaused; bool simulationPaused;
// Debug // Debug

+ 29
- 0
src/game/tool.cpp View File

@ -376,3 +376,32 @@ void Lens::update(float dt)
modelInstance.setTranslation(translation); modelInstance.setTranslation(translation);
modelInstance.setRotation(rotation); 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);
}

+ 7
- 0
src/game/tool.hpp View File

@ -233,7 +233,14 @@ private:
class Brush: public Tool class Brush: public Tool
{ {
public: public:
Brush(const Model* model);
~Brush();
virtual void update(float dt); virtual void update(float dt);
private:
Pose* pose;
float hoverDistance;
}; };
#endif // TOOL_HPP #endif // TOOL_HPP

+ 8
- 0
src/states/play-state.cpp View File

@ -25,6 +25,7 @@
#include "../game/ant.hpp" #include "../game/ant.hpp"
#include "../game/tool.hpp" #include "../game/tool.hpp"
#include "../ui/toolbar.hpp" #include "../ui/toolbar.hpp"
#include "../ui/pie-menu.hpp"
#include <cmath> #include <cmath>
PlayState::PlayState(Application* application): PlayState::PlayState(Application* application):
@ -52,6 +53,8 @@ void PlayState::enter()
// Add tools to scene // Add tools to scene
application->defaultLayer->addObject(application->forceps->getModelInstance()); application->defaultLayer->addObject(application->forceps->getModelInstance());
application->defaultLayer->addObject(application->lens->getModelInstance()); application->defaultLayer->addObject(application->lens->getModelInstance());
application->defaultLayer->addObject(application->brush->getModelInstance());
// Add terrain to scene // Add terrain to scene
application->defaultLayer->addObject(&application->currentLevel->terrainSurface); application->defaultLayer->addObject(&application->currentLevel->terrainSurface);
@ -90,6 +93,11 @@ void PlayState::enter()
application->simulationPaused = false; application->simulationPaused = false;
// Select forceps tool
//application->deselectTool(application->currentTool);
//application->selectTool(application->forceps);
application->pieMenu->select(1);
application->mouse->addMouseButtonObserver(this); application->mouse->addMouseButtonObserver(this);
} }

Loading…
Cancel
Save