#include <BilliardPhysics.h>
Collaboration diagram for BilliardPhysics:
Public Member Functions | |
BilliardPhysics () | |
~BilliardPhysics () | |
void | add (Object *obj) |
void | remove (Object *obj) |
void | step () |
void | dumpToFile (const std::string &file) |
void | loadFromFile (const std::string &file) |
Private Member Functions | |
void | createCollisionList () |
bool | willCollide (float &time, const Object *o1, const Object *o2) const |
bool | willHitBorder (float &time, const Object *obj, const TableBorder *border) const |
void | updateCollisionList (const std::vector< Collision * > &clsns) |
void | dumpCollisions () const |
Private Attributes | |
std::vector< Object * > | mObjects |
Objects that should be updated. | |
TableBorder * | mBorders [4] |
Table borders. | |
std::vector< Collision * > | mCollisions |
Internal list of collisions that will occur in the next step sorted by time. | |
float | mTime |
Current time. | |
std::string | mLoadFile |
File name to load from. | |
std::ifstream | mInFile |
Input file stream. | |
std::string | mSaveFile |
File name to write to. | |
std::ofstream | mOutFile |
Output file stream. |
Definition at line 20 of file BilliardPhysics.h.
BilliardPhysics::BilliardPhysics | ( | ) |
Constructor
Definition at line 22 of file BilliardPhysics.cpp.
References BALL_MASS, COLLISION_LOSS, CONTACT_RADIUS, EPSILON, FRAME_LENGTH, GRAVITY, LOG, mBorders, MUE_BALLS, MUE_ROLLING, MUE_SLIDING, PHYS_EPS, T_IMPULSE, TABLE_MAX, TABLE_MIN, Vec3f::x(), and Vec3f::z().
BilliardPhysics::~BilliardPhysics | ( | ) |
void BilliardPhysics::add | ( | Object * | obj | ) | [inline] |
Add an object to internal list
Definition at line 33 of file BilliardPhysics.h.
References mObjects.
Referenced by Scene::addObject().
void BilliardPhysics::remove | ( | Object * | obj | ) |
Remove object
Definition at line 66 of file BilliardPhysics.cpp.
References mObjects.
Referenced by Scene::removeObject().
void BilliardPhysics::step | ( | ) |
Recalculate positions for the next time step
Definition at line 81 of file BilliardPhysics.cpp.
References createCollisionList(), dumpCollisions(), EPSILON, FRAME_LENGTH, LOG, mCollisions, mInFile, mLoadFile, mObjects, mOutFile, mSaveFile, mTime, and updateCollisionList().
Referenced by Scene::step().
void BilliardPhysics::dumpToFile | ( | const std::string & | file | ) |
Dump every later step to given file
file | File name to write to |
Definition at line 534 of file BilliardPhysics.cpp.
References BALL_MASS, BALL_RADIUS, COLLISION_LOSS, CONTACT_RADIUS, FRAME_LENGTH, GRAVITY, mOutFile, mSaveFile, MUE_BALLS, MUE_ROLLING, MUE_SLIDING, PHYS_EPS, SPREAD_MAX_V, SPREAD_POW, and T_IMPULSE.
Referenced by Scene::physicsDump().
void BilliardPhysics::loadFromFile | ( | const std::string & | file | ) |
Load later steps from given file instead of calculating
file | File name to read from |
Definition at line 575 of file BilliardPhysics.cpp.
References BALL_MASS, BALL_RADIUS, COLLISION_LOSS, CONTACT_RADIUS, EPSILON, FRAME_LENGTH, GRAVITY, mInFile, mLoadFile, MUE_BALLS, MUE_ROLLING, MUE_SLIDING, PHYS_EPS, SPREAD_MAX_V, SPREAD_POW, and T_IMPULSE.
Referenced by Scene::physicsLoad().
void BilliardPhysics::createCollisionList | ( | ) | [private] |
Create list of collisions in the next time step (mTime .. mTime + FRAME_LENGTH)
Definition at line 175 of file BilliardPhysics.cpp.
References Collision::compare(), mBorders, mCollisions, mObjects, mTime, willCollide(), and willHitBorder().
Referenced by step().
bool BilliardPhysics::willCollide | ( | float & | time, | |
const Object * | o1, | |||
const Object * | o2 | |||
) | const [private] |
Check if 2 given objects will collide in the next time step after given time. Time is set to next collision time if collision occurs
Definition at line 204 of file BilliardPhysics.cpp.
References PhysicalObject::applyPhysics(), BALL_RADIUS, Vec3f::dot(), EPSILON, FRAME_LENGTH, Vec3f::length(), mTime, Object::name(), PhysicalObject::position(), PhysicalObject::time(), and PhysicalObject::velocity().
Referenced by createCollisionList(), and updateCollisionList().
bool BilliardPhysics::willHitBorder | ( | float & | time, | |
const Object * | obj, | |||
const TableBorder * | border | |||
) | const [private] |
Check if an object will hit a border in the near furture after given time. Time is set to next collision time if collision occurs
Definition at line 285 of file BilliardPhysics.cpp.
References BALL_RADIUS, TableBorder::dist(), EPSILON, FRAME_LENGTH, mBorders, mTime, Object::name(), PHYS_EPS, PhysicalObject::position(), PhysicalObject::time(), PhysicalObject::velocity(), Vec3f::x(), TableBorder::xAligned(), and Vec3f::z().
Referenced by createCollisionList(), and updateCollisionList().
void BilliardPhysics::updateCollisionList | ( | const std::vector< Collision * > & | clsns | ) | [private] |
Update collision list by recalculating collisions that happen with 2 objects from collision afterwards.
clsns | Current collision list. They are deleted too! |
Definition at line 358 of file BilliardPhysics.cpp.
References Collision::compare(), dumpCollisions(), mBorders, mCollisions, mObjects, Collision::predicate(), Collision::ucompare(), willCollide(), and willHitBorder().
Referenced by step().
void BilliardPhysics::dumpCollisions | ( | ) | const [private] |
Dump collision list
Definition at line 510 of file BilliardPhysics.cpp.
References LOG, and mCollisions.
Referenced by step(), and updateCollisionList().
std::vector<Object *> BilliardPhysics::mObjects [private] |
Objects that should be updated.
Definition at line 60 of file BilliardPhysics.h.
Referenced by add(), createCollisionList(), remove(), step(), and updateCollisionList().
TableBorder* BilliardPhysics::mBorders[4] [private] |
Table borders.
Definition at line 63 of file BilliardPhysics.h.
Referenced by BilliardPhysics(), createCollisionList(), updateCollisionList(), willHitBorder(), and ~BilliardPhysics().
std::vector<Collision *> BilliardPhysics::mCollisions [private] |
Internal list of collisions that will occur in the next step sorted by time.
Definition at line 66 of file BilliardPhysics.h.
Referenced by createCollisionList(), dumpCollisions(), step(), updateCollisionList(), and ~BilliardPhysics().
float BilliardPhysics::mTime [private] |
Current time.
Definition at line 69 of file BilliardPhysics.h.
Referenced by createCollisionList(), step(), willCollide(), and willHitBorder().
std::string BilliardPhysics::mLoadFile [private] |
File name to load from.
Definition at line 72 of file BilliardPhysics.h.
Referenced by loadFromFile(), and step().
std::ifstream BilliardPhysics::mInFile [private] |
Input file stream.
Definition at line 75 of file BilliardPhysics.h.
Referenced by loadFromFile(), and step().
std::string BilliardPhysics::mSaveFile [private] |
File name to write to.
Definition at line 78 of file BilliardPhysics.h.
Referenced by dumpToFile(), and step().
std::ofstream BilliardPhysics::mOutFile [private] |
Output file stream.
Definition at line 81 of file BilliardPhysics.h.
Referenced by dumpToFile(), and step().