void Racer::fireRocket() { Sound::sound->playSoundEffect(SFX_ROCKETLAUNCH, emitter); hkpWorldRayCastInput input; hkpWorldRayCastOutput output = hkpWorldRayCastOutput(); hkVector4 from; hkTransform trans = body->getTransform(); from.setTransformedPos(trans, attachGun); input = fireWeapon(); hkVector4 to = input.m_to; to.sub(from); to.normalize3(); // Change this so rocket is facing rocketDir when launched Rocket* currentRocket = new Rocket(Renderer::device, this); currentRocket->owner = this; hkVector4 rocketPos; hkTransform bodyTransform; bodyTransform.set4x4ColumnMajor((const hkFloat32*) gunDraw->getTransform()); hkVector4 rocketAttach; rocketAttach.setXYZ(Racer::attachGun); rocketPos.setTransformedPos(bodyTransform, rocketAttach); currentRocket->body->setTransform(bodyTransform); currentRocket->body->setPosition(rocketPos); to.mul(125.0f); currentRocket->body->setLinearVelocity(to); currentRocket->update(0.0f); DynamicObjManager::manager->addObject(currentRocket); currentRocket = NULL; }
void idle(int value) { glutTimerFunc(41, idle, 0); // Lunar-lander Shooting from cannon. if (artillery.getLock()) { if (!artillery.checkRocketRelease()) { float playerAngle = artillery.getPlayerAngle(); float cannonAngle = artillery.getCannonRotate(); float AdjPlayerAngle = playerAngle; int turns = ceil(abs(playerAngle) / (2 * M_PI)) - 1; if (turns >= 1) { if (playerAngle< 0) { AdjPlayerAngle = playerAngle + (M_PI * 2) * turns; } else { AdjPlayerAngle = playerAngle - (M_PI * 2) * turns; } } player.setVelocity(40, (M_PI/2) - AdjPlayerAngle + cannonAngle); } artillery.setRocketRelease(true); } //Calculate Physics for each frame for (int i = 0; i < numStars; i++) { star[i]->update(); } for (int i = 0; i < numMoons; i++) { player.gravitateTo(moons[i]); if (i == moonLand) { player.update(moons[i], true); } else { player.update(moons[i], false); } } player.update(artillery, false); player.gravitateTo(artillery); player.update(); artillery.updateTank(); if (!artillery.getLock()) { player.follow(artillery); } /* End of Calculation */ glutPostRedisplay(); }