Warheads 3-D

Pete Lawrence’s contribution:

 

Disclaimer:

I have never nor will I ever claim to be a good web page "programmer". A buddy of mine said web programming is like playing with leggos instead of actually engineering something. I said sure but who wants to learn a whole new syntax (HTML) just to play with leggos. Anyway, this is not my forte and if you think it's clunky or badly laid out, you're right!

 

Background

The background or world setup was simply 2 cubes one within another. I decided to use cubes instead of spheres to keep the number of texture-mapped faces down. The inner texture mapped with a mask that renders it mostly clear. The outer box is an opaque texture map of space. To make the space background look infinitely far away, Eric had the novel solution to move the background along with the eye keeping their relative distance constant. Where the eye goes the space goes with it and produces a very effective and simple effect.

 

Lens Flare

This was my topic for the oral reports and thought it would be acceptable to add the effect to our game it being in space and all. The only modification we needed was not to draw it when a planet was in the way. Even so, our equation tested against all planets and so sometimes would hid the flare even when it was in plain sight. The trick was to only test planets which were in the view frustum. Enter view-frustum-culling, once again.

 

Camera Movement / Effects

For general movement, the camera is based on the typical pitch and yaw angles. Forward movement was based on the Gaze vector while strafing movements were based on a vector orthogonal to the gaze and up vectors.

To add smoothness to the user driven camera mode, I used the glutSpecialUpFunc( ) callback to only stop moving when an arrow key is released. This is better than relying on the OS to automatically repeat the key when held down.

The zooming camera effects were by far the hardest to debug but well worth the effort. It works by determining a path from the current location to the desired spot and then calculates and offset and sideways vector to give the camera a sweeping sensation before it homes in on the target location.

For the camera-follow-shot mode I just set the look as the projectile and the eye as the negative vector of the projectile's velocity.

Gravity         

This was surprisingly easy to write. I'd say 10-12 lines at most. Using the acceleration equation shown below, all I have to do is add the collective acceleration vectors of all the planets based on their direction and distance from the projectile. I didn't use the Force based equation since I only needed acceleration. Divide both sides by the projectiles mass and you have acceleration. Thank you PHYS 131!

 

void Projectile::step ( float dt )

{

vector<Planet*> &list = Planet::mRoster;

vector<Planet*>::iterator itr;

Vector accel, radV, radUnit;

double factor;

for (itr = list.begin(); itr != list.end(); itr++) {

radV = pos - (*itr)->pos;

radUnit = radV.unit();

factor = (GRAV_CONST * (*itr)->gravity) / (radV.dot(radV));

accel += (radUnit * factor);

}

vel -= accel * dt;

dir = vel;

pos += vel * dt;

 

 

Executable???