Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_Joint6DOFEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameBase/Joints", description: "Physics joint - 6DOF (supports spring)", sizeMin: "-0.05 -0.05 -0.05", sizeMax: "0.05 0.05 0.05", color: "0 0 255 255")]
3 {
4  const int AXIS_YAW = 4;
5  const int AXIS_PITCH = 3;
6  const int AXIS_ROLL = 5;
7 
8  const int AXIS_RIGHT = 0;
9  const int AXIS_UP = 1;
10  const int AXIS_FORWARD = 2;
11 };
12 
13 //------------------------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------------------------
19 {
20  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values on the yaw axis")]
21  bool m_YawSetSpring;
22  [Attribute("0", UIWidgets.CheckBox, "Whether the yaw axis may rotate freely (ignores limits)")]
23  bool m_YawIsFree;
24  [Attribute("0", UIWidgets.Slider, "Minimum yaw range in degrees", "-180 0 0.01")]
25  float m_YawMin;
26  [Attribute("0", UIWidgets.Slider, "Maximum yaw range in degrees", "0 180 0.01")]
27  float m_YawMax;
28  //------------------------------------------------------------------------------------------------
29 
30  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values on the pitch axis")]
31  bool m_PitchSetSpring;
32  [Attribute("0", UIWidgets.CheckBox, "Whether the pitch axis may rotate freely (ignores limits)")]
33  bool m_PitchIsFree;
34  [Attribute("0", UIWidgets.Slider, "Minimum pitch range in degrees", "-180 0 0.01")]
35  float m_PitchMin;
36  [Attribute("0", UIWidgets.Slider, "Maximum pitch range in degrees", "0 180 0.01")]
37  float m_PitchMax;
38  //------------------------------------------------------------------------------------------------
39 
40  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values on the roll axis")]
41  bool m_RollSetSpring;
42  [Attribute("0", UIWidgets.CheckBox, "Whether the roll axis may rotate freely (ignores limits)")]
43  bool m_RollIsFree;
44  [Attribute("0", UIWidgets.Slider, "Minimum roll range in degrees", "-180 0 0.01")]
45  float m_RollMin;
46  [Attribute("0", UIWidgets.Slider, "Maximum roll range in degrees", "0 180 0.01")]
47  float m_RollMax;
48  //------------------------------------------------------------------------------------------------
49 
50  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values along the right axis")]
51  bool m_RightSetSpring;
52  [Attribute("0", UIWidgets.CheckBox, "Whether the right axis may move freely (ignores limits)")]
53  bool m_RightIsFree;
54  [Attribute("0", UIWidgets.Slider, "Minimum right axis range in meters", "-50 0 0.01")]
55  float m_RightMin;
56  [Attribute("0", UIWidgets.Slider, "Maximum right axis range in meters", "0 50 0.01")]
57  float m_RightMax;
58  //------------------------------------------------------------------------------------------------
59 
60  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values along the up axis")]
61  bool m_UpSetSpring;
62  [Attribute("0", UIWidgets.CheckBox, "Whether the up axis may move freely (ignores limits)")]
63  bool m_UpIsFree;
64  [Attribute("0", UIWidgets.Slider, "Minimum up axis range in meters", "-50 0 0.01")]
65  float m_UpMin;
66  [Attribute("0", UIWidgets.Slider, "Maximum up axis range in meters", "0 50 0.01")]
67  float m_UpMax;
68  //------------------------------------------------------------------------------------------------
69 
70  [Attribute("0", UIWidgets.CheckBox, "Whether to set spring values along the forward axis" )]
71  bool m_ForwardSetSpring;
72  [Attribute("0", UIWidgets.CheckBox, "Whether the forward axis may move freely (ignores limits)")]
73  bool m_ForwardIsFree;
74  [Attribute("0", UIWidgets.Slider, "Minimum forward axis range in meters", "-50 0 0.01")]
75  float m_ForwardMin;
76  [Attribute("0", UIWidgets.Slider, "Maximum forward axis range in meters", "0 50 0.01")]
77  float m_ForwardMax;
78  //------------------------------------------------------------------------------------------------
79 
80  [Attribute("10", UIWidgets.Slider, "Stiffness of the spring", "0 1000 0.001")]
81  float m_SpringStiffness;
82  [Attribute("0.5", UIWidgets.Slider, "Damping of the spring, lower values means more damping", "0 1 0.001")]
83  float m_SpringDamping;
84 
85  //------------------------------------------------------------------------------------------------
86 
87 
88  //------------------------------------------------------------------------------------------------
89  override void DebugDisplay()
90  {
91  vector mat[4];
92  GetTransform(mat);
93  vector pos = mat[3];
94 
95  vector axisVec = mat[0];
96  vector axisVec2 = mat[1];
97  vector axisVec3 = mat[2];
98 
99  bool noOffsets = true;
100  if (m_YawIsFree || m_YawMax != 0 || m_YawMin != 0)
101  noOffsets = false;
102  else if (m_PitchIsFree || m_PitchMax != 0 || m_PitchMin != 0)
103  noOffsets = false;
104  else if (m_RollIsFree || m_RollMax != 0 || m_RollMin != 0)
105  noOffsets = false;
106  else if (m_RightIsFree || m_RightMax != 0 || m_RightMin != 0)
107  noOffsets = false;
108  else if (m_UpIsFree || m_UpMax != 0 || m_UpMin != 0)
109  noOffsets = false;
110  else if (m_ForwardIsFree || m_ForwardMax != 0 || m_ForwardMin != 0)
111  noOffsets = false;
112 
113  if (noOffsets)
114  {
115  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * -0.05 + pos, axisVec * 0.05 + pos);
116  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * -0.05 + pos, axisVec2 * 0.05 + pos);
117  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * -0.05 + pos, axisVec3 * 0.05 + pos);
118 
119  return;
120  }
121 
122  if (m_YawIsFree)
123  CreateCircleSlice(pos, axisVec2, axisVec, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
124  else
125  {
126  if (m_YawMin != 0 || m_YawMax != 0)
127  CreateCircleSlice(pos, axisVec2, axisVec, m_YawMin, m_YawMax, 0.075, ARGB(255, 0, 255, 255), Math.Ceil(Math.AbsFloat(m_YawMax - m_YawMin) / 360 * 16), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
128  }
129  if (m_PitchIsFree)
130  CreateCircleSlice(pos, -axisVec, axisVec2, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
131  else
132  {
133  if (m_PitchMin != 0 || m_PitchMax != 0)
134  CreateCircleSlice(pos, -axisVec, axisVec2, m_PitchMin, m_PitchMax, 0.075, ARGB(255, 0, 255, 255), Math.Ceil(Math.AbsFloat(m_PitchMax - m_PitchMin) / 360 * 16), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
135  }
136  if (m_RollIsFree)
137  CreateCircleSlice(pos, -axisVec3, axisVec, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
138  else
139  {
140  if (m_RollMin != 0 || m_RollMax != 0)
141  CreateCircleSlice(pos, -axisVec3, axisVec, m_RollMin, m_RollMax, 0.075, ARGB(255, 0, 255, 255), Math.Ceil(Math.AbsFloat(m_RollMax - m_RollMin) / 360 * 16), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
142  }
143 
144  if (m_RightIsFree)
145  Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * -0.15 + pos, axisVec * 0.15 + pos);
146  else
147  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * m_RightMin + pos, axisVec * m_RightMax + pos);
148  if (m_UpIsFree)
149  Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * -0.15 + pos, axisVec2 * 0.15 + pos);
150  else
151  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * m_UpMin + pos, axisVec2 * m_UpMax + pos);
152  if (m_ForwardIsFree)
153  Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * -0.15 + pos, axisVec3 * 0.15 + pos);
154  else
155  Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * m_ForwardMin + pos, axisVec3 * m_ForwardMax + pos);
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  float GetSpringScale()
160  {
161  float result = (SCR_Global.g_fPhysicsHz - 60) / 60;
162  result = Math.Clamp(result, 0, 1);
163  result = 1 - result + 1;
164  result *= 10;
165  result *= m_SpringStiffness * m_SpringStiffness;
166 
167  return result;
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  float GetSpringLinDampScale()
172  {
173  return 0.001 * m_SpringDamping;
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  float GetSpringAngDampScale()
178  {
179  return 0.001 * m_SpringDamping;
180  }
181 
182  //------------------------------------------------------------------------------------------------
183  override void CreateJoint(IEntity parent, IEntity child, vector jointMat1[4], vector jointMat2[4])
184  {
185  bool isSpring = false;
186  if (m_YawSetSpring || m_PitchSetSpring || m_RollSetSpring || m_RightSetSpring || m_UpSetSpring || m_ForwardSetSpring)
187  isSpring = true;
188 
189  // Create the joint
190  if (isSpring)
191  {
192  m_Joint = PhysicsJoint.Create6DOFSpring(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
193  Physics6DOFSpringJoint joint6DOF = m_Joint;
194  if (m_YawSetSpring)
195  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_YAW, GetSpringScale(), GetSpringAngDampScale());
196  if (m_PitchSetSpring)
197  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_PITCH, GetSpringScale(), GetSpringAngDampScale());
198  if (m_RollSetSpring)
199  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_ROLL, GetSpringScale(), GetSpringAngDampScale());
200  if (m_RightSetSpring)
201  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_RIGHT, GetSpringScale(), GetSpringLinDampScale());
202  if (m_UpSetSpring)
203  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_UP, GetSpringScale(), GetSpringLinDampScale());
204  if (m_ForwardSetSpring)
205  joint6DOF.SetSpring(SCR_Joint6DOFEntityClass.AXIS_FORWARD, GetSpringScale(), GetSpringLinDampScale());
206  }
207  else
208  m_Joint = PhysicsJoint.Create6DOF(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
209 
210  Physics6DOFJoint joint6DOF = m_Joint;
211  if (m_YawIsFree)
212  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_YAW, 1, -1);
213  else
214  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_YAW, m_YawMax * Math.DEG2RAD, m_YawMin * Math.DEG2RAD);
215  if (m_PitchIsFree)
216  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_PITCH, 1, -1);
217  else
218  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_PITCH, m_PitchMin * Math.DEG2RAD, m_PitchMax * Math.DEG2RAD);
219  if (m_RollIsFree)
220  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_ROLL, 1, -1);
221  else
222  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_ROLL, m_RollMin * Math.DEG2RAD, m_RollMax * Math.DEG2RAD);
223 
224  if (m_RightIsFree)
225  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_RIGHT, 1, -1);
226  else
227  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_RIGHT, m_RightMin, m_RightMax);
228  if (m_UpIsFree)
229  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_UP, 1, -1);
230  else
231  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_UP, m_UpMin, m_UpMax);
232  if (m_ForwardIsFree)
233  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_FORWARD, 1, -1);
234  else
235  joint6DOF.SetLimit(SCR_Joint6DOFEntityClass.AXIS_FORWARD, m_ForwardMin, m_ForwardMax);
236  }
237 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_Joint6DOFEntity
Definition: SCR_Joint6DOFEntity.c:18
SCR_JointBaseEntityClass
Definition: SCR_JointBaseEntity.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_JointBaseEntity
Definition: SCR_JointBaseEntity.c:11
CreateCircleSlice
Shape CreateCircleSlice(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
Definition: DebugShapes.c:165
SCR_Global
Definition: Functions.c:6
SCR_Joint6DOFEntityClass
Definition: SCR_Joint6DOFEntity.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180