diff --git a/Assets/Scripts/options.lua b/Assets/Scripts/options.lua index 0afc55f..6aacf1a 100644 --- a/Assets/Scripts/options.lua +++ b/Assets/Scripts/options.lua @@ -48,13 +48,14 @@ mappings = { {bind = 36, trigger = 312, action = false, bindType = 2, inOptions = false}, {bind = 37, trigger = 313, action = false, bindType = 2, inOptions = false}, {bind = 38, trigger = 71, action = true, bindType = 0, inOptions = false}, - {bind = 39, trigger = 256, action = true, bindType = 0, inOptions = false}, - {bind = 40, trigger = 90, action = true, bindType = 0, inOptions = false}, - {bind = 41, trigger = 89, action = true, bindType = 0, inOptions = false}, - {bind = 42, trigger = 88, action = true, bindType = 0, inOptions = false}, - {bind = 43, trigger = 87, action = true, bindType = 0, inOptions = false}, - {bind = 44, trigger = 72, action = true, bindType = 0, inOptions = false}, - {bind = 45, trigger = 68, action = true, bindType = 0, inOptions = false}, + {bind = 39, trigger = 83, action = true, bindType = 0, inOptions = false}, + {bind = 40, trigger = 256, action = true, bindType = 0, inOptions = false}, + {bind = 41, trigger = 90, action = true, bindType = 0, inOptions = false}, + {bind = 42, trigger = 89, action = true, bindType = 0, inOptions = false}, + {bind = 43, trigger = 88, action = true, bindType = 0, inOptions = false}, + {bind = 44, trigger = 87, action = true, bindType = 0, inOptions = false}, + {bind = 45, trigger = 72, action = true, bindType = 0, inOptions = false}, + {bind = 46, trigger = 68, action = true, bindType = 0, inOptions = false}, } graphics = { resolution = {x = 1920, y = 1080} diff --git a/binds.h b/binds.h index 1fd4d59..f7cfa26 100644 --- a/binds.h +++ b/binds.h @@ -42,10 +42,11 @@ namespace battleship{ PUSH_VERTS_UP, PUSH_VERTS_DOWN, MOVE_TERR_OBJ, + SCALE_TERR_OBJ, STOP_TERR_OBJ, - MOVE_X_AXIS, - MOVE_Y_AXIS, - MOVE_Z_AXIS, + ENABLE_X_AXIS, + ENABLE_Y_AXIS, + ENABLE_Z_AXIS, CREATE_WATERBODY, GENERATE_WEIGHTS, TOGGLE_CELL_MARKERS diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 1ad703f..d8b8876 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -116,23 +116,46 @@ namespace battleship{ } void MapEditorAppState::MapEditor::moveTerrainObject(float strength){ - Vector3 pos = selectedTerrainNode->getPosition(); + if(fabs(strength) < .00001) return; - switch(movementAxis){ - case MovementAxis::X_AXIS: - pos += strength * Vector3::VEC_I; + Vector3 axis; + + switch(transformAxis){ + case TransformAxis::X_AXIS: + axis = Vector3::VEC_I; break; - case MovementAxis::Y_AXIS: - pos += strength * Vector3::VEC_J; + case TransformAxis::Y_AXIS: + axis = -Vector3::VEC_J; break; - case MovementAxis::Z_AXIS: - pos += strength * Vector3::VEC_K; + case TransformAxis::Z_AXIS: + axis = Vector3::VEC_K; break; } + Vector3 pos = selectedTerrainNode->getPosition() + 10 * strength * axis; selectedTerrainNode->setPosition(pos); } + void MapEditorAppState::MapEditor::scaleTerrainObject(float strength){ + if(fabs(strength) < .00001) return; + + Vector2 axis; + + switch(transformAxis){ + case TransformAxis::X_AXIS: + axis = Vector2::VEC_I; + break; + case TransformAxis::Z_AXIS: + axis = Vector2::VEC_J; + break; + } + + Quad *quad = (Quad*)selectedTerrainNode->getMesh(0); + Vector3 size = quad->getSize() + 10 * strength * Vector3(axis.x, axis.y, 0); + quad->setSize(Vector3(size.x, size.y, 1)); + quad->updateVerts(quad->getMeshBase()); + } + void MapEditorAppState::MapEditor::pushLandmassVerts(float strength){ Mesh *mesh = map->getNodeParent()->getChild(0)->getMesh(0); MeshData meshData = mesh->getMeshBase(); @@ -589,17 +612,29 @@ namespace battleship{ if(isPressed) mapEditor->createWaterbody(); break; case Bind::MOVE_TERR_OBJ: - if(isPressed) mapEditor->setMovingTerrainObject(true); - break; + if(isPressed){ + mapEditor->setMovingTerrainObject(true); + mapEditor->setScalingTerrainObject(false); + break; + } + case Bind::SCALE_TERR_OBJ: + if(isPressed){ + mapEditor->setMovingTerrainObject(false); + mapEditor->setScalingTerrainObject(true); + break; + } case Bind::STOP_TERR_OBJ: - if(isPressed) mapEditor->setMovingTerrainObject(false); - break; - case Bind::MOVE_X_AXIS: - case Bind::MOVE_Y_AXIS: - case Bind::MOVE_Z_AXIS: - if(isPressed && mapEditor->isMovingTerrainObject()){ - MapEditor::MovementAxis axis = MapEditor::MovementAxis((int)bind - (int)Bind::MOVE_X_AXIS); - mapEditor->setMovementAxis(axis); + if(isPressed){ + mapEditor->setMovingTerrainObject(false); + mapEditor->setScalingTerrainObject(false); + break; + } + case Bind::ENABLE_X_AXIS: + case Bind::ENABLE_Y_AXIS: + case Bind::ENABLE_Z_AXIS: + if(isPressed && (mapEditor->isMovingTerrainObject() || mapEditor->isScalingTerrainObject())){ + MapEditor::TransformAxis axis = MapEditor::TransformAxis((int)bind - (int)Bind::ENABLE_X_AXIS); + mapEditor->setTransformAxis(axis); } break; @@ -628,8 +663,12 @@ namespace battleship{ case Bind::PUSH_VERTS_UP: case Bind::PUSH_VERTS_DOWN: if(mapEditor->isPushing()) mapEditor->pushLandmassVerts(strength); - else if(mapEditor->isMovingTerrainObject() && mapEditor->getSelectedNode() != Map::getSingleton()->getNodeParent()->getChild(0)) - mapEditor->moveTerrainObject(strength); + else if(mapEditor->getSelectedNode() != Map::getSingleton()->getNodeParent()->getChild(0)){ + if(mapEditor->isScalingTerrainObject()) + mapEditor->scaleTerrainObject(strength); + else if(mapEditor->isMovingTerrainObject()) + mapEditor->moveTerrainObject(strength); + } break; } diff --git a/mapEditorAppState.h b/mapEditorAppState.h index 5fc1eca..8502f69 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -23,7 +23,7 @@ namespace battleship{ public: class MapEditor{ public: - enum MovementAxis{ + enum TransformAxis{ X_AXIS, Y_AXIS, Z_AXIS @@ -35,6 +35,7 @@ namespace battleship{ void castSelectionRay(); void createWaterbody(); void moveTerrainObject(float); + void scaleTerrainObject(float); void exportMap(); void prepareTerrainObjects(int = 0, int = -1); void togglePush(bool); @@ -45,8 +46,10 @@ namespace battleship{ inline void setPushPos(vb01::Vector3 p){pushPos = p;} inline bool isMovingTerrainObject(){return movingTerrainObject;} inline void setMovingTerrainObject(bool m){movingTerrainObject = m;} - inline MovementAxis getMovementAxis(){return movementAxis;} - inline void setMovementAxis(MovementAxis m){movementAxis = m;} + inline bool isScalingTerrainObject(){return scalingTerrainObject;} + inline void setScalingTerrainObject(bool s){scalingTerrainObject = s;} + inline TransformAxis getTransformAxis(){return transformAxis;} + inline void setTransformAxis(TransformAxis m){transformAxis = m;} inline bool isWeightsGenerated(){return weightsGenerated;} inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];} inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];} @@ -61,10 +64,10 @@ namespace battleship{ Map *map; vb01::Node *selectedTerrainNode = nullptr; - MovementAxis movementAxis = X_AXIS; + TransformAxis transformAxis = X_AXIS; vb01Gui::Listbox *skyListbox = nullptr; float *oldLandmassVertHeights = nullptr; - bool pushing = false, movingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false; + bool pushing = false, movingTerrainObject = false, scalingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false; const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1; const int NUM_SUBDIVS = 100; float circleRadius = MIN_RADIUS, guiThreshold = 200;