#include <cylinder.h>
Collaboration diagram for Cylinder:
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 () |
Agent * | getAgent () |
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). | |
World * | getWorld () |
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. | |
Collision * | checkGroundCollision (void) |
Check collisions against ground. | |
Collision * | checkCylinderCollision (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 |
Agent * | agent |
World * | world |
The world from which the cylinder cames. | |
unsigned char | cylinderId |
Action | desiredAction |
double | height |
double | length |
double | width |
double | radius |
Cylinder Physical Status | |
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 |
Definition at line 42 of file cylinder.h.
|
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(). |
|
Free a little dynamically allocated memory Definition at line 119 of file cylinder.cc. References World::delCylinder(), son, and world. |
|
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. |
|
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(). |
|
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. |
|
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. |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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. |
|
Definition at line 170 of file cylinder.h. Referenced by World::newAgent(). |
|
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. |
|
Definition at line 174 of file cylinder.h. References energy. Referenced by Client::grow(), Client::move(), Client::newCylinder(), GraphicClient::Run(), and Client::sendEnergy(). |
|
Definition at line 169 of file cylinder.h. Referenced by Client::dropCylinder(). |
|
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. |
|
Definition at line 171 of file cylinder.h. References height. Referenced by GraphicClient::Run(). |
|
Definition at line 177 of file cylinder.h. References cylinderId. Referenced by newCycle(). |
|
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(). |
|
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(). |
|
Definition at line 168 of file cylinder.h. Referenced by GraphicClient::Run(). |
|
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(). |
|
Definition at line 172 of file cylinder.h. References width. Referenced by GraphicClient::Run(). |
|
Returns the actual world of this cylinder Definition at line 236 of file cylinder.cc. References world. Referenced by drop(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
Search by number.
Definition at line 182 of file cylinder.h. |
|
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. |
|
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. |
|
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(). |
|
Traspases some of own energy to a son's cylinder energy Definition at line 140 of file cylinder_actions.cc. Referenced by performAction(). |
|
Definition at line 176 of file cylinder_actions.cc. References World::addMessage(), agent, World::getAgent(), Agent::getId(), Agent::receiveMessage(), and world. Referenced by performAction(). |
|
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(). |
|
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. |
|
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. |
|
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. |
|
Definition at line 238 of file cylinder.h. Referenced by checkGroundCollision(). |
|
The agent to which this cylinder belongs Definition at line 124 of file cylinder.h. Referenced by Cylinder(), and sendMessage(). |
|
Angular Velocity.
Definition at line 85 of file cylinder.h. Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity(). |
|
The identifier of this cylinder, on this agent Definition at line 129 of file cylinder.h. Referenced by Cylinder(), getId(), and operator[](). |
|
The action that the cylinder wants to perform in this cycle Definition at line 132 of file cylinder.h. Referenced by performAction(). |
|
Energy of the cylinder.
Definition at line 94 of file cylinder.h. Referenced by createCylinder(), Cylinder(), dropEnergy(), getEnergy(), grow(), move(), and sendEnergyTo(). |
|
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(). |
|
Force.
Definition at line 87 of file cylinder.h. Referenced by applyForce(), applyForceOnBody(), applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity(). |
|
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(). |
|
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. |
|
Definition at line 51 of file cylinder.h. Referenced by checkGroundCollision(), Cylinder(), getHeight(), grow(), newCycle(), and updateMomentOfInertia(). |
|
Inertia tensor.
Definition at line 60 of file cylinder.h. Referenced by applyVelocity(), Collision::resolveGroundCollision(), and updateMomentOfInertia(). |
|
Inertia tensor inversed.
Definition at line 62 of file cylinder.h. Referenced by applyVelocity(), Collision::resolveGroundCollision(), and updateMomentOfInertia(). |
|
Definition at line 52 of file cylinder.h. Referenced by applyVelocity(), checkGroundCollision(), getCentreOfGravity(), and newCycle(). |
|
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(). |
|
Torque.
Definition at line 89 of file cylinder.h. Referenced by applyForceOnBody(), applyVelocity(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity(). |
|
Angular Velocity.
Definition at line 110 of file cylinder.h. Referenced by applyVelocity(), and undoVelocity(). |
|
Force.
Definition at line 112 of file cylinder.h. Referenced by applyVelocity(), newCycle(), and undoVelocity(). |
|
Torque.
Definition at line 114 of file cylinder.h. Referenced by applyVelocity(), newCycle(), and undoVelocity(). |
|
Orientation base of the cylinder (maybe should be a quaternion?).
Definition at line 106 of file cylinder.h. Referenced by applyVelocity(), and undoVelocity(). |
|
position of the cylinder in world coordinates
Definition at line 104 of file cylinder.h. Referenced by applyVelocity(), and undoVelocity(). |
|
Velocity.
Definition at line 108 of file cylinder.h. Referenced by applyVelocity(), and undoVelocity(). |
|
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(). |
|
Orientation of the cylinder, in world coordinates.
Definition at line 81 of file cylinder.h. Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), getCentreOfGravity(), newCycle(), and undoVelocity(). |
|
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(). |
|
Definition at line 57 of file cylinder.h. |
|
Pointers to sons Definition at line 120 of file cylinder.h. Referenced by createCylinder(), dist(), drop(), getNumCylinders(), newCycle(), operator()(), operator[](), sendEnergyTo(), and ~Cylinder(). |
|
Velocity.
Definition at line 83 of file cylinder.h. Referenced by applyVelocity(), checkGroundCollision(), Cylinder(), newCycle(), Collision::resolveGroundCollision(), and undoVelocity(). |
|
Definition at line 56 of file cylinder.h. Referenced by createCylinder(), Cylinder(), getWidth(), grow(), newCycle(), and updateMomentOfInertia(). |
|
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(). |