[Teleus-cvs] teleus/src/game game.cpp,1.17,1.18 game.hpp,1.4,1.5
Status: Inactive
Brought to you by:
spiffgq
|
From: Daniel R. <sp...@us...> - 2004-05-25 21:12:52
|
Update of /cvsroot/teleus/teleus/src/game In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29132/src/game Modified Files: game.cpp game.hpp Log Message: All kinds of changes to test the updates in other files (math::mass comes to mind). Index: game.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/game/game.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** game.hpp 22 Feb 2004 00:42:26 -0000 1.4 --- game.hpp 25 May 2004 21:12:40 -0000 1.5 *************** *** 37,40 **** --- 37,41 ---- void initFonts (); bool getInput(); + bool checkCollisions(double secondsPerFrame, double coeffRest); Index: game.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/game/game.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** game.cpp 11 Mar 2004 03:08:42 -0000 1.17 --- game.cpp 25 May 2004 21:12:40 -0000 1.18 *************** *** 2,6 **** * Teleus Space Combat Simulator * Copyright 2004 Daniel Royer ! * sp...@us... * http://teleus.sf.net * --- 2,6 ---- * Teleus Space Combat Simulator * Copyright 2004 Daniel Royer ! * sp...@us... * http://teleus.sf.net * *************** *** 8,12 **** * modify it under the terms of the Teleus Artistic License as * detailed on the Teleus website. ! * * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED --- 8,12 ---- * modify it under the terms of the Teleus Artistic License as * detailed on the Teleus website. ! * * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED *************** *** 42,48 **** --- 42,51 ---- #include "obj/ship.hpp" #include "obj/cube.hpp" + #include "obj/sphere.hpp" + #include "obj/collision.hpp" #include "util/timer.hpp" #include "util/log.hpp" #include "util/settings.hpp" + #include "util/debugrecord.hpp" #include "debug.hpp" *************** *** 58,65 **** util::Timer timer; ! const unsigned int NUM_CUBES = 2000; obj::Cube *cubes[NUM_CUBES]; obj::Cube *axes[3]; obj::Cube *lightCube; std::vector<std::pair<obj::Cube*, double> > laserCubes; --- 61,73 ---- util::Timer timer; ! const unsigned int NUM_CUBES = 30; obj::Cube *cubes[NUM_CUBES]; obj::Cube *axes[3]; obj::Cube *lightCube; + obj::Cube *testCube; + obj::Ship *activeObject; + + const unsigned int NUM_SPHERES = 3; + obj::Sphere *spheres[NUM_SPHERES]; std::vector<std::pair<obj::Cube*, double> > laserCubes; *************** *** 80,83 **** --- 88,93 ---- void gameloop (){ + debugrecord::initDebugRecord(); + // TODO: change this to use the Input class *************** *** 117,124 **** --- 127,142 ---- math::ApproxSphere lightSphere (10, 10); math::ApproxSphere worldSphere (12, 12); + math::ApproxSphere testSphere (32, 32); + bool sphereCollide = false; + double coeffRest = util::userSettings->getDoubleSetting ("Coefficient of Restitution", 1.0); + + //double timeStep = 1.0/60.0; + //secondsPerFrame = timeStep; while (!done){ + debugrecord::printf("Starting frame %d (%f seconds in)\n", totalFrames, totalSeconds); + // Check for the escape key // TODO: remove this SDL stuff when Input *************** *** 129,136 **** --- 147,189 ---- if (!firstFrame){ + player->resetForces(); player->updatePhysics (secondsPerFrame); + testCube->resetForces(); + testCube->updatePhysics(secondsPerFrame); + + checkCollisions(secondsPerFrame, coeffRest); + + if (obj::Collision::boundingSphereCheck(*spheres[0], *spheres[1])){ + sphereCollide = true; + + math::Vector3d normalVec = math::direction(spheres[0]->pos(), spheres[1]->pos()); + + math::Vector3d impulseForce = math::impulseForce( + spheres[0]->mass(), /* Body 1 */ + spheres[0]->vel(), /* Body 1 */ + spheres[1]->mass(), /* Body 2 */ + spheres[1]->vel(), /* Body 2 */ + normalVec, /* Normal */ + coeffRest, /* Coefficient of restitution*/ + secondsPerFrame); /* Impact time */ + + spheres[0]->addForceWorld(impulseForce, spheres[0]->pos()); + spheres[1]->addForceWorld(-impulseForce, spheres[1]->pos()); + + }else{ + sphereCollide = false; + } + + for (uint i = 0; i < NUM_SPHERES; ++i){ + spheres[i]->updatePhysics(secondsPerFrame); + spheres[i]->resetForces(); + } + + #if 1 + for (unsigned int i = 0; i < NUM_CUBES; ++i){ cubes[i]->updatePhysics (secondsPerFrame); + cubes[i]->resetForces(); } *************** *** 146,152 **** } } } ! //******************************************************// //* START FRAME RENDERING *// --- 199,206 ---- } } + #endif } ! #if 1 //******************************************************// //* START FRAME RENDERING *// *************** *** 164,171 **** --- 218,227 ---- gfx::renderWireSphere(lightSphere, 3, 0.0, lightPos); + gfx::enableLights(); gfx::modifyLight(gfx::LIGHT_ZERO, gfx::LIGHT_POSITION, lightPos); + #if 1 for (unsigned int i = 0; i < NUM_CUBES; ++i){ gfx::renderCube(cubes[i]); *************** *** 176,179 **** --- 232,251 ---- } + for (uint i = 0; i < NUM_SPHERES; ++i){ + /* + obj::Sphere &s = *spheres[i]; + //gfx::renderSphere(*spheres[i], true); + float pos[4]; + pos[0] = (float)s.pos().v[0]; + pos[1] = (float)s.pos().v[1]; + pos[2] = (float)s.pos().v[2]; + pos[3] = 1.0; + gfx::renderWireSphere(s.geometry(), (unsigned int)s.radius(), 0.0, pos); + */ + gfx::renderSphere(*spheres[i], true); + } + + #endif + gfx::renderCube (axes[0]); gfx::renderCube (axes[1]); *************** *** 190,196 **** gfx::renderWireSphere(worldSphere, 2000, 0.0, NULL); math::Vector3d velPoint, uvsc, nvsc; ! double pgOr, rgOr, orOr; // Calculate the screen coordinates for the prograde --- 262,271 ---- gfx::renderWireSphere(worldSphere, 2000, 0.0, NULL); + //gfx::drawRefGrid(); + gfx::renderCube (testCube); + math::Vector3d velPoint, uvsc, nvsc; ! double pgOr, rgOr, orOr, cubeOr; // Calculate the screen coordinates for the prograde *************** *** 227,230 **** --- 302,322 ---- orOr = math::radiansToDegrees(orOr); + // Calculate the screen coordinates of the test cube object + velPoint = testCube->pos(); + math::Vector3d testCubePoint = gfx::getScreenCoordinates(velPoint); + + // Calculate the angle between the player's forward vector + // and the test cube's location. + cubeOr = math::angle(player->forward(), + math::distance(player->pos(), testCube->pos())); + cubeOr = math::radiansToDegrees(cubeOr); + + + math::Vector3d cubeScrnPos[NUM_CUBES]; + for (uint i = 0; i < NUM_CUBES; ++i){ + velPoint = cubes[i]->pos(); + cubeScrnPos[i] = gfx::getScreenCoordinates(velPoint); + } + gfx::disableLights(); *************** *** 236,239 **** --- 328,335 ---- gfx::enableTextures2D(); + //gfx::renderQuad(550.0, 300.0); + /*math::Vector3d(gfx::screenWidth/2.0, gfx::screenHeight/2.0, 1.0), + math::Vector3d(0.0, gfx::screenHeight, 1.0));*/ + int titleHeight = textFont->baseLineDrop() + 5; *************** *** 246,270 **** } ! float yPos = gfx::screenHeight - 3 * (gfx::screenHeight / 4); ! textFont->printf (10.0f, yPos, "Position: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! player->pos().x, ! player->pos().y, ! player->pos().z, ! player->pos().length()); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Velocity: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! player->vel().x, player->vel().y, ! player->vel().z, player->speed()); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Rotational: <%+0.2f, %+0.2f, %+0.2f>", ! player->rotVel().h, player->rotVel().p, ! player->rotVel().r); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Vector: <%+0.2f, %+0.2f, %+0.2f>", ! player->forward().x, player->forward().y, ! player->forward().z); yPos -= textFont->baseLineDrop() + 3; --- 342,433 ---- } ! ! if (uvsc.z < 1.0 && uvsc.z > 0.0){ ! textFont->printf (uvsc.x, uvsc.y, "o"); ! } ! ! if (nvsc.z < 1.0 && nvsc.z > 0.0){ ! textFont->printf (nvsc.x, nvsc.y, "x"); ! } ! ! if (testCubePoint.z < 1.0 && testCubePoint.z > 0.0){ ! textFont->printf (testCubePoint.x, testCubePoint.y, "TC"); ! } ! ! //math::Vector3d cubeScrnPos[NUM_CUBES]; ! for (uint i = 0; i < NUM_CUBES; ++i){ ! //cubeScrnPos[i] = gfx::getScreenCoordinates (cubes[i]->pos()); ! if (cubeScrnPos[i].z < 1.0 && cubeScrnPos[i].z > 0.0){ ! textFont->printf (cubeScrnPos[i].x, cubeScrnPos[i].y, "%d", i); ! } ! } ! ! ! float yPos = gfx::screenHeight - titleHeight - textFont->baseLineDrop() - 3; //gfx::screenHeight - 3 * (gfx::screenHeight / 4); ! /*textFont->printf (10.0f, yPos, "Main Thrust: %.0f RCS Thrust: R: %.0f; P: %.0f; Y: %.0f", ! activeObject->forwardThrust(), ! activeObject->rollThrust(), ! activeObject->pitchThrust(), ! activeObject->yawThrust()); ! yPos -= textFont->baseLineDrop() + 3;*/ ! ! ! ! textFont->printf (10.0f, yPos, "Active object: %s", activeObject == player?"player":"cube"); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Net External Force: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->netForce().x, ! activeObject->netForce().y, ! activeObject->netForce().z, ! activeObject->netForce().length()); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Velocity: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->vel().x, activeObject->vel().y, ! activeObject->vel().z, activeObject->speed()); yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Position: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->pos().x, ! activeObject->pos().y, ! activeObject->pos().z, ! activeObject->pos().length()); ! yPos -= textFont->baseLineDrop() + 3; ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Net External Torque: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->netTorque().x, ! activeObject->netTorque().y, ! activeObject->netTorque().z, ! activeObject->netTorque().length()); ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Ang Vel: R: %+0.2f; P: %+0.2f; Y: %+0.2f (Mag %+0.2f)", ! activeObject->angVelocity().r, ! activeObject->angVelocity().p, ! activeObject->angVelocity().h, ! activeObject->angVelocity().length()); ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Orientation: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->orientation().x, ! activeObject->orientation().y, ! activeObject->orientation().z, ! activeObject->orientation().length()); ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Quaternion: <%+0.2f, %+0.2f, %+0.2f, %+0.2f> %+0.2f", ! activeObject->rotation().w, ! activeObject->rotation().x, ! activeObject->rotation().y, ! activeObject->rotation().z, ! activeObject->rotation().length()); ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Forward: <%+0.2f, %+0.2f, %+0.2f>", ! activeObject->forward().x, activeObject->forward().y, ! activeObject->forward().z); ! yPos -= textFont->baseLineDrop() + 3; yPos -= textFont->baseLineDrop() + 3; *************** *** 278,291 **** yPos -= textFont->baseLineDrop() + 3; textFont->printf (10.0f, yPos, "Shots alive: %d", laserCubes.size()); yPos -= textFont->baseLineDrop() + 3; ! if (uvsc.z < 1.0 && uvsc.z > 0.0){ ! textFont->printf (uvsc.x, uvsc.y, "o"); ! } - if (nvsc.z < 1.0 && nvsc.z > 0.0){ - textFont->printf (nvsc.x, nvsc.y, "x"); - } gfx::disableTextures2D(); --- 441,549 ---- yPos -= textFont->baseLineDrop() + 3; + textFont->printf (10.0f, yPos, "TCb: %.1f°", cubeOr); + yPos -= textFont->baseLineDrop() + 3; + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Spheres are %s", sphereCollide?"colliding or intersecting":"separate"); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Pos: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[0]->pos().x, + cubes[0]->pos().y, + cubes[0]->pos().z, + cubes[0]->pos().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Vel: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[0]->vel().x, + cubes[0]->vel().y, + cubes[0]->vel().z, + cubes[0]->vel().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Force: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[0]->netForce().x, + cubes[0]->netForce().y, + cubes[0]->netForce().z, + cubes[0]->netForce().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Quaternion: <%+0.2f, %+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[0]->rotation().w, + cubes[0]->rotation().x, + cubes[0]->rotation().y, + cubes[0]->rotation().z, + cubes[0]->rotation().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Ang Vel: R: %+0.2f; P: %+0.2f; Y: %+0.2f (Mag %+0.2f)", + cubes[0]->angVelocity().r, + cubes[0]->angVelocity().p, + cubes[0]->angVelocity().h, + cubes[0]->angVelocity().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 0 Torque: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[0]->netTorque().x, + cubes[0]->netTorque().y, + cubes[0]->netTorque().z, + cubes[0]->netTorque().length()); + yPos -= textFont->baseLineDrop() + 3; + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Pos: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[1]->pos().x, + cubes[1]->pos().y, + cubes[1]->pos().z, + cubes[1]->pos().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Vel: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[1]->vel().x, + cubes[1]->vel().y, + cubes[1]->vel().z, + cubes[1]->vel().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Force: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[1]->netForce().x, + cubes[1]->netForce().y, + cubes[1]->netForce().z, + cubes[1]->netForce().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Quaternion: <%+0.2f, %+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[1]->rotation().w, + cubes[1]->rotation().x, + cubes[1]->rotation().y, + cubes[1]->rotation().z, + cubes[1]->rotation().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Ang Vel: R: %+0.2f; P: %+0.2f; Y: %+0.2f (Mag %+0.2f)", + cubes[1]->angVelocity().r, + cubes[1]->angVelocity().p, + cubes[1]->angVelocity().h, + cubes[1]->angVelocity().length()); + yPos -= textFont->baseLineDrop() + 3; + + textFont->printf (10.0f, yPos, "Sphere 1 Torque: <%+0.2f, %+0.2f, %+0.2f> %+0.2f", + cubes[1]->netTorque().x, + cubes[1]->netTorque().y, + cubes[1]->netTorque().z, + cubes[1]->netTorque().length()); + yPos -= textFont->baseLineDrop() + 3; + /* textFont->printf (10.0f, yPos, "Shots alive: %d", laserCubes.size()); yPos -= textFont->baseLineDrop() + 3; + yPos -= textFont->baseLineDrop() + 3; ! textFont->printf (10.0f, yPos, "Azimuth: %f", math::radiansToDegrees(camera->mAzimuthAngle)); ! yPos -= textFont->baseLineDrop() + 3; ! ! textFont->printf (10.0f, yPos, "Heading: %f", math::radiansToDegrees(camera->mHeadingAngle)); ! yPos -= textFont->baseLineDrop() + 3; ! */ gfx::disableTextures2D(); *************** *** 301,309 **** --- 559,571 ---- gfx::swapBuffer (); + #endif timer.stop(); + //double elapsedTime = timer.getTime(); + //util::Timer::sleep(timeStep - elapsedTime); secondsPerFrame = timer.getTime(); timer.start(); + totalSeconds += secondsPerFrame; totalFrames++; *************** *** 320,323 **** --- 582,586 ---- Log::record ("Exited game loop after %f seconds\n", totalSeconds); Log::record ("Average frame rate: %f fps\n", totalFrames / totalSeconds); + debugrecord::shutdownDebugRecord (); } *************** *** 347,352 **** --- 610,617 ---- SDL_Event event; while (SDL_PollEvent (&event)){ + math::Vector3d thrustForce, thrustLoc; switch (event.type){ case SDL_KEYUP: + debugrecord::keyUp(event.key.keysym.sym); switch (event.key.keysym.sym){ case SDLK_ESCAPE: done = true; break; *************** *** 354,376 **** case SDLK_TAB: case SDLK_z: ! case SDLK_a: player->setForwardThrust (0.0); ! break; case SDLK_DOWN: ! case SDLK_UP: player->setPitchThrust (0.0); ! break; case SDLK_LEFT: ! case SDLK_RIGHT: player->setYawThrust (0.0); ! break; case SDLK_q: ! case SDLK_e: player->setRollThrust (0.0); ! break; case SDLK_0: ! player->killVelocity (); ! break; default: break; } --- 619,649 ---- case SDLK_TAB: case SDLK_z: ! case SDLK_a: activeObject->setForwardThrust (0.0); ! break; case SDLK_DOWN: ! case SDLK_UP: activeObject->setPitchThrust (0.0); ! break; case SDLK_LEFT: ! case SDLK_RIGHT: activeObject->setYawThrust (0.0); ! break; case SDLK_q: ! case SDLK_e: activeObject->setRollThrust (0.0); ! break; case SDLK_0: ! activeObject->killVelocity (); ! break; ! ! case SDLK_t: ! if (activeObject == player){ ! activeObject = testCube; ! }else{ ! activeObject = player; ! } ! break; default: break; } *************** *** 379,410 **** case SDL_KEYDOWN: ! switch (event.key.keysym.sym){ ! case SDLK_a: player->setForwardThrust (1.0); ! break; ! case SDLK_z: player->setForwardThrust (-0.75); ! break; ! case SDLK_TAB: player->setForwardThrust (3.0); ! break; - case SDLK_UP: player->setPitchThrust (-1.0); - break; ! case SDLK_DOWN: player->setPitchThrust (1.0); ! break; ! case SDLK_LEFT: player->setYawThrust (1.0); ! break; ! case SDLK_RIGHT: player->setYawThrust (-1.0); ! break; ! case SDLK_q: player->setRollThrust (-1.0); break; ! case SDLK_e: player->setRollThrust (1.0); ! break; /* case SDLK_SPACE: --- 652,685 ---- case SDL_KEYDOWN: ! debugrecord::keyDown(event.key.keysym.sym); ! switch (event.key.keysym.sym){ ! case SDLK_a: activeObject->setForwardThrust (1.0); ! break; ! case SDLK_z: activeObject->setForwardThrust (-0.75); ! break; + case SDLK_TAB: activeObject->setForwardThrust (3.0); + break; ! case SDLK_UP: activeObject->setPitchThrust (-1.0); ! break; ! case SDLK_DOWN: activeObject->setPitchThrust (1.0); ! break; ! case SDLK_LEFT: activeObject->setYawThrust (-1.0); ! break; ! case SDLK_RIGHT: activeObject->setYawThrust (1.0); break; ! case SDLK_q: activeObject->setRollThrust (-1.0); ! break; ! ! case SDLK_e: activeObject->setRollThrust (1.0); ! break; /* case SDLK_SPACE: *************** *** 427,431 **** unsigned char *keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_SPACE] ){ ! shootCube(*player); } --- 702,706 ---- unsigned char *keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_SPACE] ){ ! //shootCube(*player); } *************** *** 446,460 **** DEBUG_PRINT ("Initializing player object\n"); player = new obj::Ship; ! player->setMass (1000.0); ! player->setBoundingBox (3.0, 7.0, 10.0); ! player->setBoundingSphere (5.0); DEBUG_PRINT ("Generating random cubes\n"); for (uint i = 0; i < NUM_CUBES; ++i){ //DEBUG_PRINT ("\t Generating cube %d\n", i); cubes[i] = obj::Cube::getRandomCube(); } DEBUG_PRINT ("Done generating random cubes\n"); DEBUG_PRINT ("Creating Axis Cubes\n"); --- 721,791 ---- DEBUG_PRINT ("Initializing player object\n"); + { + double mass = util::userSettings->getDoubleSetting ("Player Mass", 1000.0); + double length = util::userSettings->getDoubleSetting ("Player Length", 3.0); + double width = util::userSettings->getDoubleSetting ("Player Width", 7.0); + double height = util::userSettings->getDoubleSetting ("Player Height", 10.0); + double radius = util::userSettings->getDoubleSetting ("Player Radius", 12.6); + math::Vector3d startPos ( + util::userSettings->getDoubleSetting ("Player Pos X", 0.0), + util::userSettings->getDoubleSetting ("Player Pos Y", 0.0), + util::userSettings->getDoubleSetting ("Player Pos Z", 0.0)); + double roll = util::userSettings->getDoubleSetting ("Player Roll", 0.0); + double pitch = util::userSettings->getDoubleSetting ("Player Pitch", 0.0); + double yaw = util::userSettings->getDoubleSetting ("Player Yaw", 0.0); + player = new obj::Ship; ! activeObject = player; ! player->setMass (mass); ! player->setDimensions (length, width, height); ! player->setRadius (radius); ! math::Vector3d moi = math::rectanglePrismMOI(mass, length, width, height); ! player->setInertia(moi.x, moi.y, moi.z); ! player->setPos (startPos); ! player->setRotation(roll, pitch, yaw); ! } ! + { DEBUG_PRINT ("Generating random cubes\n"); + + #if 1 for (uint i = 0; i < NUM_CUBES; ++i){ //DEBUG_PRINT ("\t Generating cube %d\n", i); cubes[i] = obj::Cube::getRandomCube(); + if (i == 1 || i == 16){ + DEBUG_PRINT("Generating Cube %d\n", i); + DEBUG_PRINT("\t Mass = %f\n", cubes[i]->mass()); + DEBUG_PRINT("\t Dim = <w: %f, h: %f, l: %f>\n", cubes[i]->width(), cubes[i]->height(), cubes[i]->length()); + DEBUG_PRINT("\t Pos = <%f ,%f, %f>\n", cubes[i]->pos().x, cubes[i]->pos().y, cubes[i]->pos().z); + DEBUG_PRINT("\t Vel = <%f, %f, %f>\n", cubes[i]->vel().x, cubes[i]->vel().y, cubes[i]->vel().z); + } } + + #else + + + cubes[0] = new obj::Cube (33.852158, 49.578415, 72.558426); + cubes[0]->setPos(math::Vector3d (-182.245306, 425.234981, 47.340701)); + cubes[0]->setVel(math::Vector3d (77.942532, 42.429180, 99.970549)); + cubes[0]->setMass(12177.743947); + math::Vector3d moi = math::rectanglePrismMOI(cubes[0]->mass(), + cubes[0]->width(), cubes[0]->height(), cubes[0]->length()); + cubes[0]->setInertia (moi.x, moi.y, moi.z); + cubes[0]->setColor (gfx::Color3f (1.0, 0.0, 0.0)); + + cubes[1] = new obj::Cube (46.640263, 65.248253, 32.662235); + cubes[1]->setPos(math::Vector3d (-80.855301, 588.687454, 346.158765)); + cubes[1]->setVel(math::Vector3d (80.984930, 10.641954, 14.499654)); + cubes[1]->setMass(9939.756969); + moi = math::rectanglePrismMOI(cubes[1]->mass(), + cubes[1]->width(), cubes[1]->height(), cubes[1]->length()); + cubes[1]->setInertia (moi.x, moi.y, moi.z); + cubes[1]->setColor (gfx::Color3f (1.0, 1.0, 0.0)); + + #endif + DEBUG_PRINT ("Done generating random cubes\n"); + } DEBUG_PRINT ("Creating Axis Cubes\n"); *************** *** 471,475 **** --- 802,908 ---- DEBUG_PRINT ("Done creating axis cubes\n"); + DEBUG_PRINT ("Creating test cube\n"); + + testCube = new obj::Cube (3.0, 7.0, 10.0); + testCube->setColor (gfx::Color3f(1.0f, 1.0f, 0.0f)); + testCube->setMass (1000.0); + testCube->setDimensions (3.0, 7.0, 10.0); + testCube->setRadius (12.6); + math::Vector3d moi = math::rectanglePrismMOI(1000.0, 7.0, 10.0, 3.0); + testCube->setInertia(moi.x, moi.y, moi.z); + + DEBUG_PRINT ("Done creating test cube\n"); + + { + DEBUG_PRINT ("Creating test spheres\n"); + + double radius = util::userSettings->getDoubleSetting ("Sphere 0 Radius", 50.0); + math::Vector3d startPos ( + util::userSettings->getDoubleSetting ("Sphere 0 Pos X", 200.0), + util::userSettings->getDoubleSetting ("Sphere 0 Pos Y", 0.0), + util::userSettings->getDoubleSetting ("Sphere 0 Pos Z", 0.0)); + math::Vector3d startVel ( + util::userSettings->getDoubleSetting ("Sphere 0 Vel X", -70.0), + util::userSettings->getDoubleSetting ("Sphere 0 Vel Y", 0.0), + util::userSettings->getDoubleSetting ("Sphere 0 Vel Z", 0.0)); + double mass = util::userSettings->getDoubleSetting ("Sphere 0 Mass", math::volSphere(radius) * 1000.0); + spheres[0] = new obj::Sphere (radius, gfx::Color3f(1.0, 0.0, 0.0), startPos, startVel); + spheres[0]->setMass(mass); + + radius = util::userSettings->getDoubleSetting ("Sphere 1 Radius", 50.0); + startPos = math::Vector3d( + util::userSettings->getDoubleSetting ("Sphere 1 Pos X", -200.0), + util::userSettings->getDoubleSetting ("Sphere 1 Pos Y", 0.0), + util::userSettings->getDoubleSetting ("Sphere 1 Pos Z", 0.0)); + startVel = math::Vector3d( + util::userSettings->getDoubleSetting ("Sphere 1 Vel X", 70.0), + util::userSettings->getDoubleSetting ("Sphere 1 Vel Y", 0.0), + util::userSettings->getDoubleSetting ("Sphere 1 Vel Z", 0.0)); + mass = util::userSettings->getDoubleSetting ("Sphere 1 Mass", math::volSphere(radius) * 1000.0); + + spheres[1] = new obj::Sphere (radius, gfx::Color3f(1.0, 1.0, 0.0), startPos, startVel); + spheres[1]->setMass(mass); + + spheres[2] = new obj::Sphere (110.0, gfx::Color3f(0.0, 0.0, 1.0), + math::Vector3d( 500.0, 500.0, 500.0), + math::Vector3d(0.0, 0.0, 0.0)); + spheres[2]->setMass(math::volSphere(110.0) * 1000.0); + + DEBUG_PRINT ("Done creating test spheres\n"); + } + } + + bool checkCollisions(double secondsPerFrame, double coeffRest) { + + bool cd = false; + + for (uint i = 0; i < NUM_CUBES; ++i){ + for (uint j = i+1; j < NUM_CUBES; ++j){ + + assert (i != j, "Checking for collision with self"); + + if (obj::Collision::boundingSphereCheck(*cubes[i], *cubes[j])){ + + cd = true; + + if (i == 1 || j == 1){ + DEBUG_PRINT ("6 in collision (i == %d; j == %d)\n", i, j); + DEBUG_PRINT ("\t %d) Radius = %f; Pos = <%f, %f, %f> (%f)\n", i, + cubes[i]->radius(), + cubes[i]->pos().x, + cubes[i]->pos().y, + cubes[i]->pos().z, + cubes[i]->pos().length()); + + DEBUG_PRINT ("\t %d) Radius = %f; Pos = <%f, %f, %f> (%f)\n", j, + cubes[j]->radius(), + cubes[j]->pos().x, + cubes[j]->pos().y, + cubes[j]->pos().z, + cubes[j]->pos().length()); + + DEBUG_PRINT ("\t Distance between the two is %f\n", + math::distance(cubes[i]->pos(), cubes[j]->pos()).length()); + } + + math::Vector3d normalVec = math::direction(cubes[i]->pos(), cubes[j]->pos()); + math::Vector3d impulseForce = math::impulseForce( + cubes[i]->mass(), /* Body 1 */ + cubes[i]->vel(), /* Body 1 */ + cubes[j]->mass(), /* Body 2 */ + cubes[j]->vel(), /* Body 2 */ + normalVec, /* Normal */ + coeffRest, /* Coefficient of restitution*/ + secondsPerFrame); /* Impact time */ + + cubes[i]->addForceWorld(impulseForce, cubes[i]->pos()); + cubes[j]->addForceWorld(-impulseForce, cubes[j]->pos()); + + } + } + } + + return cd; } |