1 [
EntityEditorProps(
category:
"GameBase/Joints", description:
"Physics joint - Cone Twist", sizeMin:
"-0.05 -0.05 -0.05", sizeMax:
"0.05 0.05 0.05", color:
"0 0 255 255")]
13 [
Attribute(
"0", UIWidgets.Slider,
"Yaw swing range in degrees",
"0 180 0.01")]
15 [
Attribute(
"0", UIWidgets.Slider,
"Pitch swing range in degrees",
"0 180 0.01")]
16 float m_SwingSpanPitch;
17 [
Attribute(
"0", UIWidgets.Slider,
"Twist range in degrees (if below zero, can twist freely)",
"-1 180 0.01")]
19 [
Attribute(
"0.5", UIWidgets.Slider,
"Percentage of limits where movement is free, above this the limit is gradually enforced",
"0 1 0.001")]
21 [
Attribute(
"0.3", UIWidgets.Slider,
"The strength with which the constraint resists limit violations",
"0 1 0.001")]
23 [
Attribute(
"1", UIWidgets.Slider,
"The lower the values, the less the constraint will fight velocities which violate the angular limits",
"0 1 0.001")]
24 float m_RelaxationFactor;
30 override void DebugDisplay()
36 vector axisVec = mat[2];
37 vector axisVec2 = mat[1];
38 vector axisVec3 = mat[0];
40 int coneSubDiv = Math.Ceil(Math.AbsFloat(Math.Sin((m_SwingSpanYaw + m_SwingSpanPitch) / 2 * Math.DEG2RAD)) * 50);
43 sliceSubDiv = Math.Ceil(m_TwistSpan / 360 * 16);
45 CreateCone(pos, axisVec, m_SwingSpanYaw, m_SwingSpanPitch, 0.05, ARGB(255, 0, 255, 0), coneSubDiv, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
47 CreateCircleSlice(pos, axisVec, -axisVec3, -1, 1, 0.075, ARGB(255, 0, 255, 255), sliceSubDiv, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
49 CreateCircleSlice(pos, axisVec, -axisVec3, 0, m_TwistSpan, 0.075, ARGB(255, 0, 255, 255), sliceSubDiv, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
50 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec * -0.05 + pos, axisVec * 0.05 + pos);
51 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec2 * -0.05 + pos, axisVec2 * 0.05 + pos);
52 Shape.Create(ShapeType.LINE, ARGB(255, 0, 255, 0), ShapeFlags.ONCE|ShapeFlags.NOZBUFFER, axisVec3 * -0.05 + pos, axisVec3 * 0.05 + pos);
56 override void RotateJoint(inout vector jointMat[4])
58 vector oldJointMat[3], rotMat[3];
59 oldJointMat[0] = jointMat[0];
60 oldJointMat[1] = jointMat[1];
61 oldJointMat[2] = jointMat[2];
62 Math3D.AnglesToMatrix(
"-90 0 0", rotMat);
63 Math3D.MatrixMultiply3(oldJointMat, rotMat, jointMat);
67 override void CreateJoint(IEntity parent, IEntity child, vector jointMat1[4], vector jointMat2[4])
70 m_Joint = PhysicsJoint.CreateConeTwist(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
71 PhysicsConeTwistJoint jointConeTwist = m_Joint;
72 jointConeTwist.SetLimits(m_SwingSpanPitch * Math.DEG2RAD, m_SwingSpanYaw * Math.DEG2RAD, m_TwistSpan * Math.DEG2RAD, m_Softness, m_BiasFactor, m_RelaxationFactor);