Skip to content

Commit

Permalink
Merge pull request #299 from Hoikas/hor-plus
Browse files Browse the repository at this point in the history
Implement Hor+ FOVs
  • Loading branch information
Branan Purvine-Riley committed Feb 8, 2013
2 parents 777197c + 38f5e6e commit 1e7cbc3
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 154 deletions.
7 changes: 2 additions & 5 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,11 +1578,8 @@ bool plClient::StartInit()
fNewCamera->Init();
fNewCamera->SetPipeline( GetPipeline() );

float aspectratio = (float)fPipeline->Width() / (float)fPipeline->Height();
plVirtualCam1::SetAspectRatio(aspectratio);
plVirtualCam1::SetFOV(plVirtualCam1::GetFOVw(), plVirtualCam1::GetFOVh());

pfGameGUIMgr::GetInstance()->SetAspectRatio( aspectratio );
plVirtualCam1::Refresh();
pfGameGUIMgr::GetInstance()->SetAspectRatio( (float)fPipeline->Width() / (float)fPipeline->Height() );
plMouseDevice::Instance()->SetDisplayResolution((float)fPipeline->Width(), (float)fPipeline->Height());
plInputManager::SetRecenterMouse(false);

Expand Down
92 changes: 62 additions & 30 deletions Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,32 @@ void plCameraBrain1::Pop()
}

// set the goal to which we want to animate the fov
void plCameraBrain1::SetFOVGoal(float h, double t)
void plCameraBrain1::SetFOVGoal(float w, float h, double t)
{
if (fFOVGoal == h || h == fCamera->GetFOVh())
if (fFOVhGoal == h || h == fCamera->GetFOVh() &&
fFOVwGoal == w || w == fCamera->GetFOVw())
return;

float dif = h - fCamera->GetFOVh();
fFOVAnimRate = dif / ((float)t);
fFOVhAnimRate = dif / ((float)t);

fFOVGoal = h;
fFOVhGoal = h;
fFOVStartTime = hsTimer::GetSysSeconds();
fFOVEndTime = fFOVStartTime + t;

if (w == 0.f)
{
fFOVwGoal = IMakeFOVwZoom(h);
dif = fFOVwGoal - fCamera->GetFOVw();
fFOVwAnimRate = dif / ((float)t);
}
else
{
dif = w - fCamera->GetFOVw();
fFOVwAnimRate = dif / ((float)t);
fFOVwGoal = w;
}

fFlags.SetBit(kAnimateFOV);
}

Expand Down Expand Up @@ -241,28 +255,33 @@ void plCameraBrain1::Update(bool forced)
// adjust FOV based on elapsed time
void plCameraBrain1::IAnimateFOV(double time)
{
float dH = fFOVAnimRate * hsTimer::GetDelSysSeconds();

float dH = fFOVhAnimRate * hsTimer::GetDelSysSeconds();
float dW = fFOVwAnimRate * hsTimer::GetDelSysSeconds();
dH += fCamera->GetFOVh();
dW += fCamera->GetFOVw();

if ( (fFOVAnimRate < 0.0f && dH <= fFOVGoal) ||
(fFOVAnimRate > 0.0f && dH >= fFOVGoal) )
if ( (fFOVhAnimRate < 0.0f && dH <= fFOVhGoal) ||
(fFOVhAnimRate > 0.0f && dH >= fFOVhGoal) )
{
fFlags.ClearBit(kAnimateFOV);
dH = fFOVGoal;
dH = fFOVhGoal;
}
if ( (fFOVwAnimRate < 0.0f && dW <= fFOVwGoal) ||
(fFOVwAnimRate > 0.0f && dW >= fFOVwGoal) )
{
dW = fFOVwGoal;
}

fCamera->SetFOVw( (float)(dH * plVirtualCam1::Instance()->GetAspectRatio()) );
fCamera->SetFOVh( dH );

if (dW == fFOVwGoal && dH == fFOVhGoal)
fFlags.ClearBit(kAnimateFOV);
fCamera->SetFOV( dW, dH );
}

// move the camera's origin point (not where it is looking) toward where it is going
void plCameraBrain1::IMoveTowardGoal(double elapsedTime)
{
bool current = plVirtualCam1::Instance()->IsCurrentCamera(GetCamera());

if (fFlags.IsBitSet(kCutPos) || fFlags.IsBitSet(kNonPhys) || !current)
if (fFlags.IsBitSet(kCutPos) || fFlags.IsBitSet(kNonPhys) || !current)
{
fCamera->SetTargetPos(fGoal);
return;
Expand All @@ -280,12 +299,12 @@ void plCameraBrain1::IMoveTowardGoal(double elapsedTime)
//smooth out stoppage...
float adjMaxVel = fVelocity;
if (distToGoal <= 5.0f && distToGoal > 0.1f)
{
{
float mult = (distToGoal - 5.0f)*0.1f;
adjMaxVel = fVelocity - hsABS(fVelocity*mult);
}
}



if (distToGoal > 0.0f)
dir.Normalize();

Expand Down Expand Up @@ -536,6 +555,14 @@ void plCameraBrain1::Write(hsStream* stream, hsResMgr* mgr)
stream->WriteLEFloat(fZoomMin);
stream->WriteLEFloat(fZoomMax);
}

float plCameraBrain1::IMakeFOVwZoom(float fovH) const
{
float num = tan(hsDegreesToRadians(fovH / 2)) * tan(hsDegreesToRadians(fCamera->GetFOVw() / 2));
float denom = tan(hsDegreesToRadians(fCamera->GetFOVh() / 2));
return 2 * hsABS(hsRadiansToDegrees(atan(num / denom)));
}

bool plCameraBrain1::MsgReceive(plMessage* msg)
{
plCameraMsg* pCamMsg = plCameraMsg::ConvertNoRef(msg);
Expand All @@ -544,16 +571,18 @@ bool plCameraBrain1::MsgReceive(plMessage* msg)
if (pCamMsg->Cmd(plCameraMsg::kStartZoomIn))
{
fFlags.SetBit(kAnimateFOV);
fFOVGoal = fZoomMin;
fFOVAnimRate = -1*fZoomRate;
fFOVhGoal = fZoomMin;
fFOVwGoal = IMakeFOVwZoom(fZoomMin);
fFOVwAnimRate = fFOVhAnimRate = -1*fZoomRate;
return true;
}
else
if (pCamMsg->Cmd(plCameraMsg::kStartZoomOut))
{
fFlags.SetBit(kAnimateFOV);
fFOVGoal = fZoomMax;
fFOVAnimRate = fZoomRate;
fFOVhGoal = fZoomMax;
fFOVwGoal = IMakeFOVwZoom(fZoomMax);
fFOVwAnimRate = fFOVhAnimRate = fZoomRate;
return true;
}
else
Expand Down Expand Up @@ -637,17 +666,19 @@ bool plCameraBrain1::MsgReceive(plMessage* msg)
if (pCMsg->GetControlCode() == B_CAMERA_ZOOM_IN && fFlags.IsBitSet(kZoomEnabled))
{
fFlags.SetBit(kAnimateFOV);
fFOVGoal = fZoomMin;
fFOVAnimRate = -1*fZoomRate;
fFOVhGoal = fZoomMin;
fFOVwGoal = IMakeFOVwZoom(fZoomMin);
fFOVwAnimRate = fFOVhAnimRate = -1*fZoomRate;
fFOVEndTime = hsTimer::GetSysSeconds() + 60;
return true;
}
else
if (pCMsg->GetControlCode() == B_CAMERA_ZOOM_OUT && fFlags.IsBitSet(kZoomEnabled))
{
fFlags.SetBit(kAnimateFOV);
fFOVGoal = fZoomMax;
fFOVAnimRate = fZoomRate;
fFOVhGoal = fZoomMax;
fFOVwGoal = IMakeFOVwZoom(fZoomMin);
fFOVwAnimRate = fFOVhAnimRate = fZoomRate;
fFOVEndTime = hsTimer::GetSysSeconds() + 60;
return true;
}
Expand All @@ -657,11 +688,12 @@ bool plCameraBrain1::MsgReceive(plMessage* msg)
if (fFlags.IsBitSet(kZoomEnabled))
{
fFlags.SetBit(kAnimateFOV);
fFOVGoal = fZoomMin + ((fZoomMax - fZoomMin) / 2);
if (fCamera->GetFOVw() >= fFOVGoal)
fFOVAnimRate = -1*fZoomRate;
fFOVhGoal = fZoomMin + ((fZoomMax - fZoomMin) / 2);
fFOVwGoal = IMakeFOVwZoom(fFOVhGoal);
if (fCamera->GetFOVh() >= fFOVhGoal)
fFOVwAnimRate = fFOVhAnimRate = -1*fZoomRate;
else
fFOVAnimRate = fZoomRate;
fFOVwAnimRate = fFOVhAnimRate = fZoomRate;
fFOVEndTime = hsTimer::GetSysSeconds() + 60;
}
return true;
Expand Down
37 changes: 19 additions & 18 deletions Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class plCameraBrain1 : public hsKeyedObject

void SetGoal(hsPoint3 pt) { fGoal = pt; }
void SetPOAGoal(hsPoint3 pt) { fPOAGoal = pt; }
void SetFOVGoal(float h, double t);
void SetFOVGoal(float w, float h, double t);
void SetZoomParams(float max, float min, float rate);

void SetXPanLimit(float x) {fXPanLimit = x;}
Expand Down Expand Up @@ -173,16 +173,17 @@ class plCameraBrain1 : public hsKeyedObject
void IMoveTowardGoal(double time);
void IPointTowardGoal(double time);
void IAnimateFOV(double time);
void IAdjustVelocity(float adjAccelRate,
float adjDecelRate,
hsVector3* dir,
hsVector3* vel,
float maxSpeed,
void IAdjustVelocity(float adjAccelRate,
float adjDecelRate,
hsVector3* dir,
hsVector3* vel,
float maxSpeed,
float distToGoal,
double elapsedTime);

float IClampVelocity(hsVector3* vel, float maxSpeed, double elapsedTime);
bool IShouldDecelerate(float decelSpeed, float curSpeed, float distToGoal);
bool IShouldDecelerate(float decelSpeed, float curSpeed, float distToGoal);
float IMakeFOVwZoom(float fovH) const;

plCameraModifier1* fCamera;
plKey fSubjectKey;
Expand All @@ -197,25 +198,25 @@ class plCameraBrain1 : public hsKeyedObject
float fPOAVelocity;
float fPOAAccel;
float fPOADecel;
hsVector3 fPOAOffset;
hsPoint3 fGoal;
hsPoint3 fPOAGoal;
hsVector3 fPOAOffset;
hsPoint3 fGoal;
hsPoint3 fPOAGoal;
float fXPanLimit;
float fZPanLimit;
float fPanSpeed;
float fFOVGoal;
double fFOVStartTime;
double fFOVEndTime;
float fFOVAnimRate;
float fFOVwGoal, fFOVhGoal;
double fFOVStartTime;
double fFOVEndTime;
float fFOVwAnimRate, fFOVhAnimRate;
float fZoomRate;
float fZoomMax;
float fZoomMin;
hsBitVector fMoveFlags;
hsBitVector fFlags;
hsMatrix44 fTargetMatrix;
hsBitVector fMoveFlags;
hsBitVector fFlags;
hsMatrix44 fTargetMatrix;
float fOffsetLength;
float fOffsetPct;
double fFallTimer;
double fFallTimer;
};

class plControlEventMsg;
Expand Down
17 changes: 13 additions & 4 deletions Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,28 @@ plSceneObject* plCameraModifier1::GetSubject()
return GetBrain()->GetSubject();
else
return fSubObj;
}
}

void plCameraModifier1::SetFOV(float w, float h, bool fUpdateVCam)
{
fFOVw = w;
fFOVh = h;
if (plVirtualCam1::Instance() && fUpdateVCam)
plVirtualCam1::SetFOV(this);
}

void plCameraModifier1::SetFOVw(float f, bool fUpdateVCam)
{
fFOVw = f;
if (plVirtualCam1::Instance() && fUpdateVCam)
plVirtualCam1::SetFOV(fFOVw, fFOVh, this);
plVirtualCam1::SetFOV(this);
}

void plCameraModifier1::SetFOVh(float f, bool fUpdateVCam)
{
fFOVh = f;
if (plVirtualCam1::Instance() && fUpdateVCam)
plVirtualCam1::SetFOV(fFOVw, fFOVh, this);
plVirtualCam1::SetFOV(this);
}

bool plCameraModifier1::SetFaded(bool b)
Expand Down Expand Up @@ -192,8 +200,9 @@ bool plCameraModifier1::MsgReceive(plMessage* msg)
double time2 = (double)pEventMsg->fEventTime;
time = hsABS(time - time2);
float h = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVh;
float w = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVw;
if (GetBrain())
GetBrain()->SetFOVGoal(h, time);
GetBrain()->SetFOVGoal(w, h, time);
}

plAnimCmdMsg* pAnimMsg = plAnimCmdMsg::ConvertNoRef(msg);
Expand Down
5 changes: 3 additions & 2 deletions Sources/Plasma/FeatureLib/pfCamera/plCameraModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class plCameraModifier1 : public plSingleModifier
void SetTargetPOA(hsPoint3 pos) { fAt = pos; }
void SetSubworldPos(hsPoint3 pos) { fLastSubPos = pos; }
void SetSubworldPOA(hsPoint3 pos) { fLastSubPOA = pos; }
float GetFOVw() { return fFOVw; }
float GetFOVh() { return fFOVh; }
float GetFOVw() const { return fFOVw; }
float GetFOVh() const { return fFOVh; }
void SetFOV(float w, float h, bool fUpdateVCam = true);
void SetFOVw(float f, bool fUpdateVCam = true);
void SetFOVh(float f, bool fUpdateVCam = true);
bool GetInSubworld() { return fInSubLastUpdate; }
Expand Down
Loading

0 comments on commit 1e7cbc3

Please sign in to comment.