34 #ifndef __ENKI_PHYSICALENGINE_H 35 #define __ENKI_PHYSICALENGINE_H 158 static const double g;
198 Part(
double l1,
double l2,
double height);
201 void applyTransformation(
const Matrix22& rot,
const Point& trans,
double* radius);
204 inline double getHeight()
const {
return height; }
205 inline double getArea()
const {
return area; }
206 inline const Polygone& getShape()
const {
return shape; }
207 inline const Polygone& getTransformedShape()
const {
return transformedShape; }
208 inline const Point& getCentroid()
const {
return centroid; }
209 inline const Point& getTransformedCentroid()
const {
return transformedCentroid; }
210 inline const Textures& getTextures()
const {
return textures; }
211 inline bool isTextured()
const {
return !textures.empty(); }
237 void computeAreaAndCentroid();
252 Hull operator+(
const Hull& that)
const;
256 void applyTransformation(
const Matrix22& rot,
const Point& trans,
double* radius = 0);
296 inline double getRadius()
const {
return r; }
297 inline double getHeight()
const {
return height; }
298 inline bool isCylindric()
const {
return hull.empty(); }
299 inline const Hull& getHull()
const {
return hull; }
300 inline const Color& getColor()
const {
return color; }
301 inline double getMass()
const {
return mass; }
308 void setCylindric(
double radius,
double height,
double mass);
310 void setRectangular(
double l1,
double l2,
double height,
double mass);
318 LEFT_MOUSE_BUTTON = 1<<0,
319 RIGHT_MOUSE_BUTTON = 1<<1,
320 MIDDLE_MOUSE_BUTTON = 1<<3
323 virtual void clickedInteraction(
bool pressed,
unsigned int buttonCode,
double pointX,
double pointY,
double pointZ){};
404 void sortLocalInteractions(
void);
449 GroundTexture(
unsigned width,
unsigned height,
const uint32_t* data);
455 typedef std::set<PhysicalObject *> Objects;
456 typedef Objects::iterator ObjectsIterator;
486 bool hasGroundTexture()
const;
491 virtual void step(
double dt,
unsigned physicsOversampling = 1);
498 void disconnectExternalObjectsUserData();
501 void setRandomSeed(
unsigned long seed);
503 void initBluetoothBase();
508 static void takeObjectOwnership(
bool doTake);
const double r
The radius of the world, if wallsType is WALLS_CIRCLE.
Definition: PhysicalEngine.h:429
A vector in a 2D space.
Definition: Geometry.h:68
virtual void initGlobalInteractions(double dt, World *w)
Initialize the global interactions, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:358
double r
The radius of circular objects or, if hull is not empty, the bounding circle.
Definition: PhysicalEngine.h:281
WallsType
Type of walls around the world.
Definition: PhysicalEngine.h:415
virtual void doLocalWallsInteraction(double dt, World *w)
Do the interactions with the walls of world w, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:353
PhysicalObject()
Constructor.
Definition: PhysicalEngine.cpp:228
double interlacedDistance
How much this object did penetrate other objects in the course of physics steps since last control st...
Definition: PhysicalEngine.h:267
A 2x2 matrix.
Definition: Geometry.h:142
Header of the bluetooth base.
const double h
The height of the world, if wallsType is WALLS_SQUARE.
Definition: PhysicalEngine.h:427
User specific data that can be attached to any object in the world.
Definition: PhysicalEngine.h:140
double area
The area of this part.
Definition: PhysicalEngine.h:220
double dryFrictionCoefficient
The dry friction coefficient mu.
Definition: PhysicalEngine.h:165
Implementation of a Bluetooth base coordinating the Bluetooth modules.
Definition: BluetoothBase.h:54
void collideWithStaticObject(const Vector &n, const Point &cp)
Dynamics for collision with a static object at points cp with normal vector n.
Definition: PhysicalEngine.cpp:522
A part is one of the convex geometrical element that composes the physical object.
Definition: PhysicalEngine.h:190
Hull(const Part &part)
Construct a hull with a single part.
Definition: PhysicalEngine.h:248
A hull is a vector of Hull.
Definition: PhysicalEngine.h:243
double viscousFrictionCoefficient
The viscous friction coefficient. Premultiplied by mass. A value of k applies a force of -k * speed *...
Definition: PhysicalEngine.h:167
void collideWithObject(PhysicalObject &that, const Point &cp, const Vector &dist)
Dynamics for collision with that at point cp with a penetrated distance of dist.
Definition: PhysicalEngine.cpp:544
virtual void doGlobalInteractions(double dt, World *w)
Do the global interactions with the world, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:360
virtual void initLocalInteractions(double dt, World *w)
Initialize the object specific interactions, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:349
double collisionElasticity
Elasticity of collisions of this object. If 0, soft collision, 100% energy dissipation; if 1...
Definition: PhysicalEngine.h:163
const WallsType wallsType
type of walls this world is using
Definition: PhysicalEngine.h:423
virtual void doLocalInteractions(double dt, World *w, PhysicalObject *o)
Do the interactions with the other PhysicalObject, do nothing for PhysicalObject. ...
Definition: PhysicalEngine.h:351
virtual void clickedInteraction(bool pressed, unsigned int buttonCode, double pointX, double pointY, double pointZ)
called for robot if a click is performed on it
Definition: PhysicalEngine.h:323
Hull()
Construct an empty hull.
Definition: PhysicalEngine.h:246
virtual void finalizeLocalInteractions(double dt, World *w)
All interactions are finished, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:355
A situated object in the world with mass, geometry properties, physical properties, ...
Definition: PhysicalEngine.h:131
const double w
The width of the world, if wallsType is WALLS_SQUARE.
Definition: PhysicalEngine.h:425
Polygone shape
The shape of the part in object coordinates.
Definition: PhysicalEngine.h:222
A fast random generator.
Definition: Random.h:48
void setCylindric(double radius, double height, double mass)
Make the object cylindric with a given mass.
Definition: PhysicalEngine.cpp:259
void addGlobalInteraction(GlobalInteraction *gi)
Add a global interaction, just add it at the end of the vector.
Definition: PhysicalEngine.h:391
static const Color gray
gray (0.5, 0.5, 0.5)
Definition: Types.h:154
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
unsigned height
the height of the ground texture, if any
Definition: PhysicalEngine.h:442
double viscousMomentFrictionCoefficient
The viscous friction moment coefficient. Premultiplied by momentOfInertia. A value of k applies a for...
Definition: PhysicalEngine.h:169
double mass
The mass of the object. If below zero, the object can't move (infinite mass).
Definition: PhysicalEngine.h:272
std::vector< Texture > Textures
Textures for all sides of an object.
Definition: Types.h:169
2-D Texture for ground
Definition: PhysicalEngine.h:437
BluetoothBase * bluetoothBase
Base for the Bluetooth connections between robots.
Definition: PhysicalEngine.h:461
The interfaces for the interactions.
void setRectangular(double l1, double l2, double height, double mass)
Make the object rectangular of size l1 x l2 with a given mass.
Definition: PhysicalEngine.cpp:277
Textures textures
Texture for several faces of this object.
Definition: PhysicalEngine.h:233
bool deletedWithObject
if true, deleted along with the physical object.
Definition: PhysicalEngine.h:143
void dirtyUserData()
When a physical parameter (color, shape, ...) has been changed, the user data must be updated...
Definition: PhysicalEngine.cpp:250
virtual void finalizeGlobalInteractions(double dt, World *w)
All global interactions are finished, do nothing for PhysicalObject.
Definition: PhysicalEngine.h:362
void computeMomentOfInertia()
Compute the moment of inertia tensor depending on radius, mass, height, and hull, assuming that the h...
Definition: PhysicalEngine.cpp:323
Point centroid
The centroid (barycenter) of the part in object coordinates.
Definition: PhysicalEngine.h:226
Objects objects
All the objects in the world.
Definition: PhysicalEngine.h:459
virtual void controlStep(double dt)
Can implement world specific control. By default do nothing.
Definition: PhysicalEngine.h:512
virtual void collisionEvent(PhysicalObject *o)
The object collided with o during the current physical step, if o is null, it collided with walls...
Definition: PhysicalEngine.h:346
double momentOfInertia
! The moment of inertia tensor
Definition: PhysicalEngine.h:274
std::vector< GlobalInteraction * > globalInteractions
Vector of global interactions.
Definition: PhysicalEngine.h:385
The mathematic classes for random work.
Point pos
The position of the object.
Definition: PhysicalEngine.h:176
The world is the container of all objects and robots.
Definition: PhysicalEngine.h:411
std::vector< LocalInteraction * > localInteractions
Vector of local interactions.
Definition: PhysicalEngine.h:383
Interacts with the whole world.
Definition: Interaction.h:93
double angSpeed
The rotation speed of the object, standard trigonometric orientation.
Definition: PhysicalEngine.h:185
void setColor(const Color &color)
Set the overall color of this object, if hull is empty or if it does not contain any texture...
Definition: PhysicalEngine.cpp:315
void finalizePhysicsInteractions(double dt)
All collisions are finished, deinterlace the object.
Definition: PhysicalEngine.cpp:514
const GroundTexture groundTexture
Current ground texture.
Definition: PhysicalEngine.h:453
UserData * userData
Data attached by the user to this physical object. If non-null, will be destroyed with the object...
Definition: PhysicalEngine.h:153
circle walls, use r for radius
Definition: PhysicalEngine.h:418
void setCustomHull(const Hull &hull, double mass)
Set a custom shape and mass to the object.
Definition: PhysicalEngine.cpp:295
virtual void applyForces(double dt)
Apply forces, typically friction to reduce speed, but one can override to change behaviour.
Definition: PhysicalEngine.cpp:455
virtual void controlStep(double dt)
Control step, not oversampled.
Definition: PhysicalEngine.cpp:450
A color in RGBA.
Definition: Types.h:55
Polygone, which is a vector of points. Anti-clockwise, standard trigonometric orientation.
Definition: Geometry.h:238
std::vector< uint32_t > data
the date of the ground texture, organised as scanlines of pixels in ARGB (0xAARRGGBB in little endian...
Definition: PhysicalEngine.h:444
double height
The height of circular object or, if hull is not empty, the maximum height.
Definition: PhysicalEngine.h:283
void setupCenterOfMass()
Compute the center of mass and move bounding surfaces accordingly. Does not update the moment of iner...
Definition: PhysicalEngine.cpp:355
Hull hull
The hull of this object, which can be composed of several Hull.
Definition: PhysicalEngine.h:279
Interacts with another object or wall only up to a certain distance.
Definition: Interaction.h:53
const Color color
The color of the world walls and ground.
Definition: PhysicalEngine.h:434
void initPhysicsInteractions(double dt)
Initialize the collision logic.
Definition: PhysicalEngine.cpp:501
Polygone transformedShape
The shape of the part in world coordinates, updated on initPhysicsInteractions(). ...
Definition: PhysicalEngine.h:224
void computeTransformedShape()
Compute the hull of this object in world coordinates.
Definition: PhysicalEngine.cpp:407
Color color
The overall color of this object, if hull is empty or if it does not contain any texture.
Definition: PhysicalEngine.h:285
Vector speed
The speed of the object.
Definition: PhysicalEngine.h:183
Vector posBeforeCollision
position before collision, used to compute interlacedDistance
Definition: PhysicalEngine.h:264
FastRandom random
Fast random for use by Enki.
Definition: PhysicalEngine.cpp:49
unsigned width
the width of the ground texture, if any
Definition: PhysicalEngine.h:440
Point transformedCentroid
The centroid (barycenter) of the part in world coordinates, updated on initPhysicsInteractions().
Definition: PhysicalEngine.h:228
virtual ~UserData()
Virtual destructor, call destructor of child classes.
Definition: PhysicalEngine.h:149
A robot is a PhysicalObject that has additional interactions and a controller.
Definition: PhysicalEngine.h:379
The mathematic classes for 2D geometry.
virtual ~PhysicalObject()
Destructor.
Definition: PhysicalEngine.cpp:242
double height
The height of the part, used for interaction with the sensors of other robots.
Definition: PhysicalEngine.h:218
void deleteIfRequired()
Ask the user data to garbage collect itself if appropriate (i.e. not a singleton) ...
Definition: PhysicalEngine.h:147
double angle
The orientation of the object in the world, standard trigonometric orientation.
Definition: PhysicalEngine.h:178