#include <PhysicalObject.h>
Inherited by Object.
Inheritance diagram for PhysicalObject:
Public Member Functions | |
PhysicalObject (bool enablePhysics) | |
virtual | ~PhysicalObject () |
void | resetTransform () |
void | translate (const Vec3f &vector) |
void | rotate (const float angle, const Vec3f &axis) |
void | scale (const float x, const float y, const float z) |
void | toLocalCoordinates (Ray &ray) const |
void | toLocalCoordinates (Vec3f &vector) const |
void | toGlobalCoordinates (Ray &ray) const |
void | toGlobalCoordinates (Vec3f &vector) const |
bool | applyPhysics () const |
float | mass () const |
void | setMass (float m) |
const Vec3f & | velocity () const |
void | setVelocity (const Vec3f &v) |
const Vec3f & | angularVelocity () const |
void | setAngularVelocity (const Vec3f &omega) |
const Vec3f & | position () const |
void | offset (const Vec3f off) |
float | time () const |
void | updateProperties (float t) |
virtual void | dump () const=0 |
virtual void | writeDump (std::ostream &outs) |
virtual void | readDump (std::istream &ins) |
Protected Attributes | |
Matrix | mTransform |
Transformation matrix for local coordinate system. | |
Matrix | mInverseTransform |
Inverted transformation matrix for local coordinate system. | |
bool | mPhysicsOn |
Whether this object is controlled by physics. | |
float | mMass |
Mass in kg. | |
Vec3f | mPosition |
Current position. | |
float | mScaling |
Scaling factor. | |
Vec3f | mRotation |
Current rotation (direction = axis, length = angle). | |
Vec3f | mVelocity |
Velocity v in m/s. | |
Vec3f | mAngularVelocity |
Angular velocity omega in sterradian/s. | |
float | mTime |
Current time. |
If object is controlled by physics engine, possible transformations are limited to the sequence scale->rotate->translate and should only be used for initialization.
Definition at line 22 of file PhysicalObject.h.
PhysicalObject::PhysicalObject | ( | bool | enablePhysics | ) |
Constructor
enablePhysics | If this object should be controlled by physics engine |
Definition at line 18 of file PhysicalObject.cpp.
PhysicalObject::~PhysicalObject | ( | ) | [virtual] |
Destructor
Definition at line 35 of file PhysicalObject.cpp.
void PhysicalObject::resetTransform | ( | ) | [inline] |
Reset all transformations (movements, rotations and scale). Sets transformation matrices to identity. Physics related scaling, position and rotation are not changed.
Definition at line 40 of file PhysicalObject.h.
References mInverseTransform, and mTransform.
Referenced by updateProperties().
void PhysicalObject::translate | ( | const Vec3f & | vector | ) | [inline] |
Translate the object by some vector. Local coordinate system is changed accordingly. All transformations are applied in order.
vector | Translation vector |
Definition at line 51 of file PhysicalObject.h.
References mInverseTransform, mPhysicsOn, mPosition, and mTransform.
Referenced by Translator::transform(), and updateProperties().
void PhysicalObject::rotate | ( | const float | angle, | |
const Vec3f & | axis | |||
) | [inline] |
Rotate the object by some angle around a given axis.
This rotation follows the right-hand rule, so if the vector axis points toward the user, the rotation will be counterclockwise.
angle | Rotation angle in radian | |
axis | Rotation axis vector, normalized if needed |
Definition at line 68 of file PhysicalObject.h.
References EPSILON, Vec3f::length(), mInverseTransform, mPhysicsOn, mRotation, mTransform, and Vec3f::normal().
Referenced by Rotator::transform(), and updateProperties().
void PhysicalObject::scale | ( | const float | x, | |
const float | y, | |||
const float | z | |||
) | [inline] |
Scale the object by given factors for each coordinate axis. Normally you want to call this method before other transformations.
x | Scaling factor in x-direction | |
y | Scaling factor in y-direction | |
z | Scaling factor in z-direction |
Definition at line 92 of file PhysicalObject.h.
References mInverseTransform, mPhysicsOn, mScaling, and mTransform.
Referenced by Scaler::transform(), and updateProperties().
void PhysicalObject::toLocalCoordinates | ( | Ray & | ray | ) | const [inline] |
Transform given ray to local coordinate system
ray | Ray in global coordinates |
Definition at line 104 of file PhysicalObject.h.
References mInverseTransform.
Referenced by Object::intersect().
void PhysicalObject::toLocalCoordinates | ( | Vec3f & | vector | ) | const [inline] |
Transform given vector to local coordinate system. Note that vector is treaten as a _vector_ and NOT as point
vector | 3D-vector in global coordinates |
Definition at line 114 of file PhysicalObject.h.
References mInverseTransform, and Matrix::transformVector().
void PhysicalObject::toGlobalCoordinates | ( | Ray & | ray | ) | const [inline] |
Transform given ray to global coordinate system
ray | Ray in local coordinates |
Definition at line 123 of file PhysicalObject.h.
References mTransform.
Referenced by Object::intersect(), Triangle::normal(), TexturedSmoothTriangle::normal(), and Sphere::normal().
void PhysicalObject::toGlobalCoordinates | ( | Vec3f & | vector | ) | const [inline] |
Transform given vector to global coordinate system. Note that vector is treaten as a _vector_ and NOT as point
vector | 3D-vector in local coordinates |
Definition at line 133 of file PhysicalObject.h.
References mTransform, and Matrix::transformVector().
bool PhysicalObject::applyPhysics | ( | ) | const [inline] |
Whether physics should be applyed
Definition at line 140 of file PhysicalObject.h.
References mPhysicsOn.
Referenced by Scene::addObject(), BorderCollision::collide(), BallCollision::collide(), and BilliardPhysics::willCollide().
float PhysicalObject::mass | ( | ) | const [inline] |
Get mass
Definition at line 147 of file PhysicalObject.h.
References mMass.
Referenced by BorderCollision::collide(), and BallCollision::collide().
void PhysicalObject::setMass | ( | float | m | ) | [inline] |
const Vec3f& PhysicalObject::velocity | ( | ) | const [inline] |
Get velocity
Definition at line 161 of file PhysicalObject.h.
References mVelocity.
Referenced by BorderCollision::collide(), BallCollision::collide(), BilliardPhysics::willCollide(), and BilliardPhysics::willHitBorder().
void PhysicalObject::setVelocity | ( | const Vec3f & | v | ) | [inline] |
Set velocity
Definition at line 168 of file PhysicalObject.h.
References mVelocity.
Referenced by PhysicsStep::animate(), BorderCollision::collide(), and BallCollision::collide().
const Vec3f& PhysicalObject::angularVelocity | ( | ) | const [inline] |
Get angular velocity
Definition at line 175 of file PhysicalObject.h.
References mAngularVelocity.
Referenced by BorderCollision::collide(), and BallCollision::collide().
void PhysicalObject::setAngularVelocity | ( | const Vec3f & | omega | ) | [inline] |
Set angular velocity
Definition at line 182 of file PhysicalObject.h.
References mAngularVelocity.
Referenced by PhysicsStep::animate(), BorderCollision::collide(), and BallCollision::collide().
const Vec3f& PhysicalObject::position | ( | ) | const [inline] |
Get position. See translate() if you want to change it
Definition at line 189 of file PhysicalObject.h.
References mPosition.
Referenced by BorderCollision::collide(), BallCollision::collide(), BilliardPhysics::willCollide(), and BilliardPhysics::willHitBorder().
void PhysicalObject::offset | ( | const Vec3f | off | ) | [inline] |
float PhysicalObject::time | ( | ) | const [inline] |
Get object time
Definition at line 203 of file PhysicalObject.h.
References mTime.
Referenced by BilliardPhysics::willCollide(), and BilliardPhysics::willHitBorder().
void PhysicalObject::updateProperties | ( | float | t | ) |
Update position and velocity to given time
Definition at line 42 of file PhysicalObject.cpp.
References BALL_RADIUS, CONTACT_RADIUS, Vec3f::cross(), Vec3f::dot(), EPSILON, GRAVITY, Vec3f::length(), mAngularVelocity, mMass, mPosition, mRotation, mScaling, mTime, MUE_ROLLING, MUE_SLIDING, mVelocity, Vec3f::normal(), PHYS_EPS, resetTransform(), rotate(), scale(), Vec3f::scaled(), translate(), WORLD_UP, and WORLD_UP_MASK.
Referenced by BorderCollision::collide(), and BallCollision::collide().
virtual void PhysicalObject::dump | ( | ) | const [pure virtual] |
Dump all info to console
Implemented in Object.
void PhysicalObject::writeDump | ( | std::ostream & | outs | ) | [virtual] |
Write all data to file stream in binary format
outs | Output file stream |
Reimplemented in Object.
Definition at line 197 of file PhysicalObject.cpp.
References mAngularVelocity, mInverseTransform, mMass, mPhysicsOn, mPosition, mRotation, mScaling, mTime, mTransform, and mVelocity.
Referenced by Object::writeDump().
void PhysicalObject::readDump | ( | std::istream & | ins | ) | [virtual] |
Read all data from file stream in binary format
ins | Input file stream |
Reimplemented in Object.
Definition at line 223 of file PhysicalObject.cpp.
References mAngularVelocity, mInverseTransform, mMass, mPhysicsOn, mPosition, mRotation, mScaling, mTime, mTransform, and mVelocity.
Referenced by Object::readDump().
Matrix PhysicalObject::mTransform [protected] |
Transformation matrix for local coordinate system.
Definition at line 230 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), resetTransform(), rotate(), scale(), toGlobalCoordinates(), translate(), and writeDump().
Matrix PhysicalObject::mInverseTransform [protected] |
Inverted transformation matrix for local coordinate system.
Definition at line 233 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), resetTransform(), rotate(), scale(), toLocalCoordinates(), translate(), and writeDump().
bool PhysicalObject::mPhysicsOn [protected] |
Whether this object is controlled by physics.
Definition at line 236 of file PhysicalObject.h.
Referenced by applyPhysics(), readDump(), rotate(), scale(), translate(), and writeDump().
float PhysicalObject::mMass [protected] |
Mass in kg.
Definition at line 239 of file PhysicalObject.h.
Referenced by Object::dump(), mass(), readDump(), setMass(), SphereObject::SphereObject(), updateProperties(), and writeDump().
Vec3f PhysicalObject::mPosition [protected] |
Current position.
Definition at line 242 of file PhysicalObject.h.
Referenced by Object::dump(), offset(), position(), readDump(), translate(), updateProperties(), and writeDump().
float PhysicalObject::mScaling [protected] |
Scaling factor.
Definition at line 245 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), scale(), updateProperties(), and writeDump().
Vec3f PhysicalObject::mRotation [protected] |
Current rotation (direction = axis, length = angle).
Definition at line 248 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), rotate(), updateProperties(), and writeDump().
Vec3f PhysicalObject::mVelocity [protected] |
Velocity v in m/s.
Definition at line 251 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), setVelocity(), updateProperties(), velocity(), and writeDump().
Vec3f PhysicalObject::mAngularVelocity [protected] |
Angular velocity omega in sterradian/s.
Definition at line 254 of file PhysicalObject.h.
Referenced by angularVelocity(), Object::dump(), readDump(), setAngularVelocity(), updateProperties(), and writeDump().
float PhysicalObject::mTime [protected] |
Current time.
Definition at line 257 of file PhysicalObject.h.
Referenced by Object::dump(), readDump(), time(), updateProperties(), and writeDump().