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
|
|
|
*/
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
#include <string.h> // memset
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "SumoPhysicsEnvironment.h"
|
|
|
|
|
#include "PHY_IMotionState.h"
|
|
|
|
|
#include "SumoPhysicsController.h"
|
|
|
|
|
#include "SM_Scene.h"
|
2005-03-25 10:33:39 +00:00
|
|
|
#include "SumoPHYCallbackBridge.h"
|
|
|
|
|
#include <SOLID/SOLID.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
SumoPhysicsEnvironment::SumoPhysicsEnvironment()
|
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
m_fixedTimeStep = 1.f/60.f;
|
|
|
|
|
m_useFixedTimeStep = true;
|
|
|
|
|
m_currentTime = 0.f;
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_sumoScene = new SM_Scene();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SumoPhysicsEnvironment::~SumoPhysicsEnvironment()
|
|
|
|
|
{
|
|
|
|
|
delete m_sumoScene;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
|
|
|
|
|
|
2004-11-06 04:58:10 +00:00
|
|
|
void SumoPhysicsEnvironment::beginFrame()
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
2004-11-06 04:58:10 +00:00
|
|
|
m_sumoScene->beginFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SumoPhysicsEnvironment::endFrame()
|
|
|
|
|
{
|
|
|
|
|
m_sumoScene->endFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
void SumoPhysicsEnvironment::setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
|
2004-11-06 04:58:10 +00:00
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
m_useFixedTimeStep = useFixedTimeStep;
|
|
|
|
|
if (m_useFixedTimeStep)
|
|
|
|
|
{
|
|
|
|
|
m_fixedTimeStep = fixedTimeStep;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
m_fixedTimeStep = 0.f;
|
|
|
|
|
}
|
|
|
|
|
//reset current time ?
|
|
|
|
|
m_currentTime = 0.f;
|
|
|
|
|
}
|
|
|
|
|
float SumoPhysicsEnvironment::getFixedTimeStep()
|
|
|
|
|
{
|
|
|
|
|
return m_fixedTimeStep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-01 16:35:06 +00:00
|
|
|
bool SumoPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep,float interval)
|
2005-03-25 10:33:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (m_useFixedTimeStep)
|
|
|
|
|
{
|
|
|
|
|
m_currentTime += timeStep;
|
|
|
|
|
float ticrate = 1.f/m_fixedTimeStep;
|
|
|
|
|
|
|
|
|
|
result = m_sumoScene->proceed(curTime, ticrate);
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
m_currentTime += timeStep;
|
|
|
|
|
result = m_sumoScene->proceed(m_currentTime, timeStep);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SumoPhysicsEnvironment::setGravity(float x,float y,float z)
|
|
|
|
|
{
|
|
|
|
|
m_sumoScene->setForceField(MT_Vector3(x,y,z));
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-14 05:57:24 +00:00
|
|
|
int SumoPhysicsEnvironment::createConstraint(
|
|
|
|
|
class PHY_IPhysicsController* ctrl,
|
|
|
|
|
class PHY_IPhysicsController* ctrl2,
|
|
|
|
|
PHY_ConstraintType type,
|
|
|
|
|
float pivotX,float pivotY,float pivotZ,
|
2006-12-16 05:50:38 +00:00
|
|
|
float axisX,float axisY,float axisZ,
|
|
|
|
|
float axis1X,float axis1Y,float axis1Z,
|
2008-10-10 05:12:57 +00:00
|
|
|
float axis2X,float axis2Y,float axis2Z,
|
|
|
|
|
int flag
|
2006-12-16 05:50:38 +00:00
|
|
|
)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
int constraintid = 0;
|
|
|
|
|
return constraintid;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-15 11:34:55 +00:00
|
|
|
void SumoPhysicsEnvironment::removeConstraint(int constraintid)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
if (constraintid)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
PHY_IPhysicsController* SumoPhysicsEnvironment::rayTest(PHY_IRayCastFilterCallback &filterCallback,
|
2004-03-22 22:02:18 +00:00
|
|
|
float fromX,float fromY,float fromZ,
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
float toX,float toY,float toZ)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
SumoPhysicsController* ignoreCtr = static_cast<SumoPhysicsController*> (filterCallback.m_ignoreController);
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
//collision detection / raytesting
|
2004-03-22 22:02:18 +00:00
|
|
|
MT_Point3 hit, normal;
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
PHY_RayCastResult result;
|
2005-03-25 10:33:39 +00:00
|
|
|
|
|
|
|
|
SM_Object* sm_ignore = 0;
|
|
|
|
|
if (ignoreCtr)
|
|
|
|
|
sm_ignore = ignoreCtr->GetSumoObject();
|
|
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
memset(&result, 0, sizeof(result));
|
2005-03-25 10:33:39 +00:00
|
|
|
|
|
|
|
|
SM_Object* smOb = m_sumoScene->rayTest(sm_ignore,MT_Point3(fromX, fromY, fromZ),MT_Point3(toX, toY, toZ), hit, normal);
|
|
|
|
|
if (smOb)
|
|
|
|
|
{
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
result.m_controller = (PHY_IPhysicsController *) smOb->getPhysicsClientObject();
|
|
|
|
|
result.m_hitPoint[0] = hit[0];
|
|
|
|
|
result.m_hitPoint[1] = hit[1];
|
|
|
|
|
result.m_hitPoint[2] = hit[2];
|
|
|
|
|
result.m_hitNormal[0] = normal[0];
|
|
|
|
|
result.m_hitNormal[1] = normal[1];
|
|
|
|
|
result.m_hitNormal[2] = normal[2];
|
|
|
|
|
filterCallback.reportHit(&result);
|
2005-03-25 10:33:39 +00:00
|
|
|
}
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
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.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
return result.m_controller;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
//gamelogic callbacks
|
|
|
|
|
void SumoPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
|
|
|
|
|
{
|
|
|
|
|
SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
|
|
|
|
|
SM_Object* smObject = smctrl->GetSumoObject();
|
|
|
|
|
assert(smObject);
|
|
|
|
|
if (smObject)
|
|
|
|
|
{
|
|
|
|
|
m_sumoScene->addSensor(*smObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void SumoPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
|
|
|
|
|
{
|
|
|
|
|
SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
|
|
|
|
|
SM_Object* smObject = smctrl->GetSumoObject();
|
|
|
|
|
assert(smObject);
|
|
|
|
|
if (smObject)
|
|
|
|
|
{
|
|
|
|
|
m_sumoScene->remove(*smObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SumoPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int sumoRespClass = 0;
|
|
|
|
|
|
|
|
|
|
//map PHY_ convention into SM_ convention
|
|
|
|
|
switch (response_class)
|
|
|
|
|
{
|
|
|
|
|
case PHY_FH_RESPONSE:
|
|
|
|
|
sumoRespClass = FH_RESPONSE;
|
|
|
|
|
break;
|
|
|
|
|
case PHY_SENSOR_RESPONSE:
|
|
|
|
|
sumoRespClass = SENSOR_RESPONSE;
|
|
|
|
|
break;
|
|
|
|
|
case PHY_CAMERA_RESPONSE:
|
|
|
|
|
sumoRespClass =CAMERA_RESPONSE;
|
|
|
|
|
break;
|
|
|
|
|
case PHY_OBJECT_RESPONSE:
|
|
|
|
|
sumoRespClass = OBJECT_RESPONSE;
|
|
|
|
|
break;
|
|
|
|
|
case PHY_STATIC_RESPONSE:
|
|
|
|
|
sumoRespClass = PHY_STATIC_RESPONSE;
|
|
|
|
|
break;
|
2008-03-01 19:17:37 +00:00
|
|
|
case PHY_BROADPH_RESPONSE:
|
|
|
|
|
return;
|
2005-03-25 10:33:39 +00:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SumoPHYCallbackBridge* bridge = new SumoPHYCallbackBridge(user,callback);
|
|
|
|
|
|
|
|
|
|
m_sumoScene->addTouchCallback(sumoRespClass,SumoPHYCallbackBridge::StaticSolidToPHYCallback,bridge);
|
|
|
|
|
}
|
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
|
|
|
bool SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
|
2005-03-25 10:33:39 +00:00
|
|
|
{
|
|
|
|
|
SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
|
|
|
|
|
MT_assert(smctrl);
|
|
|
|
|
SM_Object* smObject = smctrl->GetSumoObject();
|
|
|
|
|
MT_assert(smObject);
|
|
|
|
|
if (smObject)
|
|
|
|
|
{
|
|
|
|
|
//assert(smObject->getPhysicsClientObject() == ctrl);
|
|
|
|
|
smObject->setPhysicsClientObject(ctrl);
|
|
|
|
|
|
|
|
|
|
m_sumoScene->requestCollisionCallback(*smObject);
|
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
|
|
|
return true;
|
2005-03-25 10:33:39 +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
|
|
|
return false;
|
2005-03-25 10:33:39 +00:00
|
|
|
}
|
2008-07-30 17:41:47 +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
|
|
|
bool SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
|
2008-07-30 17:41:47 +00:00
|
|
|
{
|
|
|
|
|
// intentionally empty
|
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
|
|
|
return false;
|
2008-07-30 17:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsController* SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)
|
|
|
|
|
{
|
|
|
|
|
DT_ShapeHandle shape = DT_NewSphere(0.0);
|
|
|
|
|
SM_Object* ob = new SM_Object(shape,0,0,0);
|
|
|
|
|
ob->setPosition(MT_Point3(position));
|
|
|
|
|
//testing
|
|
|
|
|
MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
|
|
|
|
|
ob->setOrientation(rotquatje);
|
|
|
|
|
|
|
|
|
|
PHY_IPhysicsController* ctrl = new SumoPhysicsController(m_sumoScene,ob,0,false);
|
|
|
|
|
ctrl->SetMargin(radius);
|
|
|
|
|
return ctrl;
|
|
|
|
|
}
|
|
|
|
|
PHY_IPhysicsController* SumoPhysicsEnvironment::CreateConeController(float coneradius,float coneheight)
|
|
|
|
|
{
|
|
|
|
|
DT_ShapeHandle shape = DT_NewCone(coneradius,coneheight);
|
|
|
|
|
SM_Object* ob = new SM_Object(shape,0,0,0);
|
|
|
|
|
ob->setPosition(MT_Point3(0.f,0.f,0.f));
|
|
|
|
|
MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
|
|
|
|
|
ob->setOrientation(rotquatje);
|
|
|
|
|
|
|
|
|
|
PHY_IPhysicsController* ctrl = new SumoPhysicsController(m_sumoScene,ob,0,false);
|
|
|
|
|
|
|
|
|
|
return ctrl;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|