finally I am a bit happy with the "f4" camera view
This commit is contained in:
parent
784ccb7e56
commit
8dd43e2e31
|
@ -1506,16 +1506,26 @@ void Game::update() {
|
||||||
|
|
||||||
if(currentCameraFollowUnit!=NULL){
|
if(currentCameraFollowUnit!=NULL){
|
||||||
Vec3f c=currentCameraFollowUnit->getCurrVector();
|
Vec3f c=currentCameraFollowUnit->getCurrVector();
|
||||||
|
int rotation=currentCameraFollowUnit->getRotation();
|
||||||
|
float angle=rotation+180;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_STREFLOP
|
||||||
|
c.z=c.z+4*streflop::cosf(static_cast<streflop::Simple>(degToRad(angle)));
|
||||||
|
c.x=c.x+4*streflop::sinf(static_cast<streflop::Simple>(degToRad(angle)));
|
||||||
|
#else
|
||||||
|
c.z=c.z+4*cosf(degToRad(angle));
|
||||||
|
c.x=c.x+4*sinf(degToRad(angle));
|
||||||
|
#endif
|
||||||
c.y=c.y+currentCameraFollowUnit->getType()->getHeight()/2.f+2.0f;
|
c.y=c.y+currentCameraFollowUnit->getType()->getHeight()/2.f+2.0f;
|
||||||
|
|
||||||
getGameCameraPtr()->setPos(c);
|
getGameCameraPtr()->setPos(c);
|
||||||
|
|
||||||
int rotation=currentCameraFollowUnit->getRotation();
|
rotation=(540-rotation)%360;
|
||||||
getGameCameraPtr()->rotateToVH(18.0f,(540-rotation)%360);
|
getGameCameraPtr()->rotateToVH(18.0f,rotation);
|
||||||
|
|
||||||
if(currentCameraFollowUnit->isAlive()==false){
|
if(currentCameraFollowUnit->isAlive()==false){
|
||||||
currentCameraFollowUnit=NULL;
|
currentCameraFollowUnit=NULL;
|
||||||
gameCamera.resetPosition();
|
|
||||||
getGameCameraPtr()->setClampDisabled(false);
|
|
||||||
getGameCameraPtr()->setGameState();
|
getGameCameraPtr()->setGameState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1931,7 +1941,7 @@ void Game::render() {
|
||||||
isFirstRender = false;
|
isFirstRender = false;
|
||||||
|
|
||||||
if(this->loadGameNode == NULL) {
|
if(this->loadGameNode == NULL) {
|
||||||
gameCamera.resetPosition();
|
gameCamera.setGameState();
|
||||||
this->restoreToStartXY();
|
this->restoreToStartXY();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2881,7 +2891,7 @@ void Game::mouseDownRight(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mouseMoved == false) {
|
if(mouseMoved == false) {
|
||||||
gameCamera.resetPosition();
|
gameCamera.setGameState();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mouseMoved = false;
|
mouseMoved = false;
|
||||||
|
@ -3169,7 +3179,6 @@ void Game::startCameraFollowUnit() {
|
||||||
Unit *currentUnit = selection->getUnitPtr(0);
|
Unit *currentUnit = selection->getUnitPtr(0);
|
||||||
if(currentUnit != NULL) {
|
if(currentUnit != NULL) {
|
||||||
currentCameraFollowUnit = currentUnit;
|
currentCameraFollowUnit = currentUnit;
|
||||||
getGameCameraPtr()->setClampDisabled(true);
|
|
||||||
getGameCameraPtr()->setUnitState();
|
getGameCameraPtr()->setUnitState();
|
||||||
getGameCameraPtr()->setPos(currentCameraFollowUnit->getCurrVector());
|
getGameCameraPtr()->setPos(currentCameraFollowUnit->getCurrVector());
|
||||||
|
|
||||||
|
@ -3303,7 +3312,16 @@ void Game::keyDown(SDL_KeyboardEvent key) {
|
||||||
//change camera mode
|
//change camera mode
|
||||||
//else if(key == configKeys.getCharKey("FreeCameraMode")) {
|
//else if(key == configKeys.getCharKey("FreeCameraMode")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("FreeCameraMode"),key, false) == true) {
|
else if(isKeyPressed(configKeys.getSDLKey("FreeCameraMode"),key, false) == true) {
|
||||||
gameCamera.switchState();
|
if(gameCamera.getState()==GameCamera::sFree)
|
||||||
|
{
|
||||||
|
gameCamera.setGameState();
|
||||||
|
}
|
||||||
|
else if(gameCamera.getState()==GameCamera::sGame)
|
||||||
|
{
|
||||||
|
gameCamera.setFreeState();
|
||||||
|
}
|
||||||
|
//else ignore!
|
||||||
|
|
||||||
string stateString= gameCamera.getState()==GameCamera::sGame? lang.get("GameCamera"): lang.get("FreeCamera");
|
string stateString= gameCamera.getState()==GameCamera::sGame? lang.get("GameCamera"): lang.get("FreeCamera");
|
||||||
console.addLine(lang.get("CameraModeSet")+" "+ stateString);
|
console.addLine(lang.get("CameraModeSet")+" "+ stateString);
|
||||||
}
|
}
|
||||||
|
@ -3313,9 +3331,7 @@ void Game::keyDown(SDL_KeyboardEvent key) {
|
||||||
if(currentCameraFollowUnit != NULL) {
|
if(currentCameraFollowUnit != NULL) {
|
||||||
currentCameraFollowUnit = NULL;
|
currentCameraFollowUnit = NULL;
|
||||||
}
|
}
|
||||||
|
gameCamera.setGameState();
|
||||||
gameCamera.resetPosition();
|
|
||||||
gameCamera.setClampDisabled(false);
|
|
||||||
}
|
}
|
||||||
//pause
|
//pause
|
||||||
//else if(key == configKeys.getCharKey("PauseGame")) {
|
//else if(key == configKeys.getCharKey("PauseGame")) {
|
||||||
|
|
|
@ -287,20 +287,24 @@ Quad2i GameCamera::computeVisibleQuad() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameCamera::switchState(){
|
void GameCamera::setGameState() {
|
||||||
if(state==sGame){
|
state = sGame;
|
||||||
state= sFree;
|
setClampDisabled(false);
|
||||||
}
|
resetPosition();
|
||||||
else{
|
}
|
||||||
state= sGame;
|
void GameCamera::setUnitState() {
|
||||||
destAng.x = startingVAng;
|
state = sUnit;
|
||||||
destAng.y = startingHAng;
|
setClampDisabled(true);
|
||||||
destPos.y = calculatedDefault;
|
}
|
||||||
}
|
void GameCamera::setFreeState() {
|
||||||
|
state = sFree;
|
||||||
|
setClampDisabled(false);
|
||||||
|
resetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GameCamera::resetPosition(){
|
void GameCamera::resetPosition(){
|
||||||
state= sGame;
|
|
||||||
destAng.x = startingVAng;
|
destAng.x = startingVAng;
|
||||||
destAng.y = startingHAng;
|
destAng.y = startingHAng;
|
||||||
destPos.y = calculatedDefault;
|
destPos.y = calculatedDefault;
|
||||||
|
|
|
@ -105,9 +105,10 @@ public:
|
||||||
float getHAng() const {return hAng;};
|
float getHAng() const {return hAng;};
|
||||||
float getVAng() const {return vAng;}
|
float getVAng() const {return vAng;}
|
||||||
State getState() const {return state;}
|
State getState() const {return state;}
|
||||||
void setGameState() { state = sGame; }
|
|
||||||
void setUnitState() { state = sUnit; }
|
void setGameState();
|
||||||
void setState(State value) { state = value; }
|
void setUnitState();
|
||||||
|
void setFreeState();
|
||||||
|
|
||||||
const Vec3f &getPos() const {return pos;}
|
const Vec3f &getPos() const {return pos;}
|
||||||
float getFov() const {return fov;}
|
float getFov() const {return fov;}
|
||||||
|
@ -140,8 +141,7 @@ public:
|
||||||
//other
|
//other
|
||||||
void update();
|
void update();
|
||||||
Quad2i computeVisibleQuad();
|
Quad2i computeVisibleQuad();
|
||||||
void switchState();
|
|
||||||
void resetPosition();
|
|
||||||
|
|
||||||
void centerXZ(float x, float z);
|
void centerXZ(float x, float z);
|
||||||
void transitionXYZ(float x, float y, float z);
|
void transitionXYZ(float x, float y, float z);
|
||||||
|
@ -155,8 +155,6 @@ public:
|
||||||
void load(const XmlNode *node);
|
void load(const XmlNode *node);
|
||||||
void save(XmlNode *node) const;
|
void save(XmlNode *node) const;
|
||||||
|
|
||||||
void setClampBounds(bool value) { clampBounds = value; }
|
|
||||||
void setClampDisabled(bool value) { clampDisable = value; };
|
|
||||||
void setMaxHeight(float value);
|
void setMaxHeight(float value);
|
||||||
float getCalculatedDefault() const{ return calculatedDefault; }
|
float getCalculatedDefault() const{ return calculatedDefault; }
|
||||||
void setCalculatedDefault(float calculatedDefault);
|
void setCalculatedDefault(float calculatedDefault);
|
||||||
|
@ -173,6 +171,9 @@ public:
|
||||||
void loadGame(const XmlNode *rootNode);
|
void loadGame(const XmlNode *rootNode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setClampBounds(bool value) { clampBounds = value; }
|
||||||
|
void resetPosition();
|
||||||
|
void setClampDisabled(bool value) { clampDisable = value; };
|
||||||
void clampPosXYZ(float x1, float x2, float y1, float y2, float z1, float z2);
|
void clampPosXYZ(float x1, float x2, float y1, float y2, float z1, float z2);
|
||||||
void clampPosXZ(float x1, float x2, float z1, float z2);
|
void clampPosXZ(float x1, float x2, float z1, float z2);
|
||||||
void clampAng();
|
void clampAng();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user