-
-
Notifications
You must be signed in to change notification settings - Fork 452
/
Copy pathCPositionRotationAnimation.h
69 lines (56 loc) · 2.45 KB
/
CPositionRotationAnimation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.1
* LICENSE: See LICENSE in the top level directory
* FILE: animation/CPositionRotationAnimation.h
* PURPOSE: Shared (server/client) way of performing position & rotation interpolation.
* Could be put in a more general animation framework in the future.
* Could also be used in a more general way to use slerp on quaternions
* Could also be used in a more general way to use non-delta but target rotation
*
*****************************************************************************/
#pragma once
#include "TInterpolation.h"
#include "CVector.h"
class NetBitStreamInterface;
struct SPositionRotation
{
SPositionRotation() {}
SPositionRotation(const CVector& a_rvecPosition, const CVector& a_rvecRotation) : m_vecPosition(a_rvecPosition), m_vecRotation(a_rvecRotation) {}
SPositionRotation operator+(const SPositionRotation& a_rOther) const
{
SPositionRotation result;
result.m_vecPosition = m_vecPosition + a_rOther.m_vecPosition;
result.m_vecRotation = m_vecRotation + a_rOther.m_vecRotation;
return result;
}
SPositionRotation operator-(const SPositionRotation& a_rOther) const
{
SPositionRotation result;
result.m_vecPosition = m_vecPosition - a_rOther.m_vecPosition;
result.m_vecRotation = m_vecRotation - a_rOther.m_vecRotation;
return result;
}
SPositionRotation& operator*=(float a_fScalar)
{
m_vecPosition *= a_fScalar;
m_vecRotation *= a_fScalar;
return *this;
}
CVector m_vecPosition;
CVector m_vecRotation;
};
class CPositionRotationAnimation : public TInterpolation<SPositionRotation>
{
public:
CPositionRotationAnimation();
void SetSourceValue(const SPositionRotation& a_rValue);
// a_bDeltaRotationMode defines if the rotation provided is a relative rotation
void SetTargetValue(const SPositionRotation& a_rValue, bool a_bDeltaRotationMode);
// bResumeMode = considering the already elapsed time, full animation from start otherwise
void ToBitStream(NetBitStreamInterface& a_rBitStream, bool a_bResumeMode) const;
// Returned pointer must be deleted by caller
static CPositionRotationAnimation* FromBitStream(NetBitStreamInterface& a_rBitStream);
protected:
bool m_bDeltaRotationMode; // defines if the rotation provided is a relative rotation
};