Box2D
- Joints
- Filter group Index
- multi shapes
- moving “manually”
- Contact Listener & Interface!
Toxiclibs
- vs. Box2D
- using inhabitance
-what is verlet physics
- connected systems
- force directed graphs
Complex Systems
- simple units
- parallel
- emergence
Autonomous Agent
- limited perception of environment (predict future)
- process & calculate action
- no commands from leader??
Vehicle
- Action/Selection
- Path Determination
- Locomotion
Goals/Strategy
- week
- flee
- hug wall
- follow path
- braitenby??
##BOX2D
Review:
World (contains) Body (contains) Shapes
JOINT: Connects 2 bodies (not shape)
Joint definitions:
- distance joint
— imagine an inflexible steel rod
— NOT a shape. No substance
— can be springy
- revolute joint
— for turning stuff
— like the revolutionary point in transformice
- mouse joint*
— DJDO: Distance Joint Def Object
jd.body1=__________
jd.body2=__________
Filtering collisions
sd.filter.groupIndex = 1-8
If snowman & snow are both 8, they’ll collide with each other
-8 and 8 = Do not collide with each other
How to build more complex shapes in box2d
[] setAsBox();
O CircleDef
What if you wanted to make a O=||<< (person sideways)
1. Define the shape
- set properties: local position
2. Define the body
- set properties
3. Attach shape to body
- n times
To attach many shapes to body.
Define shape multiple times & attach to body
4. However: Every single shape is going to be attached at the center unless you set the 'local position' of the shape
MANUAL MOVEMENT
paddle.x = mouse.x (CANNOT DO)
How to move paddle with mouse?
Set an object's location
paddle.setXForm(mouseX,Y,angle 0) (TELEPORTATION)
Convert X/Y to WORLD coordinates
EVEN SO
- If you don't, BOX2D will think of things as teleportation.
- It cannot figure out the physics for it, so just jumps it
You need to connect a joint from the paddle to the mouse. So when you pull the mouse it pull the paddle.
In BOX2D, the "ground" is not the bottom of the screen. It's a Plane, so it's actually 'itself' or what we see.
Attach paddle to Mouse AND Ground. One to anchor it?
MouseJointDef mjd = ____
mjd.body1 = box.body;
mjd.body2 = box2d.getGroundBody(); <--
MouseJoint m; = _____
mj.setTarget(___,___); <--
INTERFACE
The only way BOX2D can tell processing when a collision is happening you have to conform to its standard and add required functions:
void add(){}
void persist(){}
void remove(){}
void results(){}
You don't have to have anything in it, but you have to write all of them!
MyListener ml;
box2d.add(ml);
voidAdd(ContactPoint cp) {
}
To make a particle turn red
Contact point btwn shape 1 & shape 2 --> bodies –> particle object
body –> particle
getUserData
box & particle
shape 1 & shape 2
filter vs ContactListener
grouping particles vs. collision of specific particles
##TOXICLIBS: A giant collection of libaries
BOX2D
World, Body, Shape, Joint
TOXICLIBS – Verlet physics packet
Verlet physics, V. Particle, X (no shape. Does not too collision), – V. Spring
— 3 kinds of springs:
– Verlet Spring
– constitutional????
– min distance
- Has it’s own vector class: Vec2D, Vec3D
- You can lock(); a particle
- boundaries in toxiclibs is the “background” in processing
-
Toxiclibs PRO:
+ 3D – has 3D capabilities. Box2d…2d only
+ Designed for Processing
+ Good documentation
+ Uses pixel coordinates (no headache conversions)
+ Faster (because it doesn’t do collisions?)
+ Connected systems (Genevieve’s string on balloon)
+ Inheritance – Toxiclibs has a nice big library we can use and we EXTENDS it.
Coding it up: //elegant processign coding
class Particle extends Verlet Particle {
void display(){
ellipse(x,y,10,10);
}
}
## COMPLEX SYSTEMS
- examples stock market
- many small parts moving to get a group composition
- no LEADER not controlled
Our “Vehicle” has locomotion, a path, and actions that we creatively use, but the key is it needs to have GOALS (seek, flee etc.)
Craig Reynolds: seek, flee, water, flow field, path crowd path, float. (Maker of these behaviors in movies, games etc.)
1. Competition: Up to you to make a combination of competing behaviors of the above drives
2. Make up stuff
Back to Craig: STEERING BEHAVIOR
Steering force = Desire – Velocity
An embeded “perception of the environment” meaning there’s a sense the object understand and interacts around/with environment. Eg. Obstacle avoidance = obvious ‘perception of envi’
Desire Vector = Target Vector – Loc Vector
Desired velocity want to hit max velocity. (there has to be an acceleration and directional change)
maximum force: determines steerablility to garget
float maxspeed;
float maxforce;
##TARGET SEEKING – basic seekign behavior
Books: Casey Reeves – Vehicles (emotional drives rather than hug wall etc.)
Turbles termites & traffic jams
“Animal a, new animal…we are so amazing, we can make an animal.” (mumbled 2nd half)
“How this scenario is giogn to pan out…i’ve already rehearesd this in my head…”
“We really shouldn’t do this but i can’t resist”
“This looks kind of right, but clearly not at all.” (box2d physics. body&image incongruent)
“That class was a big time energy suck…in a good way” (Big screens)
“And say you want the snow to bounce off the snowman… I don’t know if that really makes sense, but pretend you want the snow to bounce off the snow man”
“Lollipop…what was it thhe lollipop….gang?”
“guild”