Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Cylinder Class Reference

#include <cylinder.h>

Collaboration diagram for Cylinder:

Collaboration graph
[legend]
List of all members.

Public Methods

 Cylinder (World *_world, Cylinder *_father, double newEnergy, double newWidth, double newHeight, Vector3d newGluePositionBody, bool onAgent)
 ~Cylinder ()
void setNewAgent (Agent *)
 Changes parent agent of the cylinder (and it's sons).

Cylinder * dropEnergy (double energyMass)
 Returns a energy cylinder of desired energy (that's energy+mass).

void newIntention (const Action &a)
 New intention of the cylinder for this turn.

void newCycle ()
 A new cycle begins, we should reset forces and moments.

Cylinder * performAction ()
 Really performs desired actions.

Get Properties
Methods to get several properties of the cylinder

Point3d getPosition (bool relative=false)
Point3d getGluePosition (bool relative=false)
Point3d getCentreOfGravity (void)
Vector3d getOrientation ()
Cylinder * getFather ()
AgentgetAgent ()
double getHeight ()
double getWidth ()
double getEnergy ()
double getMass (bool pending=false)
unsigned char getId ()
Cylinder * operator[] (unsigned short int)
 Search by id.

Cylinder * operator() (unsigned short int n)
 Search by number.

unsigned short int getNumCylinders ()
signed short int dist (Cylinder *cyl)
 Returns the logical distance between two cylinders (-1 if cyl is not a son).

WorldgetWorld ()
void updateMomentOfInertia ()
 Updates the moment of inertia of the cylinder.

Physics
void applyForce (const Vector3d &force, const Point3d &where)
void applyForceOnBody (const Vector3d &force, const Point3d &where)
 Apply a force over the cylinder, on a given body position.

void applyVelocity (double dtime)
 Move the cylinders.

void undoVelocity (void)
 Undo last velocity (only applicable once).

void setToGluePosition (void)
 sets the cylinder to the glue position

void movePosition (const Vector3d &ammount)
 moves the position of the cylinder, but with care about father

Collission checkers
Several checks about colissions

vector< Collision * > checkCollisions ()
 Checks all collisions.

CollisioncheckGroundCollision (void)
 Check collisions against ground.

CollisioncheckCylinderCollision (Cylinder *other)
 Check collisions against other cylinder.


Protected Methods

Cylinder * operator() (unsigned short int, unsigned short int &actual)
 Second part of operator()(unsigned short int);.

Change status
Methods to change the status of the cylinder.

All them returns the energy cylinders that is generated when energy is consummed

Cylinder * grow (GrowType type, unsigned short int energy)
Cylinder * move (MoveType type, unsigned short int energy)
Cylinder * drop (unsigned char son, const char *creationMessage, unsigned long int messageSize)
Cylinder * createCylinder (double angle, double height, unsigned short int energy)
Cylinder * sendEnergyTo (unsigned char son, unsigned short int energy)
Cylinder * sendMessage (unsigned long int agentId, const char *message, unsigned long int size)

Protected Attributes

vector< Cylinder * > son
Cylinder * father
Agentagent
Worldworld
 The world from which the cylinder cames.

unsigned char cylinderId
Action desiredAction
double height
double length
double width
double radius
Cylinder Physical Status
The physical status of the Cylinder

Matrix3x3 inertia
 Inertia tensor.

Matrix3x3 inertiaInverse
 Inertia tensor inversed.

Point3d gluePosition
Point3d gluePositionBody
Point3d position
 position of the cylinder respect to the parent cylinder, in world coordinates, if any, or world if none

Quaternion orientationBase
 Base for the orientation of the cylinder.

Vector3d orientationWorld
 Orientation of the cylinder, in world coordinates.

Vector3d velocity
 Velocity.

Vector3d angularVelocity
 Angular Velocity.

Vector3d force
 Force.

Vector3d moment
 Torque.

double energy
 Energy of the cylinder.

double mass
 Mass of the cylinder.

Old Physical properties (for undo)
Point3d oldPosition
 position of the cylinder in world coordinates

Quaternion oldOrientationBase
 Orientation base of the cylinder (maybe should be a quaternion?).

Vector3d oldVelocity
 Velocity.

Vector3d oldAngularVelocity
 Angular Velocity.

Vector3d oldForce
 Force.

Vector3d oldMoment
 Torque.


Friends

class Collision

Detailed Description

This is the main physical body of the world. The cylinders. Each agent is composed of one or more cylinders.

See also:
Vector3d

Definition at line 42 of file cylinder.h.


Constructor & Destructor Documentation

Cylinder::Cylinder World   _world,
Cylinder *    _father,
double    newEnergy,
double    newWidth,
double    newHeight,
Vector3d    newGluePositionBody,
bool    onAgent
 

It constructs the cylinder with the desired energy, mass and position.

There is also an Id of the cylinder into the agent. The main cylinder is id=0, the rest are one more number, till 255, where no more cylinders will be created.

Definition at line 39 of file cylinder.cc.

References World::addCylinder(), agent, angularVelocity, cylinderId, energy, father, force, Agent::getCylinderCount(), gluePosition, gluePositionBody, height, M_PI, mass, moment, Vector3d::normalize(), Quaternion::normalize(), orientationBase, orientationWorld, position, radius, Quaternion::toWorld(), updateMomentOfInertia(), velocity, width, world, Vector3d::X(), and Vector3d::Y().

Referenced by createCylinder(), and dropEnergy().

Cylinder::~Cylinder  
 

Free a little dynamically allocated memory

Definition at line 119 of file cylinder.cc.

References World::delCylinder(), son, and world.


Member Function Documentation

void Cylinder::applyForce const Vector3d   force,
const Point3d &    where
 

Apply a force over the cylinder, from a world coordinate, it calculates the position of the body

Definition at line 167 of file cylinder_physics.cc.

References force, log, and Point3d.

void Cylinder::applyForceOnBody const Vector3d   _force,
const Point3d &    where
 

Apply a force over the cylinder, on a given body position.

Apply a force over the cylinder, causing linear and angular acceleration

The force and point are both in body coordinates

Definition at line 178 of file cylinder_physics.cc.

References force, moment, orientationBase, Point3d, and Quaternion::toWorld().

void Cylinder::applyVelocity double    dtime
 

Move the cylinders.

Move the cylinders, and check collissions. Returns true if it's bellow the floor

Definition at line 188 of file cylinder_physics.cc.

References angularVelocity, force, inertia, inertiaInverse, length, mass, moment, Vector3d::normalize(), Quaternion::normalize(), oldAngularVelocity, oldForce, oldMoment, oldOrientationBase, oldPosition, oldVelocity, orientationBase, orientationWorld, position, Quaternion::toWorld(), and velocity.

vector< Collision * > Cylinder::checkCollisions  
 

Checks all collisions.

Checks all collisions; against other cylinders, ground...

Definition at line 245 of file cylinder_physics.cc.

References checkCylinderCollision(), checkGroundCollision(), World::getCylinder(), World::getNumCylinders(), and world.

Collision * Cylinder::checkCylinderCollision Cylinder *    other
 

Check collisions against other cylinder.

Check a collision against another cylinder.

The way to calculate this is to first check the distance between the two centers of gravity; if it's grater then the sum of both lengths then sure they do not collide; then I check the distance from both lines (each from one cylinder point, and with the orientation).

Definition at line 350 of file cylinder_physics.cc.

Referenced by checkCollisions().

Collision * Cylinder::checkGroundCollision void   
 

Check collisions against ground.

Check the collision against the ground

The way it works is:

The cylinder is defined by two planes at position (p1) and at position+orientation*height (p2) (the two extremes) and the radius (width).

1.We check that p1 and p2 are above the plane, else they are in contact, or more probably penetrating

2.then we check the lines that are the cut's of both planes to the ground (l1 and l2), and the distance from the lines l1 and l2 to p1 and p2, respectively, if it's less than the radius, then the cylinder cuts the plane. We check also for contact.

Definition at line 284 of file cylinder_physics.cc.

References angularVelocity, Collision, COLLISION_SPACE_EPSILUM, COLLISION_VELOCITY_EPSILUM, contact, force, getPosition(), height, length, orientationBase, orientationWorld, penetrating, Point3d, Quaternion::toWorld(), velocity, and Vector3d::Z().

Referenced by checkCollisions(), and newCycle().

Cylinder * Cylinder::createCylinder double    angle,
double    atHeight,
unsigned short int    usedEnergy
[protected]
 

A new cylinder is created in this agent with that position (angle and height) on it's parent cylinder (this). Total energy of new agent is parameter energy

Definition at line 122 of file cylinder_actions.cc.

References Cylinder(), energy, M_PI, Quaternion::normalize(), orientationBase, son, width, and world.

Referenced by performAction().

signed short int Cylinder::dist Cylinder *    cyl
 

Returns the logical distance between two cylinders (-1 if cyl is not a son).

Returns the distance between two cylinders, assuming that this is the father of cyl (-1 if not)

Definition at line 175 of file cylinder.cc.

References son.

Referenced by Client::sendEnergy().

Cylinder * Cylinder::drop unsigned char    sonId,
const char *    creationMessage,
unsigned long int    messageSize
[protected]
 

Drop a cylinder

Definition at line 89 of file cylinder_actions.cc.

References getWorld(), log, World::newAgent(), son, and world.

Referenced by newCycle(), and performAction().

Cylinder * Cylinder::dropEnergy double    droppedEnergy
 

Returns a energy cylinder of desired energy (that's energy+mass).

Creates an energy cylinder of desired energy+mass.

It is created in pseudo-random position in the cylinder surface, with a relation between the energy and mass of 7/8

Definition at line 159 of file cylinder_actions.cc.

References cos(), Cylinder(), energy, M_PI, mass, and world.

Referenced by grow(), and move().

Agent* Cylinder::getAgent   [inline]
 

Definition at line 170 of file cylinder.h.

Referenced by World::newAgent().

Point3d Cylinder::getCentreOfGravity void   
 

Returns the centre of gravity.

The centre of gravity is the centre of this and of this sons.

Definition at line 228 of file cylinder.cc.

References getPosition(), length, orientationWorld, and Point3d.

double Cylinder::getEnergy   [inline]
 

Definition at line 174 of file cylinder.h.

References energy.

Referenced by Client::grow(), Client::move(), Client::newCylinder(), GraphicClient::Run(), and Client::sendEnergy().

Cylinder* Cylinder::getFather   [inline]
 

Definition at line 169 of file cylinder.h.

Referenced by Client::dropCylinder().

Vector3d Cylinder::getGluePosition bool    relative = false
 

Returns the glue position of the cylinder:

* if relative is true, it returns the position relative to its parent,

* if it's false, returns it relative to the world

Definition at line 213 of file cylinder.cc.

References father, and gluePosition.

double Cylinder::getHeight   [inline]
 

Definition at line 171 of file cylinder.h.

References height.

Referenced by GraphicClient::Run().

unsigned char Cylinder::getId void    [inline]
 

Definition at line 177 of file cylinder.h.

References cylinderId.

Referenced by newCycle().

double Cylinder::getMass bool    pending = false
 

Reutrns current mass, and, if true, the pending mass

Definition at line 243 of file cylinder.cc.

References getNumCylinders(), and mass.

Referenced by GraphicClient::Run().

unsigned short int Cylinder::getNumCylinders void   
 

Returns the number of cylinders that hangs from this one plus this one

Definition at line 163 of file cylinder.cc.

References son.

Referenced by getMass(), Agent::getNumCylinders(), and setNewAgent().

Vector3d Cylinder::getOrientation   [inline]
 

Definition at line 168 of file cylinder.h.

Referenced by GraphicClient::Run().

Vector3d Cylinder::getPosition bool    relative = false
 

Returns the position of the cylinder:

* if relative is true, it returns the position relative to its parent,

* if it's false, returns it relative to the world

Definition at line 196 of file cylinder.cc.

References father, and position.

Referenced by checkGroundCollision(), getCentreOfGravity(), Agent::into(), GraphicClient::Run(), and setNewAgent().

double Cylinder::getWidth   [inline]
 

Definition at line 172 of file cylinder.h.

References width.

Referenced by GraphicClient::Run().

World * Cylinder::getWorld void   
 

Returns the actual world of this cylinder

Definition at line 236 of file cylinder.cc.

References world.

Referenced by drop().

Cylinder * Cylinder::grow GrowType    type,
unsigned short int    usedEnergy
[protected]
 

Make the cylinder grow. It wastes energy, in a proportion similar to the new area, to make more mass.

Definition at line 34 of file cylinder_actions.cc.

References dropEnergy(), energy, grow(), growHorizontal, GrowType, height, M_PI, mass, and width.

Referenced by grow(), and performAction().

Cylinder * Cylinder::move MoveType    type,
unsigned short int    usedEnergy
[protected]
 

Move the cylinder

Definition at line 53 of file cylinder_actions.cc.

References dropEnergy(), energy, father, log, mass, moveHorizontalCCW, moveHorizontalCW, MoveType, moveVerticalCCW, and moveVerticalCW.

Referenced by performAction().

void Cylinder::movePosition const Vector3d   ammount
 

moves the position of the cylinder, but with care about father

Moves the position of the cylinder, but with care with parent; in case the cylinder have a parent, it moves the parent too. Have care about gluePosition too.

Definition at line 152 of file cylinder_physics.cc.

References position.

Referenced by Agent::Agent().

void Cylinder::newCycle  
 

A new cycle begins, we should reset forces and moments.

As a new cycle begins, we need to reset the forces, moments... It also adds the forces due to gravity, linear drag and angular drag.

Definition at line 50 of file cylinder_physics.cc.

References angularVelocity, checkGroundCollision(), COLLISION_ANGULARVELOCITY_EPSILUM, COLLISION_VELOCITY_EPSILUM, contact, cos(), drop(), force, World::getAngularDragCoefficient(), World::getDamperCoefficient(), World::getGravity(), getId(), World::getLinearDragCoefficient(), World::getSpringCoefficient(), Collision::getType(), gluePositionBody, height, length, mass, Vector3d::module(), moment, oldForce, oldMoment, orientationWorld, radius, Collision::resolve(), sin(), son, updateMomentOfInertia(), velocity, width, Vector3d::X(), Vector3d::Y(), and Vector3d::Z().

void Cylinder::newIntention const Action   a [inline]
 

New intention of the cylinder for this turn.

Definition at line 197 of file cylinder.h.

Referenced by Client::dropCylinder(), Client::grow(), Client::move(), Client::newCylinder(), Client::sendEnergy(), and Client::sendMessage().

Cylinder* Cylinder::operator() unsigned short int    n [inline]
 

Search by number.

Definition at line 182 of file cylinder.h.

Cylinder * Cylinder::operator() unsigned short int    n,
unsigned short int &    actual
[protected]
 

Second part of operator()(unsigned short int);.

Returns the cylinder number=n, in this agent, or NULL if there is not one

Definition at line 145 of file cylinder.cc.

References son.

Cylinder * Cylinder::operator[] unsigned short int    n
 

Search by id.

Returns the cylinder with id=n, or NULL if there is not one

Definition at line 129 of file cylinder.cc.

References cylinderId, and son.

Cylinder * Cylinder::performAction  
 

Really performs desired actions.

According to desiredAction it realizes an Action

Definition at line 202 of file cylinder_actions.cc.

References Action::action, Action::agentId, Action::angle, createCylinder(), Action::cylinder, desiredAction, drop(), dropCylinder, Action::energy, grow(), growTo, Action::growType, GrowType, Action::height, log, Action::message, Action::messageSize, move(), moveCylinder, Action::moveType, newCylinder, none, sendEnergy, sendEnergyTo(), sendMessage(), and sendMessageAction.

Referenced by Agent::performActions().

Cylinder * Cylinder::sendEnergyTo unsigned char    son,
unsigned short int    energy
[protected]
 

Traspases some of own energy to a son's cylinder energy

Definition at line 140 of file cylinder_actions.cc.

References energy, and son.

Referenced by performAction().

Cylinder * Cylinder::sendMessage unsigned long int    agentId,
const char *    message,
unsigned long int    size
[protected]
 

Definition at line 176 of file cylinder_actions.cc.

References World::addMessage(), agent, World::getAgent(), Agent::getId(), Agent::receiveMessage(), and world.

Referenced by performAction().

void Cylinder::setNewAgent Agent   _agent
 

Changes parent agent of the cylinder (and it's sons).

Change the agent parent of this cylinder. This is a consecuence of a drop cylinder, when a new agent is born. We must make some little things, but in general nothing important change.

This call is only made to the new first-cylinder.

Definition at line 102 of file cylinder.cc.

References father, getNumCylinders(), getPosition(), gluePosition, and position.

Referenced by Agent::Agent(), and World::newAgent().

void Cylinder::setToGluePosition void   
 

sets the cylinder to the glue position

Moves the cylinder to the glue position, if any

Definition at line 142 of file cylinder_physics.cc.

References father, gluePosition, and position.

void Cylinder::undoVelocity void   
 

Undo last velocity (only applicable once).

Undoes latest velocity, setting the oldXXX values that were saved

Definition at line 228 of file cylinder_physics.cc.

References angularVelocity, force, moment, Vector3d::normalize(), oldAngularVelocity, oldForce, oldMoment, oldOrientationBase, oldPosition, oldVelocity, orientationBase, orientationWorld, position, Quaternion::toWorld(), and velocity.

void Cylinder::updateMomentOfInertia  
 

Updates the moment of inertia of the cylinder.

Updates the moment of inertia of the cylinder

Definition at line 34 of file cylinder_physics.cc.

References height, inertia, inertiaInverse, Matrix3x3::Inverse(), mass, and width.

Referenced by Cylinder(), and newCycle().


Friends And Related Function Documentation

friend class Collision [friend]
 

Definition at line 238 of file cylinder.h.

Referenced by checkGroundCollision().


Member Data Documentation

Agent* Cylinder::agent [protected]
 

The agent to which this cylinder belongs

Definition at line 124 of file cylinder.h.

Referenced by Cylinder(), and sendMessage().

Vector3d Cylinder::angularVelocity [protected]
 

Angular Velocity.

Definition at line 85 of file cylinder.h.

Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity().

unsigned char Cylinder::cylinderId [protected]
 

The identifier of this cylinder, on this agent

Definition at line 129 of file cylinder.h.

Referenced by Cylinder(), getId(), and operator[]().

Action Cylinder::desiredAction [protected]
 

The action that the cylinder wants to perform in this cycle

Definition at line 132 of file cylinder.h.

Referenced by performAction().

double Cylinder::energy [protected]
 

Energy of the cylinder.

Definition at line 94 of file cylinder.h.

Referenced by createCylinder(), Cylinder(), dropEnergy(), getEnergy(), grow(), move(), and sendEnergyTo().

Cylinder* Cylinder::father [protected]
 

The father of the cylinder, if it's on the same agent (else NULL)

Definition at line 122 of file cylinder.h.

Referenced by Cylinder(), getGluePosition(), getPosition(), move(), setNewAgent(), and setToGluePosition().

Vector3d Cylinder::force [protected]
 

Force.

Definition at line 87 of file cylinder.h.

Referenced by applyForce(), applyForceOnBody(), applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity().

Point3d Cylinder::gluePosition [protected]
 

position of the cylinder respect to the parent cylinder, in world coordinates, if any, or (0,0,0) if none Indicate the position that the cylinder should have (and that the glue force sets)

Definition at line 69 of file cylinder.h.

Referenced by Cylinder(), getGluePosition(), setNewAgent(), and setToGluePosition().

Point3d Cylinder::gluePositionBody [protected]
 

position of the cylinder with respect to the father, if any, in body coordinates in cylindrical "svas-coordinates": (height, angle,0)

Definition at line 73 of file cylinder.h.

Referenced by Cylinder(), and newCycle().

double Cylinder::height [protected]
 

Definition at line 51 of file cylinder.h.

Referenced by checkGroundCollision(), Cylinder(), getHeight(), grow(), newCycle(), and updateMomentOfInertia().

Matrix3x3 Cylinder::inertia [protected]
 

Inertia tensor.

Definition at line 60 of file cylinder.h.

Referenced by applyVelocity(), Collision::resolveGroundCollision(), and updateMomentOfInertia().

Matrix3x3 Cylinder::inertiaInverse [protected]
 

Inertia tensor inversed.

Definition at line 62 of file cylinder.h.

Referenced by applyVelocity(), Collision::resolveGroundCollision(), and updateMomentOfInertia().

double Cylinder::length [protected]
 

Definition at line 52 of file cylinder.h.

Referenced by applyVelocity(), checkGroundCollision(), getCentreOfGravity(), and newCycle().

double Cylinder::mass [protected]
 

Mass of the cylinder.

Definition at line 96 of file cylinder.h.

Referenced by applyVelocity(), Cylinder(), dropEnergy(), getMass(), grow(), move(), newCycle(), Collision::resolveGroundCollision(), and updateMomentOfInertia().

Vector3d Cylinder::moment [protected]
 

Torque.

Definition at line 89 of file cylinder.h.

Referenced by applyForceOnBody(), applyVelocity(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity().

Vector3d Cylinder::oldAngularVelocity [protected]
 

Angular Velocity.

Definition at line 110 of file cylinder.h.

Referenced by applyVelocity(), and undoVelocity().

Vector3d Cylinder::oldForce [protected]
 

Force.

Definition at line 112 of file cylinder.h.

Referenced by applyVelocity(), newCycle(), and undoVelocity().

Vector3d Cylinder::oldMoment [protected]
 

Torque.

Definition at line 114 of file cylinder.h.

Referenced by applyVelocity(), newCycle(), and undoVelocity().

Quaternion Cylinder::oldOrientationBase [protected]
 

Orientation base of the cylinder (maybe should be a quaternion?).

Definition at line 106 of file cylinder.h.

Referenced by applyVelocity(), and undoVelocity().

Point3d Cylinder::oldPosition [protected]
 

position of the cylinder in world coordinates

Definition at line 104 of file cylinder.h.

Referenced by applyVelocity(), and undoVelocity().

Vector3d Cylinder::oldVelocity [protected]
 

Velocity.

Definition at line 108 of file cylinder.h.

Referenced by applyVelocity(), and undoVelocity().

Quaternion Cylinder::orientationBase [protected]
 

Base for the orientation of the cylinder.

Definition at line 79 of file cylinder.h.

Referenced by applyForceOnBody(), applyVelocity(), checkGroundCollision(), createCylinder(), Cylinder(), Collision::resolveGroundCollision(), and undoVelocity().

Vector3d Cylinder::orientationWorld [protected]
 

Orientation of the cylinder, in world coordinates.

Definition at line 81 of file cylinder.h.

Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), getCentreOfGravity(), newCycle(), and undoVelocity().

Point3d Cylinder::position [protected]
 

position of the cylinder respect to the parent cylinder, in world coordinates, if any, or world if none

Definition at line 77 of file cylinder.h.

Referenced by applyVelocity(), Cylinder(), getPosition(), movePosition(), setNewAgent(), setToGluePosition(), and undoVelocity().

double Cylinder::radius [protected]
 

Definition at line 57 of file cylinder.h.

Referenced by Cylinder(), and newCycle().

vector<Cylinder *> Cylinder::son [protected]
 

Pointers to sons

Definition at line 120 of file cylinder.h.

Referenced by createCylinder(), dist(), drop(), getNumCylinders(), newCycle(), operator()(), operator[](), sendEnergyTo(), and ~Cylinder().

Vector3d Cylinder::velocity [protected]
 

Velocity.

Definition at line 83 of file cylinder.h.

Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity().

double Cylinder::width [protected]
 

Definition at line 56 of file cylinder.h.

Referenced by createCylinder(), Cylinder(), getWidth(), grow(), newCycle(), and updateMomentOfInertia().

World* Cylinder::world [protected]
 

The world from which the cylinder cames.

Definition at line 126 of file cylinder.h.

Referenced by checkCollisions(), createCylinder(), Cylinder(), drop(), dropEnergy(), getWorld(), sendMessage(), and ~Cylinder().


The documentation for this class was generated from the following files:
Generated on Mon Jun 17 19:54:17 2002 for Svas Server by doxygen1.2.16