Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_JointHingeEntity.c
Go to the documentation of this file.
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")]
3{
4 const int AXIS_YAW = 1;
5 const int AXIS_PITCH = 0;
6 const int AXIS_ROLL = 2;
7};
8
9//------------------------------------------------------------------------------------------------
13//------------------------------------------------------------------------------------------------
14class SCR_JointHingeEntity: SCR_JointBaseEntity
15{
16 [Attribute("0", UIWidgets.ComboBox, "Which axis to use for the hinge", "", { ParamEnum("Yaw", "1"), ParamEnum("Pitch", "0"), ParamEnum("Roll", "2")} )]
17 int m_Axis;
18 [Attribute("0", UIWidgets.CheckBox, "Whether may rotate freely (ignores limits)")]
19 bool m_RotateIsFree;
20 [Attribute("0", UIWidgets.Slider, "Minimum rotate range in degrees (if minimum is higher than maximum, hinge can rotate freely)", "-180 0 0.01")]
21 float m_RotateMin;
22 [Attribute("0", UIWidgets.Slider, "Maximum rotate range in degrees (if minimum is higher than maximum, hinge can rotate freely)", "0 180 0.01")]
23 float m_RotateMax;
24 [Attribute("0.5", UIWidgets.Slider, "Percentage of limits where movement is free, above this the limit is gradually enforced", "0 1 0.001")]
25 float m_Softness;
26 [Attribute("0.3", UIWidgets.Slider, "The strength with which the constraint resists limit violations", "0 1 0.001")]
27 float m_BiasFactor;
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;
30
31 //------------------------------------------------------------------------------------------------
32
33
34 //------------------------------------------------------------------------------------------------
35 // NOTE: dSCR_JointHingeEntitySetAxis seems to reset the joint to zero orientations!!!
36 /*void SetAxis(int axis)
37 {
38 Axis = axis;
39
40 if (m_Joint)
41 {
42 vector axisVec;
43 if (Axis == SCR_JointHingeEntityClass.AXIS_PITCH) axisVec = "1 0 0";
44 if (Axis == SCR_JointHingeEntityClass.AXIS_YAW) axisVec = "0 1 0";
45 if (Axis == SCR_JointHingeEntityClass.AXIS_ROLL) axisVec = "0 0 1";
46 //dSCR_JointHingeEntitySetAxis(m_Joint, axisVec);
47 }
48 }*/
49
50 //------------------------------------------------------------------------------------------------
51 override void DebugDisplay()
52 {
53 vector mat[4];
54 GetTransform(mat);
55 vector pos = mat[3];
56
57 int axis2 = m_Axis + 1;
58 if (axis2 > 2)
59 axis2 -= 2;
60 int axis3 = axis2 + 1;
61 if (axis3 > 2)
62 axis3 -= 2;
63 vector axisVec = mat[m_Axis];
64 vector axisVec2 = mat[axis2];
65 vector axisVec3 = mat[axis3];
66 float addVisAng = 0;
67 if (m_Axis == SCR_JointHingeEntityClass.AXIS_PITCH) addVisAng = 180; // Pitch
68 if (m_Axis == SCR_JointHingeEntityClass.AXIS_YAW) addVisAng = 90; // Yaw
69 if (m_Axis == SCR_JointHingeEntityClass.AXIS_ROLL) addVisAng = 90; // Roll
70
71 int sliceSubDiv = 16;
72 if (m_RotateMax > m_RotateMin)
73 sliceSubDiv = Math.Ceil(Math.AbsFloat(-m_RotateMax - -m_RotateMin) / 360 * 16);
74
75 CreateCircle(pos, axisVec, 0.05, ARGB(255, 0, 255, 0), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
76 if (m_RotateIsFree)
77 CreateCircle(pos, axisVec, 0.075, ARGB(255, 0, 255, 255), 16, ShapeFlags.ONCE|ShapeFlags.NOZBUFFER);
78 else
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);
83 }
84
85 //------------------------------------------------------------------------------------------------
86 override void RotateJoint(inout vector jointMat[4])
87 {
88 if (m_Axis == SCR_JointHingeEntityClass.AXIS_ROLL) // Roll
89 return;
90
91 vector oldJointMat[3], rotMat[3];
92 oldJointMat[0] = jointMat[0];
93 oldJointMat[1] = jointMat[1];
94 oldJointMat[2] = jointMat[2];
95 if (m_Axis == SCR_JointHingeEntityClass.AXIS_PITCH) // Pitch
96 Math3D.AnglesToMatrix("90 0 0", rotMat);
97 else if (m_Axis == SCR_JointHingeEntityClass.AXIS_YAW) // Yaw
98 Math3D.AnglesToMatrix("0 90 0", rotMat);
99 Math3D.MatrixMultiply3(oldJointMat, rotMat, jointMat);
100 }
101
102 //------------------------------------------------------------------------------------------------
103 override void CreateJoint(IEntity parent, IEntity child, vector jointMat1[4], vector jointMat2[4])
104 {
105 // Create the joint
106 m_Joint = PhysicsJoint.CreateHinge2(parent, child, jointMat1, jointMat2, m_CollisionBlocker, -1);
107 PhysicsHingeJoint jointHinge = m_Joint;
108 if (m_RotateIsFree)
109 jointHinge.SetLimits(1, -1, m_Softness, m_BiasFactor, m_RelaxationFactor);
110 else
111 jointHinge.SetLimits(-m_RotateMax * Math.DEG2RAD, -m_RotateMin * Math.DEG2RAD, m_Softness, m_BiasFactor, m_RelaxationFactor);
112 }
113};
Shape CreateCircleSlice(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
Shape CreateCircle(vector pos, vector aroundDir, float radius, int color, int subdivisions, ShapeFlags flags)
Definition DebugShapes.c:91
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external void GetTransform(out vector mat[])
Definition Math.c:13
Instance of created debug visualizer.
Definition Shape.c:14
ShapeType
Definition ShapeType.c:13
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
proto int ARGB(int a, int r, int g, int b)