fisica
Class FMouseJoint

java.lang.Object
  extended by fisica.FDrawable
      extended by fisica.FJoint
          extended by fisica.FMouseJoint

public class FMouseJoint
extends FJoint

Represents a mouse joint that tries to keep a body at a constant distance from the target. This joint is similar to connecting a spring from from the body to a target whose position can be changed programatically using setTarget(float, float).


Constructor Summary
FMouseJoint(FBody body, float x, float y)
          Construct a mouse joint between a body and a target.
 
Method Summary
 void draw(processing.core.PGraphics applet)
          This method is called when calling world.draw().
 void drawDebug(processing.core.PGraphics applet)
          This method is called when calling world.drawDebug().
 float getAnchorX()
          Get the horizontal coordinate of the anchor point on the body.
 float getAnchorY()
          Get the vertical coordinate of the anchor point on the body.
 FBody getGrabbedBody()
          Returns the body grabbed by this joint.
 float getTargetX()
          Returns the horizontal target position of the joint.
 float getTargetY()
          Returns the vertical target position of the joint.
 void releaseGrabbedBody()
          Releases the body grabbed by this joint.
 void setAnchor(float x, float y)
          Sets the anchor position at which the joint grabs the body.
 void setDamping(float damping)
          Sets the damping of the spring used to maintain the body and the target together.
 void setFrequency(float frequency)
          Sets the frequency of the spring used to maintain the body and the target together.
 void setGrabbedBodyAndTarget(FBody body, float x, float y)
          Sets the body grabbed by this joint and the target position.
 void setTarget(float x, float y)
          Sets the target position of the joint.
 
Methods inherited from class fisica.FJoint
addToWorld, getBody1, getBody2, getBox2dJoint, getReactionForceX, getReactionForceY, getReactionTorque, removeFromWorld, setCollideConnected
 
Methods inherited from class fisica.FDrawable
attachImage, dettachImage, draw, drawDebug, getFillColor, getImageAlpha, isDrawable, setDrawable, setFill, setFill, setFill, setFill, setFillColor, setImageAlpha, setNoFill, setNoStroke, setStroke, setStroke, setStroke, setStroke, setStrokeColor, setStrokeWeight
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FMouseJoint

public FMouseJoint(FBody body,
                   float x,
                   float y)
Construct a mouse joint between a body and a target. The constructor automatically sets the anchors of the joint to the center of the body.

Parameters:
body - the body to be grabbed by the joint
x - horizontal coordinate of the initial target of the joint
y - vertical coordinate of the initial target of the joint
Method Detail

setDamping

public void setDamping(float damping)
Sets the damping of the spring used to maintain the body and the target together. This property must be set before adding the joint to the world.

Parameters:
damping - the damping of the spring

setFrequency

public void setFrequency(float frequency)
Sets the frequency of the spring used to maintain the body and the target together. This property must be set before adding the joint to the world.

Parameters:
frequency - the frequency of the spring

setTarget

public void setTarget(float x,
                      float y)
Sets the target position of the joint. By setting this property everytime the mouse is used we are able to make the body of this joint follow mouse.

Parameters:
x - horizontal coordinate of the target of the joint
y - vertical coordinate of the target of the joint

getTargetX

public float getTargetX()
Returns the horizontal target position of the joint.

Returns:
horizontal coordinate of the target of the joint

getTargetY

public float getTargetY()
Returns the vertical target position of the joint.

Returns:
vertical coordinate of the target of the joint

setGrabbedBodyAndTarget

public void setGrabbedBodyAndTarget(FBody body,
                                    float x,
                                    float y)
Sets the body grabbed by this joint and the target position.

Parameters:
body - the body to be grabbed by the joint
x - horizontal coordinate of the target of the joint
y - vertical coordinate of the target of the joint

releaseGrabbedBody

public void releaseGrabbedBody()
Releases the body grabbed by this joint.


getGrabbedBody

public FBody getGrabbedBody()
Returns the body grabbed by this joint.

Returns:
the body grabbed by this joint

setAnchor

public void setAnchor(float x,
                      float y)
Sets the anchor position at which the joint grabs the body. The anchor point is the point used to apply forces in order to move the body.

Parameters:
x - the horizontal coordinate of the anchor relative to the center of the body
y - the vertical coordinate of the anchor relative to the center of the body

getAnchorX

public float getAnchorX()
Get the horizontal coordinate of the anchor point on the body. This position is given relative to the center of the body.

Returns:
the horizontal coordinate of the anchor relative to the center of the first body

getAnchorY

public float getAnchorY()
Get the vertical coordinate of the anchor point on the body. This position is given relative to the center of the body.

Returns:
the vertical coordinate of the anchor relative to the center of the first body

draw

public void draw(processing.core.PGraphics applet)
Description copied from class: FDrawable
This method is called when calling world.draw(). This method may be overriden to allow custom drawing of the object.

Overrides:
draw in class FDrawable
Parameters:
applet - the graphics onto which the object must be drawn.

drawDebug

public void drawDebug(processing.core.PGraphics applet)
Description copied from class: FDrawable
This method is called when calling world.drawDebug(). This method may be overriden to allow custom debug drawing of the object.

Overrides:
drawDebug in class FDrawable
Parameters:
applet - the graphics onto which the object must be drawn.


processing library fisica by Ricard Marxer. (c) 2009-2013