Skip to content

Commit 1e658ce

Browse files
committed
UPBGE: Use mathfu types in KX_ConstraintActuator.
1 parent 179edd8 commit 1e658ce

File tree

4 files changed

+28
-36
lines changed

4 files changed

+28
-36
lines changed

source/gameengine/Converter/BL_ConvertActuators.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,16 @@ void BL_ConvertActuators(const char *maggiename,
687687
}
688688
}
689689
KX_ConstraintActuator *tmpconact = new KX_ConstraintActuator(
690-
gameobj,
691-
conact->damp,
692-
conact->rotdamp,
693-
min,
694-
max,
695-
conact->maxrot,
696-
locrot,
697-
conact->time,
698-
conact->flag,
699-
prop);
690+
gameobj,
691+
conact->damp,
692+
conact->rotdamp,
693+
min,
694+
max,
695+
mt::vec3(conact->maxrot),
696+
locrot,
697+
conact->time,
698+
conact->flag,
699+
prop);
700700
baseact = tmpconact;
701701
break;
702702
}

source/gameengine/Ketsji/KX_ConstraintActuator.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,15 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
5252
int rotDampTime,
5353
float minBound,
5454
float maxBound,
55-
float refDir[3],
55+
const mt::vec3& refDir,
5656
int locrotxyz,
5757
int time,
5858
int option,
5959
char *property) :
6060
SCA_IActuator(gameobj, KX_ACT_CONSTRAINT),
61-
m_refDirVector(refDir),
61+
m_refDirection(refDir),
6262
m_currentTime(0)
6363
{
64-
m_refDirection[0] = refDir[0];
65-
m_refDirection[1] = refDir[1];
66-
m_refDirection[2] = refDir[2];
6764
m_posDampTime = posDampTime;
6865
m_rotDampTime = rotDampTime;
6966
m_locrot = locrotxyz;
@@ -84,17 +81,14 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
8481
case KX_ACT_CONSTRAINT_ORIY:
8582
case KX_ACT_CONSTRAINT_ORIZ:
8683
{
87-
float len = m_refDirVector.Length();
84+
float len = m_refDirection.Length();
8885
if (mt::FuzzyZero(len)) {
8986
// missing a valid direction
9087
CM_LogicBrickWarning(this, "there is no valid reference direction!");
9188
m_locrot = KX_ACT_CONSTRAINT_NODEF;
9289
}
9390
else {
94-
m_refDirection[0] /= len;
95-
m_refDirection[1] /= len;
96-
m_refDirection[2] /= len;
97-
m_refDirVector /= len;
91+
m_refDirection /= len;
9892
}
9993
m_minimumBound = cosf(minBound);
10094
m_maximumBound = cosf(maxBound);
@@ -218,7 +212,7 @@ bool KX_ConstraintActuator::Update(double curtime)
218212
if ((m_maximumBound < (1.0f - FLT_EPSILON)) || (m_minimumBound < (1.0f - FLT_EPSILON))) {
219213
// reference direction needs to be evaluated
220214
// 1. get the cosine between current direction and target
221-
cosangle = mt::dot(direction, m_refDirVector);
215+
cosangle = mt::dot(direction, m_refDirection);
222216
if (cosangle >= (m_maximumBound - FLT_EPSILON) && cosangle <= (m_minimumBound + FLT_EPSILON)) {
223217
// no change to do
224218
result = true;
@@ -227,31 +221,31 @@ bool KX_ConstraintActuator::Update(double curtime)
227221
// 2. define a new reference direction
228222
// compute local axis with reference direction as X and
229223
// Y in direction X refDirection plane
230-
mt::vec3 zaxis = mt::cross(m_refDirVector, direction);
224+
mt::vec3 zaxis = mt::cross(m_refDirection, direction);
231225
if (mt::FuzzyZero(zaxis.LengthSquared())) {
232226
// direction and refDirection are identical,
233227
// choose any other direction to define plane
234228
if (direction[0] < 0.9999f) {
235-
zaxis = mt::cross(m_refDirVector, mt::axisX3);
229+
zaxis = mt::cross(m_refDirection, mt::axisX3);
236230
}
237231
else {
238-
zaxis = mt::cross(m_refDirVector, mt::axisY3);
232+
zaxis = mt::cross(m_refDirection, mt::axisY3);
239233
}
240234
}
241-
mt::vec3 yaxis = mt::cross(zaxis, m_refDirVector);
235+
mt::vec3 yaxis = mt::cross(zaxis, m_refDirection);
242236
yaxis.Normalize();
243237
if (cosangle > m_minimumBound) {
244238
// angle is too close to reference direction,
245239
// 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;
247241
}
248242
else {
249243
// 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;
251245
}
252246
}
253247
else {
254-
refDirection = m_refDirVector;
248+
refDirection = m_refDirection;
255249
}
256250
// apply damping on the direction
257251
direction = filter * direction + (1.0f - filter) * refDirection;
@@ -504,7 +498,7 @@ bool KX_ConstraintActuator::Update(double curtime)
504498
// Fh force is stored in m_maximum
505499
float springForce = springExtent * m_maximumBound;
506500
// 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];
508502
mt::vec3 newVelocity = spc->GetLinearVelocity() - (springForce + springDamp) * direction;
509503
if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
510504
newVelocity += (springForce + springDamp) * (newnormal - mt::dot(newnormal, direction) * direction);
@@ -515,7 +509,7 @@ bool KX_ConstraintActuator::Update(double curtime)
515509
mt::vec3 angVelocity = spc->GetAngularVelocity();
516510
// remove component that is parallel to normal
517511
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]);
519513
spc->SetAngularVelocity(spc->GetAngularVelocity() + (angSpring - angDamp), false);
520514
}
521515
}
@@ -630,7 +624,7 @@ int KX_ConstraintActuator::pyattr_check_direction(EXP_PyObjectPlus *self_v, cons
630624
PyErr_SetString(PyExc_ValueError, "actuator.direction = vec: KX_ConstraintActuator, invalid direction");
631625
return 1;
632626
}
633-
act->m_refDirVector = dir / len;
627+
act->m_refDirection = dir / len;
634628
return 0;
635629
}
636630

source/gameengine/Ketsji/KX_ConstraintActuator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class KX_ConstraintActuator : public SCA_IActuator, public mt::SimdClassAllocato
5757
// sinus of maximum angle
5858
float m_maximumSine;
5959
// reference direction
60-
float m_refDirection[3];
61-
mt::vec3 m_refDirVector; // same as m_refDirection
60+
mt::vec3 m_refDirection;
6261
// locrotxyz choice (pick one): only one choice allowed at a time!
6362
int m_locrot;
6463
// active time of actuator
@@ -117,7 +116,7 @@ class KX_ConstraintActuator : public SCA_IActuator, public mt::SimdClassAllocato
117116
int rotDampTime,
118117
float min,
119118
float max,
120-
float refDir[3],
119+
const mt::vec3& refDir,
121120
int locrot,
122121
int time,
123122
int option,

source/gameengine/Ketsji/KX_MouseActuator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ bool KX_MouseActuator::Update()
7878

7979
if (bNegativeEvent) {
8080
// Reset previous position on negative events.
81-
m_oldposition[0] = -1.0f;
82-
m_oldposition[1] = -1.0f;
81+
m_oldPosition = mt::vec2(-1.0f, -1.0f);
8382
return false;
8483
}
8584

0 commit comments

Comments
 (0)