2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KX_TouchEventManager.h"
|
|
|
|
#include "SCA_ISensor.h"
|
|
|
|
#include "KX_TouchSensor.h"
|
|
|
|
#include "KX_GameObject.h"
|
2005-03-25 10:33:39 +00:00
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
|
|
|
#include "PHY_IPhysicsController.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2002-11-25 15:29:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsEnvironment* physEnv)
|
2009-09-25 16:30:15 +00:00
|
|
|
: SCA_EventManager(logicmgr, TOUCH_EVENTMGR),
|
2005-03-25 10:33:39 +00:00
|
|
|
m_physEnv(physEnv)
|
2004-03-22 22:02:18 +00:00
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
//notm_scene->addTouchCallback(STATIC_RESPONSE, KX_TouchEventManager::collisionResponse, this);
|
|
|
|
|
|
|
|
//m_scene->addTouchCallback(OBJECT_RESPONSE, KX_TouchEventManager::collisionResponse, this);
|
|
|
|
//m_scene->addTouchCallback(SENSOR_RESPONSE, KX_TouchEventManager::collisionResponse, this);
|
|
|
|
|
|
|
|
m_physEnv->addTouchCallback(PHY_OBJECT_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
|
|
|
|
m_physEnv->addTouchCallback(PHY_SENSOR_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
|
2008-03-01 19:17:37 +00:00
|
|
|
m_physEnv->addTouchCallback(PHY_BROADPH_RESPONSE, KX_TouchEventManager::newBroadphaseResponse, this);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-11-06 04:58:10 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
bool KX_TouchEventManager::NewHandleCollision(void* object1, void* object2, const PHY_CollData *coll_data)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-03-22 22:02:18 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsController* obj1 = static_cast<PHY_IPhysicsController*>(object1);
|
|
|
|
PHY_IPhysicsController* obj2 = static_cast<PHY_IPhysicsController*>(object2);
|
2004-03-22 22:02:18 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
m_newCollisions.insert(std::pair<PHY_IPhysicsController*, PHY_IPhysicsController*>(obj1, obj2));
|
|
|
|
|
|
|
|
return false;
|
2004-03-22 22:02:18 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-11-06 04:58:10 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
bool KX_TouchEventManager::newCollisionResponse(void *client_data,
|
2004-03-22 22:02:18 +00:00
|
|
|
void *object1,
|
|
|
|
void *object2,
|
2005-03-25 10:33:39 +00:00
|
|
|
const PHY_CollData *coll_data)
|
2004-03-22 22:02:18 +00:00
|
|
|
{
|
|
|
|
KX_TouchEventManager *touchmgr = (KX_TouchEventManager *) client_data;
|
2005-03-25 10:33:39 +00:00
|
|
|
touchmgr->NewHandleCollision(object1, object2, coll_data);
|
|
|
|
return false;
|
2004-03-22 22:02:18 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
bool KX_TouchEventManager::newBroadphaseResponse(void *client_data,
|
|
|
|
void *object1,
|
|
|
|
void *object2,
|
|
|
|
const PHY_CollData *coll_data)
|
|
|
|
{
|
|
|
|
PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1);
|
|
|
|
KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL;
|
|
|
|
// This call back should only be called for controllers of Near and Radar sensor
|
BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
* Actor option: the collisioning object must have the Actor flag set to be detected
* property/material: as specified in the collision sensors attached to it
Broadphase filtering is important for performance reason: the collision points
will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it
Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it
Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.
The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
to the suface by increasing the margin in the Advanced Settings panel.
The margin applies on both sides of the surface.
Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
because of the Scenegraph optimizations and they can have multiple collision sensors
on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
on the sensor object, it is removed from the simulation and consume no CPU.
Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
"warning btCollisionDispatcher::needsCollision: static-static collision!"
In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.
Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.
Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00
|
|
|
if (!info)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
switch (info->m_type)
|
2008-03-01 19:17:37 +00:00
|
|
|
{
|
BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
* Actor option: the collisioning object must have the Actor flag set to be detected
* property/material: as specified in the collision sensors attached to it
Broadphase filtering is important for performance reason: the collision points
will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it
Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it
Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.
The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
to the suface by increasing the margin in the Advanced Settings panel.
The margin applies on both sides of the surface.
Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
because of the Scenegraph optimizations and they can have multiple collision sensors
on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
on the sensor object, it is removed from the simulation and consume no CPU.
Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
"warning btCollisionDispatcher::needsCollision: static-static collision!"
In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.
Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.
Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00
|
|
|
case KX_ClientObjectInfo::SENSOR:
|
|
|
|
if (info->m_sensors.size() == 1)
|
|
|
|
{
|
|
|
|
// only one sensor for this type of object
|
|
|
|
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
|
|
|
|
return touchsensor->BroadPhaseFilterCollision(object1,object2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KX_ClientObjectInfo::OBSENSOR:
|
2009-05-29 16:55:22 +00:00
|
|
|
case KX_ClientObjectInfo::OBACTORSENSOR:
|
BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
* Actor option: the collisioning object must have the Actor flag set to be detected
* property/material: as specified in the collision sensors attached to it
Broadphase filtering is important for performance reason: the collision points
will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it
Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it
Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.
The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
to the suface by increasing the margin in the Advanced Settings panel.
The margin applies on both sides of the surface.
Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
because of the Scenegraph optimizations and they can have multiple collision sensors
on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
on the sensor object, it is removed from the simulation and consume no CPU.
Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
"warning btCollisionDispatcher::needsCollision: static-static collision!"
In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.
Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.
Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00
|
|
|
// this object may have multiple collision sensors,
|
|
|
|
// check is any of them is interested in this object
|
|
|
|
for(std::list<SCA_ISensor*>::iterator it = info->m_sensors.begin();
|
|
|
|
it != info->m_sensors.end();
|
|
|
|
++it)
|
|
|
|
{
|
2009-05-24 12:53:49 +00:00
|
|
|
if ((*it)->GetSensorType() == SCA_ISensor::ST_TOUCH)
|
BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
* Actor option: the collisioning object must have the Actor flag set to be detected
* property/material: as specified in the collision sensors attached to it
Broadphase filtering is important for performance reason: the collision points
will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it
Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it
Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.
The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
to the suface by increasing the margin in the Advanced Settings panel.
The margin applies on both sides of the surface.
Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
because of the Scenegraph optimizations and they can have multiple collision sensors
on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
on the sensor object, it is removed from the simulation and consume no CPU.
Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
"warning btCollisionDispatcher::needsCollision: static-static collision!"
In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.
Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.
Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00
|
|
|
{
|
|
|
|
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*it);
|
|
|
|
if (touchsensor->BroadPhaseSensorFilterCollision(object1, object2))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2008-03-01 19:17:37 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-03-22 22:02:18 +00:00
|
|
|
void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
|
2009-05-10 20:53:58 +00:00
|
|
|
if (m_sensors.AddBack(touchsensor))
|
2008-08-05 16:23:33 +00:00
|
|
|
// the sensor was effectively inserted, register it
|
|
|
|
touchsensor->RegisterSumo(this);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
void KX_TouchEventManager::RemoveSensor(SCA_ISensor* sensor)
|
|
|
|
{
|
|
|
|
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
|
2009-05-10 20:53:58 +00:00
|
|
|
if (touchsensor->Delink())
|
2008-08-05 16:23:33 +00:00
|
|
|
// the sensor was effectively removed, unregister it
|
|
|
|
touchsensor->UnregisterSumo(this);
|
2008-07-30 17:41:47 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KX_TouchEventManager::EndFrame()
|
|
|
|
{
|
2009-05-10 20:53:58 +00:00
|
|
|
SG_DList::iterator<KX_TouchSensor> it(m_sensors);
|
|
|
|
for (it.begin();!it.end();++it)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-05-10 20:53:58 +00:00
|
|
|
(*it)->EndFrame();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
void KX_TouchEventManager::NextFrame()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-05-10 20:53:58 +00:00
|
|
|
if (!m_sensors.Empty())
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-05-10 20:53:58 +00:00
|
|
|
SG_DList::iterator<KX_TouchSensor> it(m_sensors);
|
|
|
|
for (it.begin();!it.end();++it)
|
|
|
|
(*it)->SynchronizeTransform();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
for (std::set<NewCollision>::iterator cit = m_newCollisions.begin(); cit != m_newCollisions.end(); ++cit)
|
2004-11-22 10:19:19 +00:00
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsController* ctrl1 = (*cit).first;
|
2005-06-04 16:22:50 +00:00
|
|
|
// PHY_IPhysicsController* ctrl2 = (*cit).second;
|
2005-03-25 10:33:39 +00:00
|
|
|
// KX_GameObject* gameOb1 = ctrl1->getClientInfo();
|
|
|
|
// KX_GameObject* gameOb1 = ctrl1->getClientInfo();
|
|
|
|
|
|
|
|
KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo *>(ctrl1->getNewClientInfo());
|
2004-11-22 10:19:19 +00:00
|
|
|
list<SCA_ISensor*>::iterator sit;
|
2008-07-08 22:43:44 +00:00
|
|
|
if (client_info) {
|
|
|
|
for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) {
|
|
|
|
static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision((*cit).first, (*cit).second, NULL);
|
|
|
|
}
|
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
client_info = static_cast<KX_ClientObjectInfo *>((*cit).second->getNewClientInfo());
|
2008-07-08 22:43:44 +00:00
|
|
|
if (client_info) {
|
|
|
|
for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) {
|
|
|
|
static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision((*cit).second, (*cit).first, NULL);
|
|
|
|
}
|
|
|
|
}
|
2004-11-22 10:19:19 +00:00
|
|
|
}
|
2004-11-06 04:58:10 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
m_newCollisions.clear();
|
2004-11-06 04:58:10 +00:00
|
|
|
|
2009-05-10 20:53:58 +00:00
|
|
|
for (it.begin();!it.end();++it)
|
|
|
|
(*it)->Activate(m_logicmgr);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|