Skip to content
Masoug edited this page Oct 24, 2013 · 7 revisions

DodgeballEngine is the heart of the entire program. It encapsulates Bullet and Irrlicht (and eventually enet) to unify the system under one roof. So you'll find Bullet's dynamics worlds and Irrlicht's device and scene managers in this class. The main.cpp file just initializes the engine and runs it.

The heart of DodgeballEngine is the run() method. This little guy runs the main while loop and steps the physics and graphics engines. It also calls the update methods that copy Bullet's calculated movements to the Irrlicht objects.

Some key things to know when surfing the code:

  • Keyboard and mouse events are handled through Irrlicht's IEventReciever class. More details are in the OnEvent() method.
    • Key states are stored in the m_keyStates variable that stores whether each key is pushed down or not. This allows for smooth movement of the player as the W, S, A and D keys are checked each frame tick.
  • RodriguesRotate() is a simple utility function that applies Rodrigues' Formula for rotating a vector about an arbitrary axis. This is used for mapping the mouse movements to camera rotations to achieve an FPS-like control.
  • fromRigidBody() is a template function that can return different types depending on how its called. This is convenient because the rigidbody-to-dynamicobject conversion is symmetric to for both dodgeballs and avatar nodes.
  • FPS control is done through the trackCamera() method, which takes the mouse coordinates and calculates the target position for the camera (look-at). It does this by normalizing the mouse's position relative to the center of the window (no fullscreen yet :) and applies that percentage to how much the forward vector should rotate horizontally and vertically. The camera can only rotate 90-degrees to the left/right/up/down. There should not be a big reason for looking behind you?
  • Dodgeballs are introduce via fireDodgeball(). This method addDodgeball()s and then applies an impulse to the ball to simulate a throw. It uses simple vector math to get the impulse vector for throwing the ball.
  • DodgeballEngine handles collisions through handleCollisions(). This method (based off of this wiki page) iterates through each contact manifold and notifies each ball of a collision with the ground. This will eventually be extended to deal with player-player contact, player-ball contact, and player-wall contact.
    • checkCollisions() is a function that calls the appropriate "callback" functions with a given pair of colliding bodies. Since bodyA and bodyB could be reversed depending on Bullet's temper, checkCollisions() is a useful and flexible way to update the collision handling cases.
  • The scene can be reconstructed and destroyed via setupScene() and clearScene(). This allows for games to be reset or changed without having to reinitialize the system.
  • The HUD is managed by the updateHUD() method. It is called every time a frame is rendered and displays the crosshairs, team scores and balls possessed for the user.

Clone this wiki locally