1 [
EntityEditorProps(
category:
"GameBase/Joints", description:
"Physics joint - Hinge", sizeMin:
"-0.05 -0.05 -0.05", sizeMax:
"0.05 0.05 0.05", color:
"0 0 255 255")]
4 const int AXIS_YAW = 1;
5 const int AXIS_PITCH = 0;
6 const int AXIS_ROLL = 2;
16 [
Attribute(
"0", UIWidgets.ComboBox,
"Which axis to use for the hinge",
"", { ParamEnum(
"Yaw",
"1"), ParamEnum(
"Pitch",
"0"), ParamEnum(
"Roll",
"2")} )]
18 [
Attribute(
"0", UIWidgets.CheckBox,
"Whether may rotate freely (ignores limits)")]
20 [
Attribute(
"0", UIWidgets.Slider,
"Minimum rotate range in degrees (if minimum is higher than maximum, hinge can rotate freely)",
"-180 0 0.01")]
22 [
Attribute(
"0", UIWidgets.Slider,
"Maximum rotate range in degrees (if minimum is higher than maximum, hinge can rotate freely)",
"0 180 0.01")]
24 [
Attribute(
"0.5", UIWidgets.Slider,
"Percentage of limits where movement is free, above this the limit is gradually enforced",
"0 1 0.001")]
26 [
Attribute(
"0.3", UIWidgets.Slider,
"The strength with which the constraint resists limit violations",
"0 1 0.001")]
28 [
Attribute(
"1", UIWidgets.Slider,
"The lower the values, the less the constraint will fight velocities which violate the angular limits",
"0 1 0.001")]
29 float m_RelaxationFactor;
51 override void DebugDisplay()
57 int axis2 = m_Axis + 1;
60 int axis3 = axis2 + 1;
63 vector axisVec = mat[m_Axis];
64 vector axisVec2 = mat[axis2];
65 vector axisVec3 = mat[axis3];
72 if (m_RotateMax > m_RotateMin)
73 sliceSubDiv = Math.Ceil(Math.AbsFloat(-m_RotateMax - -m_RotateMin) / 360 * 16);
75 CreateCircle(pos, axisVec, 0.05, ARGB(255, 0, 255, 0), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
77 CreateCircle(pos, axisVec, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
79 CreateCircleSlice(pos, axisVec, axisVec2, m_RotateMin + addVisAng, m_RotateMax + addVisAng, 0.075, ARGB(255, 0, 255, 255), sliceSubDiv, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
80 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * -0.1 + pos, axisVec * 0.1 + pos);
81 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * -0.05 + pos, axisVec2 * 0.05 + pos);
82 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * -0.05 + pos, axisVec3 * 0.05 + pos);
86 override void RotateJoint(inout vector jointMat[4])
91 vector oldJointMat[3], rotMat[3];
92 oldJointMat[0] = jointMat[0];
93 oldJointMat[1] = jointMat[1];
94 oldJointMat[2] = jointMat[2];
96 Math3D.AnglesToMatrix(
"90 0 0", rotMat);
98 Math3D.AnglesToMatrix(
"0 90 0", rotMat);
99 Math3D.MatrixMultiply3(oldJointMat, rotMat, jointMat);
103 override void CreateJoint(IEntity parent, IEntity child, vector jointMat1[4], vector jointMat2[4])
106 m_Joint = PhysicsJoint.CreateHinge2(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
107 PhysicsHingeJoint jointHinge = m_Joint;
109 jointHinge.SetLimits(1, -1, m_Softness, m_BiasFactor, m_RelaxationFactor);
111 jointHinge.SetLimits(-m_RotateMax * Math.DEG2RAD, -m_RotateMin * Math.DEG2RAD, m_Softness, m_BiasFactor, m_RelaxationFactor);