Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUObstacleSelector.h>
Public Member Functions | |
bool | isSelected () const |
Obstacle * | getObstacle () |
bool | select (const Vec2 &pos) |
void | moveTo (const Vec2 &pos) |
void | deselect () |
bool | onQuery (b2Fixture *fixture) |
float | getFrequency () const |
void | setFrequency (float speed) |
float | getDamping () const |
void | setDamping (float ratio) |
float | getForce () const |
void | setForce (float force) |
const Size & | getMouseSize () const |
void | setMouseSize (const Size &size) |
CC_CONSTRUCTOR_ACCESS | _selection (nullptr) |
CC_CONSTRUCTOR_ACCESS | _ground (nullptr) |
CC_CONSTRUCTOR_ACCESS | _mouseJoint (nullptr) |
~ObstacleSelector (void) | |
bool | init (WorldController *controller) |
bool | init (WorldController *controller, const Size &mouseSize) |
Static Public Member Functions | |
static ObstacleSelector * | create (WorldController *controller) |
static ObstacleSelector * | create (WorldController *controller, const Size &mouseSize) |
Public Attributes | |
CC_CONSTRUCTOR_ACCESS | __pad0__: ObstacleSelector(void) : _controller(nullptr) |
Protected Attributes | |
WorldController * | _controller |
b2Fixture * | _selection |
b2Body * | _ground |
b2MouseJointDef | _jointDef |
b2MouseJoint * | _mouseJoint |
Rect | _pointer |
float | _force |
Selection tool to move and drag physics obstacles
This class is essentially an instance of b2MouseJoint, but with an API that makes it a lot easier to use. It must be attached to a WorldController on creation, and this controller can never change. If you want a selector for a different WorldController, make a new instance.
As with all instances of b2MouseJoint, there will be some lag in the drag (though this is true on touch devices in general). You can adjust the degree of this lag by adjusting the force. However, larger forces can cause artifacts when dragging an obstacle through other obstacles.
ObstacleSelector::~ObstacleSelector | ( | void | ) |
Disposes of this selector, releasing all resources.
|
static |
Creates a new ObstacleSelector for the given WorldController
This controller can never change. If you want a selector for a different WorldController, make a new instance.
This constructor uses the default mouse size.
controller | the physics controller |
a reference to the world controller
|
static |
Creates a new ObstacleSelector for the given WorldController and mouse size.
This controller can never change. If you want a selector for a different WorldController, make a new instance. However, the mouse size can be changed at any time.
controller | the physics controller |
a reference to the world controller
void ObstacleSelector::deselect | ( | ) |
Deselects the physics body, discontinuing any mouse movement.
The body may still continue to move of its own accord.
|
inline |
Returns the damping ratio of the mouse joint
See the documentation of b2JointDef for more information on the damping ratio.
|
inline |
Returns the force multiplier of the mouse joint
The mouse joint will move the attached fixture with a force of this value times the object mass.
|
inline |
Returns the response speed of the mouse joint
See the documentation of b2JointDef for more information on the response speed.
|
inline |
Returns the size of the mouse pointer
When a selection is made, this selector will create an axis-aligned bounding box centered at the mouse position. Any fixture overlapping this box will be selected. The size of this box is determined by this value.
Obstacle * ObstacleSelector::getObstacle | ( | ) |
|
inline |
Initializes a new ObstacleSelector for the given WorldController
This controller can never change. If you want a selector for a different WorldController, make a new instance.
This initializer uses the default mouse size.
controller | the physics controller |
a reference to the world controller
bool ObstacleSelector::init | ( | WorldController * | controller, |
const Size & | mouseSize | ||
) |
Initializes a new ObstacleSelector for the given WorldController and mouse size.
This controller can never change. If you want a selector for a different WorldController, make a new instance. However, the mouse size can be changed at any time.
controller | the physics controller |
a reference to the world controller
|
inline |
Returns true if a physics body is currently selected
void ObstacleSelector::moveTo | ( | const Vec2 & | pos | ) |
Moves the selected body to the given position.
pos | the position (in physics space) to move to |
If nothing is selected, this method does nothing.
bool ObstacleSelector::onQuery | ( | b2Fixture * | fixture | ) |
Callback function for mouse selection.
This is the callback function used by the method queryAABB to select a physics body at the current mouse location.
fixture | the fixture selected |
bool ObstacleSelector::select | ( | const Vec2 & | pos | ) |
Returns true if a physics body was selected at the given position.
This method contructs and AABB the size of the mouse pointer, centered at the given position. If any part of the AABB overlaps a fixture, it is selected.
pos | the position (in physics space) to select |
|
inline |
Sets the damping ratio of the mouse joint
See the documentation of b2JointDef for more information on the damping ratio.
ration | the damping ratio of the mouse joint |
|
inline |
Sets the force multiplier of the mouse joint
The mouse joint will move the attached fixture with a force of this value times the object mass.
force | the force multiplier of the mouse joint |
|
inline |
Sets the response speed of the mouse joint
See the documentation of b2JointDef for more information on the response speed.
speed | the response speed of the mouse joint |
|
inline |
Sets the size of the mouse pointer
When a selection is made, this selector will create an axis-aligned bounding box centered at the mouse position. Any fixture overlapping this box will be selected. The size of this box is determined by this value.
size | the size of the mouse pointer |
|
protected |
The WorldController associated with this selection
|
protected |
The amount to multiply by the mass to move the object
|
protected |
A default body used as the other half of the mouse joint
|
protected |
A reusable definition for creating a mouse joint
|
protected |
The current mouse joint, if an item is selected
|
protected |
The region of world space to select an object from
|
protected |
The current fixture selected by this tool (may be nullptr)