import java.util.List;
import toxi.geom.*;
import toxi.geom.PointOctree;
import toxi.color.*;
import controlP5.*;
import peasy.*;
import toxi.geom.mesh.*;
import java.util.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.math.noise.*;
import toxi.physics.*;
import toxi.physics.behaviors.*;
import java.awt.Frame;
import java.awt.BorderLayout;
import controlP5.*;
import toxi.color.*;
import peasy.*;
import java.util.Calendar;
import toxi.processing.*;
Tracker a;
ControlP5 cp5;
Culebra_UI cgui;
Path tempPath;
PVector locStart;
PVector triggerLoc = new PVector(0, 0, 0);
boolean simulate, spawnEdge, addNew, D2;
boolean drawPathTargets, toggleUI, drawMovement, mathBehavior, genRandom, triggerSeekers, drawConn, createOctree;
boolean drawBoundary = true;
boolean toggleColor = true;
boolean masterBehavior_C = true;
boolean masterBehavior_D = true;
boolean masterBehavior_F = true;
boolean masterBehavior_A, masterBehavior_B, masterBehavior_E, subBehavior_AA, subBehavior_AB;
boolean drawPaths = false;
boolean SpawnEdge = true;
boolean Dimension = true;
boolean enablePathTrack = false;
boolean showOctree = true;
boolean spawnLowEdge = true;
int triggerCount = 0;
int agentCount = 300;
int resetAmount = 0;
int camToggle = 0;
int pathCount = 15;
int nWidth = 1920;
int nDepth = 1080;
int nHeight = 1000;
float WanderRadius, WanderDist, WanderTheta, WanderRotTrigger, MaxChildren;
float PathRad, ScalarProjectDist, PathThresh;
float InitSpeed, MaxSpeed, MaxForce, MaxSep;
float AgentCount;
float seekerTrail, childSeekerTrail;
float HeadWidth, StrokeWidth, Transparency;
float stepCount = 0;
float sepTrigger = 0.0f;
ArrayList<PVector>childSpawners;
ArrayList childSpawnType;
ArrayList<Path> pathList;
List<Tracker> agentList;
java.util.List occTreeList;
List<Vec3D>vec3DList;
VisibleOctree octree;
Button btypeA, btypeAA, btypeAB, btypeB, btypeC, btypeD, btypeE, btypeF;
PeasyCam cam;
CameraState state;
ToxiclibsSupport gfx;
boolean renderMesh = true;
Mesh mesh;
VisibleOctree octreeMesh;
int frameIter;
List<Vec3D>vec3DVertList;
java.util.List occTreeVertList;
//-----------------------------------------Mesh----------------------------------------------
String operationMesh = "Baby_G2.stl";
String displayMesh = "Baby_G3.stl";
//---------------------------------------Settings--------------------------------------------
void settings() {
size(1820, 980, P3D);
smooth();
}
//---------------------------------------Setup-----------------------------------------------
void setup() {
background(0);
this.frameIter = 0;
this.mesh = new Mesh(operationMesh,displayMesh);
gfx = new ToxiclibsSupport(this);
this.octree = new VisibleOctree(new Vec3D(0, 0, 0), nWidth);
this.octree.setTreeAutoReduction(true);
this.agentList = new ArrayList<Tracker>();
this.childSpawners = new ArrayList<PVector>();
this.childSpawnType = new ArrayList();
this.pathList = new ArrayList<Path>();
if (!this.D2 && this.camToggle < 1) {
this.camToggle ++;
this.cam = new PeasyCam(this, 1500);
this.cam.setMinimumDistance(100);
this.cam.setMaximumDistance(10000);
this.cam.lookAt(this.nWidth/2, this.nDepth/2, this.nHeight/2);
this.cam.setSuppressRollRotationMode();
}
if (D2) {
this.cam.reset();
this.cam.setMinimumDistance(100);
this.cam.setMaximumDistance(10000);
this.cam.lookAt(this.nWidth/2, this.nDepth/2, 0);
this.cam.setDistance(1000); // distance from looked-at point
this.cam.setSuppressRollRotationMode();
}
simulate = true;
if (this.resetAmount == 0) {
this.cgui = new Culebra_UI();
this.cgui.run(this);
}
for (int pth = 0; pth < this.pathCount; pth++) {
newPath();
}
for (int i = 0; i < this.agentCount; i ++) {
PVector speed;
if (this.D2) {
if (this.spawnEdge) {
locStart = new PVector(0, random(height), 0);
speed = new PVector(1, 0, 0);
} else {
locStart = new PVector(random(width), random(height), 0);
speed = new PVector(random(-1, 1), random(-1, 1), 0);
}
this.a = new Tracker(locStart, speed, true, "parent", "main");
} else if (!this.D2 && !spawnLowEdge) {
if (this.spawnEdge) {
locStart = new PVector(random(width), random(height), 0);
speed = new PVector(random(-1, 1), random(-1, 1), random(0, 2));
} else {
locStart = new PVector(random(width), random(height), random(0, nHeight));
speed = new PVector(random(-1, 1), random(-1, 1), random(-1, 1));
}
this.a = new Tracker(locStart, speed, true, "parent", "main");
} else {
locStart = new PVector(width, random(height), random(0, nHeight));
speed = new PVector(random(-2, -1), random(-1, 1), random(-2, 2));
this.a = new Tracker(locStart, speed, true, "parent", "main");
}
this.agentList.add(this.a);
}
}
//---------------------------------------Draw-----------------------
void draw() {
background(0);
if(this.renderMesh){
mesh.render();
}
this.sepTrigger = this.cgui.msep.getValue();
if (this.createOctree || this.masterBehavior_E || this.sepTrigger > 0) {
this.createOctree = true;
this.octree.empty();
this.vec3DList = new ArrayList<Vec3D>();
for (Tracker ag : agentList) {
this.vec3DList.add(new Vec3D(ag.loc.x, ag.loc.y, ag.loc.z));
}
this.octree.addAll(vec3DList);
}
//---------------------------------------------------------------
this.D2 = this.cgui.d.getState();
if (!this.D2 && this.drawBoundary) {
drawExtents();
}
this.spawnEdge = this.cgui.se.getState();
this.agentCount = (int)this.cgui.ac.getValue();
for (Path pths : pathList) {
if (this.drawPaths) {
pths.display();
}
pths.dim = this.cgui.d.getState();
pths.radius = this.cgui.pr.getValue();
}
//--Agents-------------------------------------------------------------------------------
for (Tracker ag : agentList) {
if (ag.type == "parent") {
ag.wanderD = this.cgui.wd.getValue();
ag.wanderR = this.cgui.wr.getValue();
ag.wanderT = this.cgui.wt.getValue();
ag.wanderTVal = this.cgui.wrt.getValue();
ag.headWidth = this.cgui.hw.getValue();
ag.strokeWidth = this.cgui.stw.getValue();
ag.tranparency = this.cgui.t.getValue();
ag.seekerMT = (int)this.cgui.st.getValue();
ag.maxforce = this.cgui.mf.getValue();
ag.max = this.cgui.ms.getValue();
ag.amp = this.cgui.sd.getValue();
ag.vel = this.cgui.is.getValue();
ag.maxDist = this.cgui.pt.getValue();
ag.r = this.cgui.msep.getValue();
ag.maxChildren = (int)this.cgui.mc.getValue();
ag.dim = this.cgui.d.getState();
ag.randomize = this.genRandom;
ag.wandertheta = 0.0f;
ag.av = this.cgui.f_av.getValue();
ag.cv = this.cgui.f_cv.getValue();
ag.sv = this.cgui.f_sv.getValue();
ag.searchRad = this.cgui.f_sR.getValue();
ag.creeperCollection = this.agentList;
ag.run();
} else {
ag.wanderD = this.cgui.c_wd.getValue();
ag.wanderR = this.cgui.c_wr.getValue();
ag.wanderT = this.cgui.c_wt.getValue();
ag.wanderTVal = this.cgui.c_wrt.getValue();
ag.headWidth = this.cgui.c_hw.getValue();
ag.strokeWidth = this.cgui.c_stw.getValue();
ag.tranparency = this.cgui.c_t.getValue();
ag.seekerChildMT = (int)this.cgui.c_ct.getValue();
ag.maxforce = this.cgui.c_mf.getValue();
ag.max = this.cgui.c_ms.getValue();
ag.amp = this.cgui.c_sd.getValue();
ag.vel = this.cgui.c_is.getValue();
ag.maxDist = this.cgui.c_pt.getValue();
ag.maxChildren = 0;
ag.dim = this.cgui.d.getState();
ag.randomize = this.genRandom;
ag.wandertheta = 0.0f;
ag.av = this.cgui.f_av.getValue();
ag.cv = this.cgui.f_cv.getValue();
ag.sv = this.cgui.f_sv.getValue();
ag.searchRad = this.cgui.f_sR.getValue();
ag.creeperCollection = this.agentList;
ag.run();
}
}
if (this.createOctree) {
if (this.showOctree) this.octree.draw();
}
if (this.childSpawners.size() > 0) {
newDude();
this.childSpawners = new ArrayList<PVector>();
this.childSpawnType = new ArrayList();
}
stepCount++;
if (this.D2) {
surface.setSize(this.nWidth, this.nDepth);
}
this.cgui.createGui();
}
//---------------------------------------Create Static Paths---------------------------------
void newPath() {
if (this.D2) {
this.tempPath = new Path();
this.tempPath.addPoint(random(30, 300), random(height/4, height), 0);
this.tempPath.addPoint(random(101, width/2), random(0, height), 0);
this.tempPath.addPoint(random(width/2, width), random(0, height), 0);
this.tempPath.addPoint(random(width-100, width), height/2, 0);
} else {
this.tempPath = new Path();
this.tempPath.addPoint(random(0, 300), random(0, height), random(0, this.nHeight));
this.tempPath.addPoint(random(0, width/2), random(0, height), random(0, this.nHeight));
this.tempPath.addPoint(random(0, width), random(0, height), random(0, this.nHeight));
this.tempPath.addPoint(random(0, width), 0, random(0, this.nHeight));
}
this.pathList.add(this.tempPath);
}
//---------------------------------------Keyboard Inputs-------------------------------------
void keyPressed() {
if (key == 'r') {
this.resetAmount ++;
this.triggerCount = 0;
setup();
}
if (key == 's') this.simulate = !this.simulate;
if (key == 'w') this.newPath();
if (key == 'q') this.drawPathTargets = !this.drawPathTargets;
if (key == 'p') this.drawPaths = !this.drawPaths;
if (key == 't') this.toggleUI = !this.toggleUI;
if (key == 'm') this.mathBehavior = !this.mathBehavior;
if (key == 'n') this.genRandom = !this.genRandom;
if (key == 'd') this.drawMovement = !this.drawMovement;
if (key == 'P') this.enablePathTrack = !this.enablePathTrack;
if (key == 'b') this.triggerSeekers = !this.triggerSeekers;
if (key == 'c') this.toggleColor = !this.toggleColor;
if (key == 'i') saveFrame("img-######.png");
if (key == 'v') this.drawBoundary = !this.drawBoundary;
if (key=='o') this.showOctree=!this.showOctree;
if (key=='z') this.createOctree =!this.createOctree;
if (key=='1') this.drawConn=!this.drawConn;
if (key == 'l') this.renderMesh = !this.renderMesh;
if (key == '0')this.spawnLowEdge = !this.spawnLowEdge;
}
//---------------------------------------Children Creation-----------------------------------
void newDude() {
int babyCount = 0;
for (PVector px : this.childSpawners) {
PVector speed;
if (this.spawnEdge) {
speed = new PVector(1, 0, 0);
} else {
speed = new PVector(random(-1, 1), random(-1, 1), 0);
}
if ((int)this.childSpawnType.get(babyCount) % 2 == 0) {
this.agentList.add(new Tracker(new PVector(px.x, px.y, px.z), speed, false, "child", "w_a"));
} else {
this.agentList.add(new Tracker(new PVector(px.x, px.y, px.z), speed, false, "child", "w_b"));
}
babyCount++;
}
}
//---------------------------------------Draw Bounds-----------------------------------------
void drawExtents()
{
pushStyle();
pushMatrix();
strokeWeight(.5);
stroke(200);
noFill();
translate(this.nWidth/2, this.nDepth/2, this.nHeight/2);
box(this.nWidth, this.nDepth, this.nHeight);
popMatrix();
popStyle();
}
void Beh_A(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_A = !this.masterBehavior_A;
}
}
void Beh_B(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_B = !this.masterBehavior_B;
}
}
void Beh_C(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_C = !this.masterBehavior_C;
}
}
void Beh_D(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_D = !this.masterBehavior_D;
}
}
void Beh_E(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_E = !this.masterBehavior_E;
}
}
void Beh_F(boolean resetFlag) {
if (resetFlag) {
this.masterBehavior_F = !this.masterBehavior_F;
}
}
void Beh_AA(boolean resetFlag) {
if (resetFlag) {
this.subBehavior_AA = !this.subBehavior_AA;
}
}
void Beh_AB(boolean resetFlag) {
if (resetFlag) {
this.subBehavior_AB = !this.subBehavior_AB;
}
}