# Physics¶

## Summary¶

Movement

 `LinearVelocity` The current speed of the body. `AngularVelocity` Sets the angular velocity of the object, causing it to spin around its center of mass. `ApplyLinearImpulse`(force[, point]) Similar to ApplyForce, but applies an impulse rather than a force. `ApplyAngularImpulse`(impulse) Applies an angular impulse to the object, causing it to spin around it center of mass. `ApplyForce`(force[, point]) Applies a force to the provided point on the object. `ApplyTorque`(impulse) ApplyTorque is to ApplyAngularImpulse what ApplyForce is to ApplyLinearImpulse.

Physics Properties

 `Mass` The mass of the object. `Inertia` Determines how much torque is required to cause this object to rotate. `Friction` The friction this body has with other bodies. `LinearDamping` By setting linear damping the body will constantly slow-down a little. `AngularDamping` Applies a constant slow-down on rotations, thus preventing objects from spinning forever. `Restitution` How much velocity will be retained on collision. `FixedRotation` By settings this to True, the body will no longer rotate as a result of forces applied to it (you can still rotate it manually). `IgnoreCCD` CCD stands for Continuous Collision Detection, and it is form of collision detection that prevents one object from being able to go through another object if it goes fast enough. `IgnoreGravity` As the name implies, allows the body to ignore the gravity of the world. `IsBullet` If True, enables CCD (Continuous Collision Detection) on a dynamic object. `IsSensor` If True, this object will function as a sensor. `LocalCenter` The center of mass in local (relative to the body) coordinates. `WorldCenter` The center of mass in world coordinates.

Collisions

 `OnCollision` The list of collision functions. `OnSeparation` The list of separation functions. `IgnoreCollisionWith`(body) Presumably allows this body to ignore all collision with the passed body, but I have not tested this yet. `RestoreCollisionWith`(body) Probably allows you to undo a call to IgnoreCollisionWith. `CollidesWith` The category of objects this object collides with. `CollisionCategories` Something similar to CollidesWith (maybe these are the categories this object belongs to). `CollisionGroup` Something to do with collisions, but I don’t know how it works. `ResetDynamics`() Resets the dynamics of this object. `ResetMassData`() Resets the mass data of this object.

Conversions

 `GetLocalPoint`(point) Takes a world point and turns it into a local point. `GetLocalVector`(point) Takes a world vector and turns it into a local vector. `GetWorldPoint`(point) Takes a local point and turns it into a world point. `GetWorldVector`(point) Takes a local vector and turns it into a world vector. `GetLinearVelocityFromLocalPoint`(point) Beats me. `GetLinearVelocityFromWorldPoint`(point) Beats me.

Position

 `Position` The current position of the object is simulator coordinates. `Rotation` The current rotation of the object. `Revolutions` How many times did this object rotate around its own axis. `SetTransform`(transform) Presumably allows you to change the position and rotation simultaneously. `SetTransformIgnoreContacts`(transform) I guess similar to SetTransform, but ignores collisions that may occur because of its new position or orientation. `GetTransform`() I don’t have a clue.

Other

 `Clone`() C# method for creating a copy. `DeepClone`() C# method for creating a deep copy. `CreateFixture`(shape) Adds another “fixture” to this body. `DestroyFixture`(fixture) Removes and destroys a “fixture” in this body. `Dispose`() C# destructor. `IsDisposed` Whether or not tis object is disposed. `ContactList` The list this object is currently in (potentially) in contact with. `ControllerFilter` Beats me. `FixtureList` The list of fixture part of this body. `JointList` The list of joints attached to this body. `PhysicsLogicFilter` Some sort of filter that I don’t know how to use. `Awake` Boolean that determines whether the object is awake or not. `BodyId` Unique identifier of this particular body in the physics simulator. `BodyType` The body type of an object is either Static, Dynamic, or Kinematic. `Enabled` Boolean determining whether this body is enabled or not. `IsStatic` Indicates whether this object is static or not. `SleepingAllowed` Whether or not this object should be allowed to sleep. `UserData` Pointer to anything that you want.

## Class¶

class `Body`[source]

The Farseer body object is the object returned when calling shape.body after drawing the body to a window. As such, all functions and attributes below can be accessed with:

```c=Circle((0,0), 10)
c.draw(win)
c.body.AngularDamping
```
`ApplyAngularImpulse`(impulse)[source]

Applies an angular impulse to the object, causing it to spin around it center of mass. In contrast to setting the AngularVelocity attribute, applying an angular impulse will add or subtract from the current speed. This means that, if the object is rotating clockwise, applying a counter-clockwise impulse may simple slow down the rotation, rather than having the object immediately start spinning the other way.

Example:

```r=Rectangle((0,0), (50,50))
r.draw(win)
r.body.ApplyAngularImpulse (1)
```
`ApplyForce`(force, point=None)[source]

Applies a force to the provided point on the object. Normally, the point is provided in world coordinates, which may be difficult to work with. As such, it is often more useful to first transform the point to object coordinates instead with GetWorldPoint. If no point is provided, the force is applied to center-of-mass of the object, meaning the force will not cause rotation.

Example::

from Graphics import * win = Window(500, 500) win.mode = “physics” win.gravity = Vector(0, 0)

r=Rectangle((0,0), (50,50)) r.draw(win) point = r.body.GetWorldPoint(Vector(1,0)) r.body.ApplyForce(Vector(0, 1), point)

win.run()

`ApplyLinearImpulse`(force, point=None)[source]

Similar to ApplyForce, but applies an impulse rather than a force. The main difference between a force and an impulse is that the impulse will immediately change the speed of the object, while a force will only do so after being summed with all other forces.

As with ApplyForce, the point is provided in world coordinates, which may be difficult to work with. As such, it is often more useful to first transform the point to object coordinates instead with GetWorldPoint. If no point is provided, the force is applied to center-of-mass of the object, meaning the impulse will not cause rotation.

Example::

from Graphics import * win = Window(500, 500) win.mode = “physics” win.gravity = Vector(0, 0)

r=Rectangle((0,0), (50,50)) r.draw(win) point = r.body.GetWorldPoint(Vector(1,0)) r.body.ApplyLinearImpulse(Vector(0, 1), point)

win.run()

`ApplyTorque`(impulse)[source]

ApplyTorque is to ApplyAngularImpulse what ApplyForce is to ApplyLinearImpulse. That is, rather than causing an immediate angular acceleration, all different kinds of torque will be summed before the final speed adjustment is made.

Example:

```r=Rectangle((0,0), (50,50))
r.draw(win)
r.body.ApplyTorque(1)
```
`Clone`()[source]

C# method for creating a copy. Should probably never be called from python.

`CreateFixture`(shape)[source]

Adds another “fixture” to this body. Will explain more later.

`DeepClone`()[source]

C# method for creating a deep copy. Should probably never be called from python.

`DestroyFixture`(fixture)[source]

Removes and destroys a “fixture” in this body. Will explain more later.

`Dispose`()[source]

C# destructor. Should probably never be called from python.

`GetLinearVelocityFromLocalPoint`(point)[source]

Beats me.

`GetLinearVelocityFromWorldPoint`(point)[source]

Beats me.

`GetLocalPoint`(point)[source]

Takes a world point and turns it into a local point.

`GetLocalVector`(point)[source]

Takes a world vector and turns it into a local vector.

`GetTransform`()[source]

I don’t have a clue.

`GetWorldPoint`(point)[source]

Takes a local point and turns it into a world point.

`GetWorldVector`(point)[source]

Takes a local vector and turns it into a world vector.

`IgnoreCollisionWith`(body)[source]

Presumably allows this body to ignore all collision with the passed body, but I have not tested this yet.

`ResetDynamics`()[source]

Resets the dynamics of this object. I do not know what that means in practice.

`ResetMassData`()[source]

Resets the mass data of this object. Mass data will be recalculated from its fixtures, but because most bodies in Calico will only have one fixture, this usually just resets the mass to its default (initial) value.

`RestoreCollisionWith`(body)[source]

Probably allows you to undo a call to IgnoreCollisionWith.

`SetTransform`(transform)[source]

Presumably allows you to change the position and rotation simultaneously.

`SetTransformIgnoreContacts`(transform)[source]

I guess similar to SetTransform, but ignores collisions that may occur because of its new position or orientation.

`AngularDamping` = 0

Applies a constant slow-down on rotations, thus preventing objects from spinning forever. You should probably add some angular damping to all your objects, unless you specifically WANT the object to spin forever.

Example:

```r=Rectangle((0,0), (50,50))
r.draw(win)
r.body.AngularDamping = 0.5
r.body.AngularVelocity = 1
```
`AngularVelocity` = <Microsoft.Xna.Framework.Vector2 instance>

Sets the angular velocity of the object, causing it to spin around its center of mass.

Example:

```r=Rectangle((0,0), (50,50))
r.draw(win)
r.body.AngularVelocity = 1
```
`Awake` = True

Boolean that determines whether the object is awake or not. By default, if an object did not move or interact with other objects for a while, the object will be put “asleep” by the physics simulator, which is a mode in which it object will no longer be considered when calculating movements and forces. If you notice odd behavior of an object that hasn’t been active for a while, it may be possible that you need to “wake” the object first.

`BodyId` = 0

Unique identifier of this particular body in the physics simulator. Might be useful if you want to check the identity of an object your colliding with. Should probably not be changed, as that could cause issues for the simulator.

`BodyType` = 'dynamic'

The body type of an object is either Static, Dynamic, or Kinematic. Static objects never move in the physics simulator, though the can be moved manually. Dynamic objects are the objects will move as a result of forces and collision in the physics simulator. I am currently unsure about Kinematic objects.

`CollidesWith` = None

The category of objects this object collides with. I will update this entry when I learn more.

`CollisionCategories` = None

Something similar to CollidesWith (maybe these are the categories this object belongs to). I will update this entry when I learn more.

`CollisionGroup` = None

Something to do with collisions, but I don’t know how it works.

`ContactList` = None

The list this object is currently in (potentially) in contact with. The contact list is useful for determining things like collisions, but it may be a bit tricky to work with. Here is an example:

```from Graphics import *
win = Window(500, 500)
win.mode = "physics"

c = Circle((250,0), 25)
c.draw(win)

r = Rectangle((0, 400), (500, 500))
r.bodyType = "static"
r.draw(win)

while True:
contactList = c.body.ContactList
while contactList:
cont = contactList.Contact
if cont.IsTouching():
print("Touching!")
contactList = contactList.Next
win.step(0.01)
```
`ControllerFilter` = None

Beats me.

`Enabled` = True

Boolean determining whether this body is enabled or not. The exact implications of this are unclear to me at this point.

`FixedRotation` = False

By settings this to True, the body will no longer rotate as a result of forces applied to it (you can still rotate it manually). This is useful for objects like the player character in a platformer.

`FixtureList` = None

The list of fixture part of this body. Will expand on this later.

`Friction` = 1

The friction this body has with other bodies. Friction is only applied when two bodies are touching or colliding, and thus, this does not simulate air friction.

`IgnoreCCD` = False

CCD stands for Continuous Collision Detection, and it is form of collision detection that prevents one object from being able to go through another object if it goes fast enough. By default CCD is enabled between dynamic and static objects (but not between dynamic and dynamic objects). Disabling CCD can increase performance.

`IgnoreGravity` = False

As the name implies, allows the body to ignore the gravity of the world.

`Inertia` = 1

Determines how much torque is required to cause this object to rotate.

`IsBullet` = False

If True, enables CCD (Continuous Collision Detection) on a dynamic object. The attribute is called IsBullet because this property is most useful on fast moving bullets that need to hit other dynamic objects (rather than pass through them).

`IsDisposed` = False

Whether or not tis object is disposed. I do not understand the implications of this.

`IsSensor` = False

If True, this object will function as a sensor. It will not collide with anything (everything will pass through it), but it will call its collision function if one is installed. Creating sensor objects is useful is you want to create triggered events based on an area (if the player moves into this room, the doors close and a boss-fight starts).

`IsStatic` = False

Indicates whether this object is static or not. Provides effectively the same information as BodyType, because Calico does not usually create kinematic bodies.

`JointList` = None

The list of joints attached to this body. More on this later.

`LinearDamping` = 0

By setting linear damping the body will constantly slow-down a little. LinearDamping is effectively a cheap way to simulate some kind of air resistance, and can be useful if you want an object to behave a bit like a feather.

`LinearVelocity` = <Microsoft.Xna.Framework.Vector2 instance>

The current speed of the body. You can change this to move your body around.

`LocalCenter` = <Microsoft.Xna.Framework.Vector2 instance>

The center of mass in local (relative to the body) coordinates. Changing the local center can make an object feel “wobbly” as it turns around a different point.

`Mass` = 1

The mass of the object. The mass of an object determines how much force is required to move the object at a certain speed.

`OnCollision` = None

The list of collision functions.

`OnSeparation` = None

The list of separation functions.

`PhysicsLogicFilter` = None

Some sort of filter that I don’t know how to use.

`Position` = <Microsoft.Xna.Framework.Vector2 instance>

The current position of the object is simulator coordinates.

`Restitution` = 0.5

How much velocity will be retained on collision. Determines the “bounce” of the object.

`Revolutions` = 0

How many times did this object rotate around its own axis.

`Rotation` = 0

The current rotation of the object.

`SleepingAllowed` = True

Whether or not this object should be allowed to sleep. Setting this to False makes you a cruel person.

`UserData` = None

Pointer to anything that you want. In calico, by default, this will point back to the calico shape associated with this body, which is very useful in collision functions.

`WorldCenter` = <Microsoft.Xna.Framework.Vector2 instance>

The center of mass in world coordinates.