117 uint32 pathId = goInfo->moTransport.taxiPathID;
119 std::vector<KeyFrame>& keyFrames = transport->
keyFrames;
121 bool mapChange =
false;
122 for (
size_t i = 0; i < path.size(); ++i)
123 allPoints.push_back(
G3D::Vector3(path[i]->Loc.X, path[i]->Loc.Y, path[i]->Loc.Z));
126 allPoints.insert(allPoints.begin(), allPoints.front().lerp(allPoints[1], -0.2f));
127 allPoints.push_back(allPoints.back().lerp(allPoints[allPoints.size() - 2], -0.2f));
128 allPoints.push_back(allPoints.back().lerp(allPoints[allPoints.size() - 2], -1.0f));
132 orientationSpline.init_spline_custom(initer);
135 for (
size_t i = 0; i < path.size(); ++i)
142 keyFrames.back().Teleport =
true;
152 keyFrames.push_back(k);
154 transport->
mapsUsed.insert(k.Node->MapID);
161 if (splinePath.size() >= 2)
164 if (!keyFrames.front().IsStopFrame() && !keyFrames.front().Node->ArrivalEventID && !keyFrames.front().Node->DepartureEventID)
166 splinePath.erase(splinePath.begin());
167 keyFrames.erase(keyFrames.begin());
169 if (!keyFrames.back().IsStopFrame() && !keyFrames.back().Node->ArrivalEventID && !keyFrames.back().Node->DepartureEventID)
171 splinePath.pop_back();
172 keyFrames.pop_back();
176 ASSERT(!keyFrames.empty());
180 for (std::set<uint32>::const_iterator itr = transport->
mapsUsed.begin(); itr != transport->
mapsUsed.end(); ++itr)
189 keyFrames.back().Teleport =
true;
191 const float speed = float(goInfo->moTransport.moveSpeed);
192 const float accel = float(goInfo->moTransport.accelRate);
193 const float accel_dist = 0.5f * speed * speed / accel;
198 int32 firstStop = -1;
202 keyFrames[0].DistFromPrev = 0;
203 keyFrames[0].Index = 1;
204 if (keyFrames[0].IsStopFrame())
213 for (
size_t i = 1; i < keyFrames.size(); ++i)
215 if (keyFrames[i - 1].Teleport || i + 1 == keyFrames.size())
217 size_t extra = !keyFrames[i - 1].Teleport ? 1 : 0;
221 for (
size_t j = start; j < i + extra; ++j)
223 keyFrames[j].Index = j - start + 1;
224 keyFrames[j].DistFromPrev = float(spline->
length(j - start, j + 1 - start));
226 keyFrames[j - 1].NextDistFromPrev = keyFrames[j].DistFromPrev;
227 keyFrames[j].Spline = spline;
230 if (keyFrames[i - 1].Teleport)
232 keyFrames[i].Index = i - start + 1;
233 keyFrames[i].DistFromPrev = 0.0f;
234 keyFrames[i - 1].NextDistFromPrev = 0.0f;
235 keyFrames[i].Spline = spline;
241 if (keyFrames[i].IsStopFrame())
250 keyFrames.back().NextDistFromPrev = keyFrames.front().DistFromPrev;
252 if (firstStop == -1 || lastStop == -1)
253 firstStop = lastStop = 0;
258 float tmpDist = 0.0f;
259 for (
size_t i = 0; i < keyFrames.size(); ++i)
261 int32 j = (i + lastStop) % keyFrames.size();
262 if (keyFrames[j].IsStopFrame() || j == lastStop)
265 tmpDist += keyFrames[j].DistFromPrev;
266 keyFrames[j].DistSinceStop = tmpDist;
270 for (
int32 i =
int32(keyFrames.size()) - 1; i >= 0; i--)
272 int32 j = (i + firstStop) % keyFrames.size();
273 tmpDist += keyFrames[(j + 1) % keyFrames.size()].DistFromPrev;
274 keyFrames[j].DistUntilStop = tmpDist;
275 if (keyFrames[j].IsStopFrame() || j == firstStop)
279 for (
size_t i = 0; i < keyFrames.size(); ++i)
281 float total_dist = keyFrames[i].DistSinceStop + keyFrames[i].DistUntilStop;
282 if (total_dist < 2 * accel_dist)
284 if (keyFrames[i].DistSinceStop < keyFrames[i].DistUntilStop)
287 float segment_time = 2.0f * std::sqrt((keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / accel);
289 keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel);
292 keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel);
294 else if (keyFrames[i].DistSinceStop < accel_dist)
297 float segment_time = (keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / speed + (speed / accel);
299 keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel);
301 else if (keyFrames[i].DistUntilStop < accel_dist)
302 keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel);
304 keyFrames[i].TimeTo = (keyFrames[i].DistUntilStop / speed) + (0.5f * speed / accel);
308 float segmentTime = 0.0f;
309 for (
size_t i = 0; i < keyFrames.size(); ++i)
311 int32 j = (i + lastStop) % keyFrames.size();
312 if (keyFrames[j].IsStopFrame() || j == lastStop)
313 segmentTime = keyFrames[j].TimeTo;
314 keyFrames[j].TimeFrom = segmentTime - keyFrames[j].TimeTo;
318 keyFrames[0].ArriveTime = 0;
319 float curPathTime = 0.0f;
320 if (keyFrames[0].IsStopFrame())
322 curPathTime = float(keyFrames[0].Node->Delay);
326 for (
size_t i = 1; i < keyFrames.size(); ++i)
328 curPathTime += keyFrames[i - 1].TimeTo;
329 if (keyFrames[i].IsStopFrame())
332 keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime;
333 curPathTime += float(keyFrames[i].Node->Delay);
338 curPathTime -= keyFrames[i].TimeTo;
340 keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime;
341 keyFrames[i].DepartureTime = keyFrames[i].ArriveTime;
345 keyFrames.back().NextArriveTime = keyFrames.back().DepartureTime;
347 transport->
pathTime = keyFrames.back().DepartureTime;
float Z
Definition: DBCEnums.h:36
float x
Definition: Vector3.h:62
float Y
Definition: DBCEnums.h:35
#define M_PI
Definition: Common.h:163
void init_spline(const Vector3 *controls, index_type count, EvaluationMode m)
Definition: Spline.h:172
Movement::Spline< double > TransportSpline
Definition: TransportMgr.h:31
void initLengths()
Definition: SplineImpl.h:79
float accelTime
Definition: TransportMgr.h:78
Definition: TransportMgr.cpp:98
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition: DB2Stores.cpp:139
static float NormalizeOrientation(float o)
Definition: Position.h:211
float y
Definition: Vector3.h:62
std::set< uint32 > mapsUsed
Definition: TransportMgr.h:74
uint32 MapID
Definition: DB2Structure.h:1350
KeyFrameVec keyFrames
Definition: TransportMgr.h:77
uint32 Flags
Definition: DB2Structure.h:1352
length_type length() const
Definition: Spline.h:199
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:30
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
float X
Definition: DBCEnums.h:34
Definition: DB2Structure.h:1345
bool inInstance
Definition: TransportMgr.h:75
DBCPosition3D Loc
Definition: DB2Structure.h:1351
DBCStorage< MapEntry > sMapStore(Mapfmt)
int32_t int32
Definition: g3dmath.h:167
#define ASSERT
Definition: Errors.h:55
uint32_t uint32
Definition: g3dmath.h:168
Definition: TransportMgr.h:40
uint32 pathTime
Definition: TransportMgr.h:76
Definition: DBCEnums.h:701
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:29
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition: DB2Structure.h:1449
float accelDist
Definition: TransportMgr.h:79