~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_GameObject.cpp

  • Committer: Dietrich Bollmann
  • Date: 2009-05-31 06:18:40 UTC
  • mfrom: (184.1.850)
  • Revision ID: diresu@web.de-20090531061840-r8gn72wodu0vvhok
Command Port Blender 2.49

Update to state of blender repository from 2009-05-29 revision 20508.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: KX_GameObject.cpp 20130 2009-05-10 20:53:58Z ben2610 $
 
2
 * $Id: KX_GameObject.cpp 20500 2009-05-29 13:37:51Z ben2610 $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
49
49
#include "RAS_IPolygonMaterial.h"
50
50
#include "KX_BlenderMaterial.h"
51
51
#include "KX_GameObject.h"
 
52
#include "KX_Camera.h" // only for their ::Type
 
53
#include "KX_Light.h"  // only for their ::Type
52
54
#include "RAS_MeshObject.h"
53
55
#include "KX_MeshProxy.h"
54
56
#include "KX_PolyProxy.h"
224
226
        
225
227
}
226
228
 
227
 
void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj)
 
229
void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj, bool addToCompound, bool ghost)
228
230
{
229
231
        // check on valid node in case a python controller holds a reference to a deleted object
230
232
        if (obj && GetSGNode() && obj->GetSGNode() && GetSGNode()->GetSGParent() != obj->GetSGNode())
245
247
 
246
248
                if (m_pPhysicsController1) 
247
249
                {
248
 
                        m_pPhysicsController1->SuspendDynamics(true);
 
250
                        m_pPhysicsController1->SuspendDynamics(ghost);
249
251
                }
250
252
                // Set us to our new scale, position, and orientation
251
253
                scale2[0] = 1.0/scale2[0];
266
268
                        Release();
267
269
                // if the new parent is a compound object, add this object shape to the compound shape.
268
270
                // step 0: verify this object has physical controller
269
 
                if (m_pPhysicsController1)
 
271
                if (m_pPhysicsController1 && addToCompound)
270
272
                {
271
273
                        // step 1: find the top parent (not necessarily obj)
272
274
                        KX_GameObject* rootobj = (KX_GameObject*)obj->GetSGNode()->GetRootSGParent()->GetSGClientObject();
312
314
                                rootobj->m_pPhysicsController1->RemoveCompoundChild(m_pPhysicsController1);
313
315
                        }
314
316
                        m_pPhysicsController1->RestoreDynamics();
 
317
                        if (m_pPhysicsController1->IsDyna() && rootobj->m_pPhysicsController1)
 
318
                        {
 
319
                                // dynamic object should remember the velocity they had while being parented
 
320
                                MT_Point3 childPoint = GetSGNode()->GetWorldPosition();
 
321
                                MT_Point3 rootPoint = rootobj->GetSGNode()->GetWorldPosition();
 
322
                                MT_Point3 relPoint;
 
323
                                relPoint = (childPoint-rootPoint);
 
324
                                MT_Vector3 linVel = rootobj->m_pPhysicsController1->GetVelocity(relPoint);
 
325
                                MT_Vector3 angVel = rootobj->m_pPhysicsController1->GetAngularVelocity();
 
326
                                m_pPhysicsController1->SetLinearVelocity(linVel, false);
 
327
                                m_pPhysicsController1->SetAngularVelocity(angVel, false);
 
328
                        }
315
329
                }
316
330
                // graphically, the object hasn't change place, no need to update m_pGraphicController
317
331
        }
332
346
                
333
347
}
334
348
 
335
 
static void setGraphicController_recursive(SG_Node* node, bool v)
 
349
static void setGraphicController_recursive(SG_Node* node)
336
350
{
337
351
        NodeList& children = node->GetSGChildren();
338
352
 
341
355
                SG_Node* childnode = (*childit);
342
356
                KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
343
357
                if (clientgameobj != NULL) // This is a GameObject
344
 
                        clientgameobj->ActivateGraphicController(v, false);
 
358
                        clientgameobj->ActivateGraphicController(false);
345
359
                
346
360
                // if the childobj is NULL then this may be an inverse parent link
347
361
                // so a non recursive search should still look down this node.
348
 
                setGraphicController_recursive(childnode, v);
 
362
                setGraphicController_recursive(childnode);
349
363
        }
350
364
}
351
365
 
352
366
 
353
 
void KX_GameObject::ActivateGraphicController(bool active, bool recurse)
 
367
void KX_GameObject::ActivateGraphicController(bool recurse)
354
368
{
355
369
        if (m_pGraphicController)
356
370
        {
357
 
                m_pGraphicController->Activate(active);
 
371
                m_pGraphicController->Activate(m_bVisible);
358
372
        }
359
373
        if (recurse)
360
374
        {
361
 
                setGraphicController_recursive(GetSGNode(), active);
 
375
                setGraphicController_recursive(GetSGNode());
362
376
        }
363
377
}
364
378
 
446
460
{
447
461
        for (size_t i=0;i<m_meshes.size();i++)
448
462
        {
449
 
                m_meshes[i]->AddMeshUser(this, &m_meshSlots);
 
463
                m_meshes[i]->AddMeshUser(this, &m_meshSlots, GetDeformer());
450
464
        }
451
465
        // set the part of the mesh slot that never change
452
466
        double* fl = GetOpenGLMatrixPtr()->getPointer();
453
 
        RAS_Deformer *deformer = GetDeformer();
454
467
 
455
468
        SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
 
469
        RAS_MeshSlot* ms;
456
470
        for(mit.begin(); !mit.end(); ++mit)
457
471
        {
458
472
                (*mit)->m_OpenGLMatrix = fl;
459
 
                (*mit)->SetDeformer(deformer);
460
473
        }
461
474
        UpdateBuckets(false);
462
475
}
538
551
        ((KX_GameObject*)gameobj)->UpdateTransform();
539
552
}
540
553
 
 
554
void KX_GameObject::SynchronizeTransform()
 
555
{
 
556
        // only used for sensor object, do full synchronization as bullet doesn't do it
 
557
        if (m_pPhysicsController1)
 
558
                m_pPhysicsController1->SetTransform();
 
559
        if (m_pGraphicController)
 
560
                m_pGraphicController->SetGraphicTransform();
 
561
}
 
562
 
 
563
void KX_GameObject::SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene)
 
564
{
 
565
        ((KX_GameObject*)gameobj)->SynchronizeTransform();
 
566
}
 
567
 
541
568
 
542
569
void KX_GameObject::SetDebugColor(unsigned int bgra)
543
570
{
1146
1173
        {"disableRigidBody", (PyCFunction)KX_GameObject::sPyDisableRigidBody,METH_NOARGS},
1147
1174
        {"applyImpulse", (PyCFunction) KX_GameObject::sPyApplyImpulse, METH_VARARGS},
1148
1175
        {"setCollisionMargin", (PyCFunction) KX_GameObject::sPySetCollisionMargin, METH_O},
1149
 
        {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O},
 
1176
        {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_VARARGS},
1150
1177
        {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
1151
1178
        {"setOcclusion",(PyCFunction) KX_GameObject::sPySetOcclusion, METH_VARARGS},
1152
1179
        {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
1162
1189
        KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo),
1163
1190
        KX_PYMETHODTABLE_O(KX_GameObject, getVectTo),
1164
1191
        KX_PYMETHODTABLE(KX_GameObject, sendMessage),
1165
 
 
 
1192
        
 
1193
        // dict style access for props
 
1194
        {"has_key",(PyCFunction) KX_GameObject::sPyhas_key, METH_O},
 
1195
        {"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS},
 
1196
        
1166
1197
        // deprecated
1167
1198
        {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
1168
1199
        {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
1197
1228
        KX_PYATTRIBUTE_RW_FUNCTION("worldOrientation",KX_GameObject,pyattr_get_worldOrientation,pyattr_set_worldOrientation),
1198
1229
        KX_PYATTRIBUTE_RW_FUNCTION("localPosition",     KX_GameObject, pyattr_get_localPosition,        pyattr_set_localPosition),
1199
1230
        KX_PYATTRIBUTE_RW_FUNCTION("worldPosition",     KX_GameObject, pyattr_get_worldPosition,    pyattr_set_worldPosition),
1200
 
        KX_PYATTRIBUTE_RW_FUNCTION("localScaling",      KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling),
1201
 
        KX_PYATTRIBUTE_RO_FUNCTION("worldScaling",      KX_GameObject, pyattr_get_worldScaling),
 
1231
        KX_PYATTRIBUTE_RW_FUNCTION("localScale",        KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling),
 
1232
        KX_PYATTRIBUTE_RO_FUNCTION("worldScale",        KX_GameObject, pyattr_get_worldScaling),
 
1233
        KX_PYATTRIBUTE_RO_FUNCTION("children",  KX_GameObject, pyattr_get_children),
 
1234
        KX_PYATTRIBUTE_RO_FUNCTION("childrenRecursive", KX_GameObject, pyattr_get_children_recursive),
1202
1235
        KX_PYATTRIBUTE_RO_FUNCTION("attrDict",  KX_GameObject, pyattr_get_attrDict),
1203
1236
        
1204
1237
        /* Experemental, dont rely on these yet */
1312
1345
                
1313
1346
                if (del==0) {
1314
1347
                        if(attr_str)    PyErr_Format(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key \"%s\" could not be set", attr_str);
1315
 
                        else                    PyErr_SetString(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key could not be set");
 
1348
                        else                    PyErr_SetString(PyExc_KeyError, "del gameOb[key]: KX_GameObject, key could not be deleted");
1316
1349
                        return -1;
1317
1350
                }
1318
1351
                else if (self->m_attr_dict) {
1452
1485
        MT_Scalar val = PyFloat_AsDouble(value);
1453
1486
        if (val < 0.0f) { /* also accounts for non float */
1454
1487
                PyErr_SetString(PyExc_AttributeError, "gameOb.mass = float: KX_GameObject, expected a float zero or above");
1455
 
                return 1;
 
1488
                return PY_SET_ATTR_FAIL;
1456
1489
        }
1457
1490
 
1458
1491
        if (spc)
1459
1492
                spc->SetMass(val);
1460
1493
 
1461
 
        return 0;
 
1494
        return PY_SET_ATTR_SUCCESS;
1462
1495
}
1463
1496
 
1464
1497
PyObject* KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1475
1508
        MT_Scalar val = PyFloat_AsDouble(value);
1476
1509
        if (val < 0.0f) { /* also accounts for non float */
1477
1510
                PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMin = float: KX_GameObject, expected a float zero or above");
1478
 
                return 1;
 
1511
                return PY_SET_ATTR_FAIL;
1479
1512
        }
1480
1513
 
1481
1514
        if (spc)
1482
1515
                spc->SetLinVelocityMin(val);
1483
1516
 
1484
 
        return 0;
 
1517
        return PY_SET_ATTR_SUCCESS;
1485
1518
}
1486
1519
 
1487
1520
PyObject* KX_GameObject::pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1498
1531
        MT_Scalar val = PyFloat_AsDouble(value);
1499
1532
        if (val < 0.0f) { /* also accounts for non float */
1500
1533
                PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMax = float: KX_GameObject, expected a float zero or above");
1501
 
                return 1;
 
1534
                return PY_SET_ATTR_FAIL;
1502
1535
        }
1503
1536
 
1504
1537
        if (spc)
1505
1538
                spc->SetLinVelocityMax(val);
1506
1539
 
1507
 
        return 0;
 
1540
        return PY_SET_ATTR_SUCCESS;
1508
1541
}
1509
1542
 
1510
1543
 
1520
1553
        int param = PyObject_IsTrue( value );
1521
1554
        if (param == -1) {
1522
1555
                PyErr_SetString(PyExc_AttributeError, "gameOb.visible = bool: KX_GameObject, expected True or False");
1523
 
                return 1;
 
1556
                return PY_SET_ATTR_FAIL;
1524
1557
        }
1525
1558
 
1526
1559
        self->SetVisible(param, false);
1527
1560
        self->UpdateBuckets(false);
1528
 
        return 0;
 
1561
        return PY_SET_ATTR_SUCCESS;
1529
1562
}
1530
1563
 
1531
1564
PyObject* KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1539
1572
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
1540
1573
        MT_Point3 pos;
1541
1574
        if (!PyVecTo(value, pos))
1542
 
                return 1;
 
1575
                return PY_SET_ATTR_FAIL;
1543
1576
        
1544
1577
        self->NodeSetWorldPosition(pos);
1545
1578
        self->NodeUpdateGS(0.f);
1546
 
        return 0;
 
1579
        return PY_SET_ATTR_SUCCESS;
1547
1580
}
1548
1581
 
1549
1582
PyObject* KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1560
1593
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
1561
1594
        MT_Point3 pos;
1562
1595
        if (!PyVecTo(value, pos))
1563
 
                return 1;
 
1596
                return PY_SET_ATTR_FAIL;
1564
1597
        
1565
1598
        self->NodeSetLocalPosition(pos);
1566
1599
        self->NodeUpdateGS(0.f);
1567
 
        return 0;
 
1600
        return PY_SET_ATTR_SUCCESS;
1568
1601
}
1569
1602
 
1570
1603
PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1590
1623
        /* if value is not a sequence PyOrientationTo makes an error */
1591
1624
        MT_Matrix3x3 rot;
1592
1625
        if (!PyOrientationTo(value, rot, "gameOb.worldOrientation = sequence: KX_GameObject, "))
1593
 
                return NULL;
 
1626
                return PY_SET_ATTR_FAIL;
1594
1627
 
1595
1628
        if (self->GetSGNode() && self->GetSGNode()->GetSGParent()) {
1596
1629
                self->NodeSetLocalOrientation(self->GetSGNode()->GetSGParent()->GetWorldOrientation().inverse()*rot);
1600
1633
        }
1601
1634
        
1602
1635
        self->NodeUpdateGS(0.f);
1603
 
        return 0;
 
1636
        return PY_SET_ATTR_SUCCESS;
1604
1637
}
1605
1638
 
1606
1639
PyObject* KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1619
1652
        /* if value is not a sequence PyOrientationTo makes an error */
1620
1653
        MT_Matrix3x3 rot;
1621
1654
        if (!PyOrientationTo(value, rot, "gameOb.localOrientation = sequence: KX_GameObject, "))
1622
 
                return NULL;
 
1655
                return PY_SET_ATTR_FAIL;
1623
1656
 
1624
1657
        self->NodeSetLocalOrientation(rot);
1625
1658
        self->NodeUpdateGS(0.f);
1626
 
        return 0;
 
1659
        return PY_SET_ATTR_SUCCESS;
1627
1660
}
1628
1661
 
1629
1662
PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1646
1679
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
1647
1680
        MT_Vector3 scale;
1648
1681
        if (!PyVecTo(value, scale))
1649
 
                return 1;
 
1682
                return PY_SET_ATTR_FAIL;
1650
1683
 
1651
1684
        self->NodeSetLocalScale(scale);
1652
1685
        self->NodeUpdateGS(0.f);
1653
 
        return 0;
 
1686
        return PY_SET_ATTR_SUCCESS;
1654
1687
}
1655
1688
 
1656
1689
PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1672
1705
                SG_Node* sg_parent= self->GetSGNode()->GetSGParent();
1673
1706
                if (val < 0.0f) { /* also accounts for non float */
1674
1707
                        PyErr_SetString(PyExc_AttributeError, "gameOb.timeOffset = float: KX_GameObject, expected a float zero or above");
1675
 
                        return 1;
 
1708
                        return PY_SET_ATTR_FAIL;
1676
1709
                }
1677
1710
                if (sg_parent && sg_parent->IsSlowParent())
1678
1711
                        static_cast<KX_SlowParentRelation *>(sg_parent->GetParentRelation())->SetTimeOffset(val);
1679
1712
        }
1680
 
        return 0;
 
1713
        return PY_SET_ATTR_SUCCESS;
1681
1714
}
1682
1715
 
1683
1716
PyObject* KX_GameObject::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1696
1729
        
1697
1730
        if (state_i == -1 && PyErr_Occurred()) {
1698
1731
                PyErr_SetString(PyExc_TypeError, "gameOb.state = int: KX_GameObject, expected an int bit field");
1699
 
                return 1;
 
1732
                return PY_SET_ATTR_FAIL;
1700
1733
        }
1701
1734
        
1702
1735
        state |= state_i;
1703
1736
        if ((state & ((1<<30)-1)) == 0) {
1704
1737
                PyErr_SetString(PyExc_AttributeError, "gameOb.state = int: KX_GameObject, state bitfield was not between 0 and 30 (1<<0 and 1<<29)");
1705
 
                return 1;
 
1738
                return PY_SET_ATTR_FAIL;
1706
1739
        }
1707
1740
        self->SetState(state);
1708
 
        return 0;
 
1741
        return PY_SET_ATTR_SUCCESS;
1709
1742
}
1710
1743
 
1711
1744
PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1739
1772
        return KX_PythonSeq_CreatePyObject((static_cast<KX_GameObject*>(self_v))->m_proxy, KX_PYGENSEQ_OB_TYPE_ACTUATORS);
1740
1773
}
1741
1774
 
 
1775
PyObject* KX_GameObject::pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 
1776
{
 
1777
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 
1778
        return self->GetChildren()->NewProxy(true);
 
1779
}
 
1780
 
 
1781
PyObject* KX_GameObject::pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 
1782
{
 
1783
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 
1784
        return self->GetChildrenRecursive()->NewProxy(true);
 
1785
}
 
1786
 
1742
1787
PyObject* KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
1743
1788
{
1744
1789
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
1819
1864
 
1820
1865
int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method
1821
1866
{
1822
 
        int ret;
1823
 
        
1824
 
        ret= py_setattro__internal(attr, value);
 
1867
        int ret= py_setattro__internal(attr, value);
1825
1868
        
1826
1869
        if (ret==PY_SET_ATTR_SUCCESS) {
1827
1870
                /* remove attribute in our own dict to avoid double ups */
1859
1902
 
1860
1903
int     KX_GameObject::py_delattro(PyObject *attr)
1861
1904
{
 
1905
        ShowDeprecationWarning("del ob.attr", "del ob['attr'] for user defined properties");
 
1906
        
1862
1907
        char *attr_str= PyString_AsString(attr); 
1863
1908
        
1864
1909
        if (RemoveProperty(attr_str)) // XXX - should call CValues instead but its only 2 lines here
1865
 
                return 0;
 
1910
                return PY_SET_ATTR_SUCCESS;
1866
1911
        
1867
1912
        if (m_attr_dict && (PyDict_DelItem(m_attr_dict, attr) == 0))
1868
 
                return 0;
 
1913
                return PY_SET_ATTR_SUCCESS;
1869
1914
        
1870
1915
        PyErr_Format(PyExc_AttributeError, "del gameOb.myAttr: KX_GameObject, attribute \"%s\" dosnt exist", attr_str);
1871
 
        return 1;
 
1916
        return PY_SET_ATTR_MISSING;
1872
1917
}
1873
1918
 
1874
1919
 
2053
2098
        MT_Point3 point(0.0,0.0,0.0);
2054
2099
        PyObject* pypos = NULL;
2055
2100
        
2056
 
        if (PyArg_ParseTuple(args, "|O:getVelocity", &pypos))
2057
 
        {
2058
 
                if (pypos)
2059
 
                        PyVecTo(pypos, point);
2060
 
        }
2061
 
        else {
 
2101
        if (!PyArg_ParseTuple(args, "|O:getVelocity", &pypos) || (pypos && !PyVecTo(pypos, point)))
2062
2102
                return NULL;
2063
 
        }
2064
2103
        
2065
2104
        if (m_pPhysicsController1)
2066
2105
        {
2127
2166
        Py_RETURN_NONE;
2128
2167
}
2129
2168
 
2130
 
PyObject* KX_GameObject::PySetParent(PyObject* value)
 
2169
PyObject* KX_GameObject::PySetParent(PyObject* args)
2131
2170
{
2132
2171
        KX_Scene *scene = KX_GetActiveScene();
 
2172
        PyObject* pyobj;
2133
2173
        KX_GameObject *obj;
 
2174
        int addToCompound=1, ghost=1;
2134
2175
        
2135
 
        if (!ConvertPythonToGameObject(value, &obj, false, "gameOb.setParent(value): KX_GameObject"))
 
2176
        if (!PyArg_ParseTuple(args,"O|ii:setParent", &pyobj, &addToCompound, &ghost)) {
 
2177
                return NULL; // Python sets a simple error
 
2178
        }
 
2179
        if (!ConvertPythonToGameObject(pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
2136
2180
                return NULL;
2137
 
        
2138
 
        this->SetParent(scene, obj);
 
2181
        if (obj)
 
2182
                this->SetParent(scene, obj, addToCompound, ghost);
2139
2183
        Py_RETURN_NONE;
2140
2184
}
2141
2185
 
2149
2193
 
2150
2194
PyObject* KX_GameObject::PyGetChildren()
2151
2195
{
 
2196
        ShowDeprecationWarning("getChildren()", "the children property");
 
2197
        
2152
2198
        return GetChildren()->NewProxy(true);
2153
2199
}
2154
2200
 
2155
2201
PyObject* KX_GameObject::PyGetChildrenRecursive()
2156
2202
{
 
2203
        ShowDeprecationWarning("getChildrenRecursive()", "the childrenRecursive property");
 
2204
        
2157
2205
        return GetChildrenRecursive()->NewProxy(true);
2158
2206
}
2159
2207
 
2298
2346
 
2299
2347
PyObject* KX_GameObject::PySetPosition(PyObject* value)
2300
2348
{
2301
 
        ShowDeprecationWarning("setPosition()", "the position property");
 
2349
        ShowDeprecationWarning("setPosition()", "the localPosition property");
2302
2350
        MT_Point3 pos;
2303
2351
        if (PyVecTo(value, pos))
2304
2352
        {
2517
2565
        Py_RETURN_NONE;
2518
2566
}
2519
2567
 
 
2568
/* faster then Py_BuildValue since some scripts call raycast a lot */
 
2569
static PyObject *none_tuple_3()
 
2570
{
 
2571
        PyObject *ret= PyTuple_New(3);
 
2572
        PyTuple_SET_ITEM(ret, 0, Py_None);
 
2573
        PyTuple_SET_ITEM(ret, 1, Py_None);
 
2574
        PyTuple_SET_ITEM(ret, 2, Py_None);
 
2575
        
 
2576
        Py_INCREF(Py_None);
 
2577
        Py_INCREF(Py_None);
 
2578
        Py_INCREF(Py_None);
 
2579
        return ret;
 
2580
}
 
2581
static PyObject *none_tuple_4()
 
2582
{
 
2583
        PyObject *ret= PyTuple_New(4);
 
2584
        PyTuple_SET_ITEM(ret, 0, Py_None);
 
2585
        PyTuple_SET_ITEM(ret, 1, Py_None);
 
2586
        PyTuple_SET_ITEM(ret, 2, Py_None);
 
2587
        PyTuple_SET_ITEM(ret, 3, Py_None);
 
2588
        
 
2589
        Py_INCREF(Py_None);
 
2590
        Py_INCREF(Py_None);
 
2591
        Py_INCREF(Py_None);
 
2592
        Py_INCREF(Py_None);
 
2593
        return ret;
 
2594
}
 
2595
 
2520
2596
KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
2521
2597
                                   "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"
2522
2598
                                   " If no hit, return (None,None,None) or (None,None,None,None).\n"
2584
2660
        if (dist != 0.0f) {
2585
2661
                MT_Vector3 toDir = toPoint-fromPoint;
2586
2662
                if (MT_fuzzyZero(toDir.length2())) {
2587
 
                        return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2663
                        //return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2664
                        return none_tuple_3();
2588
2665
                }
2589
2666
                toDir.normalize();
2590
2667
                toPoint = fromPoint + (dist) * toDir;
2591
2668
        } else if (MT_fuzzyZero((toPoint-fromPoint).length2())) {
2592
 
                return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2669
                //return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2670
                return none_tuple_3();
2593
2671
        }
2594
2672
        
2595
2673
        PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment();
2637
2715
        }
2638
2716
        // no hit
2639
2717
        if (poly)
2640
 
                return Py_BuildValue("OOOO", Py_None, Py_None, Py_None, Py_None);
 
2718
                //return Py_BuildValue("OOOO", Py_None, Py_None, Py_None, Py_None);
 
2719
                return none_tuple_4();
2641
2720
        else
2642
 
                return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2721
                //return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
 
2722
                return none_tuple_3();
2643
2723
}
2644
2724
 
2645
2725
KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, 
2662
2742
        Py_RETURN_NONE;
2663
2743
}
2664
2744
 
 
2745
/* dict style access */
 
2746
 
 
2747
 
 
2748
/* Matches python dict.get(key, [default]) */
 
2749
PyObject* KX_GameObject::Pyget(PyObject *args)
 
2750
{
 
2751
        PyObject *key;
 
2752
        PyObject* def = Py_None;
 
2753
        PyObject* ret;
 
2754
 
 
2755
        if (!PyArg_ParseTuple(args, "O|O:get", &key, &def))
 
2756
                return NULL;
 
2757
        
 
2758
        
 
2759
        if(PyString_Check(key)) {
 
2760
                CValue *item = GetProperty(PyString_AsString(key));
 
2761
                if (item)
 
2762
                        return item->GetProxy();
 
2763
        }
 
2764
        
 
2765
        if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {
 
2766
                Py_INCREF(ret);
 
2767
                return ret;
 
2768
        }
 
2769
        
 
2770
        Py_INCREF(def);
 
2771
        return def;
 
2772
}
 
2773
 
 
2774
/* Matches python dict.has_key() */
 
2775
PyObject* KX_GameObject::Pyhas_key(PyObject* value)
 
2776
{
 
2777
        if(PyString_Check(value) && GetProperty(PyString_AsString(value)))
 
2778
                Py_RETURN_TRUE;
 
2779
        
 
2780
        if (m_attr_dict && PyDict_GetItem(m_attr_dict, value))
 
2781
                Py_RETURN_TRUE;
 
2782
        
 
2783
        Py_RETURN_FALSE;
 
2784
}
 
2785
 
 
2786
 
2665
2787
/* --------------------------------------------------------------------- 
2666
2788
 * Some stuff taken from the header
2667
2789
 * --------------------------------------------------------------------- */
2684
2806
        }
2685
2807
}
2686
2808
 
 
2809
 
2687
2810
bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
2688
2811
{
2689
2812
        if (value==NULL) {
2714
2837
                }
2715
2838
        }
2716
2839
        
2717
 
        if (PyObject_TypeCheck(value, &KX_GameObject::Type)) {
 
2840
        if (    PyObject_TypeCheck(value, &KX_GameObject::Type) ||
 
2841
                        PyObject_TypeCheck(value, &KX_LightObject::Type)        ||
 
2842
                        PyObject_TypeCheck(value, &KX_Camera::Type)     )
 
2843
        {
2718
2844
                *object = static_cast<KX_GameObject*>BGE_PROXY_REF(value);
2719
2845
                
2720
2846
                /* sets the error */