Skip to content

Commit

Permalink
added more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dfoley23 committed May 28, 2013
1 parent 0e2beac commit adb936c
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 23 deletions.
18 changes: 18 additions & 0 deletions InfiniteJumpEngine/InfiniteJumpEngine/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void Game::mouse_click(int button, int state, int x, int y){
}
}

/*
* mouse-drag function
*/
void Game::mouse_drag(int x, int y){
if ( level->ballDirHud != NULL ) {
glm::vec3 curPos = level->ballDirHud->getCenter();
Expand Down Expand Up @@ -235,6 +238,9 @@ void Game::mouse_drag(int x, int y){
}
}

/*
* mouse middle wheel function
*/
void Game::mouse_wheel( int wheel, int direction, int x, int y) {
if ( sub_levelID >= 0 ) {
if ( direction > 0 ) {
Expand All @@ -245,6 +251,9 @@ void Game::mouse_wheel( int wheel, int direction, int x, int y) {
}
}

/*
* switches the level
*/
void Game::switchLevel( ) {
string totScore_str;
stringstream out;
Expand Down Expand Up @@ -278,6 +287,9 @@ void Game::switchLevel( ) {
level->camera->lightPos = glm::vec3( 0.0, 100.0f, 0.0 );
}

/*
* the arrow key function
*/
void Game::special_keyboard(int key, int x, int y) {
//arrow keys control camera translations
if ( sub_levelID >= 0 ) {
Expand All @@ -299,6 +311,9 @@ void Game::special_keyboard(int key, int x, int y) {
}
}

/*
* the main keyboard function
*/
void Game::keyboard(unsigned char key, int x, int y){
switch (key) {
case 32: //space
Expand Down Expand Up @@ -371,6 +386,9 @@ void Game::keyboard(unsigned char key, int x, int y){
}
}

/*
* the main run method that handles a game
*/
int Game::run(int argc, char** argv){
resman = new ResManager();
char* profileName = "default";
Expand Down
9 changes: 9 additions & 0 deletions InfiniteJumpEngine/InfiniteJumpEngine/KinematicComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ glm::mat4 KinematicComponent::getTransform(){
return loc.getTransform();
}

/*
* integrates velocity and position
*/
void KinematicComponent::update(float dT){
vel = vel + (acc * dT);
loc = loc + (vel * dT);
}

/*
* applies a force impulse
*/
void KinematicComponent::applyImpulse( glm::vec3 impulse ) {
acc.setPosition( impulse );
}

/*
* recieves messages to apply kinematics
*/
void KinematicComponent::receiveMessage( IJMessage *m){
if (!m->getContent().compare("translate")
|| !m->getContent().compare("rotate")
Expand Down
47 changes: 36 additions & 11 deletions InfiniteJumpEngine/InfiniteJumpEngine/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ const int Mesh::UV_SIZE = 2;
// Constructors/Destructors
//

/*
* mesh holds all vertex data
* tex coords norms colors and
* per mesh transformations
*/
Mesh::Mesh ( ) {
initAttributes();
}

/*
* removes the mesh from memory
*/
Mesh::~Mesh ( ) {
vector<float>().swap(verts);
vector<float>().swap(norms);
Expand Down Expand Up @@ -59,6 +67,10 @@ void Mesh::draw( MeshBatch * batch ) {
}
}

/*
* draw for color id picking
* mainly used for moving around object in debug mode
*/
void Mesh::drawForPick( MeshBatch * batch, glm::vec3 id ) {
pickId.x = id.x;
pickId.y = id.y;
Expand Down Expand Up @@ -94,9 +106,7 @@ void Mesh::drawForPick( MeshBatch * batch, glm::vec3 id ) {
}

/**
* @param x
* @param y
* @param z
* translates the mesh by x y and z
*/
void Mesh::translate (float x, float y, float z )
{
Expand All @@ -110,8 +120,7 @@ void Mesh::translate (float x, float y, float z )


/**
* @param dir
* @param up
* rotates using a quaternion
*/
void Mesh::rotate (float angle, glm::vec3 axis)
{
Expand All @@ -120,8 +129,7 @@ void Mesh::rotate (float angle, glm::vec3 axis)
}

/**
*
*
* rotates around the x, y, and z axis
*/
void Mesh::rotate( float x, float y, float z ) {
dynamic = true;
Expand All @@ -133,24 +141,31 @@ void Mesh::rotate( float x, float y, float z ) {
}

/**
* @param x
* @param y
* @param z
* scales the mesh
*/
void Mesh::scale (float x, float y, float z )
{
dynamic = true;
scaling = glm::scale( glm::mat4( ), glm::vec3( x, y, z ) );
}

/*
* makes this model use seperate transformations
*/
void Mesh::setDynamic( int setting ) {
dynamic = setting;
}

/*
* set to use smooth shading
*/
void Mesh::setSmooth( int setting ) {
smooth = setting;
}

/*
* adds a vert with a position and color
*/
void Mesh::addVert (float x, float y, float z, float r, float g, float b){
float nx = 0, ny = 0, nz = 0;
//Calculate normal from previous verts if possible
Expand All @@ -161,6 +176,7 @@ void Mesh::addVert (float x, float y, float z, float r, float g, float b){
* add a vertex with normal color and tex coord to the mesh
*/
void Mesh::addVert (float x, float y, float z, float nx, float ny, float nz, float r, float g, float b, float u, float v){
//inititalize bounding box vals
if ( verts.empty( ) ) {
min = glm::vec3 ( x, y, z );
max = glm::vec3 ( x, y, z );
Expand All @@ -171,7 +187,7 @@ void Mesh::addVert (float x, float y, float z, float nx, float ny, float nz, flo
maxXPoint = max;
maxYPoint = max;
maxZPoint = max;
} else {
} else { //update bounding box vals
if ( x < minXPoint.x ) {
minXPoint = glm::vec3 ( x, y, z );
} else if ( x > maxXPoint.x ) {
Expand Down Expand Up @@ -203,10 +219,12 @@ void Mesh::addVert (float x, float y, float z, float nx, float ny, float nz, flo
max.z = z;
}
}
//recalculate the center of the mesh
center.x = (center.x + x) / static_cast<float>(verts.size());
center.y = (center.y + y) / static_cast<float>(verts.size());
center.z = (center.z + z) / static_cast<float>(verts.size());
glm::vec3 vertexNormal = glm::vec3( 0, 0, 0 );
//if object using smooth shading calulate vertex normals
if ( smooth ) {
vector<int> sharedNorms;
for ( int i=0; i<static_cast<int>(norms.size())-2; i++ ) {
Expand All @@ -226,6 +244,7 @@ void Mesh::addVert (float x, float y, float z, float nx, float ny, float nz, flo
norms.at( sharedNorms.at( i )+2 ) = (vertexNormal.z + nz)/2.0f;
}
}
//add the vertex data to the mesh data
vertexNormal.x += nx;
vertexNormal.y += ny;
vertexNormal.z += nz;
Expand Down Expand Up @@ -300,6 +319,8 @@ void Mesh::changeColor( float r, float g, float b ) {
}
}

// ACCESS FUNCTION

glm::vec3 Mesh::getCenter( ) {
return center;
}
Expand Down Expand Up @@ -355,6 +376,10 @@ uniforms = new_var;
return uniforms;
}*/

/*
* binds one meshs buffers
* not used deprecated
*/
void Mesh::bindBuffers( MeshBatch * batch, int picking ) {
//Create buffers for the vertex and normal attribute arrays

Expand Down
22 changes: 15 additions & 7 deletions InfiniteJumpEngine/InfiniteJumpEngine/MeshBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// Constructors/Destructors
//

/*
* mesh batch is used to batch meshes together for drawing
*/
MeshBatch::~MeshBatch ( ) {
vector< vector<float> >().swap(verts);
vector< vector<float> >().swap( norms);
Expand All @@ -12,6 +15,9 @@ MeshBatch::~MeshBatch ( ) {
delete shader;
}

/*
* removes the meshbatch from memory
*/
MeshBatch::MeshBatch ( Shader * shader ) {
verts.resize( 1 );
norms.resize( 1 );
Expand Down Expand Up @@ -105,17 +111,15 @@ void MeshBatch::translate (float x, float y, float z )


/**
* @param dir
* @param up
* rotates using a quaternion
*/
void MeshBatch::rotate (float angle, glm::vec3 axis)
{
rotations = glm::rotate( glm::mat4( ), angle, axis );
}

/**
*
*
* rotates around the x, y, z axis
*/
void MeshBatch::rotate( float x, float y, float z ) {
glm::mat4 rotateX = glm::rotate( glm::mat4( ), x, glm::vec3( 1, 0, 0 ) );
Expand All @@ -126,15 +130,16 @@ void MeshBatch::rotate( float x, float y, float z ) {
}

/**
* @param x
* @param y
* @param z
* scales the entire meshbatch
*/
void MeshBatch::scale (float x, float y, float z )
{
scaling = glm::scale( glm::mat4( ), glm::vec3( x, y, z ) );
}

/*
* sets the shader used by this meshbatch
*/
void MeshBatch::setShader ( Shader * new_var ) {
shader = new_var;
shader->modelViewLoc = glGetUniformLocation(shader->program, "M");
Expand Down Expand Up @@ -173,6 +178,9 @@ glm::vec3 MeshBatch::getPickColors( ) {
return pickColors;
}

/*
* binds the current buffers to be used by the shader
*/
void MeshBatch::bindBuffers( int pass ) {
//Create buffers for the vertex and normal attribute arrays

Expand Down
Loading

0 comments on commit adb936c

Please sign in to comment.