diff --git a/activeGameState.cpp b/activeGameState.cpp index 6248054..949df80 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -622,4 +622,8 @@ namespace battleship{ break; } } + + void ActiveGameState::onRawMouseWheelScroll(bool up){ + CameraController::getSingleton()->zoomCamera(up); + } } diff --git a/activeGameState.h b/activeGameState.h index 0cf60ef..105c72e 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -27,6 +27,7 @@ namespace battleship{ void update(); void onAction(int, bool); void onAnalog(int, float); + void onRawMouseWheelScroll(bool); inline void addButton(vb01Gui::Button *b){buttons.push_back(b);} inline std::vector getButtons(){return buttons;} inline Player* getPlayer(){return mainPlayer;} diff --git a/cameraController.cpp b/cameraController.cpp index 2409e01..37a5403 100644 --- a/cameraController.cpp +++ b/cameraController.cpp @@ -51,4 +51,23 @@ namespace battleship{ Vector3 dir = rotQuat * cam->getDirection(), up = rotQuat * cam->getUp(); cam->lookAt(dir, up); } + + void CameraController::zoomCamera(bool zoomIn){ + if((zoomIn && numZooms > configData::NUM_MAX_ZOOMS) || (!zoomIn && numZooms < -configData::NUM_MAX_ZOOMS)) return; + + Vector3 newPos; + float offset; + + if(zoomIn){ + numZooms++; + offset = configData::CAMERA_ZOOM_INCREMENT; + } + else{ + numZooms--; + offset = -configData::CAMERA_ZOOM_INCREMENT; + } + + Camera *cam = Root::getSingleton()->getCamera(); + cam->setPosition(cam->getPosition() + cam->getDirection() * offset); + } } diff --git a/cameraController.h b/cameraController.h index c17abc3..b4998ac 100644 --- a/cameraController.h +++ b/cameraController.h @@ -9,12 +9,14 @@ namespace battleship{ static CameraController* getSingleton(); void updateCameraPosition(); void orientCamera(vb01::Vector3, double); + void zoomCamera(bool); inline bool isLookingAround(){return lookingAround;} inline void setLookingAround(bool l){lookingAround = l;} private: CameraController(){} bool lookingAround = false; + int numZooms = 0; }; } diff --git a/defConfigs.h b/defConfigs.h index abee4fb..fdfe6f1 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -20,7 +20,7 @@ namespace battleship{ using namespace gameBase; const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg"; - const double camPanSpeed = .1, cellLength = 14, cellWidth = 14, cellDepth = 7; + const double camPanSpeed = .1, CAMERA_DISTANCE = 50, CAMERA_ZOOM_INCREMENT = 1, NUM_MAX_ZOOMS = 25, cellLength = 14, cellWidth = 14, cellDepth = 7; const int maxNumGroups = 10; const vb01::u32 IMPASS_NODE_VAL = 65535; diff --git a/inGameAppState.cpp b/inGameAppState.cpp index dbd16da..d0678de 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -79,7 +79,7 @@ namespace battleship{ } Camera *cam = Root::getSingleton()->getCamera(); - cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId - 1) + Vector3(1, 1, 1) * 40); + cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId - 1) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); mainPlayer = Game::getSingleton()->getPlayer(playerId); diff --git a/map.cpp b/map.cpp index 5cc2f90..bdc50c5 100755 --- a/map.cpp +++ b/map.cpp @@ -225,7 +225,8 @@ namespace battleship{ waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1)); Camera *cam = root->getCamera(); - cam->setPosition(Vector3(1, 1, 1) * 40); + cam->setFarPlane(300); + cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); } diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 67df437..6963038 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -710,4 +710,8 @@ namespace battleship{ break; } } + + void MapEditorAppState::onRawMouseWheelScroll(bool up){ + CameraController::getSingleton()->zoomCamera(up); + } } diff --git a/mapEditorAppState.h b/mapEditorAppState.h index 474e847..80d8018 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -86,6 +86,7 @@ namespace battleship{ void onDettached(); void onAction(int, bool); void onAnalog(int, float); + void onRawMouseWheelScroll(bool); inline MapEditor* getMapEditor(){return mapEditor;} private: MapEditor *mapEditor = nullptr;