Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
dayzplayerimplementheading.c
Go to the documentation of this file.
1/*
2DayZPlayerImplement
3
4this file is implemenation of dayzPlayer in script
5- logic of movement
6- camera switching logic
7
8*/
9
11{
12
13 //-------------------------------------------------------------
17
19 static bool ClampHeading (float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
20 {
21 float aDiff = pModel.m_fHeadingAngle - pModel.m_fOrientationAngle;
22 if (aDiff < -Math.PI)
23 {
24 aDiff += Math.PI2;
25 }
26 else if (aDiff > Math.PI)
27 {
28 aDiff -= Math.PI2;
29 }
30
31 // Print("Heading model: or: " + pModel.m_fOrientationAngle.ToString() + " head:" + pModel.m_fHeadingAngle.ToString() + " dif:" + aDiff.ToString());
32
33 if (pLastHeadingDiff < -Math.PI_HALF && aDiff > 0)
34 {
35 aDiff = -Math.PI + 0.01;
36 pLastHeadingDiff = aDiff;
37 pModel.m_fHeadingAngle = pModel.m_fOrientationAngle + aDiff;
38
39 // Print("-APA- : or: " + pModel.m_fOrientationAngle.ToString() + " head:" + pModel.m_fHeadingAngle.ToString() + " dif:" + aDiff.ToString());
40
41 return true; // modify heading
42 }
43 else if (pLastHeadingDiff > Math.PI_HALF && aDiff < 0)
44 {
45 aDiff = Math.PI - 0.01;
46 pLastHeadingDiff = aDiff;
47 pModel.m_fHeadingAngle = pModel.m_fOrientationAngle + aDiff;
48
49 // Print("-APA- : or: " + pModel.m_fOrientationAngle.ToString() + " head:" + pModel.m_fHeadingAngle.ToString() + " dif:" + aDiff.ToString());
50
51 return true; // modify heading
52 }
53
54 pLastHeadingDiff = aDiff;
55 // Print("Heading model diff " + aDiff.ToString());
56 return false;
57 }
58
59 //-------------------------------------------------------------
63
64 static float CONST_ROTLIMIT = Math.PI * 0.95;
65
67 static bool RotateOrient (float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
68 {
69 float aDiff = pModel.m_fHeadingAngle - pModel.m_fOrientationAngle;
70
71 while (aDiff < -Math.PI)
72 {
73 aDiff += Math.PI2;
74 }
75 while (aDiff > Math.PI)
76 {
77 aDiff -= Math.PI2;
78 }
79
80 // Print("Heading model: or: " + pModel.m_fOrientationAngle.ToString() + " head:" + pModel.m_fHeadingAngle.ToString() + " dif:" + aDiff.ToString());
81
82 if (pLastHeadingDiff < -Math.PI_HALF && aDiff > 0)
83 {
84 aDiff -= Math.PI2;
85 }
86 else if (pLastHeadingDiff > Math.PI_HALF && aDiff < 0)
87 {
88 aDiff += Math.PI2;
89 }
90
91 pLastHeadingDiff = aDiff;
92 if (aDiff < -CONST_ROTLIMIT)
93 {
94 // character is somehow stucked (happens in prone stance)
95 if (aDiff < -(Math.PI_HALF + CONST_ROTLIMIT))
96 {
97 pLastHeadingDiff = 0;
98 return false;
99 }
100
101 pModel.m_fOrientationAngle += aDiff + CONST_ROTLIMIT;
102 return true;
103 }
104 else if (aDiff > CONST_ROTLIMIT)
105 {
106 // character is somehow stucked (happens in prone stance)
107 if (aDiff > (Math.PI_HALF + CONST_ROTLIMIT))
108 {
109 pLastHeadingDiff = 0;
110 return false;
111 }
112
113 pModel.m_fOrientationAngle += aDiff - CONST_ROTLIMIT;
114 return true;
115 }
116
117 // Print("Heading model diff " + aDiff.ToString());
118 return false;
119
120 }
121
122 static bool RestrictHeading(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff, HeadingRestrictData restrictData)
123 {
124 pModel.m_fHeadingAngle = ClampAngle(pModel.m_fHeadingAngle, restrictData);
125 return true;
126 }
127
128 // Clamp angle between -PI to PI
129 protected static float ClampAngle(float angle, HeadingRestrictData restrictData)
130 {
131 float testOtherDir;
132
133 if (restrictData.m_RestrictedR > restrictData.m_RestrictedL)
134 {
135 if (angle > restrictData.m_RestrictedL && angle < restrictData.m_RestrictedR)
136 {
137 //Print("STANDARD NOCLAMP: " + angle*Math.RAD2DEG + " |MIN: " + restrictData.m_RestrictedL*Math.RAD2DEG + " |MAX: " + restrictData.m_RestrictedR*Math.RAD2DEG);
138 return angle;
139 }
140 else
141 {
142 //Print("STANDARD CLAMP: " + angle*Math.RAD2DEG + " |MIN: " + restrictData.m_RestrictedL*Math.RAD2DEG + " |MAX: " + restrictData.m_RestrictedR*Math.RAD2DEG);
143
144 if (angle > restrictData.m_RestrictedR + 90 * Math.DEG2RAD) // check if restrictData.m_RestrictedR/restrictData.m_RestrictedL is close to -PI and the new angle flips to +PI or vice versa
145 return restrictData.m_RestrictedL;
146 else if (angle < restrictData.m_RestrictedL - 90 * Math.DEG2RAD)
147 return restrictData.m_RestrictedR;
148
149 return Math.Clamp(angle, restrictData.m_RestrictedL, restrictData.m_RestrictedR);
150 }
151 }
152 else if (restrictData.m_RestrictedR < restrictData.m_RestrictedL) // angle is restrited through 180 -> -180, clamping follows different rules
153 {
154 if ((angle >= -180 && angle < restrictData.m_RestrictedR) || (angle <= 180 && angle > restrictData.m_RestrictedL))
155 {
156 //Print("INVERSE NOCLAMP: " + angle*Math.RAD2DEG + " |MIN: " + restrictData.m_RestrictedL*Math.RAD2DEG + " |MAX: " + restrictData.m_RestrictedR*Math.RAD2DEG);
157 return angle;
158 }
159 else
160 {
161 //Print("INVERSE CLAMP: " + angle*Math.RAD2DEG + " |MIN: " + restrictData.m_RestrictedL*Math.RAD2DEG + " |MAX: " + restrictData.m_RestrictedR*Math.RAD2DEG);
162
163 if (angle < 0)
164 {
165 testOtherDir = Math.AbsFloat(restrictData.m_RestrictedR - angle);
166 if (testOtherDir < restrictData.m_AngleRangeInverted - testOtherDir)
167 return restrictData.m_RestrictedR;
168 else
169 return restrictData.m_RestrictedL;
170 }
171 else if (angle >= 0)
172 {
173 testOtherDir = Math.AbsFloat(restrictData.m_RestrictedL - angle);
174 if (testOtherDir < restrictData.m_AngleRangeInverted - testOtherDir)
175 return restrictData.m_RestrictedL;
176 else
177 return restrictData.m_RestrictedR;
178 }
179
180 return angle;
181 }
182 }
183
184 return angle;
185 }
186
187 static bool NoHeading(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
188 {
189 pLastHeadingDiff = 0;
190 pModel.m_fHeadingAngle = pModel.m_fOrientationAngle;
191 return true;
192 }
193}
194
195class HeadingRestrictData
196{
197 float m_RestrictedL; // restricted angle left
198 float m_RestrictedR; // restricted angle right
199 float m_AngleRangeInverted; // the size of the restricted angle
200
201 void InitData(float currentHeading, Vector2 restrictedAngles)
202 {
203 m_RestrictedL = currentHeading + (Math.DEG2RAD * restrictedAngles.x);
204 if (m_RestrictedL < -Math.PI)
206
207 m_RestrictedR = currentHeading + (Math.DEG2RAD * restrictedAngles.y);
208 if (m_RestrictedR > Math.PI)
210
211 m_AngleRangeInverted = Math.PI2 - (Math.AbsFloat(restrictedAngles.x * Math.DEG2RAD) + restrictedAngles.y * Math.DEG2RAD);
212 }
213}
static bool NoHeading(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
static bool ClampHeading(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
This HeadingModel - Clamps heading.
static float ClampAngle(float angle, HeadingRestrictData restrictData)
static bool RestrictHeading(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff, HeadingRestrictData restrictData)
static bool RotateOrient(float pDt, SDayZPlayerHeadingModel pModel, out float pLastHeadingDiff)
static float CONST_ROTLIMIT
This HeadingModel - Rotates orientations - so player slides.
Definition enmath.c:7
float y
Definition vector2.c:10
float x
Definition vector2.c:9
void SDayZPlayerHeadingModel()
cannot be created from script
class DayZPlayerImplementHeading m_RestrictedL
float m_AngleRangeInverted
float m_RestrictedR
static const float PI_HALF
Definition enmath.c:14
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static const float PI
Definition enmath.c:12
static proto float AbsFloat(float f)
Returns absolute value.
static const float PI2
Definition enmath.c:13
static const float DEG2RAD
Definition enmath.c:17
static bool InitData()