void ClusterBomb::explode() { #ifdef DEBUG // printf("ClusterBomb just exploded!\n"); #endif WorldObject * wo; float angle = 6.28318 / BOMB_PIECES; Vector a = Vector(1, 0, 0); Vector b = Vector(0, 0, 1); Vector c = Vector(0, .1, 0); float mag = global::factory->getBlueprint(type).getSize().mag() / 4; Vector off; for (int i = 0; i < BOMB_PIECES; i++) { wo = new WorldObject(0, 0, DUMMY_SPHERE); off = a * mag * sin(i * angle) + b * mag * cos(i * angle) + c; wo->setPosition(position + off); wo->setVelocity(velocity + off); networkManager->network->getPhysicsPtr()->insertWorldObject(wo); wo = new WorldObject(0, 0, DUMMY_SPHERE); off = a * mag * cos(i * angle) + b * mag * sin(i * angle) - c; wo->setPosition(position + off); wo->setVelocity(velocity + off); networkManager->network->getPhysicsPtr()->insertWorldObject(wo); } }
int init_resources(void) { try{ player.moveLeft(9); player.moveForward(7); player.rotateX(-M_PI*3/4); player.rotateY(M_PI/12); player.addForce(gravity*-1); player.loadObj("crazy.o"); cube.loadObj("cube.o"); cube2.loadObj("cube.o"); setupBuffers(player); setupBuffers(cube); setupBuffers(cube2); addObjectToShader(&cube); addObjectToShader(&cube2); bool c1 = cube.loadShaders(vertexShaderFileName, fragmentShaderFileName), c2 = cube2.loadShaders(vertexShaderFileName, fragmentShaderFileName); Vector3 pos = cube2.getPosition()+ Vector3(0.5f, 3.5f, 1.5f); cube2.setPosition(pos); //cube2.setRotation(Vector3(30*M_PI/180, 0, 40*M_PI/180)); return c1 * c2; }catch(int i){ return 0; } }
void idle() { keyboardEvent(); int time_ = glutGet(GLUT_ELAPSED_TIME); float angle = time_ / 1000.0 * 10; Vector3 pos = player.getPosition(); float angX = player.getRotationX(), angY = player.getRotationY(); Vector3 cpos = cube.getPosition(), cpos2= cube2.getPosition(); GLfloat D = cpos.distance(&cpos2), W = (cube.dimension() + cube2.dimension())/2; float bound = 6.0; //if(time_%100 < 10) // gravity = Vector3(rand()%10-5, rand()%10-5, rand()%10-5); cvelocity.add(&gravity); Vector3 s = cvelocity; s.mult(-mass/1000).add(&cpos2); bool collides = true; if(cpos2.x < -bound && cvelocity.x > 0.0f){ cvelocity.x = -abs(cvelocity.x)*0.5; gravity.x = -abs(gravity.x); } else if(cpos2.x > bound && cvelocity.x < 0.0f){ cvelocity.x = abs(cvelocity.x)*0.5; gravity.x = abs(gravity.x); } else if(cpos2.y < -bound && cvelocity.y > 0.0f){ cvelocity.y = -abs(cvelocity.y)*0.5; gravity.y = -abs(gravity.y); } else if(cpos2.y > bound && cvelocity.y < 0.0f){ cvelocity.y = abs(cvelocity.y)*0.5; gravity.y = abs(gravity.y); } else if(cpos2.z < -bound && cvelocity.z > 0.0f){ cvelocity.z = -abs(cvelocity.z)*0.5; gravity.z = -abs(gravity.z); } else if(cpos2.z > bound && cvelocity.z < 0.0f){ cvelocity.z = abs(cvelocity.z)*0.5; gravity.z = abs(gravity.z); } else{ collides = false; } if(!collides){ if(cpos.x + cube.min.x <= cpos2.x + cube2.max.x && cpos.x + cube.max.x >= cpos2.x + cube2.min.x && cpos.z + cube.min.z <= cpos2.z + cube2.max.z && cpos.z + cube.max.z >= cpos2.z + cube2.min.z && cpos.y + cube.min.y <= cpos2.y + cube2.max.y && cpos.y + cube.max.y >= cpos2.y + cube2.min.y){ collides = true; cvelocity.x = cvelocity.y = cvelocity.z = 0.0f; } if(!collides) cube2.setPosition(s); } player.updateForce(); for (int i = 0; i < BALLS; i++){ balls[i].updateForce(); Vector3 ball_pos = balls[i].getPosition(), ball_vel = balls[i].dynamics.velocity; //printf("x: %f, y: %f, z %f: %f\n", ball_pos.x, ball_pos.y, ball_pos.z, BOUNDARY); if(ball_pos.x < -BOUNDARY || ball_pos.x > BOUNDARY) balls[i].addVelocity(Vector3(-2 * ball_vel.x, 0.0f, 0.0f)); if(ball_pos.y < -BOUNDARY || ball_pos.y > BOUNDARY) balls[i].addVelocity(Vector3(0.0f, -2 * ball_vel.y, 0.0f)); if(ball_pos.z < -BOUNDARY || ball_pos.z > BOUNDARY) balls[i].addVelocity(Vector3(0.0f, 0.0f, -2 * ball_vel.z)); } Matrix4 model = cube.getTransformMatrix(), model2 = cube2.getTransformMatrix(); Matrix4 projection = Matrix4().Perspective(45.0f, 1.0f*screen_width/screen_height, 0.1f, 50.0f), view = Matrix4().lookAt(pos, Vector3(pos.x-cos(angX), pos.y + sin(angY), pos.z + sin(angX)), Vector3(0.0f, 1.0f, 0.0f)); Matrix4 anim = Matrix4().RotateA(angle*3.0f, Vector3(1, 0, 0)) * // X axis Matrix4().RotateA(angle*2.0f, Vector3(0, 1, 0)) * // Y axis Matrix4().RotateA(angle*4.0f, Vector3(0, 0, 1)); // Z axis Matrix4 m_transform = projection * view; glUseProgram(cube.getProgram()); glUniformMatrix4fv(cube.getUniform("m_transform"), 1, GL_FALSE, m_transform * model); glUseProgram(cube2.getProgram()); glUniformMatrix4fv(cube2.getUniform("m_transform"), 1, GL_FALSE, m_transform * model2); for (int i = 0; i < BALLS; i++){ glUseProgram(balls[i].getProgram()); glUniformMatrix4fv( balls[i].getUniform("m_transform"), // m_transform is the transformation of balls[i] in shaders 1, // one uniform-buffer GL_FALSE, // no nprmalization m_transform * balls[i].getTransformMatrix() ); } for (int i = 0; i < DETAIL_GRID*3; i++){ grid[i].updateForce(); glUseProgram(grid[i].getProgram()); glUniformMatrix4fv( grid[i].getUniform("m_transform"), // m_transform is the transformation of grid[i] in shaders 1, // one uniform-buffer GL_FALSE, // no nprmalization m_transform * grid[i].getTransformMatrix() ); } glutPostRedisplay(); }
int init_resources(void) { try{ player.moveLeft(9); player.moveForward(7); player.rotateX(-M_PI*3/4); player.rotateY(M_PI/12); player.addForce(gravity*-1); player.loadObj("crazy.o"); cube.loadObj("cube.o"); cube2.loadObj("cube.o"); setupBuffers(player); setupBuffers(cube); setupBuffers(cube2); addObjectToShader(&cube); addObjectToShader(&cube2); bool c1 = cube.loadShaders(vertexShaderFileName, fragmentShaderFileName), c2 = cube2.loadShaders(vertexShaderFileName, fragmentShaderFileName), c3 = 1; for(int i=0; i< BALLS; i++){ balls[i].loadObj("crazy.o"); balls[i].setScale(Vector3(0.25f,0.25f,0.25f)); setupBuffers(balls[i]); addObjectToShader(&(balls[i])); c3 *= balls[i].loadShaders(vertexShaderFileName, fragmentShaderFileName); balls[i].addVelocity(Vector3(m_rand()-0.5f, m_rand()-0.5f, m_rand()-0.5f).normalize().mult(60.0)); } GLfloat scale_grid = ((GLfloat)DETAIL_GRID*2.0f)/((GLfloat)BOUNDARY); for(int i=0; i< DETAIL_GRID; i++){ for(int j = 0;j < DETAIL_GRID; j++){ grid[i].loadObj("cube.o"); grid[i].setScale(Vector3(scale_grid, scale_grid, scale_grid)); setupBuffers(grid[i]); addObjectToShader(&(grid[i])); c3 *= grid[i].loadShaders(vertexShaderFileName, fragmentShaderFileName); grid[i].setPosition(Vector3(i*scale_grid, j*scale_grid, k*scale_grid - DETAIL_GRID-2.0f)); /*if(i%6 == 0) grid[i].setPosition(Vector3(DETAIL_GRID + 1.0f, (i-3)*scale_grid-DETAIL_GRID, (i-3)*scale_grid-DETAIL_GRID)); else if(i%6 == 1) grid[i].setPosition(Vector3((i-2)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f, (i-2)*scale_grid-DETAIL_GRID)); else if(i%6 == 2) grid[i].setPosition(Vector3((i-1)*scale_grid-DETAIL_GRID, (i-1)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f)); else if(i%6 == 3) grid[i].setPosition(Vector3(-DETAIL_GRID - 1.0f , i*scale_grid-DETAIL_GRID, i*scale_grid-DETAIL_GRID)); else if(i%6 == 4) grid[i].setPosition(Vector3((i+1)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f, (i+1)*scale_grid-DETAIL_GRID)); else if(i%6 == 5) grid[i].setPosition(Vector3((i+2)*scale_grid-DETAIL_GRID, (i+2)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f));*/ } } Vector3 pos = cube2.getPosition()+ Vector3(0.5f, 3.5f, 1.5f); cube2.setPosition(pos); //cube2.setRotation(Vector3(30*M_PI/180, 0, 40*M_PI/180)); return c1 * c2 * c3; }catch(int i){ return 0; } }
void CarnageState::updateInput(long milli_time) { #ifdef CLIENT // TODO REMOVE DEMO CODE if(io::keys['8']) { io::keys['8'] = false; networkManager->network->loadLevel("resources/2base.lvl"); } if(io::keys['9']) { io::keys['9'] = false; networkManager->network->loadLevel("resources/test2.lvl"); } if(io::keys['0']) { io::keys['0'] = false; networkManager->network->loadLevel("resources/bigplus.lvl"); } if(io::keys['-']) { io::keys['-'] = false; networkManager->network->loadLevel("resources/ibigplus.lvl"); } if(io::keys['c']) { io::keys['c'] = false; networkManager->network->serverConnect("127.0.0.1", 5060); } //stop music if(io::keys['[']) { global::soundManager->stopPlayingMusic(); } //play music for carnage state if(io::keys[']'] && music_delay <= 0) { if(stateType() == RESULTS_STATE) { global::soundManager->playResultWinSong(); } else { global::soundManager->playCarnageSong(); } music_delay = MUSIC_DELAY; } if(io::keys['n'] && music_delay <= 0) { if(stateType() == RESULTS_STATE) { global::soundManager->playNextResultSong(); } else { global::soundManager->playNextCarnageSong(); } music_delay = MUSIC_DELAY; } // TODO END DEMO CODE // General Keyboard Layout if(io::keys[27]) { networkManager->network->serverDisconnect(); exit(0); } // FIRE CONTROLS if (stateType() == CARNAGE_STATE) // only fire in the real carnage state { if((io::keys[' '] || io::mouse_buttons[MOUSE_LEFT] == GLUT_DOWN) && ammoTimers[ammoIndex] <= 0 && (ammoCounts[ammoIndex] > 0 || ammoCounts[ammoIndex] == -1)) { switch(ammoIndex) { case 0: global::soundManager->playCarnageSfx(0); break; case 1: global::soundManager->playCarnageSfx(4); break; case 2: global::soundManager->playCarnageSfx(3); break; case 3: global::soundManager->playCarnageSfx(1); break; case 4: global::soundManager->playCarnageSfx(2); break; case 5: global::soundManager->playCarnageSfx(4); break; default: break; } WorldObject *newObjPtr = global::factory->makeObject(ammoTypes[ammoIndex]); newObjPtr->setPosition(camera->position() - Vector( 0.0f, 1.0f, 0.0f)); newObjPtr->setVelocity((camera->viewVec() + Vector(0.0f, 0.15f, 0.0f)) * 50); // offset the view vector a bit to more closely match the targeting reticle networkManager->network->addObject(newObjPtr); ammoTimers[ammoIndex] = ammoDelayTimers[ammoIndex]; if(ammoCounts[ammoIndex] != -1) --ammoCounts[ammoIndex]; } } #endif }