2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 /* This file is part of the hkl3d library.
18 * The hkl library is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * The hkl library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
31 * Copyright (C) 2010 Synchrotron SOLEIL
32 * L'Orme des Merisiers Saint-Aubin
33 * BP 48 91192 GIF-sur-YVETTE CEDEX
35 * Authors: Oussama Sboui <oussama.sboui@synchrotron-soleil.fr>
36 * Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
38 #include "btBulletDynamicsCommon.h"
39 #include "GLDebugDrawer.h"
41 #include "DiffabsDemo.h"
43 GLDebugDrawer debugDrawer
;
45 float mu
= 1185 * HKL_DEGTORAD
;
46 float komega
= 1185 * HKL_DEGTORAD
;
47 float kappa
= -1185 * HKL_DEGTORAD
;
48 float kphi
= 0 * HKL_DEGTORAD
;
49 float ggamma
= 0 * HKL_DEGTORAD
;
50 float delta
= 0 * HKL_DEGTORAD
;
52 // comment the next line for no animation
55 DiffabsDemo::DiffabsDemo(void)
57 const HklGeometryConfig
*config
;
59 config
= hkl_geometry_factory_get_config_from_type(HKL_GEOMETRY_TYPE_KAPPA6C
);
60 _geometry
= hkl_geometry_factory_new(config
, 50 * HKL_DEGTORAD
);
61 hkl_geometry_set_values_v(_geometry
, 6, mu
, komega
, kappa
, kphi
, ggamma
, delta
);
62 hkl_geometry_fprintf(stdout
, _geometry
);
64 _hkl3d
= new Hkl3D("../../../data/diffabs.dae", _geometry
);
67 DiffabsDemo::~DiffabsDemo(void)
73 hkl_geometry_free(_geometry
);
76 void DiffabsDemo::clientMoveAndDisplay(void)
78 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
79 this->displayCallback();
82 void DiffabsDemo::displayCallback(void)
88 btVector3 worldBoundsMin
;
89 btVector3 worldBoundsMax
;
91 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
92 glDisable(GL_LIGHTING
);
93 GL_ShapeDrawer::drawCoordSystem();
94 _hkl3d
->_btCollisionWorld
->getDispatchInfo().m_debugDraw
= &debugDrawer
;
97 // create an animation to see collisions
98 mu
+= 5 * HKL_DEGTORAD
;
99 komega
+= 5 * HKL_DEGTORAD
;
100 kappa
-= 5 * HKL_DEGTORAD
;
101 kphi
+= 5 * HKL_DEGTORAD
;
102 ggamma
-= 5 * HKL_DEGTORAD
;
103 delta
+= 5 * HKL_DEGTORAD
;
104 hkl_geometry_set_values_v(_geometry
, 6, mu
, komega
, kappa
, kphi
, ggamma
, delta
);
105 hkl_geometry_fprintf(stdout
, _geometry
);
106 _hkl3d
->is_colliding();
109 // draw the diffractometer
110 // get the world bounding box from bullet
111 _hkl3d
->_btCollisionWorld
->getBroadphase()->getBroadphaseAabb(worldBoundsMin
,
114 len
= _hkl3d
->_btCollisionObjects
.size();
115 for(i
=0; i
<len
; ++i
){
116 btCollisionObject
*object
;
118 object
= _hkl3d
->_btCollisionObjects
[i
];
119 object
->getWorldTransform().getOpenGLMatrix( m
);
120 m_shapeDrawer
->drawOpenGL(m
,
121 object
->getCollisionShape(),
123 this->getDebugMode(),
128 ///one way to draw all the contact points is iterating over contact manifolds / points:
129 numManifolds
= _hkl3d
->_btDispatcher
->getNumManifolds();
130 for (i
=0; i
<numManifolds
; i
++){
131 btPersistentManifold
*contactManifold
;
132 btCollisionObject
*obA
;
133 btCollisionObject
*obB
;
137 contactManifold
= _hkl3d
->_btDispatcher
->getManifoldByIndexInternal(i
);
138 obA
= static_cast<btCollisionObject
*>(contactManifold
->getBody0());
139 obB
= static_cast<btCollisionObject
*>(contactManifold
->getBody1());
141 // draw the colliding object in debug mode so we can see them
142 obA
->getWorldTransform().getOpenGLMatrix( m
);
143 m_shapeDrawer
->drawOpenGL(m
,
144 obA
->getCollisionShape(),
150 obB
->getWorldTransform().getOpenGLMatrix( m
);
151 m_shapeDrawer
->drawOpenGL(m
,
152 obB
->getCollisionShape(),
158 // now draw the manifolds / points
159 numContacts
= contactManifold
->getNumContacts();
160 for (j
=0; j
<numContacts
; j
++){
161 btManifoldPoint
& pt
= contactManifold
->getContactPoint(j
);
166 btVector3 ptA
= pt
.getPositionWorldOnA();
167 btVector3 ptB
= pt
.getPositionWorldOnB();
169 glVertex3d(ptA
.x(),ptA
.y(),ptA
.z());
170 glVertex3d(ptB
.x(),ptB
.y(),ptB
.z());
179 void DiffabsDemo::initPhysics(void)