~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
 * Sense if other objects are near
3
3
 *
4
 
 * $Id: KX_NearSensor.cpp,v 1.5 2004/04/11 02:50:00 kester Exp $
 
4
 * $Id: KX_NearSensor.cpp,v 1.11 2005/06/04 16:22:50 lukep Exp $
5
5
 *
6
6
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7
7
 *
37
37
#include "KX_GameObject.h"
38
38
#include "KX_TouchEventManager.h"
39
39
#include "KX_Scene.h" // needed to create a replica
 
40
#include "PHY_IPhysicsEnvironment.h"
 
41
#include "PHY_IPhysicsController.h"
40
42
 
41
 
#include "SM_Object.h"
42
43
 
43
44
#ifdef HAVE_CONFIG_H
44
45
#include <config.h>
45
46
#endif
46
47
KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
47
48
                                                         KX_GameObject* gameobj,
48
 
                                                         void *vshape,
49
 
                                                         double margin,
50
 
                                                         double resetmargin,
51
 
                                                         bool bFindMaterial,
52
 
                                                         const STR_String& touchedpropname,
53
 
                                                         class KX_Scene* scene,
54
 
                                                         PyTypeObject* T)
55
 
                         :KX_TouchSensor(eventmgr,
56
 
                                                         gameobj,
57
 
                                                         bFindMaterial,
58
 
                                                         touchedpropname,
59
 
                                                         /* scene, */
60
 
                                                         T),
61
 
                         m_Margin(margin),
62
 
                         m_ResetMargin(resetmargin)
63
 
 
64
 
{
65
 
        m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
66
 
        
67
 
        DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
68
 
        m_sumoObj = new SM_Object(shape,NULL,NULL,NULL);
69
 
        m_sumoObj->setMargin(m_Margin);
70
 
        m_sumoObj->setClientObject(m_client_info);
71
 
        
72
 
        SynchronizeTransform();
73
 
}
74
 
 
75
 
KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
76
 
                                                         KX_GameObject* gameobj,
77
 
                                                         double margin,
78
 
                                                         double resetmargin,
79
 
                                                         bool bFindMaterial,
80
 
                                                         const STR_String& touchedpropname,
81
 
                                                         class KX_Scene* scene,
82
 
                                                         PyTypeObject* T)
83
 
                         :KX_TouchSensor(eventmgr,
84
 
                                                         gameobj,
85
 
                                                         bFindMaterial,
86
 
                                                         touchedpropname,
87
 
                                                         /* scene, */
88
 
                                                         T),
89
 
                         m_Margin(margin),
90
 
                         m_ResetMargin(resetmargin)
91
 
 
92
 
{
93
 
        m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
94
 
        
95
 
        m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
96
 
        m_sumoObj->setMargin(m_Margin);
97
 
        m_sumoObj->setClientObject(m_client_info);
 
49
                                                         double margin,
 
50
                                                         double resetmargin,
 
51
                                                         bool bFindMaterial,
 
52
                                                         const STR_String& touchedpropname,
 
53
                                                         class KX_Scene* scene,
 
54
                                                         PHY_IPhysicsController*        ctrl,
 
55
                                                         PyTypeObject* T)
 
56
                         :KX_TouchSensor(eventmgr,
 
57
                                                         gameobj,
 
58
                                                         bFindMaterial,
 
59
                                                         touchedpropname,
 
60
                                                         /* scene, */
 
61
                                                         T),
 
62
                         m_Margin(margin),
 
63
                         m_ResetMargin(resetmargin)
 
64
 
 
65
{
 
66
        gameobj->getClientInfo()->m_sensors.remove(this);
 
67
        m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
 
68
        m_client_info->m_sensors.push_back(this);
 
69
        
 
70
        //DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
 
71
        m_physCtrl = ctrl;
 
72
        m_physCtrl->SetMargin(m_Margin);
 
73
        m_physCtrl->setNewClientInfo(m_client_info);
98
74
        
99
75
        SynchronizeTransform();
100
76
}
101
77
 
102
78
void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman)
103
79
{
104
 
        touchman->GetSumoScene()->addSensor(*m_sumoObj);
 
80
        touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
105
81
}
106
82
 
107
83
CValue* KX_NearSensor::GetReplica()
115
91
        // this will copy properties and so on...
116
92
        CValue::AddDataToReplica(replica);
117
93
        
118
 
        replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_clientobject, KX_ClientObjectInfo::NEAR);
 
94
        replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR);
119
95
        
120
 
        replica->m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
121
 
        replica->m_sumoObj->setMargin(m_Margin);
122
 
        replica->m_sumoObj->setClientObject(replica->m_client_info);
 
96
        replica->m_physCtrl = replica->m_physCtrl->GetReplica();
 
97
        //todo: make sure replication works fine
 
98
        //>m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
 
99
        //replica->m_sumoObj->setMargin(m_Margin);
 
100
        //replica->m_sumoObj->setClientObject(replica->m_client_info);
123
101
        
124
102
        replica->SynchronizeTransform();
125
103
        
132
110
{
133
111
        SCA_ISensor::ReParent(parent);
134
112
        
135
 
        m_client_info->m_clientobject = static_cast<KX_GameObject*>(parent); 
 
113
        m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent); 
 
114
        m_client_info->m_sensors.push_back(this);
136
115
        
137
116
        SynchronizeTransform();
138
117
}
143
122
{
144
123
        // for nearsensor, the sensor is the 'owner' of sumoobj
145
124
        // for touchsensor, it's the parent
146
 
        static_cast<KX_TouchEventManager*>(m_eventmgr)->GetSumoScene()->remove(*m_sumoObj);
147
 
 
148
 
        if (m_sumoObj)
149
 
                delete m_sumoObj;
 
125
        if (m_physCtrl)
 
126
        {
 
127
                static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
 
128
                delete m_physCtrl;
 
129
                m_physCtrl = NULL;
 
130
        }
150
131
                
151
132
        if (m_client_info)
152
133
                delete m_client_info;
156
137
bool KX_NearSensor::Evaluate(CValue* event)
157
138
{
158
139
        bool result = false;
159
 
        KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
 
140
//      KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
160
141
 
161
142
        if (m_bTriggered != m_bLastTriggered)
162
143
        {
163
144
                m_bLastTriggered = m_bTriggered;
164
145
                if (m_bTriggered)
165
146
                {
166
 
                        if (m_sumoObj)
 
147
                        if (m_physCtrl)
167
148
                        {
168
 
                                m_sumoObj->setMargin(m_ResetMargin);
 
149
                                m_physCtrl->SetMargin(m_ResetMargin);
169
150
                        }
170
151
                } else
171
152
                {
172
 
                        if (m_sumoObj)
 
153
                        if (m_physCtrl)
173
154
                        {
174
 
                                m_sumoObj->setMargin(m_Margin);
 
155
                                m_physCtrl->SetMargin(m_Margin);
175
156
                        }
176
157
 
177
158
                }
183
164
 
184
165
 
185
166
 
186
 
DT_Bool KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data)
 
167
bool    KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data)
187
168
{
188
 
        KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
 
169
//      KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
189
170
        KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
190
171
        
191
 
        // need the mapping from SM_Objects to gameobjects now
 
172
        // need the mapping from PHY_IPhysicsController to gameobjects now
192
173
        
193
 
        KX_ClientObjectInfo* client_info =static_cast<KX_ClientObjectInfo*> (obj1 == m_sumoObj? 
194
 
                                        ((SM_Object*)obj2)->getClientObject() : 
195
 
                                        ((SM_Object*)obj1)->getClientObject());
 
174
        KX_ClientObjectInfo* client_info =static_cast<KX_ClientObjectInfo*> (obj1 == m_physCtrl? 
 
175
                                        ((PHY_IPhysicsController*)obj2)->getNewClientInfo() : 
 
176
                                        ((PHY_IPhysicsController*)obj1)->getNewClientInfo());
196
177
 
197
178
        KX_GameObject* gameobj = ( client_info ? 
198
 
                        static_cast<KX_GameObject*>(client_info->m_clientobject) : 
 
179
                        client_info->m_gameobject :
199
180
                        NULL);
200
181
        
201
182
        if (gameobj && (gameobj != parent))
266
247
 
267
248
 
268
249
PyObject*
269
 
KX_NearSensor::_getattr(char* attr)
 
250
KX_NearSensor::_getattr(const STR_String& attr)
270
251
{
271
252
  _getattr_up(KX_TouchSensor);
272
253
}