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")]
4 const int AXIS_YAW = 4;
5 const int AXIS_PITCH = 3;
6 const int AXIS_ROLL = 5;
8 const int AXIS_RIGHT = 0;
10 const int AXIS_FORWARD = 2;
20 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether to set spring values on the yaw axis")]
22 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether the yaw axis may rotate freely (ignores limits)")]
24 [
Attribute(
"0", UIWidgets.Slider,
"Minimum yaw range in degrees",
"-180 0 0.01")]
26 [
Attribute(
"0", UIWidgets.Slider,
"Maximum yaw range in degrees",
"0 180 0.01")]
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)")]
34 [
Attribute(
"0", UIWidgets.Slider,
"Minimum pitch range in degrees",
"-180 0 0.01")]
36 [
Attribute(
"0", UIWidgets.Slider,
"Maximum pitch range in degrees",
"0 180 0.01")]
40 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether to set spring values on the roll axis")]
42 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether the roll axis may rotate freely (ignores limits)")]
44 [
Attribute(
"0", UIWidgets.Slider,
"Minimum roll range in degrees",
"-180 0 0.01")]
46 [
Attribute(
"0", UIWidgets.Slider,
"Maximum roll range in degrees",
"0 180 0.01")]
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)")]
54 [
Attribute(
"0", UIWidgets.Slider,
"Minimum right axis range in meters",
"-50 0 0.01")]
56 [
Attribute(
"0", UIWidgets.Slider,
"Maximum right axis range in meters",
"0 50 0.01")]
60 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether to set spring values along the up axis")]
62 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether the up axis may move freely (ignores limits)")]
64 [
Attribute(
"0", UIWidgets.Slider,
"Minimum up axis range in meters",
"-50 0 0.01")]
66 [
Attribute(
"0", UIWidgets.Slider,
"Maximum up axis range in meters",
"0 50 0.01")]
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)")]
74 [
Attribute(
"0", UIWidgets.Slider,
"Minimum forward axis range in meters",
"-50 0 0.01")]
76 [
Attribute(
"0", UIWidgets.Slider,
"Maximum forward axis range in meters",
"0 50 0.01")]
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;
89 override void DebugDisplay()
95 vector axisVec = mat[0];
96 vector axisVec2 = mat[1];
97 vector axisVec3 = mat[2];
99 bool noOffsets =
true;
100 if (m_YawIsFree || m_YawMax != 0 || m_YawMin != 0)
102 else if (m_PitchIsFree || m_PitchMax != 0 || m_PitchMin != 0)
104 else if (m_RollIsFree || m_RollMax != 0 || m_RollMin != 0)
106 else if (m_RightIsFree || m_RightMax != 0 || m_RightMin != 0)
108 else if (m_UpIsFree || m_UpMax != 0 || m_UpMin != 0)
110 else if (m_ForwardIsFree || m_ForwardMax != 0 || m_ForwardMin != 0)
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);
123 CreateCircleSlice(pos, axisVec2, axisVec, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
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);
130 CreateCircleSlice(pos, -axisVec, axisVec2, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
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);
137 CreateCircleSlice(pos, -axisVec3, axisVec, 1, -1, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
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);
145 Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * -0.15 + pos, axisVec * 0.15 + pos);
147 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * m_RightMin + pos, axisVec * m_RightMax + pos);
149 Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * -0.15 + pos, axisVec2 * 0.15 + pos);
151 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * m_UpMin + pos, axisVec2 * m_UpMax + pos);
153 Shape.Create(ShapeType.LINE, ARGB(255, 255, 0, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * -0.15 + pos, axisVec3 * 0.15 + pos);
155 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 255), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * m_ForwardMin + pos, axisVec3 * m_ForwardMax + pos);
159 float GetSpringScale()
161 float result = (
SCR_Global.g_fPhysicsHz - 60) / 60;
162 result = Math.Clamp(result, 0, 1);
163 result = 1 - result + 1;
165 result *= m_SpringStiffness * m_SpringStiffness;
171 float GetSpringLinDampScale()
173 return 0.001 * m_SpringDamping;
177 float GetSpringAngDampScale()
179 return 0.001 * m_SpringDamping;
183 override void CreateJoint(IEntity parent, IEntity child, vector jointMat1[4], vector jointMat2[4])
185 bool isSpring =
false;
186 if (m_YawSetSpring || m_PitchSetSpring || m_RollSetSpring || m_RightSetSpring || m_UpSetSpring || m_ForwardSetSpring)
192 m_Joint = PhysicsJoint.Create6DOFSpring(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
193 Physics6DOFSpringJoint joint6DOF = m_Joint;
196 if (m_PitchSetSpring)
200 if (m_RightSetSpring)
204 if (m_ForwardSetSpring)
208 m_Joint = PhysicsJoint.Create6DOF(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
210 Physics6DOFJoint joint6DOF = m_Joint;