I made some progress with the development of the game, designing the game scene. The game is now called 'Unbiased Truck Soccer': there are two 'cars' which have to bump a ball into the goal of the adversary. This is an image of the game (WIP):
And a video:
http://www.youtube.com/watch?v=SLq4_zOUjO4 (it renders very slowly on my underpowered GPU, but it should run fluently on recent GPUs).
If you have a CUDA enabled GPU, you can also try a little executable demo that you can download from
http://code.google.com/p/tokap-the-once ... loads/list
However, I'm still stuck with the integration of Bullet into the renderer (which is an open source CUDA ray tracer). Please keep in mind that I have very little programming experience (I've recently started learning C++ though). Below is some code from the main file ("tokaspt.cc"). I tried integrating the 'Hello World' example. The engine is rendering an empty room with a ball that is falling down and I'm using the y-position of the ball in the Hello World example to update the position of the rendered ball ('ballYpos' in another file called "gl_scene.cc"), but without success. The project is linking and compiling without errors, but when I start the exe, the console first shows a list of the sphere heights (going from 50 to 0) and than starts rendering the scene with the ball remaining at sphere height 0. So the ball is falling correctly, but the physics simulation ends before the rendering process starts. How should I make the physics run simultaneously with the rendering and update the sphere position? I would greatly appreciate any help. (I have also attached the relevant source code files if someone wants to take a closer look.)
Code: Select all
int main(int argc, char *argv[]) {
const char title[] = "the once known as pong with Bullet!";
//FIXME: both CUDA and GLUT want to parse that command line, find a way to gracefuly integrate it all.
int w = window_width, h = window_height;
const char *filename = "default.scene";
for (int i=1; i<argc; ++i)
if (argv[i][0] == '-')
switch(argv[i][1]) {
case 'w': if (++i < argc) w = std::atoi(argv[i]); break;
case 'h': if (++i < argc) h = std::atoi(argv[i]); break;
default: // assume it's some argument for cuda/glut, skip
++i;
}
else
filename = argv[i];
{ // CUDA setup.
CUT_DEVICE_INIT(argc, argv);
int dev;
cudaGetDevice(&dev);
cudaDeviceProp prop;
misc::wipe(prop);
cudaGetDeviceProperties(&prop, dev);
if (prop.major == 9999 && prop.minor == 9999)
fatal("no CUDA support?!");
// HACK: Useful place to play with some render params
misc::wipe(params);
params.framebuffer = 0;
params.gamma = 2.2;
params.is_progressive = false;
params.max_paths = 3;
params.num_spheres = 0;
params.pass = 0;
params.regs_per_block = prop.regsPerBlock;
params.spp = SS*SS;
params.verbose = true;
}
{ // OpenGL / GLUT setup
glutInit(&argc, argv);
glutInitDisplayString(glut_init_display_string);
glutInitWindowSize(w, h);
glutCreateWindow(title);
{
int doublebuffer = glutGet(GLUT_WINDOW_DOUBLEBUFFER);
int depth = glutGet(GLUT_WINDOW_DEPTH_SIZE);
int multi = glutGet(GLUT_WINDOW_NUM_SAMPLES);
printf("glut: doublebuffer %s depth bits %d multisamples %d\n", doublebuffer ? "yes" : "no", depth, multi);
int ms_buf, ms;
glGetIntegerv (GL_SAMPLE_BUFFERS_ARB, &ms_buf);
glGetIntegerv (GL_SAMPLES_ARB, &ms);
printf("OpenGl: %d sample buffers, %d samples.\n", ms_buf, ms);
}
// initialize necessary OpenGL extensions
glewInit();
if (!glewIsSupported("GL_VERSION_2_0 GL_ARB_pixel_buffer_object GL_EXT_framebuffer_object"))
fatal("missing OpenGL 2.0+PBO+FBO");
ui::init();
gl::init(point_t(w, h), filename);
// register callbacks
glutDisplayFunc(display);
glutKeyboardFunc(keyboard_regular<1>);
glutKeyboardUpFunc(keyboard_regular<0>);
glutSpecialFunc(keyboard_special<1>);
glutSpecialUpFunc(keyboard_special<0>);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIgnoreKeyRepeat(true);
}
{
// Initialize bullet, this is the 'Hello World' example from Wiki
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-2,0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btCollisionShape* fallShape = new btSphereShape(1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btDefaultMotionState* fallMotionState =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
for (int i=0 ; i<300 ; i++)
{
dynamicsWorld->stepSimulation(1/60.f,10);
btTransform trans;
fallRigidBody->getMotionState()->getWorldTransform(trans);
ballYpos = trans.getOrigin().getY();
std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
}
glutMainLoop();
dynamicsWorld->removeRigidBody(fallRigidBody);
delete fallRigidBody->getMotionState();
delete fallRigidBody;
dynamicsWorld->removeRigidBody(groundRigidBody);
delete groundRigidBody->getMotionState();
delete groundRigidBody;
delete fallShape;
delete groundShape;
delete dynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
}
//glutMainLoop();
return -1;
}
You do not have the required permissions to view the files attached to this post.