integrated zooming the camera in and out

This commit is contained in:
devZoGok
2024-06-29 11:50:08 +03:00
parent 615fcd70c9
commit fc6751db01
9 changed files with 35 additions and 3 deletions
+4
View File
@@ -622,4 +622,8 @@ namespace battleship{
break; break;
} }
} }
void ActiveGameState::onRawMouseWheelScroll(bool up){
CameraController::getSingleton()->zoomCamera(up);
}
} }
+1
View File
@@ -27,6 +27,7 @@ namespace battleship{
void update(); void update();
void onAction(int, bool); void onAction(int, bool);
void onAnalog(int, float); void onAnalog(int, float);
void onRawMouseWheelScroll(bool);
inline void addButton(vb01Gui::Button *b){buttons.push_back(b);} inline void addButton(vb01Gui::Button *b){buttons.push_back(b);}
inline std::vector<vb01Gui::Button*> getButtons(){return buttons;} inline std::vector<vb01Gui::Button*> getButtons(){return buttons;}
inline Player* getPlayer(){return mainPlayer;} inline Player* getPlayer(){return mainPlayer;}
+19
View File
@@ -51,4 +51,23 @@ namespace battleship{
Vector3 dir = rotQuat * cam->getDirection(), up = rotQuat * cam->getUp(); Vector3 dir = rotQuat * cam->getDirection(), up = rotQuat * cam->getUp();
cam->lookAt(dir, up); 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);
}
} }
+2
View File
@@ -9,12 +9,14 @@ namespace battleship{
static CameraController* getSingleton(); static CameraController* getSingleton();
void updateCameraPosition(); void updateCameraPosition();
void orientCamera(vb01::Vector3, double); void orientCamera(vb01::Vector3, double);
void zoomCamera(bool);
inline bool isLookingAround(){return lookingAround;} inline bool isLookingAround(){return lookingAround;}
inline void setLookingAround(bool l){lookingAround = l;} inline void setLookingAround(bool l){lookingAround = l;}
private: private:
CameraController(){} CameraController(){}
bool lookingAround = false; bool lookingAround = false;
int numZooms = 0;
}; };
} }
+1 -1
View File
@@ -20,7 +20,7 @@ namespace battleship{
using namespace gameBase; using namespace gameBase;
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg"; 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 int maxNumGroups = 10;
const vb01::u32 IMPASS_NODE_VAL = 65535; const vb01::u32 IMPASS_NODE_VAL = 65535;
+1 -1
View File
@@ -79,7 +79,7 @@ namespace battleship{
} }
Camera *cam = Root::getSingleton()->getCamera(); 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()); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
mainPlayer = Game::getSingleton()->getPlayer(playerId); mainPlayer = Game::getSingleton()->getPlayer(playerId);
+2 -1
View File
@@ -225,7 +225,8 @@ namespace battleship{
waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1)); waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1));
Camera *cam = root->getCamera(); 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()); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
} }
+4
View File
@@ -710,4 +710,8 @@ namespace battleship{
break; break;
} }
} }
void MapEditorAppState::onRawMouseWheelScroll(bool up){
CameraController::getSingleton()->zoomCamera(up);
}
} }
+1
View File
@@ -86,6 +86,7 @@ namespace battleship{
void onDettached(); void onDettached();
void onAction(int, bool); void onAction(int, bool);
void onAnalog(int, float); void onAnalog(int, float);
void onRawMouseWheelScroll(bool);
inline MapEditor* getMapEditor(){return mapEditor;} inline MapEditor* getMapEditor(){return mapEditor;}
private: private:
MapEditor *mapEditor = nullptr; MapEditor *mapEditor = nullptr;