Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp604
1 files changed, 146 insertions, 458 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index f2a554c6b2a..989cdabd491 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -51,7 +51,6 @@ typedef unsigned long uint_ptr;
#include "KX_GameObject.h"
#include "RAS_MeshObject.h"
#include "KX_MeshProxy.h"
-#include "KX_PolyProxy.h"
#include <stdio.h> // printf
#include "SG_Controller.h"
#include "KX_IPhysicsController.h"
@@ -65,8 +64,6 @@ typedef unsigned long uint_ptr;
#include "SCA_IActuator.h"
#include "SCA_ISensor.h"
-#include "PyObjectPlus.h" /* python stuff */
-
// This file defines relationships between parents and children
// in the game engine.
@@ -81,15 +78,12 @@ KX_GameObject::KX_GameObject(
m_bDyna(false),
m_layer(0),
m_pBlenderObject(NULL),
- m_pBlenderGroupObject(NULL),
m_bSuspendDynamics(false),
m_bUseObjectColor(false),
m_bIsNegativeScaling(false),
m_bVisible(true),
- m_bCulled(true),
m_pPhysicsController1(NULL),
m_pPhysicsEnvironment(NULL),
- m_xray(false),
m_pHitObject(NULL),
m_isDeformable(false)
{
@@ -105,11 +99,8 @@ KX_GameObject::KX_GameObject(
};
-
KX_GameObject::~KX_GameObject()
{
- RemoveMeshes();
-
// is this delete somewhere ?
//if (m_sumoObj)
// delete m_sumoObj;
@@ -171,6 +162,7 @@ STR_String KX_GameObject::GetName()
void KX_GameObject::SetName(STR_String name)
{
m_name = name;
+
}; // Set the name of the value
@@ -214,8 +206,7 @@ KX_GameObject* KX_GameObject::GetParent()
void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj)
{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (obj && GetSGNode() && obj->GetSGNode() && GetSGNode()->GetSGParent() != obj->GetSGNode())
+ if (obj && GetSGNode()->GetSGParent() != obj->GetSGNode())
{
// Make sure the objects have some scale
MT_Vector3 scale1 = NodeGetWorldScaling();
@@ -236,12 +227,11 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj)
m_pPhysicsController1->SuspendDynamics(true);
}
// Set us to our new scale, position, and orientation
- scale2[0] = 1.0/scale2[0];
- scale2[1] = 1.0/scale2[1];
- scale2[2] = 1.0/scale2[2];
- scale1 = scale1 * scale2;
+ scale1[0] = scale1[0]/scale2[0];
+ scale1[1] = scale1[1]/scale2[1];
+ scale1[2] = scale1[2]/scale2[2];
MT_Matrix3x3 invori = obj->NodeGetWorldOrientation().inverse();
- MT_Vector3 newpos = invori*(NodeGetWorldPosition()-obj->NodeGetWorldPosition())*scale2;
+ MT_Vector3 newpos = invori*(NodeGetWorldPosition()-obj->NodeGetWorldPosition())*scale1;
NodeSetLocalScale(scale1);
NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2]));
@@ -257,8 +247,7 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj)
void KX_GameObject::RemoveParent(KX_Scene *scene)
{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (GetSGNode() && GetSGNode()->GetSGParent())
+ if (GetSGNode()->GetSGParent())
{
// Set us to the right spot
GetSGNode()->SetLocalScale(GetSGNode()->GetWorldScaling());
@@ -294,11 +283,11 @@ void KX_GameObject::ProcessReplica(KX_GameObject* replica)
CValue* KX_GameObject::GetReplica()
{
KX_GameObject* replica = new KX_GameObject(*this);
-
+
// this will copy properties and so on...
CValue::AddDataToReplica(replica);
ProcessReplica(replica);
-
+
return replica;
}
@@ -364,47 +353,24 @@ double* KX_GameObject::GetOpenGLMatrix()
return fl;
}
-void KX_GameObject::AddMeshUser()
-{
- for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->AddMeshUser(this);
-
- UpdateBuckets(false);
-}
-static void UpdateBuckets_recursive(SG_Node* node)
-{
- NodeList& children = node->GetSGChildren();
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->UpdateBuckets(0);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- UpdateBuckets_recursive(childnode);
- }
-}
-
-void KX_GameObject::UpdateBuckets( bool recursive )
+void KX_GameObject::Bucketize()
{
double* fl = GetOpenGLMatrix();
for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->UpdateBuckets(this, fl, m_bUseObjectColor, m_objectColor, m_bVisible, m_bCulled);
-
- if (recursive) {
- UpdateBuckets_recursive(m_pSGNode);
- }
+ m_meshes[i]->Bucketize(fl, this, m_bUseObjectColor, m_objectColor);
}
+
+
void KX_GameObject::RemoveMeshes()
{
+ double* fl = GetOpenGLMatrix();
+
for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->RemoveFromBuckets(this);
+ m_meshes[i]->RemoveFromBuckets(fl, this);
//note: meshes can be shared, and are deleted by KX_BlenderSceneConverter
@@ -487,14 +453,13 @@ KX_GameObject::UpdateMaterialData(
)
{
int mesh = 0;
- if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) {
- list<RAS_MeshMaterial>::iterator mit = m_meshes[mesh]->GetFirstMaterial();
+ if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) {
+ RAS_MaterialBucket::Set::iterator mit = m_meshes[mesh]->GetFirstMaterial();
for(; mit != m_meshes[mesh]->GetLastMaterial(); ++mit)
{
- RAS_IPolyMaterial* poly = mit->m_bucket->GetPolyMaterial();
-
- if(poly->GetFlag() & RAS_BLENDERMAT )
+ RAS_IPolyMaterial* poly = (*mit)->GetPolyMaterial();
+ if(poly->GetFlag() & RAS_BLENDERMAT)
{
KX_BlenderMaterial *m = static_cast<KX_BlenderMaterial*>(poly);
@@ -502,7 +467,8 @@ KX_GameObject::UpdateMaterialData(
{
m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha);
// if mesh has only one material attached to it then use original hack with no need to edit vertices (better performance)
- SetObjectColor(rgba);
+ if(!(poly->GetFlag() & RAS_BLENDERGLSL))
+ SetObjectColor(rgba);
}
else
{
@@ -528,52 +494,14 @@ KX_GameObject::GetVisible(
return m_bVisible;
}
-static void setVisible_recursive(SG_Node* node, bool v)
-{
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->SetVisible(v, 0);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- setVisible_recursive(childnode, v);
- }
-}
-
-
void
KX_GameObject::SetVisible(
- bool v,
- bool recursive
+ bool v
)
{
m_bVisible = v;
- if (recursive)
- setVisible_recursive(m_pSGNode, v);
}
-bool
-KX_GameObject::GetCulled(
- void
- )
-{
- return m_bCulled;
-}
-
-void
-KX_GameObject::SetCulled(
- bool c
- )
-{
- m_bCulled = c;
-}
-
-
void
KX_GameObject::SetLayer(
int l
@@ -590,16 +518,51 @@ KX_GameObject::GetLayer(
return m_layer;
}
-void KX_GameObject::addLinearVelocity(const MT_Vector3& lin_vel,bool local)
+// used by Python, and the actuatorshould _not_ be misused by the
+// scene!
+void
+KX_GameObject::MarkVisible(
+ bool visible
+ )
{
- if (m_pPhysicsController1)
+ /* If explicit visibility settings are used, this is
+ * determined on this level. Maybe change this to mesh level
+ * later on? */
+
+ double* fl = GetOpenGLMatrixPtr()->getPointer();
+ for (size_t i=0;i<m_meshes.size();i++)
{
- MT_Vector3 lv = local ? NodeGetWorldOrientation() * lin_vel : lin_vel;
- m_pPhysicsController1->SetLinearVelocity(lv + m_pPhysicsController1->GetLinearVelocity(), 0);
+ m_meshes[i]->MarkVisible(fl,this,visible,m_bUseObjectColor,m_objectColor);
}
}
+// Always use the flag?
+void
+KX_GameObject::MarkVisible(
+ void
+ )
+{
+ double* fl = GetOpenGLMatrixPtr()->getPointer();
+ for (size_t i=0;i<m_meshes.size();i++)
+ {
+ m_meshes[i]->MarkVisible(fl,
+ this,
+ m_bVisible,
+ m_bUseObjectColor,
+ m_objectColor
+ );
+ }
+}
+
+
+void KX_GameObject::addLinearVelocity(const MT_Vector3& lin_vel,bool local)
+{
+ if (m_pPhysicsController1)
+ m_pPhysicsController1->SetLinearVelocity(lin_vel + m_pPhysicsController1->GetLinearVelocity(),local);
+}
+
+
void KX_GameObject::setLinearVelocity(const MT_Vector3& lin_vel,bool local)
{
@@ -615,7 +578,6 @@ void KX_GameObject::setAngularVelocity(const MT_Vector3& ang_vel,bool local)
m_pPhysicsController1->SetAngularVelocity(ang_vel,local);
}
-
void KX_GameObject::ResolveCombinedVelocities(
const MT_Vector3 & lin_vel,
const MT_Vector3 & ang_vel,
@@ -645,10 +607,6 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
MT_Vector3 vect,ori,z,x,y;
MT_Scalar len;
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
vect = dir;
len = vect.length();
if (MT_fuzzyZero(len))
@@ -779,24 +737,13 @@ MT_Vector3 KX_GameObject::GetAngularVelocity(bool local)
return velocity;
}
-MT_Vector3 KX_GameObject::GetVelocity(const MT_Point3& point)
-{
- if (m_pPhysicsController1)
- {
- return m_pPhysicsController1->GetVelocity(point);
- }
- return MT_Vector3(0.0,0.0,0.0);
-}
+
// scenegraph node stuff
void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans)
{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController1 && !GetSGNode()->GetSGParent())
+ if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent()))
{
// don't update physic controller if the object is a child:
// 1) the transformation will not be right
@@ -805,39 +752,35 @@ void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans)
m_pPhysicsController1->setPosition(trans);
}
- GetSGNode()->SetLocalPosition(trans);
+ if (GetSGNode())
+ GetSGNode()->SetLocalPosition(trans);
}
void KX_GameObject::NodeSetLocalOrientation(const MT_Matrix3x3& rot)
{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController1 && !GetSGNode()->GetSGParent())
+ if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent()))
{
// see note above
m_pPhysicsController1->setOrientation(rot);
}
- GetSGNode()->SetLocalOrientation(rot);
+ if (GetSGNode())
+ GetSGNode()->SetLocalOrientation(rot);
}
void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale)
{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController1 && !GetSGNode()->GetSGParent())
+ if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent()))
{
// see note above
m_pPhysicsController1->setScaling(scale);
}
- GetSGNode()->SetLocalScale(scale);
+
+ if (GetSGNode())
+ GetSGNode()->SetLocalScale(scale);
}
@@ -845,17 +788,7 @@ void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale)
void KX_GameObject::NodeSetRelativeScale(const MT_Vector3& scale)
{
if (GetSGNode())
- {
GetSGNode()->RelativeScale(scale);
- if (m_pPhysicsController1 && (!GetSGNode()->GetSGParent()))
- {
- // see note above
- // we can use the local scale: it's the same thing for a root object
- // and the world scale is not yet updated
- MT_Vector3 newscale = GetSGNode()->GetLocalScale();
- m_pPhysicsController1->setScaling(newscale);
- }
- }
}
void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans)
@@ -895,13 +828,6 @@ void KX_GameObject::NodeUpdateGS(double time,bool bInitiator)
const MT_Matrix3x3& KX_GameObject::NodeGetWorldOrientation() const
{
- static MT_Matrix3x3 defaultOrientation = MT_Matrix3x3( 1.0, 0.0, 0.0,
- 0.0, 1.0, 0.0,
- 0.0, 0.0, 1.0);
-
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return defaultOrientation;
return GetSGNode()->GetWorldOrientation();
}
@@ -909,12 +835,6 @@ const MT_Matrix3x3& KX_GameObject::NodeGetWorldOrientation() const
const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const
{
- static MT_Vector3 defaultScaling = MT_Vector3(1.0, 1.0, 1.0);
-
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return defaultScaling;
-
return GetSGNode()->GetWorldScaling();
}
@@ -922,12 +842,6 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const
const MT_Point3& KX_GameObject::NodeGetWorldPosition() const
{
- static MT_Point3 defaultPosition = MT_Point3(0.0, 0.0, 0.0);
-
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return defaultPosition;
-
return GetSGNode()->GetWorldPosition();
}
@@ -969,22 +883,15 @@ void KX_GameObject::Suspend()
PyMethodDef KX_GameObject::Methods[] = {
{"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
{"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
- {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, METH_O},
- {"applyForce", (PyCFunction) KX_GameObject::sPyApplyForce, METH_VARARGS},
- {"applyTorque", (PyCFunction) KX_GameObject::sPyApplyTorque, METH_VARARGS},
- {"applyRotation", (PyCFunction) KX_GameObject::sPyApplyRotation, METH_VARARGS},
- {"applyMovement", (PyCFunction) KX_GameObject::sPyApplyMovement, METH_VARARGS},
{"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
{"setLinearVelocity", (PyCFunction) KX_GameObject::sPySetLinearVelocity, METH_VARARGS},
- {"getAngularVelocity", (PyCFunction) KX_GameObject::sPyGetAngularVelocity, METH_VARARGS},
- {"setAngularVelocity", (PyCFunction) KX_GameObject::sPySetAngularVelocity, METH_VARARGS},
{"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS},
{"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS},
{"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_NOARGS},
{"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_NOARGS},
{"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_O},
{"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS},
- {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
+ {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_O},
{"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_NOARGS},
{"setState",(PyCFunction) KX_GameObject::sPySetState, METH_O},
{"alignAxisToVect",(PyCFunction) KX_GameObject::sPyAlignAxisToVect, METH_VARARGS},
@@ -1003,7 +910,6 @@ PyMethodDef KX_GameObject::Methods[] = {
{"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
{"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
- {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O},
{"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS},
KX_PYMETHODTABLE(KX_GameObject, rayCastTo),
KX_PYMETHODTABLE(KX_GameObject, rayCast),
@@ -1030,35 +936,13 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args,
}
*/
-PyObject* KX_GameObject::PyReplaceMesh(PyObject* self, PyObject* value)
-{
- KX_Scene *scene = KX_GetActiveScene();
- char* meshname;
- void* mesh_pt;
-
- meshname = PyString_AsString(value);
- if (meshname==NULL) {
- PyErr_SetString(PyExc_ValueError, "Expected a mesh name");
- return NULL;
- }
- mesh_pt = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname));
-
- if (mesh_pt==NULL) {
- PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist");
- return NULL;
- }
- scene->ReplaceMesh(this, (class RAS_MeshObject*)mesh_pt);
-
- Py_RETURN_NONE;
-}
-
PyObject* KX_GameObject::PyEndObject(PyObject* self)
{
- KX_Scene *scene = KX_GetActiveScene();
+ KX_Scene *scene = PHY_GetActiveScene();
scene->DelayedRemoveObject(this);
- Py_RETURN_NONE;
+ return Py_None;
}
@@ -1148,23 +1032,18 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr)
int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr method
{
- if (attr == "mass") {
- PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only");
+ if (attr == "mass")
return 1;
- }
- if (attr == "parent") {
- PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()");
+ if (attr == "parent")
return 1;
- }
if (PyInt_Check(value))
{
int val = PyInt_AsLong(value);
if (attr == "visible")
{
- SetVisible(val != 0, false);
- UpdateBuckets(false);
+ SetVisible(val != 0);
return 0;
}
}
@@ -1223,7 +1102,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr
}
return 1;
}
- PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence");
+
return 1;
}
@@ -1266,67 +1145,10 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr
return SCA_IObject::_setattr(attr, value);
}
-PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args)
-{
- int local = 0;
- PyObject* pyvect;
-
- if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
- MT_Vector3 force;
- if (PyVecTo(pyvect, force)) {
- ApplyForce(force, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject* KX_GameObject::PyApplyTorque(PyObject* self, PyObject* args)
-{
- int local = 0;
- PyObject* pyvect;
- if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
- MT_Vector3 torque;
- if (PyVecTo(pyvect, torque)) {
- ApplyTorque(torque, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject* KX_GameObject::PyApplyRotation(PyObject* self, PyObject* args)
-{
- int local = 0;
- PyObject* pyvect;
-
- if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
- MT_Vector3 rotation;
- if (PyVecTo(pyvect, rotation)) {
- ApplyRotation(rotation, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject* KX_GameObject::PyApplyMovement(PyObject* self, PyObject* args)
-{
- int local = 0;
- PyObject* pyvect;
-
- if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
- MT_Vector3 movement;
- if (PyVecTo(pyvect, movement)) {
- ApplyMovement(movement, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
// only can get the velocity if we have a physics object connected to us...
int local = 0;
@@ -1340,7 +1162,9 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args)
}
}
-PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
int local = 0;
PyObject* pyvect;
@@ -1355,43 +1179,17 @@ PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self, PyObject* args)
return NULL;
}
-PyObject* KX_GameObject::PyGetAngularVelocity(PyObject* self, PyObject* args)
-{
- // only can get the velocity if we have a physics object connected to us...
- int local = 0;
- if (PyArg_ParseTuple(args,"|i",&local))
- {
- return PyObjectFrom(GetAngularVelocity((local!=0)));
- }
- else
- {
- return NULL;
- }
-}
-
-PyObject* KX_GameObject::PySetAngularVelocity(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* value)
{
- int local = 0;
- PyObject* pyvect;
+ int visible = PyInt_AsLong(value);
- if (PyArg_ParseTuple(args,"O|i",&pyvect,&local)) {
- MT_Vector3 velocity;
- if (PyVecTo(pyvect, velocity)) {
- setAngularVelocity(velocity, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args)
-{
- int visible, recursive = 0;
- if (!PyArg_ParseTuple(args,"i|i",&visible, &recursive))
+ if (visible==-1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "expected 0 or 1");
return NULL;
+ }
- SetVisible(visible ? true:false, recursive ? true:false);
- UpdateBuckets(recursive ? true:false);
+ MarkVisible(visible!=0);
+ m_bVisible = (visible!=0);
Py_RETURN_NONE;
}
@@ -1430,7 +1228,9 @@ PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value)
-PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PyGetVelocity(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
// only can get the velocity if we have a physics object connected to us...
MT_Vector3 velocity(0.0,0.0,0.0);
@@ -1511,7 +1311,7 @@ PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value)
// The object we want to set as parent
CValue *m_ob = (CValue*)value;
KX_GameObject *obj = ((KX_GameObject*)m_ob);
- KX_Scene *scene = KX_GetActiveScene();
+ KX_Scene *scene = PHY_GetActiveScene();
this->SetParent(scene, obj);
@@ -1520,7 +1320,7 @@ PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value)
PyObject* KX_GameObject::PyRemoveParent(PyObject* self)
{
- KX_Scene *scene = KX_GetActiveScene();
+ KX_Scene *scene = PHY_GetActiveScene();
this->RemoveParent(scene);
Py_RETURN_NONE;
}
@@ -1562,7 +1362,9 @@ PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self)
return list;
}
-PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PyGetMesh(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
int mesh = 0;
@@ -1602,7 +1404,9 @@ PyObject* KX_GameObject::PySetCollisionMargin(PyObject* self, PyObject* value)
-PyObject* KX_GameObject::PyApplyImpulse(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PyApplyImpulse(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
PyObject* pyattach;
PyObject* pyimpulse;
@@ -1673,7 +1477,9 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value)
return NULL;
}
-PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, PyObject* args)
+PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
{
PyObject* pyvect;
int axis = 2; //z axis is the default
@@ -1718,19 +1524,6 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* value)
return NULL;
}
-PyObject* KX_GameObject::PySetWorldPosition(PyObject* self, PyObject* value)
-{
- MT_Point3 pos;
- if (PyVecTo(value, pos))
- {
- NodeSetWorldPosition(pos);
- NodeUpdateGS(0.f,true);
- Py_RETURN_NONE;
- }
-
- return NULL;
-}
-
PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self)
{
KX_IPhysicsController* ctrl = GetPhysicsController();
@@ -1758,9 +1551,9 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo,
PyErr_Clear();
PyObject *pyother;
- KX_GameObject *other;
- if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false))
+ if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
{
+ KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
}
@@ -1781,12 +1574,11 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo,
if (!PyVecArgTo(args, toPoint))
{
PyErr_Clear();
-
- KX_GameObject *other;
- if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false))
+ if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
{
+ KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
toPoint = other->NodeGetWorldPosition();
- } else
+ }else
{
PyErr_SetString(PyExc_TypeError, "Expected a 3D Vector or GameObject type");
return NULL;
@@ -1816,45 +1608,25 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo,
return returnValue;
}
-bool KX_GameObject::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data)
+bool KX_GameObject::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
{
- KX_GameObject* hitKXObj = client->m_gameobject;
-
- // if X-ray option is selected, the unwnted objects were not tested, so get here only with true hit
- // if not, all objects were tested and the front one may not be the correct one.
- if (m_xray || m_testPropName.Length() == 0 || hitKXObj->GetProperty(m_testPropName) != NULL)
- {
- m_pHitObject = hitKXObj;
- return true;
- }
- // return true to stop RayCast::RayTest from looping, the above test was decisive
- // We would want to loop only if we want to get more than one hit point
- return true;
-}
-/* this function is used to pre-filter the object before casting the ray on them.
- This is useful for "X-Ray" option when we want to see "through" unwanted object.
- */
-bool KX_GameObject::NeedRayCast(KX_ClientObjectInfo* client)
-{
KX_GameObject* hitKXObj = client->m_gameobject;
if (client->m_type > KX_ClientObjectInfo::ACTOR)
{
- // Unknown type of object, skip it.
- // Should not occur as the sensor objects are filtered in RayTest()
- printf("Invalid client type %d found in ray casting\n", client->m_type);
+ // false hit
return false;
}
-
- // if X-Ray option is selected, skip object that don't match the criteria as we see through them
- // if not, test all objects because we don't know yet which one will be on front
- if (!m_xray || m_testPropName.Length() == 0 || hitKXObj->GetProperty(m_testPropName) != NULL)
+
+ if (m_testPropName.Length() == 0 || hitKXObj->GetProperty(m_testPropName) != NULL)
{
+ m_pHitObject = hitKXObj;
return true;
}
- // skip the object
+
return false;
+
}
KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
@@ -1876,15 +1648,12 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
{
KX_GameObject *other;
PyErr_Clear();
-
- if (ConvertPythonToGameObject(pyarg, &other, false))
- {
- toPoint = other->NodeGetWorldPosition();
- } else
- {
+ if (!PyType_IsSubtype(pyarg->ob_type, &KX_GameObject::Type)) {
PyErr_SetString(PyExc_TypeError, "the first argument to rayCastTo must be a vector or a KX_GameObject");
return NULL;
}
+ other = static_cast<KX_GameObject*>(pyarg);
+ toPoint = other->NodeGetWorldPosition();
}
MT_Point3 fromPoint = NodeGetWorldPosition();
if (dist != 0.0f)
@@ -1894,6 +1663,8 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
toPoint = fromPoint + (dist) * toDir;
}
+ MT_Point3 resultPoint;
+ MT_Vector3 resultNormal;
PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment();
KX_IPhysicsController *spc = GetPhysicsController();
KX_GameObject *parent = GetParent();
@@ -1907,8 +1678,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
m_testPropName = propName;
else
m_testPropName.SetLength(0);
- KX_RayCast::Callback<KX_GameObject> callback(this,spc);
- KX_RayCast::RayTest(pe, fromPoint, toPoint, callback);
+ KX_RayCast::RayTest(spc, pe, fromPoint, toPoint, resultPoint, resultNormal, KX_RayCast::Callback<KX_GameObject>(this));
if (m_pHitObject)
{
@@ -1919,24 +1689,13 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
}
KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
- "rayCast(to,from,dist,prop,face,xray,poly): cast a ray and return 3-tuple (object,hit,normal) or 4-tuple (object,hit,normal,polygon) of contact point with object within dist that matches prop.\n"
- " If no hit, return (None,None,None) or (None,None,None,None).\n"
-" to = 3-tuple or object reference for destination of ray (if object, use center of object)\n"
+ "rayCast(to,from,dist,prop): cast a ray and return tuple (object,hit,normal) of contact point with object within dist that matches prop or (None,None,None) tuple if no hit\n"
+" prop = property name that object must have; can be omitted => detect any object\n"
+" dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to to\n"
" from = 3-tuple or object reference for origin of ray (if object, use center of object)\n"
" Can be None or omitted => start from self object center\n"
-" dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to to\n"
-" prop = property name that object must have; can be omitted => detect any object\n"
-" face = normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin\n"
-" xray = X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object\n"
-" poly = polygon option: 1=>return value is a 4-tuple and the 4th element is a KX_PolyProxy object\n"
-" which can be None if hit object has no mesh or if there is no hit\n"
-" If 0 or omitted, return value is a 3-tuple\n"
-"Note: The object on which you call this method matters: the ray will ignore it.\n"
-" prop and xray option interact as follow:\n"
-" prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray\n"
-" prop off, xray on : idem\n"
-" prop on, xray off: return closest hit if it matches prop, no hit otherwise\n"
-" prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray\n")
+" to = 3-tuple or object reference for destination of ray (if object, use center of object)\n"
+"Note: the object on which you call this method matters: the ray will ignore it if it goes through it\n")
{
MT_Point3 toPoint;
MT_Point3 fromPoint;
@@ -1945,24 +1704,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
float dist = 0.0f;
char *propName = NULL;
KX_GameObject *other;
- int face=0, xray=0, poly=0;
- if (!PyArg_ParseTuple(args,"O|Ofsiii", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly)) {
+ if (!PyArg_ParseTuple(args,"O|Ofs", &pyto, &pyfrom, &dist, &propName)) {
return NULL; // Python sets a simple error
}
if (!PyVecTo(pyto, toPoint))
{
PyErr_Clear();
-
- if (ConvertPythonToGameObject(pyto, &other, false))
- {
- toPoint = other->NodeGetWorldPosition();
- } else
- {
+ if (!PyType_IsSubtype(pyto->ob_type, &KX_GameObject::Type)) {
PyErr_SetString(PyExc_TypeError, "the first argument to rayCast must be a vector or a KX_GameObject");
return NULL;
}
+ other = static_cast<KX_GameObject*>(pyto);
+ toPoint = other->NodeGetWorldPosition();
}
if (!pyfrom || pyfrom == Py_None)
{
@@ -1971,15 +1726,12 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
else if (!PyVecTo(pyfrom, fromPoint))
{
PyErr_Clear();
-
- if (ConvertPythonToGameObject(pyfrom, &other, false))
- {
- fromPoint = other->NodeGetWorldPosition();
- } else
- {
+ if (!PyType_IsSubtype(pyfrom->ob_type, &KX_GameObject::Type)) {
PyErr_SetString(PyExc_TypeError, "the second optional argument to rayCast must be a vector or a KX_GameObject");
return NULL;
}
+ other = static_cast<KX_GameObject*>(pyfrom);
+ fromPoint = other->NodeGetWorldPosition();
}
if (dist != 0.0f) {
@@ -1993,6 +1745,8 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
}
+ MT_Point3 resultPoint;
+ MT_Vector3 resultNormal;
PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment();
KX_IPhysicsController *spc = GetPhysicsController();
KX_GameObject *parent = GetParent();
@@ -2006,41 +1760,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
m_testPropName = propName;
else
m_testPropName.SetLength(0);
- m_xray = xray;
- // to get the hit results
- KX_RayCast::Callback<KX_GameObject> callback(this,spc,NULL,face);
- KX_RayCast::RayTest(pe, fromPoint, toPoint, callback);
+ KX_RayCast::RayTest(spc, pe, fromPoint, toPoint, resultPoint, resultNormal, KX_RayCast::Callback<KX_GameObject>(this));
- if (m_pHitObject)
+ if (m_pHitObject)
{
- PyObject* returnValue = (poly) ? PyTuple_New(4) : PyTuple_New(3);
+ PyObject* returnValue = PyTuple_New(3);
if (returnValue) { // unlikely this would ever fail, if it does python sets an error
PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef());
- PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(callback.m_hitPoint));
- PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(callback.m_hitNormal));
- if (poly)
- {
- if (callback.m_hitMesh)
- {
- // if this field is set, then we can trust that m_hitPolygon is a valid polygon
- RAS_Polygon* poly = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon);
- KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, poly);
- PyTuple_SET_ITEM(returnValue, 3, polyproxy);
- }
- else
- {
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(returnValue, 3, Py_None);
- }
- }
+ PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(resultPoint));
+ PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(resultNormal));
}
return returnValue;
}
- // no hit
- if (poly)
- return Py_BuildValue("OOOO", Py_None, Py_None, Py_None, Py_None);
- else
- return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
+ return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
+ //Py_RETURN_NONE;
}
/* ---------------------------------------------------------------------
@@ -2065,48 +1798,3 @@ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter)
}
}
-bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok)
-{
- if (value==NULL) {
- PyErr_SetString(PyExc_TypeError, "Error in ConvertPythonToGameObject, python pointer NULL, should never happen");
- *object = NULL;
- return false;
- }
-
- if (value==Py_None) {
- *object = NULL;
-
- if (py_none_ok) {
- return true;
- } else {
- PyErr_SetString(PyExc_TypeError, "Expected KX_GameObject or a string for a name of a KX_GameObject, None is invalid");
- return false;
- }
- }
-
- if (PyString_Check(value)) {
- *object = (KX_GameObject *)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( PyString_AsString(value) ));
-
- if (*object) {
- return true;
- } else {
- PyErr_SetString(PyExc_ValueError, "Requested name did not match any KX_GameObject");
- return false;
- }
- }
-
- if (PyObject_TypeCheck(value, &KX_GameObject::Type)) {
- *object = static_cast<KX_GameObject*>(value);
- return true;
- }
-
- *object = NULL;
-
- if (py_none_ok) {
- PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject, a string or None");
- } else {
- PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject or a string");
- }
-
- return false;
-}