1
0
forked from 0ad/0ad

Added camera enhancements and cinematic suppport

This was SVN commit r3199.
This commit is contained in:
pyrolink 2005-12-06 06:58:30 +00:00
parent 8199091425
commit 300ff4578b
2 changed files with 113 additions and 4 deletions

View File

@ -18,6 +18,7 @@
#include "TextureManager.h"
#include "ObjectManager.h"
#include "LOSManager.h"
#include "EntityOrders.h"
#include "Bound.h"
#include "Pyrogenesis.h"
#include "Hotkey.h"
@ -37,7 +38,7 @@
#include "timer.h"
float g_MaxZoomHeight=350.0f; //note: Max terrain height is this minus YMinOffset
float g_YMinOffset=25.0f;
float g_YMinOffset=15.0f;
extern int g_xres, g_yres;
@ -77,6 +78,10 @@ CGameView::CGameView(CGame *pGame):
m_Camera.m_Orientation.Translate (100, 150, -100);
g_Renderer.SetCamera(m_Camera);
m_UnitView=NULL;
m_UnitAttach=NULL;
ONCE( ScriptingInit(); );
}
@ -345,7 +350,84 @@ void CGameView::Update(float DeltaTime)
{
if (!g_app_has_focus)
return;
if (m_UnitView)
{
CQuaternion ToRotate = m_UnitViewProp->m_Rotation - m_Camera.m_Orientation.GetRotation();
ToRotate.m_V.Y += m_UnitView->m_orientation;
m_Camera.m_Orientation.Rotate(ToRotate);
CVector3D CamTrans = m_Camera.m_Orientation.GetTranslation();
CVector3D ToMove = m_UnitView->m_position + m_UnitViewProp->m_Position - CamTrans;
//Used to fix incorrect positioning
//ToMove.Y += 3.5f;
m_Camera.m_Orientation.Translate(ToMove);
/*if( !m_UnitView->m_orderQueue.empty())
{
CEntityOrder Order = m_UnitView->m_orderQueue.front();
if (Order.m_type == CEntityOrder::ORDER_ATTACK_MELEE_NOPATHING ||
Order.m_type == CEntityOrder::ORDER_GATHER_NOPATHING)
{
CVector3D Focus = m_Camera.GetFocus();
CVector3D Target;
Target.X = (float) Order.m_data[0].location.x;
Target.Y = (float) m_Terrain->getExactGroundLevel(
Order.m_data[0].location.x, Order.m_data[0].location.y );
Target.Z = (float) Order.m_data[0].location.y;
CVector3D Distance = Target - Focus;
float length = Distance.GetLength();
//We're looking too far out. Correct by moving up or down toward the true position.
if (length > 1.0f)
{
Distance.Normalize();
CVector3D Down(0.0f, -1.0f, 0.0f);
//Find opposite side's length
float Angle = tan( acosf(Distance.Dot(Down)) );
float opp = length * Angle;
float hyp = 1 / sinf(Angle) * opp;
CVector3D CamFace = m_Camera.m_Orientation.GetIn();
CVector3D ToFace = Target - m_Camera.m_Orientation.GetTranslation();
ToFace.Normalize();
CamFace.Normalize();
//Find out if we need to move up or down. Dot product returns cosine.
//Larger cos means smaller angle. Smaller angle for target means move down.
if ( ToFace.Dot(Down) > CamFace.Dot(Down) )
m_Camera.m_Orientation.Translate(0.0f, -hyp, 0.0f);
else
m_Camera.m_Orientation.Translate(0.0f, hyp, 0.0f);
}
} //Check order type
} //Is order queue empty?
*/
m_Camera.UpdateFrustum();
return;
}
if (m_UnitAttach)
{
CVector3D ToMove = m_UnitAttach->m_position - m_Camera.GetFocus();
m_Camera.m_Orientation._14 += ToMove.X;
m_Camera.m_Orientation._34 += ToMove.Z;
m_Camera.UpdateFrustum();
return;
}
if (!m_TrackManager.m_TrackQueue.empty())
{
if(!m_TrackManager.Update(DeltaTime))
{
ResetCamera();
}
m_Camera.UpdateFrustum();
return;
}
float delta = powf( m_ViewSnapSmoothness, DeltaTime );
m_Camera.m_Orientation.Translate( m_CameraDelta * ( 1.0f - delta ) );
m_CameraDelta *= delta;
@ -562,6 +644,19 @@ void CGameView::Update(float DeltaTime)
m_Camera.UpdateFrustum ();
}
void CGameView::ToUnitView(CEntity* target, SPropPoint* prop)
{
if( !target )
{
//prevent previous zooming
m_ZoomDelta = 0.0f;
ResetCamera();
SetCameraTarget( m_UnitView->m_position );
}
m_UnitView = target;
m_UnitViewProp = prop;
}
void CGameView::PushCameraTarget( const CVector3D& target )
{
// Save the current position
@ -647,7 +742,7 @@ InReaction CGameView::HandleEvent(const SDL_Event* ev)
case HOTKEY_CAMERA_ZOOM_WHEEL_OUT:
m_ZoomDelta -= m_ViewZoomSensitivityWheel;
return( IN_HANDLED );
default:
if( ( ev->user.code >= HOTKEY_CAMERA_BOOKMARK_0 ) && ( ev->user.code <= HOTKEY_CAMERA_BOOKMARK_9 ) )

View File

@ -5,10 +5,10 @@
extern float g_MaxZoomHeight; //note: Max terrain height is this minus YMinOffset
extern float g_YMinOffset;
#include "Camera.h"
#include "CinemaTrack.h"
#include "ModelDef.h"
#include "Vector3D.h"
#include "scripting/ScriptableObject.h"
#include "lib/input.h"
@ -27,6 +27,8 @@ class CGameView: public CJSObject<CGameView>
CWorld *m_pWorld;
CTerrain *m_Terrain;
CCamera m_Camera;
CCinemaManager m_TrackManager;
////////////////////////////////////////
@ -47,6 +49,10 @@ class CGameView: public CJSObject<CGameView>
// Camera Controls State
CVector3D m_CameraDelta;
CVector3D m_CameraPivot;
CEntity* m_UnitView;
SPropPoint* m_UnitViewProp;
CEntity* m_UnitAttach;
//float m_CameraZoom;
std::vector<CVector3D> m_CameraTargets;
@ -112,6 +118,14 @@ public:
void PushCameraTarget( const CVector3D& target );
void SetCameraTarget( const CVector3D& target );
void PopCameraTarget();
//First person camera attachment (through the eyes of the unit)
void ToUnitView(CEntity* target, SPropPoint* prop);
//Keep view the same but follow the unit
void AttachToUnit(CEntity* target) { m_UnitAttach = target; }
bool IsAttached () { if( m_UnitAttach ) { return true; } return false; }
bool IsUnitView () { if( m_UnitView ) { return true; } return false; }
inline CCamera *GetCamera()
{ return &m_Camera; }