prepare for Box2D style gui demo

This commit is contained in:
ejcoumans
2007-10-18 06:37:36 +00:00
parent 8f7b132d23
commit dbe502c5a8
19 changed files with 902 additions and 101 deletions

3
Examples/Jamfile Normal file
View File

@@ -0,0 +1,3 @@
SubDir TOP Examples ;
SubInclude TOP Examples TestBed ;

View File

@@ -0,0 +1,3 @@
SubDir TOP Examples TestBed Framework ;
BulletDemo FrameWork : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,285 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 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.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include "glui/GL/glui.h"
#include "LinearMath/btScalar.h"
#include "LinearMath/btMinMax.h"
#include "Render.h"
#include "Test.h"
namespace
{
int testIndex = 0;
int testSelection = 0;
TestEntry* entry;
Test* test;
Settings settings;
int width = 640;
int height = 480;
int framePeriod = 16;
int mainWindow;
GLUI *glui;
float viewZoom = 20.0f;
float viewX = 0.0f;
float viewY = 0.0f;
int tx, ty, tw, th;
}
void Resize(int w, int h)
{
width = w;
height = h;
GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
glViewport( tx, ty, tw, th );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double ratio = (double)tw / (double)th;
gluOrtho2D(viewZoom * (viewX - ratio), viewZoom * (ratio + viewX),
viewZoom * (viewY - 0.1), viewZoom * (viewY + 1.9));
}
/*b2Vec2 ConvertScreenToWorld(int x, int y)
{
b2Vec2 p;
float ratio = float(tw) / float(th);
float u = x / float(tw);
float v = (th - y) / float(th);
p.x = viewZoom * (viewX - ratio) * (1.0f - u) + viewZoom * (ratio + viewX) * u;
p.y = viewZoom * (viewY - 0.1f) * (1.0f - v) + viewZoom * (viewY + 1.9f) * v;
return p;
}
*/
// This is used to control the frame rate (60Hz).
void Timer(int)
{
glutSetWindow(mainWindow);
glutPostRedisplay();
glutTimerFunc(framePeriod, Timer, 0);
}
void SimulationLoop()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
test->SetTextLine(30);
test->Step(&settings);
/// DrawString(5, 15, entry->name);
glutSwapBuffers();
if (testSelection != testIndex)
{
testIndex = testSelection;
delete test;
entry = g_testEntries + testIndex;
test = entry->createFcn();
viewZoom = 20.0f;
viewX = 0.0f;
viewY = 0.0f;
Resize(width, height);
}
}
void Keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
// Press 'a' to zoom in.
case 'a':
viewZoom = btMax(viewZoom - 1.0f, 1.0f);
Resize(width, height);
break;
// Press 'z' to zoom out.
case 'z':
viewZoom = btMin(viewZoom + 1.0f, 100.0f);
Resize(width, height);
break;
// Press 'r' to reset.
case 'r':
delete test;
test = entry->createFcn();
break;
// Press space to launch a bomb.
case ' ':
if (test)
{
test->LaunchBomb();
}
break;
case 'h':
settings.pause = !settings.pause;
break;
default:
if (test)
{
test->Keyboard(key);
}
}
}
void KeyboardSpecial(int key, int x, int y)
{
switch (key)
{
// Press left to pan left.
case GLUT_KEY_LEFT:
viewX += 0.1f;
Resize(width, height);
break;
// Press right to pan right.
case GLUT_KEY_RIGHT:
viewX -= 0.1f;
Resize(width, height);
break;
// Press down to pan down.
case GLUT_KEY_DOWN:
viewY += 0.1f;
Resize(width, height);
break;
// Press up to pan up.
case GLUT_KEY_UP:
viewY -= 0.1f;
Resize(width, height);
break;
// Press home to reset the view.
case GLUT_KEY_HOME:
viewZoom = 20.0f;
viewX = 0.0f;
viewY = 0.0f;
Resize(width, height);
break;
}
}
void Mouse(int button, int state, int x, int y)
{
// Use the mouse to move things around.
if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_DOWN)
{
// b2Vec2 p = ConvertScreenToWorld(x, y);
// test->MouseDown(p);
}
if (state == GLUT_UP)
{
test->MouseUp();
}
}
}
void MouseMotion(int x, int y)
{
// b2Vec2 p = ConvertScreenToWorld(x, y);
// test->MouseMove(p);
}
int main(int argc, char** argv)
{
entry = g_testEntries + testIndex;
test = entry->createFcn();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(width, height);
mainWindow = glutCreateWindow("http://bulletphysics.com");
//glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
glutDisplayFunc(SimulationLoop);
GLUI_Master.set_glutReshapeFunc(Resize);
GLUI_Master.set_glutKeyboardFunc(Keyboard);
GLUI_Master.set_glutSpecialFunc(KeyboardSpecial);
GLUI_Master.set_glutMouseFunc(Mouse);
glutMotionFunc(MouseMotion);
glui = GLUI_Master.create_glui_subwindow( mainWindow,
GLUI_SUBWINDOW_RIGHT );
glui->add_statictext("Tests");
GLUI_Listbox* testList =
glui->add_listbox("", &testSelection);
glui->add_separator();
GLUI_Spinner* iterationSpinner =
glui->add_spinner("Iterations", GLUI_SPINNER_INT, &settings.iterationCount);
iterationSpinner->set_int_limits(1, 100);
GLUI_Spinner* hertzSpinner =
glui->add_spinner("Hertz", GLUI_SPINNER_FLOAT, &settings.hz);
hertzSpinner->set_float_limits(5.0f, 200.0f);
glui->add_checkbox("Position Correction", &settings.enablePositionCorrection);
glui->add_checkbox("Warm Starting", &settings.enablePositionCorrection);
glui->add_separator();
GLUI_Panel* drawPanel = glui->add_panel("Draw");
glui->add_checkbox_to_panel(drawPanel, "AABBs", &settings.drawAABBs);
glui->add_checkbox_to_panel(drawPanel, "Pairs", &settings.drawPairs);
glui->add_checkbox_to_panel(drawPanel, "Contacts", &settings.drawContacts);
glui->add_checkbox_to_panel(drawPanel, "Impulses", &settings.drawImpulses);
glui->add_checkbox_to_panel(drawPanel, "Statistics", &settings.drawStats);
int testCount = 0;
TestEntry* e = g_testEntries;
while (e->createFcn)
{
testList->add_item(testCount, e->name);
++testCount;
++e;
}
glui->add_button("Quit", 0,(GLUI_Update_CB)exit);
glui->set_main_gfx_window( mainWindow );
// Use a timer to control the frame rate.
glutTimerFunc(framePeriod, Timer, 0);
glutMainLoop();
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 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.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "Render.h"
//#include "freeglut/gl/glut.h"
//think different
#if defined(__APPLE__) && !defined (VMDMESA)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
void DrawString(int x, int y, const char *string, ...)
{
char buffer[128];
va_list arg;
va_start(arg, string);
vsprintf(buffer, string, arg);
va_end(arg);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
int w = glutGet(GLUT_WINDOW_WIDTH);
int h = glutGet(GLUT_WINDOW_HEIGHT);
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(0.9f, 0.6f, 0.6f);
glRasterPos2i(x, y);
int length = (int)strlen(buffer);
for (int i = 0; i < length; ++i)
{
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, buffer[i]);
}
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 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.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef RENDER_H
#define RENDER_H
#include "LinearMath/btScalar.h"
struct Color
{
Color() { cx = 1.0f; cy = 1.0f; cz = 1.0f; }
Color(float x, float y, float z) { cx = x; cy = y; cz = z; }
float cx, cy, cz;
};
#endif

View File

@@ -0,0 +1,331 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 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.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "Test.h"
#include "Render.h"
//#include "freeglut/gl/glut.h"
//think different
#if defined(__APPLE__) && !defined (VMDMESA)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdio.h>
Test::Test()
{
m_textLine = 30;
}
Test::~Test()
{
// By deleting the world, we delete the bomb, mouse joint, etc.
}
/*
void Test::MouseDown(const b2Vec2& p)
{
b2Assert(m_mouseJoint == NULL);
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.minVertex = p - d;
aabb.maxVertex = p + d;
// Query the world for overlapping shapes.
const int32 k_maxCount = 10;
b2Shape* shapes[k_maxCount];
int32 count = m_world->Query(aabb, shapes, k_maxCount);
b2Body* body = NULL;
for (int32 i = 0; i < count; ++i)
{
if (shapes[i]->m_body->IsStatic() == false)
{
bool inside = shapes[i]->TestPoint(p);
if (inside)
{
body = shapes[i]->m_body;
break;
}
}
}
if (body)
{
b2MouseJointDef md;
md.body1 = m_world->m_groundBody;
md.body2 = body;
md.target = p;
md.motorForce = 400.0f * body->m_mass;
m_mouseJoint = (b2MouseJoint*)m_world->CreateJoint(&md);
body->WakeUp();
}
}
*/
void Test::MouseUp()
{
/*
if (m_mouseJoint)
{
m_world->DestroyJoint(m_mouseJoint);
m_mouseJoint = NULL;
}
*/
}
/*void Test::MouseMove(const b2Vec2& p)
{
if (m_mouseJoint)
{
m_mouseJoint->SetTarget(p);
}
}
*/
void Test::LaunchBomb()
{
/*
if (m_bomb)
{
m_world->DestroyBody(m_bomb);
m_bomb = NULL;
}
b2BoxDef sd;
float32 a = 0.5f;
sd.type = e_boxShape;
sd.extents.Set(a, a);
sd.density = 20.0f;
b2BodyDef bd;
bd.AddShape(&sd);
bd.allowSleep = true;
bd.position.Set(b2Random(-15.0f, 15.0f), 30.0f);
bd.rotation = b2Random(-1.5f, 1.5f);
bd.linearVelocity = -1.0f * bd.position;
bd.angularVelocity = b2Random(-20.0f, 20.0f);
m_bomb = m_world->CreateBody(&bd);
*/
}
//typedef const char *(APIENTRY * WGLGETEXTENSIONSSTRINGEXT_T)( void );
void Test::Step(const Settings* settings)
{
/*
float32 timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : 0.0f;
if (settings->pause)
{
timeStep = 0.0f;
}
b2World::s_enableWarmStarting = settings->enableWarmStarting;
b2World::s_enablePositionCorrection = settings->enablePositionCorrection;
m_world->Step(timeStep, settings->iterationCount);
m_world->m_broadPhase->Validate();
for (b2Body* b = m_world->m_bodyList; b; b = b->m_next)
{
for (b2Shape* s = b->m_shapeList; s; s = s->m_next)
{
if (b->IsStatic())
{
DrawShape(s, Color(0.5f, 0.9f, 0.5f));
}
else if (b->IsSleeping())
{
DrawShape(s, Color(0.5f, 0.5f, 0.9f));
}
else if (b == m_bomb)
{
DrawShape(s, Color(0.9f, 0.9f, 0.4f));
}
else
{
DrawShape(s, Color(0.9f, 0.9f, 0.9f));
}
}
}
for (b2Joint* j = m_world->m_jointList; j; j = j->m_next)
{
if (j != m_mouseJoint)
{
DrawJoint(j);
}
}
if (settings->drawContacts)
{
for (b2Contact* c = m_world->m_contactList; c; c = c->m_next)
{
b2Manifold* ms = c->GetManifolds();
for (int32 i = 0; i < c->GetManifoldCount(); ++i)
{
b2Manifold* m = ms + i;
glPointSize(4.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
for (int j = 0; j < m->pointCount; ++j)
{
b2Vec2 v = m->points[j].position;
glVertex2f(v.x, v.y);
}
glEnd();
glPointSize(1.0f);
}
}
}
if (settings->drawImpulses)
{
for (b2Contact* c = m_world->m_contactList; c; c = c->m_next)
{
b2Manifold* ms = c->GetManifolds();
for (int32 i = 0; i < c->GetManifoldCount(); ++i)
{
b2Manifold* m = ms + i;
glColor3f(0.9f, 0.9f, 0.3f);
glBegin(GL_LINES);
for (int32 j = 0; j < m->pointCount; ++j)
{
b2Vec2 v1 = m->points[j].position;
b2Vec2 v2 = v1 + m->points[j].normalImpulse * m->normal;
glVertex2f(v1.x, v1.y);
glVertex2f(v2.x, v2.y);
}
glEnd();
}
}
}
if (settings->drawPairs)
{
b2BroadPhase* bp = m_world->m_broadPhase;
b2Vec2 invQ;
invQ.Set(1.0f / bp->m_quantizationFactor.x, 1.0f / bp->m_quantizationFactor.y);
glColor3f(0.9f, 0.9f, 0.3f);
glBegin(GL_LINES);
for (int32 i = 0; i < bp->m_pairManager.m_pairCount; ++i)
{
b2Pair* pair = bp->m_pairManager.m_pairs + i;
uint16 id1 = pair->proxyId1;
uint16 id2 = pair->proxyId2;
b2Proxy* p1 = bp->m_proxyPool + id1;
b2Proxy* p2 = bp->m_proxyPool + id2;
b2AABB b1, b2;
b1.minVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p1->lowerBounds[0]].value;
b1.minVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p1->lowerBounds[1]].value;
b1.maxVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p1->upperBounds[0]].value;
b1.maxVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p1->upperBounds[1]].value;
b2.minVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p2->lowerBounds[0]].value;
b2.minVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p2->lowerBounds[1]].value;
b2.maxVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p2->upperBounds[0]].value;
b2.maxVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p2->upperBounds[1]].value;
b2Vec2 x1 = 0.5f * (b1.minVertex + b1.maxVertex);
b2Vec2 x2 = 0.5f * (b2.minVertex + b2.maxVertex);
glVertex2f(x1.x, x1.y);
glVertex2f(x2.x, x2.y);
}
glEnd();
}
if (settings->drawAABBs)
{
b2BroadPhase* bp = m_world->m_broadPhase;
b2Vec2 invQ;
invQ.Set(1.0f / bp->m_quantizationFactor.x, 1.0f / bp->m_quantizationFactor.y);
glColor3f(0.9f, 0.3f, 0.9f);
for (int32 i = 0; i < b2_maxProxies; ++i)
{
b2Proxy* p = bp->m_proxyPool + i;
if (p->IsValid() == false)
{
continue;
}
b2AABB b;
b.minVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p->lowerBounds[0]].value;
b.minVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p->lowerBounds[1]].value;
b.maxVertex.x = bp->m_worldAABB.minVertex.x + invQ.x * bp->m_bounds[0][p->upperBounds[0]].value;
b.maxVertex.y = bp->m_worldAABB.minVertex.y + invQ.y * bp->m_bounds[1][p->upperBounds[1]].value;
glBegin(GL_LINE_LOOP);
glVertex2f(b.minVertex.x, b.minVertex.y);
glVertex2f(b.maxVertex.x, b.minVertex.y);
glVertex2f(b.maxVertex.x, b.maxVertex.y);
glVertex2f(b.minVertex.x, b.maxVertex.y);
glEnd();
}
}
if (settings->drawStats)
{
DrawString(5, m_textLine, "proxies(max) = %d(%d), pairs(max) = %d(%d)",
m_world->m_broadPhase->m_proxyCount, b2_maxProxies,
m_world->m_broadPhase->m_pairManager.m_pairCount, b2_maxPairs);
m_textLine += 15;
DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d",
m_world->m_bodyCount, m_world->m_contactCount, m_world->m_jointCount);
m_textLine += 15;
}
if (m_mouseJoint)
{
b2Body* body = m_mouseJoint->m_body2;
b2Vec2 p1 = body->m_position + b2Mul(body->m_R, m_mouseJoint->m_localAnchor);
b2Vec2 p2 = m_mouseJoint->m_target;
glPointSize(4.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_POINTS);
glVertex2f(p1.x, p1.y);
glVertex2f(p2.x, p2.y);
glEnd();
glPointSize(1.0f);
glColor3f(0.8f, 0.8f, 0.8f);
glBegin(GL_LINES);
glVertex2f(p1.x, p1.y);
glVertex2f(p2.x, p2.y);
glEnd();
}
*/
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 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.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef TEST_H
#define TEST_H
class Test;
struct Settings;
#include <stdarg.h>
typedef Test* TestCreateFcn();
struct Settings
{
Settings() :
hz(60.0f),
iterationCount(10),
drawStats(0),
drawContacts(0),
drawImpulses(0),
drawAABBs(0),
drawPairs(0),
enableWarmStarting(1),
enablePositionCorrection(1),
pause(0)
{}
float hz;
int iterationCount;
int drawStats;
int drawContacts;
int drawImpulses;
int drawAABBs;
int drawPairs;
int enableWarmStarting;
int enablePositionCorrection;
int pause;
};
struct TestEntry
{
const char *name;
TestCreateFcn *createFcn;
};
extern TestEntry g_testEntries[];
class Test
{
public:
Test();
virtual ~Test();
void SetTextLine(int line) { m_textLine = line; }
virtual void Step(const Settings* settings);
virtual void Keyboard(unsigned char key) {
}
// void MouseDown(const b2Vec2& p);
void MouseUp();
// void MouseMove(const b2Vec2& p);
void LaunchBomb();
protected:
int m_textLine;
// b2World* m_world;
// b2Body* m_bomb;
// b2MouseJoint* m_mouseJoint;
};
#endif

21
Examples/TestBed/Jamfile Normal file
View File

@@ -0,0 +1,21 @@
SubDir TOP Examples TestBed ;
if $(GLUT.AVAILABLE) = "yes"
{
# All demo apps have a lot in common, so use this rule to simply things
rule BulletDemo
{
Application $(<) : $(>) : noinstall console nomanifest ;
LinkWith $(<) : Tests bulletdynamics bulletcollision bulletmath glui ;
CFlags $(<) :
[ FIncludes $(TOP)/Extras ]
;
MsvcIncDirs $(<) :
"../../Extras"
"../../src" ;
}
}
SubInclude TOP Examples TestBed FrameWork ;
SubInclude TOP Examples TestBed Tests ;

View File

@@ -0,0 +1,20 @@
#ifndef COLLISION_PROCESSING_H
#define COLLISION_PROCESSING_H
#include "../FrameWork/Test.h"
class CollisionProcessing : public Test
{
public:
void Step(Settings* settings)
{
}
static Test* Create()
{
return new CollisionProcessing;
}
};
#endif //

View File

@@ -0,0 +1,18 @@
SubDir TOP Examples TestBed Tests ;
if $(GLUT.AVAILABLE) = "yes"
{
Description Tests : "Bullet Tests" ;
Library Tests :
[ Wildcard *.h *.cpp ] : noinstall
;
CFlags Tests :
;
LibDepends Tests : bulletdynamics ;
ExternalLibs Tests : GLUT ;
}

View File

@@ -0,0 +1,10 @@
#include "../FrameWork/Test.h"
#include "CollisionProcessing.h"
TestEntry g_testEntries[] =
{
{"Collision Processing", CollisionProcessing::Create}
};

View File

@@ -14,5 +14,5 @@ CFlags glui :
LibDepends glui : ;
ExternalLibs bulletopenglsupport : GLUT ;
ExternalLibs glui : GLUT ;
}

View File

@@ -20,7 +20,7 @@ subject to the following restrictions:
#include "btCollisionMargin.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
#include "LinearMath/btPoint3.h"
#include "LinearMath/btSimdMinMax.h"
#include "LinearMath/btMinMax.h"
///btBoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box
class btBoxShape: public btPolyhedralConvexShape

View File

@@ -192,8 +192,8 @@ btScalar resolveSingleFriction(
j1 = -vrel * cpd->m_jacDiagABInvTangent0;
btScalar oldTangentImpulse = cpd->m_accumulatedTangentImpulse0;
cpd->m_accumulatedTangentImpulse0 = oldTangentImpulse + j1;
GEN_set_min(cpd->m_accumulatedTangentImpulse0, limit);
GEN_set_max(cpd->m_accumulatedTangentImpulse0, -limit);
btSetMin(cpd->m_accumulatedTangentImpulse0, limit);
btSetMax(cpd->m_accumulatedTangentImpulse0, -limit);
j1 = cpd->m_accumulatedTangentImpulse0 - oldTangentImpulse;
}
@@ -206,8 +206,8 @@ btScalar resolveSingleFriction(
j2 = -vrel * cpd->m_jacDiagABInvTangent1;
btScalar oldTangentImpulse = cpd->m_accumulatedTangentImpulse1;
cpd->m_accumulatedTangentImpulse1 = oldTangentImpulse + j2;
GEN_set_min(cpd->m_accumulatedTangentImpulse1, limit);
GEN_set_max(cpd->m_accumulatedTangentImpulse1, -limit);
btSetMin(cpd->m_accumulatedTangentImpulse1, limit);
btSetMax(cpd->m_accumulatedTangentImpulse1, -limit);
j2 = cpd->m_accumulatedTangentImpulse1 - oldTangentImpulse;
}
@@ -270,8 +270,8 @@ btScalar resolveSingleFrictionOriginal(
// calculate j that moves us to zero relative velocity
btScalar j = -vrel * cpd->m_jacDiagABInvTangent0;
btScalar total = cpd->m_accumulatedTangentImpulse0 + j;
GEN_set_min(total, limit);
GEN_set_max(total, -limit);
btSetMin(total, limit);
btSetMax(total, -limit);
j = total - cpd->m_accumulatedTangentImpulse0;
cpd->m_accumulatedTangentImpulse0 = total;
body1.applyImpulse(j * cpd->m_frictionWorldTangential0, rel_pos1);
@@ -290,8 +290,8 @@ btScalar resolveSingleFrictionOriginal(
// calculate j that moves us to zero relative velocity
btScalar j = -vrel * cpd->m_jacDiagABInvTangent1;
btScalar total = cpd->m_accumulatedTangentImpulse1 + j;
GEN_set_min(total, limit);
GEN_set_max(total, -limit);
btSetMin(total, limit);
btSetMax(total, -limit);
j = total - cpd->m_accumulatedTangentImpulse1;
cpd->m_accumulatedTangentImpulse1 = total;
body1.applyImpulse(j * cpd->m_frictionWorldTangential1, rel_pos1);
@@ -388,8 +388,8 @@ btScalar resolveSingleCollisionCombined(
(body1.getInvMass() + body2.getInvMass() + lat_vel.dot(temp1.cross(rel_pos1) + temp2.cross(rel_pos2)));
btScalar normal_impulse = cpd->m_appliedImpulse * combinedFriction;
GEN_set_min(friction_impulse, normal_impulse);
GEN_set_max(friction_impulse, -normal_impulse);
btSetMin(friction_impulse, normal_impulse);
btSetMax(friction_impulse, -normal_impulse);
body1.applyImpulse(lat_vel * -friction_impulse, rel_pos1);
body2.applyImpulse(lat_vel * friction_impulse, rel_pos2);
}

View File

@@ -508,8 +508,8 @@ btScalar calcRollingFriction(btWheelContactPoint& contactPoint)
// calculate j that moves us to zero relative velocity
j1 = -vrel * contactPoint.m_jacDiagABInv;
GEN_set_min(j1, maxImpulse);
GEN_set_max(j1, -maxImpulse);
btSetMin(j1, maxImpulse);
btSetMax(j1, -maxImpulse);
return j1;
}

View File

@@ -18,11 +18,9 @@ subject to the following restrictions:
#define AABB_UTIL2
#include "btVector3.h"
#include "btSimdMinMax.h"
#include "btMinMax.h"
#define btMin(a,b) ((a < b ? a : b))
#define btMax(a,b) ((a > b ? a : b))
/// conservative test for overlap between two aabbs

View File

@@ -18,15 +18,15 @@ subject to the following restrictions:
#define GEN_MINMAX_H
template <class T>
SIMD_FORCE_INLINE const T& GEN_min(const T& a, const T& b)
SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b)
{
return b < a ? b : a;
return a < b ? a : b ;
}
template <class T>
SIMD_FORCE_INLINE const T& GEN_max(const T& a, const T& b)
SIMD_FORCE_INLINE const T& btMax(const T& a, const T& b)
{
return a < b ? b : a;
return a > b ? a : b;
}
template <class T>
@@ -36,7 +36,7 @@ SIMD_FORCE_INLINE const T& GEN_clamped(const T& a, const T& lb, const T& ub)
}
template <class T>
SIMD_FORCE_INLINE void GEN_set_min(T& a, const T& b)
SIMD_FORCE_INLINE void btSetMin(T& a, const T& b)
{
if (b < a)
{
@@ -45,7 +45,7 @@ SIMD_FORCE_INLINE void GEN_set_min(T& a, const T& b)
}
template <class T>
SIMD_FORCE_INLINE void GEN_set_max(T& a, const T& b)
SIMD_FORCE_INLINE void btSetMax(T& a, const T& b)
{
if (a < b)
{

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#define SIMD_QUADWORD_H
#include "btScalar.h"
#include "btSimdMinMax.h"
#include "btMinMax.h"
//ATTRIBUTE_ALIGNED16(class) btQuadWordStorage
//some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. todo: look into this

View File

@@ -1,76 +0,0 @@
/*
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SIMD_MINMAX_H
#define SIMD_MINMAX_H
#include "btScalar.h"
template <class T>
SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) {
return b < a ? b : a;
}
template <class T>
SIMD_FORCE_INLINE const T& btMax(const T& a, const T& b) {
return a < b ? b : a;
}
template <class T>
SIMD_FORCE_INLINE void btSetMin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
SIMD_FORCE_INLINE void btSetMax(T& a, const T& b) {
if (a < b) a = b;
}
// Specialize on float/double for platforms that have btFsel natively
#ifdef BT_HAVE_NATIVE_FSEL
SIMD_FORCE_INLINE float btMin( float a, float b) {
return (float)btFsel((a-b), b, a);
}
SIMD_FORCE_INLINE float btMax( float a, float b) {
return (float)btFsel((a-b), a, b);
}
SIMD_FORCE_INLINE void btSetMin(float& a, float b) {
a = (float)btFsel((a-b), b, a);
}
SIMD_FORCE_INLINE void btSetMax(float& a, float b) {
a = (float)btFsel((a-b), a, b);
}
SIMD_FORCE_INLINE double btMin( double a, double b) {
return btFsel((a-b), b, a);
}
SIMD_FORCE_INLINE double btMax( double a, double b) {
return btFsel((a-b), a, b);
}
SIMD_FORCE_INLINE void btSetMin(double& a, double b) {
a = btFsel((a-b), b, a);
}
SIMD_FORCE_INLINE void btSetMax(double& a, double b) {
a = btFsel((a-b), a, b);
}
#endif
#endif