2006-07-06 05:17:44 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "MessageHandler.h"
|
|
|
|
#include "../CommandProc.h"
|
2007-01-08 02:56:46 +01:00
|
|
|
#include "graphics/Camera.h"
|
|
|
|
#include "graphics/CinemaTrack.h"
|
2006-07-06 05:17:44 +02:00
|
|
|
#include "graphics/GameView.h"
|
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "ps/CLogger.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/Filesystem.h"
|
2007-01-24 21:17:28 +01:00
|
|
|
#include "maths/MathUtil.h"
|
2006-08-22 04:24:44 +02:00
|
|
|
#include "maths/Quaternion.h"
|
|
|
|
#include "lib/res/graphics/ogl_tex.h"
|
2006-07-06 05:17:44 +02:00
|
|
|
|
|
|
|
#define LOG_CATEGORY "Cinema"
|
|
|
|
|
|
|
|
namespace AtlasMessage {
|
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
|
2006-08-22 04:24:44 +02:00
|
|
|
sCinemaPath ConstructCinemaPath(const CCinemaPath* source)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
|
|
|
sCinemaPath path;
|
2006-08-22 04:24:44 +02:00
|
|
|
const CCinemaData* data = source->GetData();
|
2006-07-06 05:17:44 +02:00
|
|
|
path.mode = data->m_Mode;
|
|
|
|
path.style = data->m_Style;
|
|
|
|
path.growth = data->m_Growth;
|
2007-02-27 03:14:18 +01:00
|
|
|
path.timescale = data->m_Timescale;
|
2006-07-06 05:17:44 +02:00
|
|
|
path.change = data->m_Switch;
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
CCinemaData ConstructCinemaData(const sCinemaPath& path)
|
|
|
|
{
|
|
|
|
CCinemaData data;
|
|
|
|
data.m_Growth = data.m_GrowthCount = path.growth;
|
|
|
|
data.m_Switch = path.change;
|
|
|
|
data.m_Mode = path.mode;
|
|
|
|
data.m_Style = path.style;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
sCinemaSplineNode ConstructCinemaNode(const SplineData& data)
|
|
|
|
{
|
|
|
|
sCinemaSplineNode node;
|
2007-02-27 03:14:18 +01:00
|
|
|
node.px = data.Position.X;
|
|
|
|
node.py = data.Position.Y;
|
|
|
|
node.pz = data.Position.Z;
|
|
|
|
|
|
|
|
node.rx = data.Rotation.X;
|
|
|
|
node.ry = data.Rotation.Y;
|
|
|
|
node.rz = data.Rotation.Z;
|
2006-07-06 05:17:44 +02:00
|
|
|
node.t = data.Distance;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
std::vector<sCinemaPath> GetCurrentPaths()
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
const std::map<CStrW, CCinemaPath>& paths = g_Game->GetView()->GetCinema()->GetAllPaths();
|
|
|
|
std::vector<sCinemaPath> atlasPaths;
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
for ( std::map<CStrW, CCinemaPath>::const_iterator it=paths.begin(); it!=paths.end(); it++ )
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
sCinemaPath path = ConstructCinemaPath(&it->second);
|
|
|
|
path.name = it->first;
|
|
|
|
|
|
|
|
const std::vector<SplineData>& nodes = it->second.GetAllNodes();
|
|
|
|
std::vector<sCinemaSplineNode> atlasNodes;
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
for ( size_t i=0; i<nodes.size(); ++i )
|
|
|
|
atlasNodes.push_back( ConstructCinemaNode(nodes[i]) );
|
|
|
|
|
|
|
|
if ( !atlasNodes.empty() )
|
|
|
|
{
|
|
|
|
float back = atlasNodes.back().t;
|
|
|
|
if ( atlasNodes.size() > 2 )
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
for ( size_t i=atlasNodes.size()-2; i>0; --i )
|
|
|
|
atlasNodes[i].t = atlasNodes[i-1].t;
|
2006-08-22 04:24:44 +02:00
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
atlasNodes.back().t = atlasNodes.front().t;
|
|
|
|
atlasNodes.front().t = back;
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
path.nodes = atlasNodes;
|
|
|
|
atlasPaths.push_back(path);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
return atlasPaths;
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
void SetCurrentPaths(const std::vector<sCinemaPath>& atlasPaths)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
std::map<CStrW, CCinemaPath> paths;
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
for ( std::vector<sCinemaPath>::const_iterator it=atlasPaths.begin(); it!=atlasPaths.end(); it++ )
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
CStrW pathName(*it->name);
|
|
|
|
paths[pathName] = CCinemaPath();
|
|
|
|
paths[pathName].SetTimescale(it->timescale);
|
|
|
|
|
|
|
|
const sCinemaPath& atlasPath = *it;
|
|
|
|
const std::vector<sCinemaSplineNode> nodes = *atlasPath.nodes;
|
|
|
|
TNSpline spline;
|
|
|
|
CCinemaData data = ConstructCinemaData(atlasPath);
|
|
|
|
|
|
|
|
for ( size_t j=0; j<nodes.size(); ++j )
|
|
|
|
{
|
|
|
|
spline.AddNode( CVector3D(nodes[j].px, nodes[j].py, nodes[j].pz),
|
|
|
|
CVector3D(nodes[j].rx, nodes[j].ry, nodes[j].rz), nodes[j].t );
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
paths[pathName] = CCinemaPath(data, spline);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
|
|
|
|
g_Game->GetView()->GetCinema()->SetAllPaths(paths);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
2006-08-22 04:24:44 +02:00
|
|
|
QUERYHANDLER(GetCameraInfo)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2006-08-22 04:24:44 +02:00
|
|
|
sCameraInfo info;
|
|
|
|
CMatrix3D* cam = &g_Game->GetView()->GetCamera()->m_Orientation;
|
|
|
|
|
|
|
|
CQuaternion quatRot = cam->GetRotation();
|
|
|
|
quatRot.Normalize();
|
|
|
|
CVector3D rotation = quatRot.ToEulerAngles();
|
|
|
|
rotation.X = RADTODEG(rotation.X);
|
|
|
|
rotation.Y = RADTODEG(rotation.Y);
|
|
|
|
rotation.Z = RADTODEG(rotation.Z);
|
|
|
|
CVector3D translation = cam->GetTranslation();
|
|
|
|
|
|
|
|
info.pX = translation.X;
|
|
|
|
info.pY = translation.Y;
|
|
|
|
info.pZ = translation.Z;
|
|
|
|
info.rX = rotation.X;
|
|
|
|
info.rY = rotation.Y;
|
|
|
|
info.rZ = rotation.Z;
|
|
|
|
msg->info = info;
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
|
|
|
|
2006-08-22 04:24:44 +02:00
|
|
|
MESSAGEHANDLER(CinemaEvent)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
|
|
|
CCinemaManager* manager = g_Game->GetView()->GetCinema();
|
2007-02-27 03:14:18 +01:00
|
|
|
|
2006-08-22 04:24:44 +02:00
|
|
|
if ( msg->mode == eCinemaEventMode::SMOOTH )
|
2007-02-27 03:14:18 +01:00
|
|
|
manager->OverridePath(*msg->path);
|
2006-08-22 04:24:44 +02:00
|
|
|
else if ( msg->mode == eCinemaEventMode::IMMEDIATE_PATH )
|
|
|
|
manager->MoveToPointAt(msg->t);
|
2007-01-17 00:22:25 +01:00
|
|
|
else if ( msg->mode == eCinemaEventMode::RESET )
|
|
|
|
g_Game->GetView()->ResetCamera();
|
2007-02-27 03:14:18 +01:00
|
|
|
else if ( msg->mode == eCinemaEventMode::SELECT )
|
|
|
|
manager->SetCurrentPath(*msg->path, msg->drawCurrent, msg->lines);
|
2006-08-22 04:24:44 +02:00
|
|
|
else
|
2007-02-27 03:14:18 +01:00
|
|
|
debug_assert(false);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
BEGIN_COMMAND(SetCinemaPaths)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
std::vector<sCinemaPath> m_oldPaths, m_newPaths;
|
2006-07-06 05:17:44 +02:00
|
|
|
void Do()
|
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
m_oldPaths = GetCurrentPaths();
|
|
|
|
m_newPaths = *msg->paths;
|
2006-07-06 05:17:44 +02:00
|
|
|
Redo();
|
|
|
|
}
|
|
|
|
void Redo()
|
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
SetCurrentPaths(m_newPaths);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
|
|
|
void Undo()
|
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
SetCurrentPaths(m_oldPaths);
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
|
|
|
};
|
2007-02-27 03:14:18 +01:00
|
|
|
END_COMMAND(SetCinemaPaths)
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
QUERYHANDLER(GetCinemaPaths)
|
2006-07-06 05:17:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
msg->paths = GetCurrentPaths();
|
2006-07-06 05:17:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|