void BallisticDemo::fire() { // Find the first available round. AmmoRound *shot; for (shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type == UNUSED) break; } // If we didn't find a round, then exit - we can't fire. if (shot >= ammo+ammoRounds) return; // Else, setup the shot with a vector 3 to offset it from it's orientation cyclone::Vector3 direction; if (currentLauncher == 0) { direction = cyclone::Vector3(0, 0, 2.0f); } else { direction = cyclone::Vector3(0, 0, -2.0f); } shot->setState( currentShotType, (launchers[currentLauncher]->body->getPosition() + direction) ); }
void BallisticDemo::updateObjects(cyclone::real duration) { if (duration <= 0.0f) return; for (int i = 0; i < NUM_LAUNCHERS; i++) { launchers[i]->body->integrate(duration); launchers[i]->calculateInternals(); } // Update the physics of each particle in turn for (AmmoRound *shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type != UNUSED) { // Run the physics shot->body->integrate(duration); shot->calculateInternals(); // Check if the particle is now invalid if (shot->body->getPosition().x < 0.0f || shot->startTime+5000 < TimingData::get().lastFrameTimestamp || shot->body->getPosition().z > 200.0f) { // We simply set the shot type to be unused, so the // memory it occupies can be reused by another shot. shot->type = UNUSED; } } } }
void BigBallisticDemo::updateObjects(cyclone::real duration) { // Update the physics of each particle in turn for (AmmoRound *shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type != UNUSED) { // Run the physics shot->body->integrate(duration); shot->calculateInternals(); // Check if the particle is now invalid if (shot->body->getPosition().y < 0.0f || shot->startTime+5000 < TimingData::get().lastFrameTimestamp || shot->body->getPosition().z > 200.0f) { // We simply set the shot type to be unused, so the // memory it occupies can be reused by another shot. shot->type = UNUSED; } } } // Update the boxes for (Box *box = boxData; box < boxData+boxes; box++) { // Run the physics box->body->integrate(duration); box->calculateInternals(); } }
void BallisticDemo::display() { const static GLfloat lightPosition[] = {-1,1,0,0}; // Clear the viewport and set the camera direction glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(-25.0, 8.0, 5.0, 0.0, 5.0, 22.0, 0.0, 1.0, 0.0); // Game3002 - Draw our launchers to the screen for (int i = 0; i < NUM_LAUNCHERS; i++) { launchers[i]->Draw(); } // Draw some scale lines glColor3f(0.75f, 0.75f, 0.75f); glBegin(GL_LINES); for (unsigned i = 0; i < 200; i += 10) { glVertex3f(-5.0f, 0.0f, i); glVertex3f(5.0f, 0.0f, i); } glEnd(); // Render each shot in turn for (AmmoRound *shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type != UNUSED) { shot->render(); } } // Render the description glColor3f(0.0f, 0.0f, 0.0f); renderText(10.0f, 34.0f, "Click: Fire\n1-4: Select Ammo"); // Render the name of the current shot type switch(currentShotType) { case PISTOL: renderText(10.0f, 10.0f, "Current Ammo: Pistol"); break; case ARTILLERY: renderText(10.0f, 10.0f, "Current Ammo: Artillery"); break; case FIREBALL: renderText(10.0f, 10.0f, "Current Ammo: Fireball"); break; case LASER: renderText(10.0f, 10.0f, "Current Ammo: Laser"); break; } // Render the shot power and angle renderText(190.0f, 22.0f, "Current Power: "); renderText(190.0f, 10.0f, "Current Angle: "); }
void BigBallisticDemo::fire() { // Find the first available round. AmmoRound *shot; for (shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type == UNUSED) break; } // If we didn't find a round, then exit - we can't fire. if (shot >= ammo+ammoRounds) return; // Set the shot shot->setState(currentShotType); }
unsigned int NetClient::handleAmmoroundState(Uint8 *data, unsigned int size) { cout << " handleAmmoroundState()\n"; Uint16 eid, unit_eid; CRC32 type; float qx, qy, qz, qw, bx, by, bz, mass; unpack(data, "hhl ffff fff f", &eid, &unit_eid, &type, &qx, &qy, &qz, &qw, &bx, &by, &bz, &mass ); // Find existing entity, unit, and weapon AmmoRound* ar = (AmmoRound*) st->getEntity(eid); Unit* u = (Unit*) st->getEntity(unit_eid); WeaponType* wt = st->mm->getWeaponType(type); // Check valid if (u == NULL) return 40; if (wt == NULL) return 40; if (wt->model == NULL) return 40; // Construct transform obj btTransform xform = btTransform( btQuaternion(qx, qy, qz, qw), btVector3(bx, by, bz) ); // Create or update if (ar == NULL) { ar = new AmmoRound(st, xform, wt, wt->model, u, mass); st->addAmmoRound(ar); ar->eid = eid; } else { ar->setTransform(xform); } return 40; }
void ProjectileDemo::Render() { // Clear the viewport glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(-25.0, 8.0, 5.0, 0.0, 5.0, 22.0, 0.0, 1.0, 0.0); // Draw a sphere at the firing point and add a shadow projected // onto the ground plane glColor3f(0.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(0.0f, 1.5f, 0.0f); glutSolidSphere(0.1f, 5, 5); glTranslatef(0.0f, -1.5f, 0.0f); glColor3f(0.75f, 0.75f, 0.75f); glScalef(1.0f, 0.1f, 1.0f); glutSolidSphere(0.1f, 5, 5); glPopMatrix(); // Draw some cool scale lines glColor3f(0.75f, 0.75f, 0.75f); glBegin(GL_LINES); for (unsigned int i = 0; i < 200; i += 10) { glVertex3f(-5.0f, 0.0f, i); glVertex3f(5.0f, 0.0f, i); } glVertex3f(0.0f, 0.0f, -1.0f); glVertex3f(0.0f, 0.0f, 200.0f); glEnd(); // Render each particle in turn for (AmmoRound *shot = ammo; shot < ammo + ammoRounds; shot++) { if (shot->type != UNUSED) { shot->render(); } } }
void BigBallisticDemo::display() { const static GLfloat lightPosition[] = {-1,1,0,0}; // Clear the viewport and set the camera direction glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(-25.0, 8.0, 5.0, 0.0, 5.0, 22.0, 0.0, 1.0, 0.0); // Draw a sphere at the firing point, and add a shadow projected // onto the ground plane. glColor3f(0.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(0.0f, 1.5f, 0.0f); glutSolidSphere(0.1f, 5, 5); glTranslatef(0.0f, -1.5f, 0.0f); glColor3f(0.75f, 0.75f, 0.75f); glScalef(1.0f, 0.1f, 1.0f); glutSolidSphere(0.1f, 5, 5); glPopMatrix(); // Draw some scale lines glColor3f(0.75f, 0.75f, 0.75f); glBegin(GL_LINES); for (unsigned i = 0; i < 200; i += 10) { glVertex3f(-5.0f, 0.0f, i); glVertex3f(5.0f, 0.0f, i); } glEnd(); // Render each particle in turn glColor3f(1,0,0); for (AmmoRound *shot = ammo; shot < ammo+ammoRounds; shot++) { if (shot->type != UNUSED) { shot->render(); } } // Render the box glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glColor3f(1,0,0); for (Box *box = boxData; box < boxData+boxes; box++) { box->render(); } glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // Render the description glColor3f(0.0f, 0.0f, 0.0f); renderText(10.0f, 34.0f, "Click: Fire\n1-4: Select Ammo"); // Render the name of the current shot type switch(currentShotType) { case PISTOL: renderText(10.0f, 10.0f, "Current Ammo: Pistol"); break; case ARTILLERY: renderText(10.0f, 10.0f, "Current Ammo: Artillery"); break; case FIREBALL: renderText(10.0f, 10.0f, "Current Ammo: Fireball"); break; case LASER: renderText(10.0f, 10.0f, "Current Ammo: Laser"); break; } }