![]() |
Angel
A 2D Game Prototyping Engine
|
An Actor that interacts with other Actors using our built-in physics system. More...
#include <PhysicsActor.h>
Inheritance diagram for PhysicsActor:Public Types | |
| enum | eShapeType { SHAPETYPE_BOX, SHAPETYPE_CIRCLE } |
Public Member Functions | |
| PhysicsActor () | |
| virtual | ~PhysicsActor () |
| void | SetDensity (float density) |
| void | SetFriction (float friction) |
| void | SetRestitution (float restitution) |
| void | SetShapeType (eShapeType shapeType) |
| void | SetIsSensor (bool isSensor) |
| void | SetGroupIndex (int groupIndex) |
| void | SetFixedRotation (bool fixedRotation) |
| virtual void | InitPhysics () |
| virtual void | CustomInitPhysics () |
| void | ApplyForce (const Vector2 &force, const Vector2 &point) |
| void | ApplyLocalForce (const Vector2 &force, const Vector2 &point) |
| void | ApplyTorque (float torque) |
| void | ApplyLinearImpulse (const Vector2 &impulse, const Vector2 &point) |
| void | ApplyAngularImpulse (float impulse) |
| b2Body * | GetBody () |
| void | ResetBody () |
| void | SetSize (float x, float y=-1.f) |
| void | SetDrawSize (float x, float y=-1.f) |
| void | SetPosition (float x, float y) |
| void | SetPosition (const Vector2 &pos) |
| void | SetRotation (float rotation) |
| void | MoveTo (const Vector2 &newPosition, float duration, String onCompletionMessage="") |
| void | RotateTo (float newRotation, float duration, String onCompletionMessage="") |
| void | ChangeSizeTo (const Vector2 &newSize, float duration, String onCompletionMessage="") |
| void | ChangeSizeTo (float newSize, float duration, String onCompletionMessage="") |
| virtual const String | GetClassName () const |
Protected Member Functions | |
| virtual void | InitShape (b2Shape *) |
Protected Attributes | |
| b2Body * | _physBody |
| float | _density |
| float | _friction |
| float | _restitution |
| eShapeType | _shapeType |
| bool | _isSensor |
| int | _groupIndex |
| bool | _fixedRotation |
Friends | |
| class | World |
Angel incorporates Box2D (http://www.box2d.org) to handle our physics simulation. This Actor is a loose wrapping around Box2D so that you don't need to worry about the underlying library if you're just doing simple physics.
Definition at line 44 of file PhysicsActor.h.
The two physics shapes we currently support. If you want anything else, you're going to be delving into the Box2D library itself.
Definition at line 67 of file PhysicsActor.h.
| PhysicsActor::PhysicsActor | ( | void | ) |
Sets up a new PhysicsActor with some reasonable default physical properties. Box-shaped; Density = 1.0; Friction = 0.3; Restitution = 0.0.
Note that the PhysicsActor won't actually start doing anything until you call PhysicsActor::InitPhysics().
Definition at line 40 of file PhysicsActor.cpp.
| PhysicsActor::~PhysicsActor | ( | ) | [virtual] |
The destructor removes the PhysicsActor from the internal simulation. It's very important to call the destructor when your remove a PhysicsActor from your World, because otherwise the physics engine will think it's still around and you'll get some strange results.
Definition at line 52 of file PhysicsActor.cpp.
| void PhysicsActor::SetDensity | ( | float | density | ) |
Set the density to be used by the physics simulation. Box2D assumes that the units are kg/m^2. If you set density to 0.0, the PhysicsActor is static and will never move in the world. (Other objects will still collide with it.)
Note that after you call PhysicsActor::InitPhysics, the density is locked and this function will do nothing but spew a warning.
| density | Desired density |
Definition at line 61 of file PhysicsActor.cpp.
| void PhysicsActor::SetFriction | ( | float | friction | ) |
Set the friction to be used by the physics simulation. 0.0 indicates no friction, while 1.0 indicates very high friction.
Note that after you call PhysicsActor::InitPhysics, the friction is locked and this function will do nothing but spew a warning.
| density | Desired friction |
Definition at line 69 of file PhysicsActor.cpp.
| void PhysicsActor::SetRestitution | ( | float | restitution | ) |
Set the restitution (bounciness) to be used by the physics simulation. 0.0 indicates no bounce at all, while 1.0 is a superball.
Note that after you call PhysicsActor::InitPhysics, the restitution is locked and this function will do nothing but spew a warning.
| density | Desired restitution |
Definition at line 77 of file PhysicsActor.cpp.
| void PhysicsActor::SetShapeType | ( | eShapeType | shapeType | ) |
Set the shape you want to use for this object.
Note that after you call PhysicsActor::InitPhysics, the restitution is locked and this function will do nothing but spew a warning.
| shapeType | Either SHAPETYPE_BOX or SHAPETYPE_CIRCLE. |
Definition at line 85 of file PhysicsActor.cpp.
| void PhysicsActor::SetIsSensor | ( | bool | isSensor | ) |
If you set an object up as a sensor, it will cause collision messages to be sent, but not actually physically react to the collision. Useful for detecting when objects have entered certain regions.
Note that after you call PhysicsActor::InitPhysics, the restitution is locked and this function will do nothing but spew a warning.
| isSensor | True if the object should be a sensor, false if not. PhysicsActors are assumed to not be sensors unless otherwise specified. |
Definition at line 93 of file PhysicsActor.cpp.
| void PhysicsActor::SetGroupIndex | ( | int | groupIndex | ) |
Set a group index if you want to have objects only collide with certain other groups of objects. Positive numbers mean that objects always collide, negative numbers mean they never will.
See the Box2D documentation for more information on collision groups
Note that after you call PhysicsActor::InitPhysics, the group index is locked and this function will do nothing but spew a warning.
| groupIndex | The new group index for this PhysicsActor |
Definition at line 101 of file PhysicsActor.cpp.
| void PhysicsActor::SetFixedRotation | ( | bool | fixedRotation | ) |
If true, this PhysicsActor will not rotate (useful for characters).
Note that after you call PhysicsActor::InitPhysics, the this value is locked and the function will do nothing but spew a warning.
| fixedRotation |
Definition at line 109 of file PhysicsActor.cpp.
| void PhysicsActor::InitPhysics | ( | ) | [virtual] |
Start simulating this PhysicsActor in the world.
Definition at line 118 of file PhysicsActor.cpp.
| virtual void PhysicsActor::CustomInitPhysics | ( | ) | [inline, virtual] |
If you want to have your own setup in a derived class, you can implement this function there. It's called at the end of the base class's PhysicsActor::InitPhysics.
Definition at line 166 of file PhysicsActor.h.
Apply a force to an object. The standard units are Newtons (kg * m/s^2). The point parameter is a location in actor space; if you want world space, you can either convert it yourself or use GetBody() to manipulate the underlying Box2D API.
ApplyForce should be called every timestep if you want the force to be continuously applied.
| force | The force to apply (direction and magnitude are significant) in Newtons |
| point | The point in actor space to which the force should be applied |
Definition at line 179 of file PhysicsActor.cpp.
Applies a force relative to the Actor. The standard units are Newtons (kg * m/s^2). The point parameter is a location in actor space; if you want world space, you can either convert it yourself or use GetBody() to manipulate the underlying Box2D API.
ApplyLocalForce should be called every timestep if you want the force to be continuously applied.
| force | The force to apply (direction and magnitude are significant) in Newtons |
| point | The point in actor space to which the force should be applied |
Definition at line 187 of file PhysicsActor.cpp.
| void PhysicsActor::ApplyTorque | ( | float | torque | ) |
Apply torque to affect angular velocity without affecting linear velocity. The standard units are Newton-meters.
| torque | Amount of torque to apply around the Z-axis. |
Definition at line 195 of file PhysicsActor.cpp.
Similar to ApplyForce, but will immediately affect a PhysicsActor's velocity, as opposed to forces which need to be applied every frame. The result is that ApplyImpulse will appear to have roughly 30x the affect of ApplyForce.
For more information: http://www.box2d.org/forum/viewtopic.php?f=3&t=260
The point parameter is a location in actor space; if you want world space, you can either convert it yourself or use GetBody() to manipulate the underlying Box2D API.
| impulse | The strength of the impulse to apply. |
| point |
Definition at line 203 of file PhysicsActor.cpp.
| void PhysicsActor::ApplyAngularImpulse | ( | float | impulse | ) |
Similar to ApplyLinearImpulse, but affects the angular rather than linear velocity.
| impulse | The strength of the impulse to apply. |
Definition at line 211 of file PhysicsActor.cpp.
| b2Body* PhysicsActor::GetBody | ( | ) | [inline] |
Get the Box2D representation of this PhysicsActor. If you're going to be directly manipulating the Box2D API, this will be useful to you.
Definition at line 240 of file PhysicsActor.h.
| void PhysicsActor::ResetBody | ( | ) | [inline] |
Resets the internal pointer to the Box2D physics body to NULL. Call this if you're manually destroying the body for some reason and need to make sure the PhysicsActor doesn't keep trying to track it.
Definition at line 248 of file PhysicsActor.h.
| void PhysicsActor::SetSize | ( | float | x, |
| float | y = -1.f |
||
| ) |
An override of the Actor::SetSize function that disables itself after InitPhysics has been called.
Reimplemented from Actor.
Definition at line 219 of file PhysicsActor.cpp.
| void PhysicsActor::SetDrawSize | ( | float | x, |
| float | y = -1.f |
||
| ) |
Sometimes you want the visible size of an Actor to be larger or smaller than its collision geometry in the world. This function lets you alter the former without affecting the latter.
| x | Horizontal draw size in OpenGL units -- negative numbers treated as zero |
| y | Vertical draw size in OpenGL units -- if less than or equal to zero, assumed to be equal to x |
Definition at line 227 of file PhysicsActor.cpp.
| void PhysicsActor::SetPosition | ( | float | x, |
| float | y | ||
| ) | [virtual] |
An override of the Actor::SetPosition function that disables itself after InitPhysics has been called.
Reimplemented from Actor.
Definition at line 232 of file PhysicsActor.cpp.
| void PhysicsActor::SetPosition | ( | const Vector2 & | pos | ) | [virtual] |
An override of the Actor::SetPosition function that disables itself after InitPhysics has been called.
Reimplemented from Actor.
Definition at line 240 of file PhysicsActor.cpp.
| void PhysicsActor::SetRotation | ( | float | rotation | ) | [virtual] |
An override of the Actor::SetRotation function that disables itself after InitPhysics has been called.
Reimplemented from Actor.
Definition at line 248 of file PhysicsActor.cpp.
| void PhysicsActor::MoveTo | ( | const Vector2 & | newPosition, |
| float | duration, | ||
| String | onCompletionMessage = "" |
||
| ) | [inline] |
An override of the Actor::MoveTo function that doesn't allow the interval to be applied to PhysicsActors.
Definition at line 290 of file PhysicsActor.h.
| void PhysicsActor::RotateTo | ( | float | newRotation, |
| float | duration, | ||
| String | onCompletionMessage = "" |
||
| ) | [inline] |
An override of the Actor::RotateTo function that doesn't allow the interval to be applied to PhysicsActors.
Definition at line 296 of file PhysicsActor.h.
| void PhysicsActor::ChangeSizeTo | ( | const Vector2 & | newSize, |
| float | duration, | ||
| String | onCompletionMessage = "" |
||
| ) | [inline] |
An override of the Actor::ChangeSizeTo function that doesn't allow the interval to be applied to PhysicsActors.
Definition at line 302 of file PhysicsActor.h.
| void PhysicsActor::ChangeSizeTo | ( | float | newSize, |
| float | duration, | ||
| String | onCompletionMessage = "" |
||
| ) | [inline] |
An override of the Actor::ChangeSizeTo function that doesn't allow the interval to be applied to PhysicsActors.
Definition at line 308 of file PhysicsActor.h.
| virtual const String PhysicsActor::GetClassName | ( | ) | const [inline, virtual] |
Used by the SetName function to create a basename for this class. Overridden from Actor::GetClassName.
Definition at line 316 of file PhysicsActor.h.


1.7.5.1