fisica
Class FDistanceJoint

java.lang.Object
  extended by fisica.FJoint
      extended by fisica.FDistanceJoint

public class FDistanceJoint
extends FJoint

Represents a distance joint that tries to keep two bodies at a constant distance. This joint is similar to connecting both bodies by a spring.


Constructor Summary
FDistanceJoint(FBody body1, FBody body2)
          Construct a distance joint between two bodies.
 
Method Summary
 void attachImage(processing.core.PImage img)
          Attach an image to the object.
 void calculateLength()
          Sets the length of the joint to the current distance between the bodies.
 void dettachImage()
          Dettach any image that has been attached to the object.
 void draw(processing.core.PApplet applet)
           
 void draw(processing.core.PGraphics applet)
          This method is called when calling world.draw().
 float getAnchor1X()
          Get the horizontal coordinate of the first anchor point on the first body.
 float getAnchor1Y()
          Get the vertical coordinate of the first anchor point on the first body.
 float getAnchor2X()
          Get the horizontal coordinate of the second anchor point on the second body.
 float getAnchor2Y()
          Get the vertical coordinate of the second anchor point on the second body.
 float getImageAlpha()
          Get the opacity with which to draw the attached image.
 boolean isDrawable()
          Get whether the object must be drawn or not.
 void setAnchor1(float x, float y)
          Sets the position of the anchor of the first end of the joint on the first body.
 void setAnchor2(float x, float y)
          Sets the position of the anchor of the second end of the joint on the second body.
 void setDamping(float damping)
          Sets the damping of the spring used to maintain the distance between the bodies constant.
 void setDrawable(boolean drawable)
          Set whether the object must be drawn or not.
 void setFill(float g)
          Set the fill color of the object.
 void setFill(float g, float a)
          Set the fill color of the object.
 void setFill(float r, float g, float b)
          Set the fill color of the object.
 void setFill(float r, float g, float b, float a)
          Set the fill color of the object.
 void setFillColor(int col)
          Set the fill color of the object.
 void setFrequency(float frequency)
          Sets the frequency of the spring used to maintain the distance between the bodies constant.
 void setImageAlpha(float alpha)
          Set the opacity with which to draw the attached image.
 void setLength(float length)
          Sets the target distance for the joint.
 void setNoFill()
          Set that the object must be drawn without fill.
 void setNoStroke()
          Set that the object must be drawn without stroke.
 void setStroke(float g)
          Set the stroke color of the object.
 void setStroke(float g, float a)
          Set the stroke color of the object.
 void setStroke(float r, float g, float b)
          Set the stroke color of the object.
 void setStroke(float r, float g, float b, float a)
          Set the stroke color of the object.
 void setStrokeColor(int col)
          Set the stroke color of the object.
 void setStrokeWeight(float weight)
          Set the stroke weight of the object.
 
Methods inherited from class fisica.FJoint
getBody1, getBody2, getReactionForceX, getReactionForceY, getReactionTorque, setCollideConnected
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FDistanceJoint

public FDistanceJoint(FBody body1,
                      FBody body2)
Construct a distance joint between two bodies. The constructor automatically sets the anchors of the joint to the centers of each body, and the length of the joint to the current distance between the bodies.

Parameters:
body1 - first body of the joint
body2 - second body of the joint
Method Detail

setDamping

public void setDamping(float damping)
Sets the damping of the spring used to maintain the distance between the bodies constant.

Parameters:
damping - the damping of the spring

setFrequency

public void setFrequency(float frequency)
Sets the frequency of the spring used to maintain the distance between the bodies constant.

Parameters:
frequency - the frequency of the spring

calculateLength

public void calculateLength()
Sets the length of the joint to the current distance between the bodies.


setLength

public void setLength(float length)
Sets the target distance for the joint. This is the distance that the joint will try to maintain between the two bodies. If you want to use as length the current distance between the two bodies, use the method calculateLength.

Parameters:
length - the length of the joint

setAnchor2

public void setAnchor2(float x,
                       float y)
Sets the position of the anchor of the second end of the joint on the second body. This position must be given relative to the center of the second body. The anchor point is the point used to calculate the distance and to apply forces in order to move the body.

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

setAnchor1

public void setAnchor1(float x,
                       float y)
Sets the position of the anchor of the first end of the joint on the first body. This position must be given relative to the center of the first body. The anchor point is the point used to calculate the distance and to apply forces in order to move the body.

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

getAnchor1X

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

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

getAnchor1Y

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

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

getAnchor2X

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

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

getAnchor2Y

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

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

draw

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

Parameters:
applet - the applet onto which the object must be drawn.

draw

public void draw(processing.core.PApplet applet)

attachImage

public void attachImage(processing.core.PImage img)
Attach an image to the object. This method allows to draw an image onto the screen instead of calling the draw(PApplet) method.

Parameters:
img - the PImage to attach to the object.

dettachImage

public void dettachImage()
Dettach any image that has been attached to the object.

See Also:
attachImage(PImage)

getImageAlpha

public float getImageAlpha()
Get the opacity with which to draw the attached image.

Returns:
the opacity, a value from 0.0 to 1.0 with which to draw the attached image
See Also:
attachImage(PImage), setImageAlpha(float)

setImageAlpha

public void setImageAlpha(float alpha)
Set the opacity with which to draw the attached image.

Parameters:
alpha - the opacity, a value from 0.0 to 1.0 with which to draw the attached image
See Also:
attachImage(PImage), getImageAlpha()

setDrawable

public void setDrawable(boolean drawable)
Set whether the object must be drawn or not.

Parameters:
drawable - if true the object will be drawn, else it will not
See Also:
isDrawable()

isDrawable

public boolean isDrawable()
Get whether the object must be drawn or not.

Returns:
drawable if true the object will be drawn, else it will not
See Also:
setDrawable(boolean)

setFillColor

public void setFillColor(int col)
Set the fill color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of setFill(float), setFill(float,float), setFill(float,float,float) or setFill(float,float,float,float)

Parameters:
col - a Processing color type. e.g. myBody.setFillColor(color(20,100,30,90));
See Also:
setNoFill(), setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setNoFill

public void setNoFill()
Set that the object must be drawn without fill.

See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float g)
Set the fill color of the object.

Parameters:
g - gray value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float g,
                    float a)
Set the fill color of the object.

Parameters:
g - gray value
a - alpha (opacity) value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float r,
                    float g,
                    float b)
Set the fill color of the object.

Parameters:
r - red value
g - green value
b - blue value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float r,
                    float g,
                    float b,
                    float a)
Set the fill color of the object.

Parameters:
r - red value
g - green value
b - blue value
a - alpha (opacity) value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setStrokeColor

public void setStrokeColor(int col)
Set the stroke color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of setStroke(float), setStroke(float,float), setStroke(float,float,float) or setStroke(float,float,float,float)

Parameters:
col - a Processing color type. e.g. myBody.setStrokeColor(color(20,100,30,90));
See Also:
setNoStroke(), setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setNoStroke

public void setNoStroke()
Set that the object must be drawn without stroke.

See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float g)
Set the stroke color of the object.

Parameters:
g - gray value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float g,
                      float a)
Set the stroke color of the object.

Parameters:
g - gray value
a - alpha (opacity) value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float r,
                      float g,
                      float b)
Set the stroke color of the object.

Parameters:
r - red value
g - green value
b - blue value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float r,
                      float g,
                      float b,
                      float a)
Set the stroke color of the object.

Parameters:
r - red value
g - green value
b - blue value
a - alpha (opacity) value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStrokeWeight

public void setStrokeWeight(float weight)
Set the stroke weight of the object.

Parameters:
weight - weight value in pixels
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)


processing library fisica by Ricard Marxer. (c) 2009