BGE cleanup: Removing the PHY__Vector classes and replacing them with MT_Vectors. The PHY__Vectors didn't offer anything (not even any real abstraction) and they required annoying MT_Vector <-> PHY_Vector conversions all over the place. No functional changes.

This commit is contained in:
Mitchell Stokes 2013-02-21 18:30:11 +00:00
parent 6b600d0793
commit 815e00917d
22 changed files with 56 additions and 141 deletions

@ -260,14 +260,9 @@ void BL_ConvertSensors(struct Object* blenderobject,
// this sumoObject is not deleted by a gameobj, so delete it ourself
// later (memleaks)!
float radius = blendernearsensor->dist;
PHY__Vector3 pos;
const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
pos[0] = (float)wpos[0];
pos[1] = (float)wpos[1];
pos[2] = (float)wpos[2];
pos[3] = 0.f;
bool bFindMaterial = false;
PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,pos);
PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,wpos);
//will be done in KX_TouchEventManager::RegisterSensor()
//if (isInActiveLayer)

@ -113,10 +113,8 @@ PyObject *KX_CharacterWrapper::pyattr_get_jump_count(void *self_v, const KX_PYAT
PyObject *KX_CharacterWrapper::pyattr_get_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
PHY__Vector3 vec = self->m_character->GetWalkDirection();
MT_Vector3 retval = MT_Vector3(vec[0], vec[1], vec[2]);
return PyObjectFrom(retval);
return PyObjectFrom(self->m_character->GetWalkDirection());
}
int KX_CharacterWrapper::pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
@ -128,12 +126,7 @@ int KX_CharacterWrapper::pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_
return PY_SET_ATTR_FAIL;
}
PHY__Vector3 vec;
vec[0] = dir[0];
vec[1] = dir[1];
vec[2] = dir[2];
self->m_character->SetWalkDirection(vec);
self->m_character->SetWalkDirection(dir);
return PY_SET_ATTR_SUCCESS;
}

@ -51,10 +51,10 @@ KX_RayCast::KX_RayCast(KX_IPhysicsController* ignoreController, bool faceNormal,
void KX_RayCast::reportHit(PHY_RayCastResult* result)
{
m_hitFound = true;
m_hitPoint.setValue((const float*)result->m_hitPoint);
m_hitNormal.setValue((const float*)result->m_hitNormal);
m_hitPoint = MT_Vector3(result->m_hitPoint);
m_hitNormal = MT_Vector3(result->m_hitNormal);
m_hitUVOK = result->m_hitUVOK;
m_hitUV.setValue((const float*)result->m_hitUV);
m_hitUV = MT_Vector2(result->m_hitUV);
m_hitMesh = result->m_meshObject;
m_hitPolygon = result->m_polygon;
}

@ -1490,7 +1490,7 @@ void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty,KX_Camera* cam, int
if (m_dbvt_culling)
{
// test culling through Bullet
PHY__Vector4 planes[6];
MT_Vector4 planes[6];
// get the clip planes
MT_Vector4* cplanes = cam->GetNormalizedClipPlanes();
// and convert
@ -1711,13 +1711,11 @@ void KX_Scene::SetGravity(const MT_Vector3& gravity)
MT_Vector3 KX_Scene::GetGravity()
{
PHY__Vector3 gravity;
MT_Vector3 vec;
MT_Vector3 gravity;
GetPhysicsEnvironment()->getGravity(gravity);
vec = gravity.m_vec;
return vec;
return gravity;
}
void KX_Scene::SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter)

@ -59,19 +59,12 @@ PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args)
PyVecTo(pylistPos,attachPos);
PyVecTo(pylistDir,attachDir);
PyVecTo(pylistAxleDir,attachAxle);
PHY__Vector3 aPos,aDir,aAxle;
aPos[0] = attachPos[0];
aPos[1] = attachPos[1];
aPos[2] = attachPos[2];
aDir[0] = attachDir[0];
aDir[1] = attachDir[1];
aDir[2] = attachDir[2];
aAxle[0] = -attachAxle[0];//someone reverse some conventions inside Bullet (axle winding)
aAxle[1] = -attachAxle[1];
aAxle[2] = -attachAxle[2];
//someone reverse some conventions inside Bullet (axle winding)
attachAxle = -attachAxle;
printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering);
m_vehicle->AddWheel(motionState,aPos,aDir,aAxle,suspensionRestLength,wheelRadius,hasSteering);
m_vehicle->AddWheel(motionState,attachPos,attachDir,attachAxle,suspensionRestLength,wheelRadius,hasSteering);
}
} else {

@ -7,7 +7,6 @@
#define __KX_VEHICLEWRAPPER_H__
#include "Value.h"
#include "PHY_DynamicTypes.h"
class PHY_IVehicle;
class PHY_IMotionState;

@ -55,7 +55,7 @@ void CcdGraphicController::setLocalAabb(const MT_Point3& aabbMin,const MT_Point3
SetGraphicTransform();
}
void CcdGraphicController::setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax)
void CcdGraphicController::setLocalAabb(const MT_Vector3& aabbMin,const MT_Vector3& aabbMax)
{
m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]);
m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]);

@ -42,7 +42,7 @@ public:
void setLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax);
void setLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax);
virtual void setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax);
virtual void setLocalAabb(const MT_Vector3& aabbMin,const MT_Vector3& aabbMax);
virtual void setLocalAabb(const float aabbMin[3],const float aabbMax[3]);
PHY_IMotionState* GetMotionState() { return m_motionState; }

@ -1092,7 +1092,7 @@ void CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvel
{
}
void CcdPhysicsController::getPosition(PHY__Vector3& pos) const
void CcdPhysicsController::getPosition(MT_Vector3& pos) const
{
const btTransform& xform = m_object->getWorldTransform();
pos[0] = xform.getOrigin().x();

@ -524,7 +524,7 @@ protected:
virtual void getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
virtual void setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
virtual void setPosition(float posX,float posY,float posZ);
virtual void getPosition(PHY__Vector3& pos) const;
virtual void getPosition(MT_Vector3& pos) const;
virtual void setScaling(float scaleX,float scaleY,float scaleZ);

@ -97,9 +97,9 @@ public:
virtual void AddWheel(
PHY_IMotionState* motionState,
PHY__Vector3 connectionPoint,
PHY__Vector3 downDirection,
PHY__Vector3 axleDirection,
MT_Vector3 connectionPoint,
MT_Vector3 downDirection,
MT_Vector3 axleDirection,
float suspensionRestLength,
float wheelRadius,
bool hasSteering
@ -311,20 +311,16 @@ public:
return m_controller->getJumpCount();
}
virtual void SetWalkDirection(PHY__Vector3 dir)
virtual void SetWalkDirection(const MT_Vector3& dir)
{
btVector3 vec = btVector3(dir[0], dir[1], dir[2]);
m_controller->setWalkDirection(vec);
}
virtual PHY__Vector3 GetWalkDirection()
virtual MT_Vector3 GetWalkDirection()
{
btVector3 vec = m_controller->getWalkDirection();
PHY__Vector3 retval;
retval[0] = vec[0];
retval[1] = vec[1];
retval[2] = vec[2];
return retval;
return MT_Vector3(vec[0], vec[1], vec[2]);
}
};
@ -951,7 +947,7 @@ void CcdPhysicsEnvironment::setSolverType(int solverType)
void CcdPhysicsEnvironment::getGravity(PHY__Vector3& grav)
void CcdPhysicsEnvironment::getGravity(MT_Vector3& grav)
{
const btVector3& gravity = m_dynamicsWorld->getGravity();
grav[0] = gravity.getX();
@ -1851,7 +1847,7 @@ struct DbvtCullingCallback : btDbvt::ICollide
};
static OcclusionBuffer gOcb;
bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16])
bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, MT_Vector4 *planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16])
{
if (!m_cullingTree)
return false;
@ -2362,7 +2358,7 @@ int numController = 0;
PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)
PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radius,const MT_Vector3& position)
{
CcdConstructionInfo cinfo;

@ -140,7 +140,7 @@ protected:
virtual void setDebugMode(int debugMode);
virtual void setGravity(float x,float y,float z);
virtual void getGravity(PHY__Vector3& grav);
virtual void getGravity(MT_Vector3& grav);
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
@ -190,7 +190,7 @@ protected:
btTypedConstraint* getConstraintById(int constraintId);
virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]);
virtual bool cullingTest(PHY_CullingCallback callback, void* userData, MT_Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]);
//Methods for gamelogic collision/physics callbacks
@ -200,7 +200,7 @@ protected:
virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl);
virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl);
//These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
virtual PHY_IPhysicsController* CreateSphereController(float radius,const MT_Vector3& position);
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);

@ -26,6 +26,7 @@
set(INC
.
../common
../../../../intern/moto/include
)
set(INC_SYS

@ -85,7 +85,7 @@ void DummyPhysicsEnvironment::setGravity(float x,float y,float z)
{
}
void DummyPhysicsEnvironment::getGravity(PHY__Vector3& grav)
void DummyPhysicsEnvironment::getGravity(class MT_Vector3& grav)
{
}

@ -56,7 +56,7 @@ public:
virtual float getFixedTimeStep();
virtual void setGravity(float x,float y,float z);
virtual void getGravity(PHY__Vector3& grav);
virtual void getGravity(class MT_Vector3& grav);
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
float pivotX,float pivotY,float pivotZ,
@ -80,7 +80,7 @@ public:
}
virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) { return false; }
virtual bool cullingTest(PHY_CullingCallback callback, void* userData, class MT_Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) { return false; }
//gamelogic callbacks
@ -91,7 +91,7 @@ public:
}
virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl) { return false; }
virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl) { return false;}
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
virtual PHY_IPhysicsController* CreateSphereController(float radius,const class MT_Vector3& position) {return 0;}
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
virtual void setConstraintParam(int constraintId,int param,float value,float value1)

@ -26,6 +26,7 @@
set(INC
.
../Dummy
../../../../intern/moto/include
)
set(INC_SYS

@ -20,69 +20,9 @@ subject to the following restrictions:
#ifndef __PHY_DYNAMICTYPES_H__
#define __PHY_DYNAMICTYPES_H__
#include "MT_Vector3.h"
struct KX_ClientObjectInfo;
class PHY_Shape;
struct PHY__Vector2
{
float m_vec[2];
operator const float* () const
{
return &m_vec[0];
}
operator float* ()
{
return &m_vec[0];
}
};
struct PHY__Vector3
{
float m_vec[4];
operator const float* () const
{
return &m_vec[0];
}
operator float* ()
{
return &m_vec[0];
}
};
struct PHY__Vector4
{
float m_vec[4];
PHY__Vector4() {}
void setValue(const float *value)
{
m_vec[0] = *value++;
m_vec[1] = *value++;
m_vec[2] = *value++;
m_vec[3] = *value++;
}
void setValue(const double *value)
{
m_vec[0] = (float)(*value++);
m_vec[1] = (float)(*value++);
m_vec[2] = (float)(*value++);
m_vec[3] = (float)(*value++);
}
operator const float* () const
{
return &m_vec[0];
}
operator float* ()
{
return &m_vec[0];
}
};
//typedef float PHY__Vector3[4];
enum
{
@ -97,9 +37,9 @@ enum
};
typedef struct PHY_CollData {
PHY__Vector3 m_point1; /* Point in object1 in world coordinates */
PHY__Vector3 m_point2; /* Point in object2 in world coordinates */
PHY__Vector3 m_normal; /* point2 - point1 */
MT_Vector3 m_point1; /* Point in object1 in world coordinates */
MT_Vector3 m_point2; /* Point in object2 in world coordinates */
MT_Vector3 m_normal; /* point2 - point1 */
} PHY_CollData;
@ -148,7 +88,4 @@ typedef enum PHY_ShapeType {
PHY_SHAPE_PROXY
} PHY_ShapeType;
typedef float PHY_Vector3[3];
#endif /* __PHY_DYNAMICTYPES_H__ */

@ -28,8 +28,8 @@ public:
virtual int GetJumpCount()= 0;
virtual void SetWalkDirection(PHY__Vector3 dir)=0;
virtual PHY__Vector3 GetWalkDirection()=0;
virtual void SetWalkDirection(const class MT_Vector3& dir)=0;
virtual MT_Vector3 GetWalkDirection()=0;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter")

@ -48,7 +48,7 @@ class PHY_IGraphicController : public PHY_IController
*/
virtual bool SetGraphicTransform()=0;
virtual void Activate(bool active=true)=0;
virtual void setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax)=0;
virtual void setLocalAabb(const class MT_Vector3& aabbMin,const class MT_Vector3& aabbMax)=0;
virtual void setLocalAabb(const float* aabbMin,const float* aabbMax)=0;
virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate) {return 0;}

@ -66,7 +66,7 @@ class PHY_IPhysicsController : public PHY_IController
virtual void getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal)=0;
virtual void setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)=0;
virtual void setPosition(float posX,float posY,float posZ)=0;
virtual void getPosition(PHY__Vector3& pos) const=0;
virtual void getPosition(class MT_Vector3& pos) const=0;
virtual void setScaling(float scaleX,float scaleY,float scaleZ)=0;
// physics methods
@ -100,7 +100,7 @@ class PHY_IPhysicsController : public PHY_IController
virtual float GetLinVelocityMax() const=0;
virtual void SetLinVelocityMax(float val) = 0;
PHY__Vector3 GetWorldPosition(PHY__Vector3& localpos);
class MT_Vector3 GetWorldPosition(class MT_Vector3& localpos);
#ifdef WITH_CXX_GUARDEDALLOC

@ -32,8 +32,10 @@
#ifndef __PHY_IPHYSICSENVIRONMENT_H__
#define __PHY_IPHYSICSENVIRONMENT_H__
#include <vector>
#include "PHY_DynamicTypes.h"
#include "MT_Vector2.h"
#include "MT_Vector3.h"
#include "MT_Vector4.h"
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
@ -50,13 +52,13 @@ class PHY_IPhysicsController;
struct PHY_RayCastResult
{
PHY_IPhysicsController* m_controller;
PHY__Vector3 m_hitPoint;
PHY__Vector3 m_hitNormal;
MT_Vector3 m_hitPoint;
MT_Vector3 m_hitNormal;
const RAS_MeshObject* m_meshObject; // !=NULL for mesh object (only for Bullet controllers)
int m_polygon; // index of the polygon hit by the ray,
// only if m_meshObject != NULL
int m_hitUVOK; // !=0 if UV coordinate in m_hitUV is valid
PHY__Vector2 m_hitUV; // UV coordinates of hit point
MT_Vector2 m_hitUV; // UV coordinates of hit point
};
/**
@ -144,7 +146,7 @@ class PHY_IPhysicsEnvironment
virtual void setUseEpa(bool epa) {}
virtual void setGravity(float x,float y,float z)=0;
virtual void getGravity(PHY__Vector3& grav) = 0;
virtual void getGravity(MT_Vector3& grav) = 0;
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
float pivotX,float pivotY,float pivotZ,
@ -167,7 +169,7 @@ class PHY_IPhysicsEnvironment
//culling based on physical broad phase
// the plane number must be set as follow: near, far, left, right, top, botton
// the near plane must be the first one and must always be present, it is used to get the direction of the view
virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) = 0;
virtual bool cullingTest(PHY_CullingCallback callback, void *userData, MT_Vector4* planeNormals, int planeNumber, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) = 0;
//Methods for gamelogic collision/physics callbacks
//todo:
@ -177,7 +179,7 @@ class PHY_IPhysicsEnvironment
virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl)=0;
//These two methods are *solely* used to create controllers for sensor! Don't use for anything else
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
virtual PHY_IPhysicsController* CreateSphereController(float radius,const MT_Vector3& position) =0;
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
virtual void setConstraintParam(int constraintId,int param,float value,float value1) = 0;

@ -22,9 +22,9 @@ public:
virtual void AddWheel(
PHY_IMotionState* motionState,
PHY__Vector3 connectionPoint,
PHY__Vector3 downDirection,
PHY__Vector3 axleDirection,
MT_Vector3 connectionPoint,
MT_Vector3 downDirection,
MT_Vector3 axleDirection,
float suspensionRestLength,
float wheelRadius,
bool hasSteering