2
This source file is part of GIMPACT Library.
4
For the latest info, see http://gimpact.sourceforge.net/
6
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
7
email: projectileman@yahoo.com
10
This software is provided 'as-is', without any express or implied warranty.
11
In no event will the authors be held liable for any damages arising from the use of this software.
12
Permission is granted to anyone to use this software for any purpose,
13
including commercial applications, and to alter it and redistribute it freely,
14
subject to the following restrictions:
16
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
22
#include "btGImpactShape.h"
23
#include "btGImpactMassUtil.h"
26
#define CALC_EXACT_INERTIA 1
28
void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
31
#ifdef CALC_EXACT_INERTIA
32
inertia.setValue(0.f,0.f,0.f);
34
int i = this->getNumChildShapes();
35
btScalar shapemass = mass/btScalar(i);
39
btVector3 temp_inertia;
40
m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia);
41
if(childrenHasTransform())
43
inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]);
47
inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity());
56
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
57
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
58
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
59
const btScalar x2 = lx*lx;
60
const btScalar y2 = ly*ly;
61
const btScalar z2 = lz*lz;
62
const btScalar scaledmass = mass * btScalar(0.08333333);
64
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
72
void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const
77
#ifdef CALC_EXACT_INERTIA
78
inertia.setValue(0.f,0.f,0.f);
80
int i = this->getVertexCount();
81
btScalar pointmass = mass/btScalar(i);
85
btVector3 pointintertia;
86
this->getVertex(i,pointintertia);
87
pointintertia = gim_get_point_inertia(pointintertia,pointmass);
88
inertia+=pointintertia;
95
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
96
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
97
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
98
const btScalar x2 = lx*lx;
99
const btScalar y2 = ly*ly;
100
const btScalar z2 = lz*lz;
101
const btScalar scaledmass = mass * btScalar(0.08333333);
103
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
110
void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
113
#ifdef CALC_EXACT_INERTIA
114
inertia.setValue(0.f,0.f,0.f);
116
int i = this->getMeshPartCount();
117
btScalar partmass = mass/btScalar(i);
121
btVector3 partinertia;
122
getMeshPart(i)->calculateLocalInertia(partmass,partinertia);
123
inertia+=partinertia;
130
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
131
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
132
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
133
const btScalar x2 = lx*lx;
134
const btScalar y2 = ly*ly;
135
const btScalar z2 = lz*lz;
136
const btScalar scaledmass = mass * btScalar(0.08333333);
138
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
143
void btGImpactMeshShape::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const
148
void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
155
btAlignedObjectArray<int> collided;
156
m_box_set.boxQuery(box,collided);
158
if(collided.size()==0)
164
int part = (int)getPart();
165
btPrimitiveTriangle triangle;
166
int i = collided.size();
169
this->getPrimitiveTriangle(collided[i],triangle);
170
callback->processTriangle(triangle.m_vertices,part,collided[i]);
176
void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
178
int i = m_mesh_parts.size();
181
m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax);
2
This source file is part of GIMPACT Library.
4
For the latest info, see http://gimpact.sourceforge.net/
6
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
7
email: projectileman@yahoo.com
10
This software is provided 'as-is', without any express or implied warranty.
11
In no event will the authors be held liable for any damages arising from the use of this software.
12
Permission is granted to anyone to use this software for any purpose,
13
including commercial applications, and to alter it and redistribute it freely,
14
subject to the following restrictions:
16
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
22
#include "btGImpactShape.h"
23
#include "btGImpactMassUtil.h"
26
#define CALC_EXACT_INERTIA 1
28
void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
31
#ifdef CALC_EXACT_INERTIA
32
inertia.setValue(0.f,0.f,0.f);
34
int i = this->getNumChildShapes();
35
btScalar shapemass = mass/btScalar(i);
39
btVector3 temp_inertia;
40
m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia);
41
if(childrenHasTransform())
43
inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]);
47
inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity());
56
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
57
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
58
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
59
const btScalar x2 = lx*lx;
60
const btScalar y2 = ly*ly;
61
const btScalar z2 = lz*lz;
62
const btScalar scaledmass = mass * btScalar(0.08333333);
64
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
72
void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const
77
#ifdef CALC_EXACT_INERTIA
78
inertia.setValue(0.f,0.f,0.f);
80
int i = this->getVertexCount();
81
btScalar pointmass = mass/btScalar(i);
85
btVector3 pointintertia;
86
this->getVertex(i,pointintertia);
87
pointintertia = gim_get_point_inertia(pointintertia,pointmass);
88
inertia+=pointintertia;
95
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
96
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
97
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
98
const btScalar x2 = lx*lx;
99
const btScalar y2 = ly*ly;
100
const btScalar z2 = lz*lz;
101
const btScalar scaledmass = mass * btScalar(0.08333333);
103
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
110
void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
113
#ifdef CALC_EXACT_INERTIA
114
inertia.setValue(0.f,0.f,0.f);
116
int i = this->getMeshPartCount();
117
btScalar partmass = mass/btScalar(i);
121
btVector3 partinertia;
122
getMeshPart(i)->calculateLocalInertia(partmass,partinertia);
123
inertia+=partinertia;
130
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
131
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
132
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
133
const btScalar x2 = lx*lx;
134
const btScalar y2 = ly*ly;
135
const btScalar z2 = lz*lz;
136
const btScalar scaledmass = mass * btScalar(0.08333333);
138
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
143
void btGImpactMeshShape::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const
148
void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
155
btAlignedObjectArray<int> collided;
156
m_box_set.boxQuery(box,collided);
158
if(collided.size()==0)
164
int part = (int)getPart();
165
btPrimitiveTriangle triangle;
166
int i = collided.size();
169
this->getPrimitiveTriangle(collided[i],triangle);
170
callback->processTriangle(triangle.m_vertices,part,collided[i]);
176
void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
178
int i = m_mesh_parts.size();
181
m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax);