removed camera stuff from unit and the camera following a unit is much more smooth now. ( Not finished, work in progress )
This commit is contained in:
parent
2f40e7735a
commit
3db7d017e3
|
@ -1504,6 +1504,20 @@ void Game::update() {
|
|||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
||||
|
||||
if(currentCameraFollowUnit!=NULL){
|
||||
Vec3f c=currentCameraFollowUnit->getCurrVector();
|
||||
c.y=c.y+currentCameraFollowUnit->getType()->getHeight()/2.f+2.f;
|
||||
getGameCameraPtr()->setPos(c);
|
||||
|
||||
int rotation=currentCameraFollowUnit->getRotation();
|
||||
getGameCameraPtr()->rotateToVH(0.0f,(180-rotation)%360);
|
||||
|
||||
if(currentCameraFollowUnit->isAlive()==false){
|
||||
currentCameraFollowUnit==NULL;
|
||||
gameCamera.resetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
// Commander
|
||||
//commander.updateNetwork();
|
||||
commander.signalNetworkUpdate(this);
|
||||
|
@ -2991,8 +3005,9 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
|
|||
float xmult = 0.2f;
|
||||
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
gameCamera.transitionVH(-(y - lastMousePos.y) * ymult, (lastMousePos.x - x) * xmult);
|
||||
if(currentCameraFollowUnit==NULL){
|
||||
gameCamera.transitionVH(-(y - lastMousePos.y) * ymult, (lastMousePos.x - x) * xmult);
|
||||
}
|
||||
mouseX=lastMousePos.x;
|
||||
mouseY=lastMousePos.y;
|
||||
Shared::Platform::Window::revertMousePos();
|
||||
|
@ -3001,7 +3016,7 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if(currentCameraFollowUnit==NULL) {
|
||||
//if(Window::isKeyDown() == false)
|
||||
if(!camLeftButtonDown && !camRightButtonDown && !camUpButtonDown && !camDownButtonDown)
|
||||
{
|
||||
|
@ -3152,12 +3167,19 @@ void Game::startCameraFollowUnit() {
|
|||
Unit *currentUnit = selection->getUnitPtr(0);
|
||||
if(currentUnit != NULL) {
|
||||
currentCameraFollowUnit = currentUnit;
|
||||
currentCameraFollowUnit->setCameraFollowUnit(true);
|
||||
getGameCameraPtr()->setClampDisabled(true);
|
||||
getGameCameraPtr()->setUnitState();
|
||||
getGameCameraPtr()->setPos(currentCameraFollowUnit->getCurrVector());
|
||||
|
||||
int rotation=currentCameraFollowUnit->getRotation();
|
||||
getGameCameraPtr()->stop();
|
||||
getGameCameraPtr()->rotateToVH(0.0f,(180-rotation)%360);
|
||||
getGameCameraPtr()->setHAng((180-rotation)%360);
|
||||
getGameCameraPtr()->setVAng(0.0f);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(currentCameraFollowUnit != NULL) {
|
||||
currentCameraFollowUnit->setCameraFollowUnit(false);
|
||||
currentCameraFollowUnit = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -3287,7 +3309,6 @@ void Game::keyDown(SDL_KeyboardEvent key) {
|
|||
//else if(key == configKeys.getCharKey("ResetCameraMode")) {
|
||||
else if(isKeyPressed(configKeys.getSDLKey("ResetCameraMode"),key, false) == true) {
|
||||
if(currentCameraFollowUnit != NULL) {
|
||||
currentCameraFollowUnit->setCameraFollowUnit(false);
|
||||
currentCameraFollowUnit = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ void GameCamera::update(){
|
|||
}
|
||||
|
||||
//free state
|
||||
if(state==sFree){
|
||||
if(state==sFree ){
|
||||
#ifdef USE_STREFLOP
|
||||
if(streflop::fabs(static_cast<streflop::Simple>(rotate)) == 1){
|
||||
#else
|
||||
|
@ -325,6 +325,12 @@ void GameCamera::transitionVH(float v, float h) {
|
|||
clampAng();
|
||||
}
|
||||
|
||||
void GameCamera::rotateToVH(float v, float h) {
|
||||
destAng.x = v;
|
||||
destAng.y = h;
|
||||
clampAng();
|
||||
}
|
||||
|
||||
void GameCamera::zoom(float dist) {
|
||||
#ifdef USE_STREFLOP
|
||||
float flatDist = dist * streflop::cosf(static_cast<streflop::Simple>(degToRad(vAng)));
|
||||
|
|
|
@ -54,7 +54,8 @@ public:
|
|||
public:
|
||||
enum State{
|
||||
sGame,
|
||||
sFree
|
||||
sFree,
|
||||
sUnit
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -104,6 +105,10 @@ public:
|
|||
float getHAng() const {return hAng;};
|
||||
float getVAng() const {return vAng;}
|
||||
State getState() const {return state;}
|
||||
void setGameState() { state = sGame; }
|
||||
void setUnitState() { state = sUnit; }
|
||||
void setState(State value) { state = value; }
|
||||
|
||||
const Vec3f &getPos() const {return pos;}
|
||||
float getFov() const {return fov;}
|
||||
//set
|
||||
|
@ -139,9 +144,10 @@ public:
|
|||
void resetPosition();
|
||||
|
||||
void centerXZ(float x, float z);
|
||||
void rotateHV(float h, float v);
|
||||
void transitionXYZ(float x, float y, float z);
|
||||
void transitionVH(float v, float h);
|
||||
void rotateToVH(float v, float h);
|
||||
|
||||
void zoom(float dist);
|
||||
void moveForwardH(float dist, float response); // response: 1.0 for immediate, 0 for full inertia
|
||||
void moveSideH(float dist, float response);
|
||||
|
@ -171,6 +177,8 @@ private:
|
|||
void clampPosXZ(float x1, float x2, float z1, float z2);
|
||||
void clampAng();
|
||||
void moveUp(float dist);
|
||||
void rotateHV(float h, float v);
|
||||
|
||||
};
|
||||
|
||||
}} //end namespace
|
||||
|
|
|
@ -401,7 +401,6 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
|
|||
this->unitPath = unitpath;
|
||||
this->unitPath->setMap(map);
|
||||
|
||||
this->cameraFollowUnit = false;
|
||||
//RandomGen random;
|
||||
random.init(id);
|
||||
pathFindRefreshCellCount = random.randRange(10,20);
|
||||
|
@ -1043,19 +1042,6 @@ void Unit::setTarget(const Unit *unit){
|
|||
targetRef= unit;
|
||||
}
|
||||
|
||||
bool Unit::getCameraFollowUnit() const {
|
||||
return cameraFollowUnit;
|
||||
}
|
||||
void Unit::setCameraFollowUnit(bool value) {
|
||||
this->cameraFollowUnit = value;
|
||||
if(this->cameraFollowUnit == true) {
|
||||
game->getGameCameraPtr()->setClampDisabled(true);
|
||||
}
|
||||
else {
|
||||
game->getGameCameraPtr()->setClampDisabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
|
||||
if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) {
|
||||
throw megaglest_runtime_error("#3 Invalid path position = " + pos.getString());
|
||||
|
@ -1068,36 +1054,36 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
|
|||
this->lastPos= this->pos;
|
||||
this->pos= pos;
|
||||
|
||||
// This code is initial code to make the camera 'follow' a unit
|
||||
//if(this->getId() == 5) {
|
||||
if(cameraFollowUnit == true) {
|
||||
//printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
|
||||
|
||||
//game->getGameCameraPtr()->setClampDisabled(true);
|
||||
|
||||
//game->getGameCameraPtr()->setFov(45);
|
||||
if(oldLastPos.x > pos.x) {
|
||||
game->getGameCameraPtr()->setHAng(270);
|
||||
game->getGameCameraPtr()->setVAng(-7.6);
|
||||
}
|
||||
else if(oldLastPos.x < pos.x) {
|
||||
game->getGameCameraPtr()->setHAng(90);
|
||||
game->getGameCameraPtr()->setVAng(1.4);
|
||||
}
|
||||
else if(oldLastPos.y > pos.y) {
|
||||
game->getGameCameraPtr()->setHAng(180);
|
||||
game->getGameCameraPtr()->setVAng(4.2);
|
||||
}
|
||||
else {
|
||||
game->getGameCameraPtr()->setHAng(-2.4);
|
||||
game->getGameCameraPtr()->setVAng(-1.4);
|
||||
}
|
||||
|
||||
game->getGameCameraPtr()->setPos(getCurrVector());
|
||||
game->getGameCameraPtr()->stop();
|
||||
|
||||
//printf("B fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
|
||||
}
|
||||
// // This code is initial code to make the camera 'follow' a unit
|
||||
// //if(this->getId() == 5) {
|
||||
// if(cameraFollowUnit == true) {
|
||||
// //printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
|
||||
//
|
||||
// //game->getGameCameraPtr()->setClampDisabled(true);
|
||||
//
|
||||
// //game->getGameCameraPtr()->setFov(45);
|
||||
// if(oldLastPos.x > pos.x) {
|
||||
// game->getGameCameraPtr()->setHAng(270);
|
||||
// game->getGameCameraPtr()->setVAng(-7.6);
|
||||
// }
|
||||
// else if(oldLastPos.x < pos.x) {
|
||||
// game->getGameCameraPtr()->setHAng(90);
|
||||
// game->getGameCameraPtr()->setVAng(1.4);
|
||||
// }
|
||||
// else if(oldLastPos.y > pos.y) {
|
||||
// game->getGameCameraPtr()->setHAng(180);
|
||||
// game->getGameCameraPtr()->setVAng(4.2);
|
||||
// }
|
||||
// else {
|
||||
// game->getGameCameraPtr()->setHAng(-2.4);
|
||||
// game->getGameCameraPtr()->setVAng(-1.4);
|
||||
// }
|
||||
//
|
||||
// game->getGameCameraPtr()->setPos(getCurrVector());
|
||||
// game->getGameCameraPtr()->stop();
|
||||
//
|
||||
// //printf("B fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
|
||||
// }
|
||||
|
||||
map->clampPos(this->pos);
|
||||
this->meetingPos= pos - Vec2i(1);
|
||||
|
|
|
@ -456,7 +456,6 @@ private:
|
|||
RandomGen random;
|
||||
int pathFindRefreshCellCount;
|
||||
|
||||
bool cameraFollowUnit;
|
||||
|
||||
public:
|
||||
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||
|
@ -471,9 +470,6 @@ public:
|
|||
void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; }
|
||||
Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; }
|
||||
|
||||
bool getCameraFollowUnit() const;
|
||||
void setCameraFollowUnit(bool value);
|
||||
|
||||
//const std::pair<const SkillType *,std::vector<Unit *> > & getCurrentAttackBoostUnits() const { return currentAttackBoostUnits; }
|
||||
const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; }
|
||||
bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const;
|
||||
|
|
Loading…
Reference in New Issue
Block a user