1 /***********************************************************************
2 GlobalWaterTool - Tool class to globally add or remove water from an
3 augmented reality sandbox.
4 Copyright (c) 2012-2018 Oliver Kreylos
6 This file is part of the Augmented Reality Sandbox (SARndbox).
8 The Augmented Reality Sandbox is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Augmented Reality Sandbox is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with the Augmented Reality Sandbox; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
23 #include "GlobalWaterTool.h"
25 #include <Vrui/ToolManager.h>
27 #include "WaterTable2.h"
30 /****************************************
31 Static elements of class GlobalWaterTool:
32 ****************************************/
34 GlobalWaterToolFactory
* GlobalWaterTool::factory
= 0;
36 /********************************
37 Methods of class GlobalWaterTool:
38 ********************************/
40 GlobalWaterToolFactory
* GlobalWaterTool::initClass(Vrui::ToolManager
& toolManager
) {
41 /* Create the tool factory: */
42 factory
= new GlobalWaterToolFactory("GlobalWaterTool", "Manage Water", 0, toolManager
);
44 /* Set up the tool class' input layout: */
45 factory
->setNumButtons(2);
46 factory
->setButtonFunction(0, "Rain");
47 factory
->setButtonFunction(1, "Dry");
49 /* Register and return the class: */
50 toolManager
.addClass(factory
, Vrui::ToolManager::defaultToolFactoryDestructor
);
54 GlobalWaterTool::GlobalWaterTool(const Vrui::ToolFactory
* factory
,
55 const Vrui::ToolInputAssignment
& inputAssignment
)
56 : Vrui::Tool(factory
, inputAssignment
) {
59 GlobalWaterTool::~GlobalWaterTool(void) {
62 const Vrui::ToolFactory
* GlobalWaterTool::getFactory(void) const {
66 void GlobalWaterTool::buttonCallback(int buttonSlotIndex
,
67 Vrui::InputDevice::ButtonCallbackData
* cbData
) {
68 /* Calculate the amount of water to add/remove: */
70 if(cbData
->newButtonState
) { // Button was just pressed
71 /* Add fixed amount of water/second: */
72 waterAmount
= application
->waterSpeed
> 0.0 ? application
->rainStrength
/ application
->waterSpeed
:
75 /* Invert water amount for drain button: */
76 if(buttonSlotIndex
== 1)
77 waterAmount
= -waterAmount
;
79 /* Remember amount for button release event: */
80 waterAmounts
[buttonSlotIndex
] = waterAmount
;
81 } else { // Button was just released
82 /* Invert the water amount added when button was pressed: */
83 waterAmount
= -waterAmounts
[buttonSlotIndex
];
86 /* Add water amount to water table: */
87 application
->waterTable
->setWaterDeposit(application
->waterTable
->getWaterDeposit() + waterAmount
);