Skip to content

Commit

Permalink
Did a good bit of clean-up in the .h files.
Browse files Browse the repository at this point in the history
Also enabled tick-based point tracking.  When a Position object is ticked, if its LookDirection object has a point to look at and has tracking enabled, a new azimuth/elevation is computed based on the point's location that it's looking at.
  • Loading branch information
JLmike7 committed Oct 16, 2014
1 parent 0f3285f commit 1bdfa88
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 117 deletions.
40 changes: 6 additions & 34 deletions SeniorDesignProject/SeniorDesignProject/Biped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,21 @@ void Biped::Init(Settings* _settings,Box* box)
settings = _settings;
stance = WALK;
teamNumber = 1;
cameraHeight = 5.0f;
crawlCameraHeight = 5.0f;
teamColor = 1;
hitbox = box;
}
Biped::Stance Biped::getStance()
Stance Biped::getStance()
{
return stance;
}
void Biped::setStance(Stance _stance)
{
stance = _stance;
}
//You can get position, but there is no set Position. Use getPosition->teleport() to set position.
Position* Biped::getPosition()
{
return position;
}
void Biped::setPosition(Position *_position)
{
position = position;
}
void Biped::beginMove(Direction direction){
if (stance == Stance::WALK){
position->beginMove(direction, stats->getMaxWalk());
Expand All @@ -60,7 +54,7 @@ void Biped::setHitbox(Box* box){
Weapon* Biped::getWeapon(){
return & weapons->front();
}
void Biped::pushWeapon(Weapon *newWeapon){
void Biped::addWeapon(Weapon *newWeapon){
weapons->push_front(*newWeapon);
}
int Biped::getTeam(){
Expand All @@ -82,36 +76,14 @@ int Biped::takeHit(int damage){
}
void Biped::jump(){
if (position->isOnGround()){
position->addVelocity(new Point(0.0, stats->getMaxJumpSpeed(), 0.0));
position->beginMove(Direction::UP, stats->getMaxJumpSpeed());
}
}
void Biped::fire(){
//TODO: implement
}

float Biped::getCameraHeight(){
return cameraHeight;
}
void Biped::setCameraHeight(float newHeight){
cameraHeight = newHeight;
}
float Biped::getCrawlCameraHeight(){
return crawlCameraHeight;
}
void Biped::setCrawlCameraHeight(float newHeight){
crawlCameraHeight = newHeight;
}
int Biped::getTeamColor(){
return teamColor;
}
void Biped::setTeamColor(int newColor){
teamColor = newColor;
}
bool Biped::getDeath(){
return dead;
}
void Biped::setDeath(bool isDead){
dead = isDead;
bool Biped::isDead(){
return stats->isDead();
}
void Biped::lookTo(Direction direction){
position->lookTo(direction,(float)settings->getLookSensitivity());
Expand Down
25 changes: 6 additions & 19 deletions SeniorDesignProject/SeniorDesignProject/Biped.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,44 @@
#include "Direction.h"
#include "Stats.h"
#include "Settings.h"
#include "Stance.h"

class Biped :
public Object{

enum Stance { RUN, WALK, CRAWL };

public:
void Init(Settings *settings, Box *hitbox);
Stance getStance();
void setStance(Stance stance);
void setHitbox(Box* box);
Box* getHitbox();
Weapon* getWeapon();
void pushWeapon(Weapon *newWeapon);
void addWeapon(Weapon *newWeapon);
void nextWeapon();
void prevWeapon();
int getTeam();
void setTeam(int team);
int takeHit(int damage);
float getCameraHeight();
void setCameraHeight(float newHeight);
float getCrawlCameraHeight();
void setCrawlCameraHeight(float newHeight);
int getTeamColor();
void setTeamColor(int newColor);
bool getDeath();
bool isDead();
void beginMove(Direction direction);
void setDeath(bool isDead);
Position* getPosition();
void setPosition(Position* position);
void fire();
void jump();
void lookTo(Direction direction);
void lookAt(Point* point);

Biped(Settings* settings, Box *hitbox);
Biped();
Biped(Settings* settings,Box *hitbox);
~Biped();

private:
Settings* settings;

protected:
Stance stance;
std::deque<Weapon>* weapons;
int teamNumber;
float cameraHeight;
float crawlCameraHeight;
int teamColor;
bool dead;
Stance stance;
Stats* stats;
std::deque<Weapon>* weapons;
Position* position;
Box* hitbox;
};
52 changes: 48 additions & 4 deletions SeniorDesignProject/SeniorDesignProject/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ Box::~Box(){

Triangle** Box::getInwardTriangles(){
Triangle* triangles[12];
rectanglesToTriangles(getInwardRectangles(),triangles,6);
rectanglesToTriangles(getInwardQuads(), triangles, 6);
return triangles;
}
Triangle** Box::getOutwardTriangles(){
Triangle* triangles[12];
rectanglesToTriangles(getOutwardRectangles(), triangles, 6);
rectanglesToTriangles(getOutwardQuads(), triangles, 6);
return triangles;
}

Quad** Box::getInwardRectangles(){
Quad** Box::getInwardQuads(){
Quad* rectangles[6];
rectangles[TOP_FACE] = getInwardTop();
rectangles[BOTTOM_FACE] = getInwardBottom();
Expand All @@ -40,7 +40,7 @@ Quad** Box::getInwardRectangles(){
rectangles[BACK_FACE] = getInwardBack();
return rectangles;
}
Quad** Box::getOutwardRectangles(){
Quad** Box::getOutwardQuads(){
Quad* rectangles[6];
rectangles[TOP_FACE] = getOutwardTop();
rectangles[BOTTOM_FACE] = getOutwardBottom();
Expand All @@ -51,6 +51,28 @@ Quad** Box::getOutwardRectangles(){
return rectangles;
}

Quad* Box::getOutwardFace(Direction d){
switch (d){
case Direction::FRONT:
return getOutwardFront();
break;
case Direction::BACK:
return getOutwardBack();
break;
case Direction::LEFT:
return getOutwardLeft();
break;
case Direction::RIGHT:
return getOutwardRight();
break;
case Direction::UP:
return getOutwardTop();
break;
case Direction::DOWN:
return getOutwardBottom();
break;
}
}
Quad* Box::getOutwardTop(){
return new Quad(points[4], points[5], points[6], points[7]);
}
Expand All @@ -70,6 +92,28 @@ Quad* Box::getOutwardBack(){
return new Quad(points[0], points[1], points[5], points[4]);
}

Quad* Box::getInwardFace(Direction d){
switch (d){
case Direction::FRONT:
return getInwardFront();
break;
case Direction::BACK:
return getInwardBack();
break;
case Direction::LEFT:
return getInwardLeft();
break;
case Direction::RIGHT:
return getInwardRight();
break;
case Direction::UP:
return getInwardTop();
break;
case Direction::DOWN:
return getInwardBottom();
break;
}
}
Quad* Box::getInwardTop(){
return new Quad(points[7], points[6], points[5], points[4]);
}
Expand Down
9 changes: 7 additions & 2 deletions SeniorDesignProject/SeniorDesignProject/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Quad.h"
#include "Point.h"
#include "Triangle.h"
#include "Direction.h"

#define FRONT_TOP_LEFT 0
#define FRONT_TOP_RIGHT 1
Expand Down Expand Up @@ -29,16 +30,20 @@ class Box

Triangle** getInwardTriangles();
Triangle** getOutwardTriangles();
Quad** getInwardRectangles();
Quad** getOutwardRectangles();
Quad** getInwardQuads();
Quad** getOutwardQuads();

//get the quad facing outward
Quad* getOutwardFace(Direction d);
Quad* getOutwardTop();
Quad* getOutwardBottom();
Quad* getOutwardLeft();
Quad* getOutwardRight();
Quad* getOutwardFront();
Quad* getOutwardBack();

//get the quad facing inward
Quad* getInwardFace(Direction d);
Quad* getInwardTop();
Quad* getInwardBottom();
Quad* getInwardLeft();
Expand Down
30 changes: 25 additions & 5 deletions SeniorDesignProject/SeniorDesignProject/LookDirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

LookDirection::LookDirection()
{
azimuth = 0.0;
elevation = 90.0;
updatePoint();
Init();
}


Expand All @@ -17,13 +15,21 @@ LookDirection::~LookDirection()

}

void LookDirection::Init(){
azimuth = 0.0;
elevation = 90.0;
updatePoint();
tracking = false;
}

float LookDirection::getAzimuth(){
return azimuth;
}

void LookDirection::setAzimuth(float _azimuth){
azimuth = _azimuth;
updatePoint();
tracking = false;
}

float LookDirection::getElevation(){
Expand All @@ -33,6 +39,7 @@ float LookDirection::getElevation(){
void LookDirection::setAzimuth(float _elevation){
elevation = _elevation;
updatePoint();
tracking = false;
}

void LookDirection::lookTo(Direction direction, float magnitude){
Expand All @@ -53,6 +60,14 @@ void LookDirection::lookTo(Direction direction, float magnitude){
}
updatePoint();
}

bool LookDirection::isTracking(){
return tracking;
}
void LookDirection::setTracking(bool _tracking){
tracking = _tracking;
}

//TODO: unit tests very much needed
void LookDirection::updatePoint(){
point->setX(sin(azimuth*DEG2RAD)*sin(elevation*DEG2RAD));
Expand All @@ -65,11 +80,16 @@ void LookDirection::updateAzEl(){
elevation = -acos(point->getY());
}

void LookDirection::lookAt(Point* _point){
void LookDirection::trackingTick(){
if (tracking)
updateAzEl();
}

void LookDirection::lookAt(Point* _point,bool _tracking){
point = _point;
updateAzEl();
setTracking(_tracking);
}

Point* LookDirection::getLookPoint(){
return point;
}
9 changes: 8 additions & 1 deletion SeniorDesignProject/SeniorDesignProject/LookDirection.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#pragma once
#include "Direction.h"
#include "Point.h"

class LookDirection
{
public:
LookDirection();
~LookDirection();
void Init();
float getAzimuth();
bool isTracking();
void setTracking(bool tracking);
void setAzimuth(float azimuth);
float getElevation();
void setElevation(float elevation);
void lookTo(Direction direction,float magnitude);
void lookAt(Point *point);
void lookAt(Point *point,bool tracking);
void trackingTick();
Point* getLookPoint();

private:
void updatePoint();
void updateAzEl();
Expand All @@ -21,5 +27,6 @@ class LookDirection
float azimuth;
float elevation;
Point* point;
bool tracking;
};

10 changes: 9 additions & 1 deletion SeniorDesignProject/SeniorDesignProject/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ Object::Object()
{
}


Object::~Object()
{
}

void Object::setGravityEnabled(bool gravity){
gravityEnabled = gravity;
}

bool Object::isGravityEnabled(){
return gravityEnabled;
}

void Object::Init(Box hitbox)
{
gravityEnabled = false;
isDead = false;
hitbox = hitbox;
}
Expand Down
Loading

0 comments on commit 1bdfa88

Please sign in to comment.