Skip to content

Commit

Permalink
UPBGE: Use mathfu types in KX_RaySensor.
Browse files Browse the repository at this point in the history
  • Loading branch information
panzergame committed Aug 5, 2018
1 parent 8a844d9 commit 11e3f98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
27 changes: 8 additions & 19 deletions source/gameengine/Ketsji/KX_RaySensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,8 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void
if (bFound) {
m_rayHit = true;
m_hitObject = hitKXObj;
m_hitPosition[0] = result->m_hitPoint[0];
m_hitPosition[1] = result->m_hitPoint[1];
m_hitPosition[2] = result->m_hitPoint[2];

m_hitNormal[0] = result->m_hitNormal[0];
m_hitNormal[1] = result->m_hitNormal[1];
m_hitNormal[2] = result->m_hitNormal[2];

m_hitPosition = result->m_hitPoint;
m_hitNormal = result->m_hitNormal;
m_hitMaterial = hitMaterial;
}
// no multi-hit search yet
Expand Down Expand Up @@ -197,13 +191,8 @@ bool KX_RaySensor::Evaluate()
bool reset = m_reset && m_level;
m_rayHit = false;
m_hitObject = nullptr;
m_hitPosition[0] = 0;
m_hitPosition[1] = 0;
m_hitPosition[2] = 0;

m_hitNormal[0] = 1;
m_hitNormal[1] = 0;
m_hitNormal[2] = 0;
m_hitPosition = mt::zero3;
m_hitNormal = mt::axisX3;

KX_GameObject *obj = (KX_GameObject *)GetParent();
mt::vec3 frompoint = obj->NodeGetWorldPosition();
Expand Down Expand Up @@ -244,7 +233,7 @@ bool KX_RaySensor::Evaluate()
}
}
todir.Normalize();
todir.Pack(m_rayDirection);
m_rayDirection = todir;

mt::vec3 topoint = frompoint + (m_distance) * todir;
PHY_IPhysicsEnvironment *pe = m_scene->GetPhysicsEnvironment();
Expand Down Expand Up @@ -341,9 +330,9 @@ PyAttributeDef KX_RaySensor::Attributes[] = {
EXP_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_RaySensor, m_propertyname),
EXP_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RaySensor, m_axis),
EXP_PYATTRIBUTE_INT_RW("mask", 1, (1 << OB_MAX_COL_MASKS) - 1, true, KX_RaySensor, m_mask),
EXP_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
EXP_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
EXP_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
EXP_PYATTRIBUTE_VECTOR_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
EXP_PYATTRIBUTE_VECTOR_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
EXP_PYATTRIBUTE_VECTOR_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
EXP_PYATTRIBUTE_STRING_RO("hitMaterial", KX_RaySensor, m_hitMaterial),
EXP_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject),
EXP_PYATTRIBUTE_NULL //Sentinel
Expand Down
6 changes: 3 additions & 3 deletions source/gameengine/Ketsji/KX_RaySensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class KX_RaySensor : public SCA_ISensor
int m_axis;
int m_mask;
bool m_rayHit;
float m_hitPosition[3];
mt::vec3 m_hitPosition;
SCA_IObject* m_hitObject;
float m_hitNormal[3];
float m_rayDirection[3];
mt::vec3 m_hitNormal;
mt::vec3 m_rayDirection;
std::string m_hitMaterial;

public:
Expand Down

0 comments on commit 11e3f98

Please sign in to comment.