Ticket #3814: cinematic_camera_cleanup_3.patch

File cinematic_camera_cleanup_3.patch, 8.9 KB (added by Vladislav Belov, 8 years ago)
  • source/graphics/CinemaManager.cpp

     
    171171    {
    172172        // TODO: implement skip
    173173    }
    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);
    176177}
    177178
    178179void CCinemaManager::Render()
  • source/graphics/CinemaPath.cpp

     
    217217    m_Timescale = scale;
    218218}
    219219
    220 void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)
     220void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera)
    221221{
    222     CCamera *camera = g_Game->GetView()->GetCamera();
    223222    t = (this->*DistModePtr)(t);
    224223
    225224    CVector3D pos = GetPosition(t);
     
    341340    return false;
    342341}
    343342
    344 bool CCinemaPath::Play(const float deltaRealTime)
     343bool CCinemaPath::Play(const float deltaRealTime, CCamera* camera)
    345344{
    346345    m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime;
    347346    if (!Validate())
    348347        return false;
    349348
    350     MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation);
     349    MoveToPointAt(m_TimeElapsed / GetDuration().ToFloat(), GetNodeFraction(), m_PreviousRotation, camera);
    351350    return true;
    352351}
    353352
  • source/graphics/CinemaPath.h

     
    6161    CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
    6262
    6363    // 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);
    6565
    6666    // Distortion mode functions-change how ratio is passed to distortion style functions
    6767    float EaseIn(float t) const;
     
    109109    /**
    110110     * Returns false if finished.
    111111     * @param deltaRealTime Elapsed real time since the last frame.
     112     * @param camera An affected camera
    112113     */
    113     bool Play(const float deltaRealTime);
     114    bool Play(const float deltaRealTime, CCamera* camera);
    114115
    115116    /**
    116117     * Validate the path
  • source/graphics/MapReader.cpp

     
    871871            CCinemaData pathData;
    872872            XMBAttributeList attrs = element.GetAttributes();
    873873            CStrW pathName(attrs.GetNamedItem(at_name).FromUTF8());
     874            pathData.m_Name = pathName;
    874875            pathData.m_Timescale = fixed::FromString(attrs.GetNamedItem(at_timescale));
    875             TNSpline pathSpline, targetSpline;
    876             fixed lastTargetTime = fixed::Zero();
    877 
    878             pathData.m_Name = pathName;
    879876            pathData.m_Orientation = attrs.GetNamedItem(at_orientation).FromUTF8();
    880877            pathData.m_Mode = attrs.GetNamedItem(at_mode).FromUTF8();
    881878            pathData.m_Style = attrs.GetNamedItem(at_style).FromUTF8();
    882879
     880            TNSpline positionSpline, targetSpline;
     881            fixed lastPositionTime = fixed::Zero();
     882            fixed lastTargetTime = fixed::Zero();
     883
    883884            XERO_ITER_EL(element, pathChild)
    884885            {
    885886                elementName = pathChild.GetNodeName();
     
    888889                // Load node data used for spline
    889890                if (elementName == el_node)
    890891                {
    891                     bool positionDeclared = false;
    892                     SplineData data;
    893                     data.Distance = fixed::FromString(attrs.GetNamedItem(at_deltatime));
     892                    lastPositionTime += fixed::FromString(attrs.GetNamedItem(at_deltatime));
    894893                    lastTargetTime += fixed::FromString(attrs.GetNamedItem(at_deltatime));
    895894                    XERO_ITER_EL(pathChild, nodeChild)
    896895                    {
     
    899898
    900899                        if (elementName == el_position)
    901900                        {
    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();
    906908                        }
    907909                        else if (elementName == el_rotation)
    908910                        {
    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
    912912                        }
    913913                        else if (elementName == el_target)
    914914                        {
     
    923923                        else
    924924                            LOGWARNING("Invalid cinematic element for node child");
    925925                    }
    926 
    927                     // Skip the node if no position
    928                     if (positionDeclared)
    929                         pathSpline.AddNode(data.Position, data.Rotation, data.Distance);
    930926                }
    931927                else
    932928                    LOGWARNING("Invalid cinematic element for path child");
     
    933929            }
    934930
    935931            // Construct cinema path with data gathered
    936             CCinemaPath path(pathData, pathSpline, targetSpline);
     932            CCinemaPath path(pathData, positionSpline, targetSpline);
    937933            if (path.Empty())
    938934            {
    939935                LOGWARNING("Path with name '%s' is empty", pathName.ToUTF8());
  • source/graphics/MapWriter.cpp

     
    409409            for ( ; it != paths.end(); ++it )
    410410            {
    411411                fixed timescale = it->second.GetTimescale();
    412                 const std::vector<SplineData>& nodes = it->second.GetAllNodes();
     412                const std::vector<SplineData>& position_nodes = it->second.GetAllNodes();
    413413                const std::vector<SplineData>& target_nodes = it->second.GetTargetSpline().GetAllNodes();
    414414                const CCinemaData* data = it->second.GetData();
    415415               
     
    420420                XML_Attribute("mode", data->m_Mode);
    421421                XML_Attribute("style", data->m_Style);
    422422
    423                 fixed last_target = fixed::Zero();
    424                 for (size_t i = 0, j = 0; i < nodes.size(); ++i)
     423                struct SEvent
    425424                {
    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)
    432432                    {
    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;
    437434                    }
     435                };
    438436
    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;
    445439
    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                }
    448447
    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                }
    450455
    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)
    454464                    {
    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);
    459470                    }
    460 
    461                     last_target = fixed::Zero();
    462                     ++j;
     471                    i = j;
    463472                }
    464473            }
    465474        }