Ticket #3814: cinematic_camera_cleanup_3.patch
File cinematic_camera_cleanup_3.patch, 8.9 KB (added by , 8 years ago) |
---|
-
source/graphics/CinemaManager.cpp
171 171 { 172 172 // TODO: implement skip 173 173 } 174 175 m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime); 174 175 CCamera *camera = g_Game->GetView()->GetCamera(); 176 m_CinematicSimulationData.m_PathQueue.front().Play(deltaRealTime, camera); 176 177 } 177 178 178 179 void CCinemaManager::Render() -
source/graphics/CinemaPath.cpp
217 217 m_Timescale = scale; 218 218 } 219 219 220 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation )220 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) 221 221 { 222 CCamera *camera = g_Game->GetView()->GetCamera();223 222 t = (this->*DistModePtr)(t); 224 223 225 224 CVector3D pos = GetPosition(t); … … 341 340 return false; 342 341 } 343 342 344 bool CCinemaPath::Play(const float deltaRealTime )343 bool CCinemaPath::Play(const float deltaRealTime, CCamera* camera) 345 344 { 346 345 m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime; 347 346 if (!Validate()) 348 347 return false; 349 348 350 MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation );349 MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation, camera); 351 350 return true; 352 351 } 353 352 -
source/graphics/CinemaPath.h
61 61 CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); 62 62 63 63 // Sets camera position to calculated point on spline 64 void MoveToPointAt(float t, float nodet, const CVector3D& );64 void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera); 65 65 66 66 // Distortion mode functions-change how ratio is passed to distortion style functions 67 67 float EaseIn(float t) const; … … 109 109 /** 110 110 * Returns false if finished. 111 111 * @param deltaRealTime Elapsed real time since the last frame. 112 * @param camera An affected camera 112 113 */ 113 bool Play(const float deltaRealTime );114 bool Play(const float deltaRealTime, CCamera* camera); 114 115 115 116 /** 116 117 * Validate the path -
source/graphics/MapReader.cpp
871 871 CCinemaData pathData; 872 872 XMBAttributeList attrs = element.GetAttributes(); 873 873 CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8()); 874 pathData.m_Name = pathName; 874 875 pathData.m_Timescale = fixed::FromString(attrs.GetNamedItem(at_timescale)); 875 TNSpline pathSpline, targetSpline;876 fixed lastTargetTime = fixed::Zero();877 878 pathData.m_Name = pathName;879 876 pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8(); 880 877 pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8(); 881 878 pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8(); 882 879 880 TNSpline positionSpline, targetSpline; 881 fixed lastPositionTime = fixed::Zero(); 882 fixed lastTargetTime = fixed::Zero(); 883 883 884 XERO_ITER_EL(element, pathChild) 884 885 { 885 886 elementName = pathChild.GetNodeName(); … … 888 889 // Load node data used for spline 889 890 if (elementName == el_node) 890 891 { 891 bool positionDeclared = false; 892 SplineData data; 893 data.Distance = fixed::FromString(attrs.GetNamedItem(at_deltatime)); 892 lastPositionTime += fixed::FromString(attrs.GetNamedItem(at_deltatime)); 894 893 lastTargetTime += fixed::FromString(attrs.GetNamedItem(at_deltatime)); 895 894 XERO_ITER_EL(pathChild, nodeChild) 896 895 { … … 899 898 900 899 if (elementName == el_position) 901 900 { 902 data.Position.X = fixed::FromString(attrs.GetNamedItem(at_x)); 903 data.Position.Y = fixed::FromString(attrs.GetNamedItem(at_y)); 904 data.Position.Z = fixed::FromString(attrs.GetNamedItem(at_z)); 905 positionDeclared = true; 901 CFixedVector3D position; 902 position.X = fixed::FromString(attrs.GetNamedItem(at_x)); 903 position.Y = fixed::FromString(attrs.GetNamedItem(at_y)); 904 position.Z = fixed::FromString(attrs.GetNamedItem(at_z)); 905 906 positionSpline.AddNode(position, CFixedVector3D(), lastPositionTime); 907 lastPositionTime = fixed::Zero(); 906 908 } 907 909 else if (elementName == el_rotation) 908 910 { 909 data.Rotation.X = fixed::FromString(attrs.GetNamedItem(at_x)); 910 data.Rotation.Y = fixed::FromString(attrs.GetNamedItem(at_y)); 911 data.Rotation.Z = fixed::FromString(attrs.GetNamedItem(at_z)); 911 // TODO: Implement rotation slerp/spline as another object 912 912 } 913 913 else if (elementName == el_target) 914 914 { … … 923 923 else 924 924 LOGWARNING("Invalid cinematic element for node child"); 925 925 } 926 927 // Skip the node if no position928 if (positionDeclared)929 pathSpline.AddNode(data.Position, data.Rotation, data.Distance);930 926 } 931 927 else 932 928 LOGWARNING("Invalid cinematic element for path child"); … … 933 929 } 934 930 935 931 // Construct cinema path with data gathered 936 CCinemaPath path(pathData, p athSpline, targetSpline);932 CCinemaPath path(pathData, positionSpline, targetSpline); 937 933 if (path.Empty()) 938 934 { 939 935 LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8()); -
source/graphics/MapWriter.cpp
409 409 for ( ; it != paths.end(); ++it ) 410 410 { 411 411 fixed timescale = it->second.GetTimescale(); 412 const std::vector<SplineData>& nodes = it->second.GetAllNodes();412 const std::vector<SplineData>& position_nodes = it->second.GetAllNodes(); 413 413 const std::vector<SplineData>& target_nodes = it->second.GetTargetSpline().GetAllNodes(); 414 414 const CCinemaData* data = it->second.GetData(); 415 415 … … 420 420 XML_Attribute("mode", data->m_Mode); 421 421 XML_Attribute("style", data->m_Style); 422 422 423 fixed last_target = fixed::Zero(); 424 for (size_t i = 0, j = 0; i < nodes.size(); ++i) 423 struct SEvent 425 424 { 426 XML_Element("Node"); 427 fixed distance = i > 0 ? nodes[i - 1].Distance : fixed::Zero(); 428 last_target += distance; 429 430 XML_Attribute("deltatime", distance); 431 425 fixed time; 426 const char* type; 427 CFixedVector3D value; 428 SEvent(fixed time, const char* type, CFixedVector3D value) 429 : time(time), type(type), value(value) 430 {} 431 bool operator<(const SEvent& another) 432 432 { 433 XML_Element("Position"); 434 XML_Attribute("x", nodes[i].Position.X); 435 XML_Attribute("y", nodes[i].Position.Y); 436 XML_Attribute("z", nodes[i].Position.Z); 433 return time < another.time; 437 434 } 435 }; 438 436 439 { 440 XML_Element("Rotation"); 441 XML_Attribute("x", nodes[i].Rotation.X); 442 XML_Attribute("y", nodes[i].Rotation.Y); 443 XML_Attribute("z", nodes[i].Rotation.Z); 444 } 437 // All events of a manipulating of camera (position/rotation/target) 438 std::vector<SEvent> events; 445 439 446 if (j >= target_nodes.size()) 447 continue; 440 fixed last_position = fixed::Zero(); 441 for (size_t i = 0; i < position_nodes.size(); ++i) 442 { 443 fixed distance = i > 0 ? position_nodes[i - 1].Distance : fixed::Zero(); 444 last_position += distance; 445 events.emplace_back(last_position, "Position", position_nodes[i].Position); 446 } 448 447 449 fixed target_distance = j > 0 ? target_nodes[j - 1].Distance : fixed::Zero(); 448 fixed last_target = fixed::Zero(); 449 for (size_t i = 0; i < target_nodes.size(); ++i) 450 { 451 fixed distance = i > 0 ? target_nodes[i - 1].Distance : fixed::Zero(); 452 last_target += distance; 453 events.emplace_back(last_target, "Target", target_nodes[i].Position); 454 } 450 455 451 if (target_distance > last_target) 452 continue; 453 456 std::sort(events.begin(), events.end()); 457 for (size_t i = 0; i < events.size();) 458 { 459 XML_Element("Node"); 460 fixed deltatime = i > 0 ? (events[i].time - events[i - 1].time) : fixed::Zero(); 461 XML_Attribute("deltatime", deltatime); 462 size_t j = i; 463 for (; j < events.size() && events[j].time == events[i].time; ++j) 454 464 { 455 XML_Element("Target"); 456 XML_Attribute("x", target_nodes[j].Position.X); 457 XML_Attribute("y", target_nodes[j].Position.Y); 458 XML_Attribute("z", target_nodes[j].Position.Z); 465 // Types: Position/Rotation/Target 466 XML_Element(events[j].type); 467 XML_Attribute("x", events[j].value.X); 468 XML_Attribute("y", events[j].value.Y); 469 XML_Attribute("z", events[j].value.Z); 459 470 } 460 461 last_target = fixed::Zero(); 462 ++j; 471 i = j; 463 472 } 464 473 } 465 474 }