First person enhancements (#656)

* only switch first-person mode while spectating

closes #655

* use first person view for first-person spectating

* don't spectate specators; refactor
This commit is contained in:
NotAFile 2017-09-17 07:15:06 +02:00 committed by YVT
parent 228f1b1ee5
commit 266d141e04
5 changed files with 29 additions and 4 deletions

View File

@ -723,6 +723,9 @@ namespace spades {
continue;
if (p->GetFront().GetPoweredLength() < .01f)
continue;
if (p->GetTeamId() >= 2){
continue; // Don't spectate spectators
}
break;
} while (nextId != followingPlayerId);

View File

@ -283,6 +283,7 @@ namespace spades {
float GetAimDownZoomScale();
bool ShouldRenderInThirdPersonView();
Player *GetViewedPlayer();
SceneDefinition CreateSceneDefinition();
std::string ScreenShotPath();

View File

@ -1042,8 +1042,10 @@ namespace spades {
}
bool ClientPlayer::ShouldRenderInThirdPersonView() {
if (player != player->GetWorld()->GetLocalPlayer())
return true;
// the player from whom's perspective the game is seen
if (player != client->GetViewedPlayer()) return true;
return client->ShouldRenderInThirdPersonView();
}

View File

@ -367,7 +367,7 @@ namespace spades {
} else if (CheckKey(cg_keySneak, name)) {
playerInput.sneak = down;
} else if (CheckKey(cg_keyJump, name)) {
if (down) {
if (down && IsFollowing()) {
firstPersonSpectate = !firstPersonSpectate;
}
playerInput.jump = down;

View File

@ -56,16 +56,35 @@ namespace spades {
#pragma mark - Drawing
bool Client::ShouldRenderInThirdPersonView() {
if (IsFollowing()){
if (!GetViewedPlayer()->IsAlive()){
return true;
}
return !firstPersonSpectate;
}
if (world && world->GetLocalPlayer()) {
if (!world->GetLocalPlayer()->IsAlive())
return true;
}
if ((int)cg_thirdperson != 0 && world->GetNumPlayers() <= 1) {
return true;
}
return false;
}
Player *Client::GetViewedPlayer() {
// what happens if we are in free mode?
// doesn't matter for the current code, but keep this in mind
if (IsFollowing()){
return world->GetPlayer(followingPlayerId);
}
else {
return world->GetLocalPlayer();
}
}
float Client::GetLocalFireVibration() {
float localFireVibration = 0.f;
localFireVibration = time - localFireVibrationTime;
@ -204,7 +223,7 @@ namespace spades {
Vector3 front = center - eye;
front = front.Normalize();
if (firstPersonSpectate == false) {
if (ShouldRenderInThirdPersonView()) {
def.viewOrigin = eye;
def.viewAxis[0] = -Vector3::Cross(up, front).Normalize();
def.viewAxis[1] = -Vector3::Cross(front, def.viewAxis[0]).Normalize();