@@ -52,18 +52,15 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
52
52
int rotDampTime,
53
53
float minBound,
54
54
float maxBound,
55
- float refDir[ 3 ] ,
55
+ const mt::vec3& refDir,
56
56
int locrotxyz,
57
57
int time,
58
58
int option,
59
59
char *property) :
60
60
SCA_IActuator(gameobj, KX_ACT_CONSTRAINT),
61
- m_refDirVector (refDir),
61
+ m_refDirection (refDir),
62
62
m_currentTime(0 )
63
63
{
64
- m_refDirection[0 ] = refDir[0 ];
65
- m_refDirection[1 ] = refDir[1 ];
66
- m_refDirection[2 ] = refDir[2 ];
67
64
m_posDampTime = posDampTime;
68
65
m_rotDampTime = rotDampTime;
69
66
m_locrot = locrotxyz;
@@ -84,17 +81,14 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
84
81
case KX_ACT_CONSTRAINT_ORIY:
85
82
case KX_ACT_CONSTRAINT_ORIZ:
86
83
{
87
- float len = m_refDirVector .Length ();
84
+ float len = m_refDirection .Length ();
88
85
if (mt::FuzzyZero (len)) {
89
86
// missing a valid direction
90
87
CM_LogicBrickWarning (this , " there is no valid reference direction!" );
91
88
m_locrot = KX_ACT_CONSTRAINT_NODEF;
92
89
}
93
90
else {
94
- m_refDirection[0 ] /= len;
95
- m_refDirection[1 ] /= len;
96
- m_refDirection[2 ] /= len;
97
- m_refDirVector /= len;
91
+ m_refDirection /= len;
98
92
}
99
93
m_minimumBound = cosf (minBound);
100
94
m_maximumBound = cosf (maxBound);
@@ -218,7 +212,7 @@ bool KX_ConstraintActuator::Update(double curtime)
218
212
if ((m_maximumBound < (1 .0f - FLT_EPSILON)) || (m_minimumBound < (1 .0f - FLT_EPSILON))) {
219
213
// reference direction needs to be evaluated
220
214
// 1. get the cosine between current direction and target
221
- cosangle = mt::dot (direction, m_refDirVector );
215
+ cosangle = mt::dot (direction, m_refDirection );
222
216
if (cosangle >= (m_maximumBound - FLT_EPSILON) && cosangle <= (m_minimumBound + FLT_EPSILON)) {
223
217
// no change to do
224
218
result = true ;
@@ -227,31 +221,31 @@ bool KX_ConstraintActuator::Update(double curtime)
227
221
// 2. define a new reference direction
228
222
// compute local axis with reference direction as X and
229
223
// Y in direction X refDirection plane
230
- mt::vec3 zaxis = mt::cross (m_refDirVector , direction);
224
+ mt::vec3 zaxis = mt::cross (m_refDirection , direction);
231
225
if (mt::FuzzyZero (zaxis.LengthSquared ())) {
232
226
// direction and refDirection are identical,
233
227
// choose any other direction to define plane
234
228
if (direction[0 ] < 0 .9999f ) {
235
- zaxis = mt::cross (m_refDirVector , mt::axisX3);
229
+ zaxis = mt::cross (m_refDirection , mt::axisX3);
236
230
}
237
231
else {
238
- zaxis = mt::cross (m_refDirVector , mt::axisY3);
232
+ zaxis = mt::cross (m_refDirection , mt::axisY3);
239
233
}
240
234
}
241
- mt::vec3 yaxis = mt::cross (zaxis, m_refDirVector );
235
+ mt::vec3 yaxis = mt::cross (zaxis, m_refDirection );
242
236
yaxis.Normalize ();
243
237
if (cosangle > m_minimumBound) {
244
238
// angle is too close to reference direction,
245
239
// choose a new reference that is exactly at minimum angle
246
- refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis;
240
+ refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis;
247
241
}
248
242
else {
249
243
// angle is too large, choose new reference direction at maximum angle
250
- refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis;
244
+ refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis;
251
245
}
252
246
}
253
247
else {
254
- refDirection = m_refDirVector ;
248
+ refDirection = m_refDirection ;
255
249
}
256
250
// apply damping on the direction
257
251
direction = filter * direction + (1 .0f - filter) * refDirection;
@@ -504,7 +498,7 @@ bool KX_ConstraintActuator::Update(double curtime)
504
498
// Fh force is stored in m_maximum
505
499
float springForce = springExtent * m_maximumBound;
506
500
// damping is stored in m_refDirection [0] = damping, [1] = rot damping
507
- float springDamp = relativeVelocityRay * m_refDirVector [0 ];
501
+ float springDamp = relativeVelocityRay * m_refDirection [0 ];
508
502
mt::vec3 newVelocity = spc->GetLinearVelocity () - (springForce + springDamp) * direction;
509
503
if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
510
504
newVelocity += (springForce + springDamp) * (newnormal - mt::dot (newnormal, direction) * direction);
@@ -515,7 +509,7 @@ bool KX_ConstraintActuator::Update(double curtime)
515
509
mt::vec3 angVelocity = spc->GetAngularVelocity ();
516
510
// remove component that is parallel to normal
517
511
angVelocity -= mt::dot (angVelocity, newnormal) * newnormal;
518
- mt::vec3 angDamp = angVelocity * (mt::FuzzyZero (m_refDirVector [1 ]) ? m_refDirVector [0 ] : m_refDirVector [1 ]);
512
+ mt::vec3 angDamp = angVelocity * (mt::FuzzyZero (m_refDirection [1 ]) ? m_refDirection [0 ] : m_refDirection [1 ]);
519
513
spc->SetAngularVelocity (spc->GetAngularVelocity () + (angSpring - angDamp), false );
520
514
}
521
515
}
@@ -630,7 +624,7 @@ int KX_ConstraintActuator::pyattr_check_direction(EXP_PyObjectPlus *self_v, cons
630
624
PyErr_SetString (PyExc_ValueError, " actuator.direction = vec: KX_ConstraintActuator, invalid direction" );
631
625
return 1 ;
632
626
}
633
- act->m_refDirVector = dir / len;
627
+ act->m_refDirection = dir / len;
634
628
return 0 ;
635
629
}
636
630
0 commit comments