Class: RigidRectangle

RigidRectangle(xf, width, height) → {RigidRectangle}

Defines a rigid rectangle shape supported by the physics systems

Found in Chapter 9, page 537 of the textbook

Examples: 9.1 Rigid Shape and Bounds, 9.3 Rectangle Collisions, 9.6 Collision Position Correction, 9.9 Physics Presets

Constructor

new RigidRectangle(xf, width, height) → {RigidRectangle}

Parameters:
Name Type Description
xf Transform the Transform for this RigidRectangle
width float the width of the rectangle
height float the height of the rectangle
Source:
Returns:
a new RigidRectangle instance
Type
RigidRectangle

Extends

Methods

adjustPositionBy(v, delta)

Adjust the position of this RigidRectangle by moving the position a distance along a specified vector. Updates the vertices
Parameters:
Name Type Description
v vec2 the [X,Y] direction vector
delta float the distance to move
Overrides:
Source:

boundTest(otherShape) → {boolean}

Test if this RigidShape is overlapping with another RigidShape
Parameters:
Name Type Description
otherShape RigidShape the other RigidShape
Inherited From:
Source:
Returns:
true if the two shapes overlap
Type
boolean

checkCircRectVertex(v1, cirCenter, r, info) → {boolean}

Determines if there is collision between the shapes
Parameters:
Name Type Description
v1 vec2 the rectangle vertex that is closest to the center of the circle
cirCenter vec2 the center of the circle
r float the radius of the circle
info CollisionInfo used to store the collision info
Source:
Returns:
true if there is collision between the 2 shapes
Type
boolean

collideRectCirc(otherCir, collisionInfo) → {boolean}

Check for collision between RigidRectangle and Circle
Parameters:
Name Type Description
otherCir RigidCircle circle to check for collision status against
collisionInfo CollisionInfo Where the Collision Info is stored
Source:
Returns:
true if collision occurs
Type
boolean

collideRectRect(r1, r2, collisionInfo) → {boolean}

Check for collision between a RigidRectangle and another RigidRectangle
Parameters:
Name Type Description
r1 RigidRectangle RigidRectangle object to check for collision status
r2 RigidRectangle RigidRectangle object to check for collision status against
collisionInfo CollisionInfo the information object for the collision
Source:
Returns:
true if collision occurs
Type
boolean

collisionTest(otherShape, collisionInfo) → {boolean}

Decides on which collision function to call based on the type of shape passed
Parameters:
Name Type Description
otherShape RigidShape The other shape to test collision
collisionInfo CollisionInfo Where the collision information is stored
Source:
Returns:
the results of the collision
Type
boolean

computeFaceNormals()

Computes the normal vectors for each of this RigidRectangle's sides
Source:

draw(aCamera)

Draws this RigidRectangle to aCamera
Parameters:
Name Type Description
aCamera Camera the Camera to draw to
Overrides:
Source:

findAxisLeastPenetration(otherRect, collisionInfo) → {boolean}

Find the shortest axis of penetration between this RigidRectangle and another
Parameters:
Name Type Description
otherRect RigidRectangle the other rectangle being tested
collisionInfo CollisionInfo Record of the collision information
Source:
Returns:
true if there is overlap in all four directions.
Type
boolean

findSupportPoint(dir, ptOnEdge)

Calculates a support point for a point on the edge of this RigidRectangle
Parameters:
Name Type Description
dir vec2 the direction of the support point
ptOnEdge vec2 a point on the edge of this RigidRectangle
Source:

flipVelocity()

Reverse the direction of the velocity vector of this RigidShape
Inherited From:
Source:

getAcceleration() → {vec2}

Returns the world coordinate acceleration vector of this RigidShape
Inherited From:
Source:
Returns:
mAcceleration - the acceleration vector
Type
vec2

getAngularVelocity() → {float}

Returns the angular velocity of this RigidShape
Inherited From:
Source:
Returns:
mAngularVelocity - the angular velocity
Type
float

getBoundRadius() → {float}

Returns the radius of the bounds for this RigidShape
Inherited From:
Source:
Returns:
mBoundRadius - the bounding radius
Type
float

getCenter() → {vec2}

Returns the world coordinates of the center of this RigidShape
Inherited From:
Source:
Returns:
[X,Y] center point
Type
vec2

getCurrentState() → {string}

Returns a string containing the mass, inertia, friction, and restitution of this RigidShape
Inherited From:
Source:
Returns:
- the information string
Type
string

getFriction() → {float}

Returns the friction for this RigidShape
Inherited From:
Source:
Returns:
mFriction - the friction
Type
float

getInertia() → {float}

Returns the inertia of this RigidShape
Inherited From:
Source:
Returns:
mInertia - the inertia
Type
float

getInvMass() → {float}

Returns the inverse mass of this RigidShape
Inherited From:
Source:
Returns:
mInvMass - the inverse mass
Type
float

getRestitution() → {float}

Returns the restitution for this RigidShape
Inherited From:
Source:
Returns:
mRestitution - the restitution
Type
float

getType() → {string}

Returns what subtype this RigidShape belongs to
Inherited From:
Source:
Returns:
mType - whether this is a RigidCircle or RigidRectangle
Type
string

getVelocity() → {vec2}

Returns the velocity vector of this RigidShape
Inherited From:
Source:
Returns:
mVelocity - [X,Y] velocity vector
Type
vec2

incShapeSizeBy(dt)

Adds a value to the width and height of this RigidRectangle. Updates the vertices and inertia automatically
Parameters:
Name Type Description
dt float the value to add
Source:

rotateVertices()

Match the rotation of the vertices and face normals to the rotation of the Transform for this RigidRectangle
Source:

setAcceleration(x, y)

Sets the world coordinate acceleration vector of this RigidShape
Parameters:
Name Type Description
x float horizontal acceleration
y float vertical acceleration
Inherited From:
Source:

setAngularVelocity(w)

Sets the angular velocity for this RigidShape
Parameters:
Name Type Description
w float the new angular velocity
Inherited From:
Source:

setAngularVelocityDelta(dw)

Adds a value to the current angular velocity for this RigidShape
Parameters:
Name Type Description
dw float value to add
Inherited From:
Source:

setBoundRadius(r)

Sets the bound radius of this RigidShape
Parameters:
Name Type Description
r float the new bound radius
Inherited From:
Source:

setFriction(f)

Sets the friction for this RigidShape
Parameters:
Name Type Description
f float the new friction
Inherited From:
Source:

setInertia(i)

Sets the inertia of this RigidShape
Parameters:
Name Type Description
i float the new inertia
Inherited From:
Source:

setMass(m)

Sets the mass of this RigidShape
Parameters:
Name Type Description
m float the new mass
Inherited From:
Source:

setPosition(x, y)

Set the world coordinate position of this RigidRectangle. Updates the vertices
Parameters:
Name Type Description
x float horizontal position
y float vertical position
Overrides:
Source:

setRestitution(r)

Sets the restitution for this RigidShape
Parameters:
Name Type Description
r float the new restitution
Inherited From:
Source:

setTransform(xf)

Change the Transform for this RigidRectangle
Parameters:
Name Type Description
xf Transform the Transform for this RigidRectangle
Overrides:
Source:

setVelocity(x, y)

Set the velocity vector of this RigidShape
Parameters:
Name Type Description
x float horizontal world coordinate velocity
y float vertical world coordinate velocity
Inherited From:
Source:

setVertices()

Calculates the world coordinates of the vertices of this RigidRectangle
Source:

toggleDrawBound()

Toggle whether the bounds of this RigidShape are drawn
Inherited From:
Source:

update()

Updates the motion and verticies of this RigidRectangle
Overrides:
Source:

updateInertia()

Update the inertia of this RigidRectangle
Source:

userSetsState()

Based on keyboard input raise or lower the mass, friction, or restitution of this RigidShape
Inherited From:
Source: