Skip to content

Commit

Permalink
Beta Version
Browse files Browse the repository at this point in the history
Fixed a bug, that caused fragments to keep hanging in the air without a
connection to a fixed object.
Added some minor improvements
  • Loading branch information
MoritzSkowronski committed Dec 12, 2015
1 parent 4e77639 commit e64cfc9
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 35 deletions.
Binary file modified bin/box2DWorld/Polygon.class
Binary file not shown.
Binary file modified bin/data/Image.class
Binary file not shown.
Binary file modified bin/data/Video.class
Binary file not shown.
Binary file modified bin/display/MuseumFinal.class
Binary file not shown.
Binary file modified bin/glass/Crack.class
Binary file not shown.
Binary file modified bin/glass/Fragment.class
Binary file not shown.
Binary file modified bin/helpers/VoronoiBuilder.class
Binary file not shown.
Binary file modified bin/movement/MovementHandler.class
Binary file not shown.
Binary file modified bin/movement/OSCReceiver.class
Binary file not shown.
Binary file modified bin/persons/TriggerBox.class
Binary file not shown.
8 changes: 7 additions & 1 deletion src/box2DWorld/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Polygon(PApplet p, Box2DProcessing box2d, Fragment fragment, PVector velo
}

this.widthheight = (fragment.getMaxX() - fragment.getMinX())
* (fragment.getMaxY() - fragment.getMinY());
+ (fragment.getMaxY() - fragment.getMinY());

corners = new Vec2[realWorldCorners.length];
mass = fragment.getArea();
Expand Down Expand Up @@ -106,6 +106,12 @@ public boolean isDead() {

return isDead;
}

public void kill(){

box2d.destroyBody(body);
isDead = true;
}

private void testIfDead() {

Expand Down
2 changes: 1 addition & 1 deletion src/data/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Image(PApplet p, PImage image) {

i++;
resizedWidth = tempResizeWidth * i;
resizedHeight = tempResizeWidth * i;
resizedHeight = tempResizeHeight * i;
}

if (i != 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/data/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Video(PApplet p, Movie video) {

i++;
resizedWidth = tempResizeWidth * i;
resizedHeight = tempResizeWidth * i;
resizedHeight = tempResizeHeight * i;
}

resizedWidth -= tempResizeWidth;
Expand Down
37 changes: 33 additions & 4 deletions src/display/MuseumFinal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import box2DWorld.Polygon;
import data.ContentGenerator;
Expand All @@ -20,6 +21,7 @@
import movement.MovementHandler;
import movement.OSCReceiver;
import persons.Person;
import persons.TriggerBox;
import processing.core.PApplet;
import processing.core.PVector;
import shiffman.box2d.Box2DProcessing;
Expand Down Expand Up @@ -89,18 +91,20 @@ public void setup() {

box2dWorld = new Box2DProcessing(this);
box2dWorld.createWorld();
box2dWorld.setGravity(0, -100);
box2dWorld.setGravity(0, -150);

movementHandler = new MovementHandler();

receiver = new OSCReceiver(movementHandler);

running = true;

frameRate(30);
}

@Override
public void draw() {
frameRate(30);
// frameRate(30);

background(firstColor);
box2dWorld.step();
Expand Down Expand Up @@ -146,6 +150,10 @@ public void updateCrack() {

Iterator<Person> iterator = movementHandler.getPersons().values()
.iterator();

Iterator<TriggerBox> boxIterator = movementHandler.getTriggerZones()
.values().iterator();

while (iterator.hasNext()) {

Person person = iterator.next();
Expand All @@ -169,6 +177,29 @@ public void updateCrack() {
height / 2, 2, velocity);
} else {
if (centroid.y < 0.6) {
// while (boxIterator.hasNext()) {
//
// TriggerBox box =
// boxIterator.next();
// if (box.getPointsInsideBox() !=
// 0) {
// System.out.println("----Person-----");
// System.out.println(person.getId());
// Iterator<Integer> hm =
// box.getPointsPerPerson()
// .keySet().iterator();
// while(hm.hasNext()){
// System.out.println("----trigger----");
// System.out.println(hm.next());
// }
// // if
// // (box.getPointsPerPerson()
// // .containsKey(person.getId()))
// // {
// //
// // }
// }
// }

glass.getCrack().breakParts(this, box2dWorld,
centroid.x, height / 2, 3, velocity);
Expand Down Expand Up @@ -205,8 +236,6 @@ public void displayAll() {
// Get current Crack
Crack crack = glass.getCrack();

// TODO update Crack

// Paint Image or Video

if (crack != null) {
Expand Down
125 changes: 112 additions & 13 deletions src/glass/Crack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package glass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

Expand Down Expand Up @@ -145,20 +146,17 @@ public void breakParts(PApplet p, Box2DProcessing box2d, float xPoint, float yPo
lastUpdate = System.currentTimeMillis();

// If there are less than half of the fragments break all
if (fragments.size() / 2 < crackAmount) {

breakCrack(p, box2d, velocity);
}
// if (fragments.size() / 2 < crackAmount) {
//
// breakCrack(p, box2d, velocity);
// }

// calculate rectangle size
float rectangleWidth = minInteractionWidthHeight.x * interactionStep;
float rectangleHeight = minInteractionWidthHeight.y * interactionStep;
if (rectangleWidth == 0 || rectangleHeight == 0)
return;

ArrayList<PVector> randomPolygon = RandomPolygonGenerator.generateRandomPolygon(xPoint,
yPoint, rectangleWidth, rectangleHeight);

ArrayList<PVector> temporaryBoundingBox = MathHelpers.createBoundingVectors(xPoint, yPoint,
rectangleWidth, rectangleHeight);

Expand All @@ -181,7 +179,7 @@ public void breakParts(PApplet p, Box2DProcessing box2d, float xPoint, float yPo
if (!line.isVisible()) {
fragment.setVisible(line);
}

fragmentIsInRange = true;
}
}
Expand All @@ -192,15 +190,13 @@ public void breakParts(PApplet p, Box2DProcessing box2d, float xPoint, float yPo

// TODO maybe also use velocity?!
if (Math.random() < 0.01f) {
// TODO check velocity and angular values
box2dWorldPolygons.add(new Polygon(p, box2d, fragment, velocity, 5));

// Remove fragment from List, since it's broken out
fragment.setBroken(true);
breakFragment(fragment, p, box2d, velocity, 0);

crackAmount++;
}
}

}

/* Test all Fragments that CANNOUT break out */
Expand Down Expand Up @@ -260,9 +256,18 @@ public void updateCrack() {

if (stage == Stage.FADING) {

if (visibility <= 0)
if (visibility <= 0) {

for (Polygon polygon : box2dWorldPolygons) {

if (!polygon.isDead())
polygon.kill();
}

stage = Stage.DEAD;

}

visibility -= 15;

}
Expand All @@ -272,4 +277,98 @@ public void updateCrack() {
stage = Stage.FADING;
}
}

// public void breakLooseFragments(Fragment fragment, PApplet p,
// Box2DProcessing box2d,
// PVector velocity, int i) {
//
// boolean breaks = true;
//
// // Check all neighbors of the given fragment
// for (Fragment temporaryFragment : fragment.getNeighbors()) {
//
// // if a fragment is not broken, we have an adjacent neigbhor
// // so it doesn't have to break
// if (!temporaryFragment.isBroken()) {
// breaks = false;
// }
// }
//
// if (breaks) {
//
// breakFragment(fragment, p, box2d, velocity, i);
// }
// }

public void breakFragment(Fragment fragment, PApplet p, Box2DProcessing box2d, PVector velocity,
int i) {

// TODO check velocity and angular values
box2dWorldPolygons.add(new Polygon(p, box2d, fragment, velocity, 5));

// Remove fragment from List, since it's broken out
fragment.setBroken(true);

for (Fragment fragment2 : fragment.getNeighbors()) {

if (fragment2.isBorderFragment() || fragment2.isBroken())
continue;

if (createPathToBorder(0, fragment2, new ArrayList<>(Arrays.asList(fragment))) == 0) {
destroyAllNeighBors(fragment2, p, box2d, velocity);
}

}

}

private void destroyAllNeighBors(Fragment fragment2, PApplet p, Box2DProcessing box2d,
PVector velocity) {

box2dWorldPolygons.add(new Polygon(p, box2d, fragment2, velocity, 5));

// Remove fragment from List, since it's broken out
fragment2.setBroken(true);

for (Fragment fragment : fragment2.getNeighbors()) {

if (!fragment.isBroken())
destroyAllNeighBors(fragment, p, box2d, velocity);
}
}

public int createPathToBorder(int i, Fragment startFragment, ArrayList<Fragment> noReturn) {

noReturn.add(startFragment);

if (i > 0)
return i;

if (startFragment.isBorderFragment()) {

i++;
return i;
}

for (Fragment fragment : startFragment.getNeighbors()) {

if (!fragment.isBroken()) {

boolean isEqual = false;

for (Fragment fragment2 : noReturn) {

if (fragment.equals(fragment2))
isEqual = true;
}
if (!isEqual) {

i += createPathToBorder(i, fragment, noReturn);
}
}
}

return i;
}

}
24 changes: 24 additions & 0 deletions src/glass/Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public class Fragment {
private PVector centroid;
private ArrayList<PVector> corners;
private ArrayList<Line> lines;
private ArrayList<Fragment> neighbors;
private int lineVisibiltyCounter;
private boolean hasBroken;
private boolean isVisible;
private float area;
private boolean isBorderFragment;

public Fragment(ArrayList<PVector> corners) {

Expand All @@ -25,6 +27,8 @@ public Fragment(ArrayList<PVector> corners) {
hasBroken = false;
lines = new ArrayList<Line>();
lineVisibiltyCounter = 0;
neighbors = new ArrayList<Fragment>();
isBorderFragment = false;
}

public float getMinX() {
Expand Down Expand Up @@ -230,4 +234,24 @@ public void addLine(Line line) {

lines.add(line);
}

public void addNeighbor(Fragment fragment) {

neighbors.add(fragment);
}

public ArrayList<Fragment> getNeighbors() {

return neighbors;
}

public void setBorderFragment(boolean isBorderFragment){

this.isBorderFragment = isBorderFragment;
}

public boolean isBorderFragment(){

return isBorderFragment;
}
}
Loading

0 comments on commit e64cfc9

Please sign in to comment.