Skip to content

Commit

Permalink
after march 2012 workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelpusher committed Mar 27, 2012
1 parent ccaa1ca commit 84e447c
Show file tree
Hide file tree
Showing 71 changed files with 4,446 additions and 57 deletions.
Binary file modified .DS_Store
Binary file not shown.
53 changes: 53 additions & 0 deletions Examples/AngleBetweenPoints/AngleBetweenPoints.pde
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,53 @@


PVector p1 = new PVector();
PVector p2 = new PVector();


void setup()
{
size(640,480);

// set point 1 to midway across the screen, at screen depth
p1.set( width/2, height/2, 0);

}


void draw()
{
smooth();
background(0); // clear screen

// set my 2nd point to be the mouse position
p2.set( mouseX, mouseY, 0);

stroke(255);
strokeWeight(4);
//line( p1.x, p1.y, p2.x, p2.y);

//float angle = PVector.angleBetween(p2,p1);

float angle = atan2(p2.y-p1.y, p2.x-p1.x);

textSize(36); // 36 pixels
text("angle:" + degrees(angle), mouseX,mouseY);


pushMatrix();
// rotate the entire screen a certain angle
translate(width/2,height/2);
rotate( angle);


fill(255,255,0);
rect(0,0, 80,60);

stroke(255,80,255);
line(0,0, 200,0);

popMatrix();

}


116 changes: 62 additions & 54 deletions Examples/SkeletonImageShootingExample/SkeletonImageShootingExample.pde
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void setup()
{ {
size(640, 480, GLConstants.GLGRAPHICS); size(640, 480, GLConstants.GLGRAPHICS);


// this next bit of code disables "screen tearing" // this next bit of code disables "screen tearing"
GL gl; GL gl;
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL(); // always use the GL object returned by beginGL gl = pgl.beginGL(); // always use the GL object returned by beginGL
gl.setSwapInterval( 1 ); // use value 0 to disable v-sync gl.setSwapInterval( 1 ); // use value 0 to disable v-sync
pgl.endGL(); pgl.endGL();





// create fireball particle "swarm" // create fireball particle "swarm"
Expand Down Expand Up @@ -100,9 +100,9 @@ void setup()


void draw() void draw()
{ {

background(0); background(0);

// update the Kinect cam // update the Kinect cam
context.update(); context.update();


Expand All @@ -122,23 +122,28 @@ void draw()
{ {
// update skeleton joints coordinates // update skeleton joints coordinates
skel.update(context); skel.update(context);




// Check if hand is straight out from elbow (parallel to floor). // Check if hand is straight out from elbow (parallel to floor).
// First get direction of hand relative to elbow // First get direction of hand relative to elbow
PVector handElbowDir = PVector.sub(skel.rightHandPos, skel.rightElbowPos); PVector handElbowDir = PVector.sub(skel.rightHandPos, skel.rightElbowPos);


//float angle = atan2(skel.rightHandPos.y-skel.rightElbowPos.y,
// skel.rightHandPos.x-skel.rightElbowPos.x);

float yangle = atan2(handElbowDir.y, handElbowDir.x); float yangle = atan2(handElbowDir.y, handElbowDir.x);

// normalize to between 0 and 1 // normalize to between 0 and 1
handElbowDir.normalize(); handElbowDir.normalize();

if ( abs(handElbowDir.y) < handElbowDiffThresh ) if ( abs(handElbowDir.y) < handElbowDiffThresh )
{ {
// hand is pretty much horizontal - shoot some fireballs! // hand is pretty much horizontal - shoot some fireballs!
newSwarm( fireballTex, skel.rightHandPos, handElbowDir ); newSwarm( fireballTex, skel.rightHandPos, handElbowDir );
} }


// these draw based on pixels // these draw based on pixels
renderRectFromVectors(skel.leftShoulderPos, skel.rightShoulderPos, skel.rightHipPos, skel.leftHipPos, 5, 10, bodyTex); renderRectFromVectors(skel.leftShoulderPos, skel.rightShoulderPos, skel.rightHipPos, skel.leftHipPos, 5, 10, bodyTex);


Expand All @@ -149,26 +154,23 @@ void draw()


renderRectFromVectors(skel.leftHipPos, skel.leftFootPos, 30, legTex); renderRectFromVectors(skel.leftHipPos, skel.leftFootPos, 30, legTex);
renderRectFromVectors(skel.rightHipPos, skel.rightFootPos, 30, legTex, 1); renderRectFromVectors(skel.rightHipPos, skel.rightFootPos, 30, legTex, 1);

fill(255,255,0); fill(255, 255, 0);
ellipse(skel.rightElbowPos.x, skel.rightElbowPos.y, skel.rightElbowPos.z*80,skel.rightElbowPos.z*80); ellipse(skel.rightElbowPos.x, skel.rightElbowPos.y, skel.rightElbowPos.z*80, skel.rightElbowPos.z*80);
fill(255,0,255); fill(255, 0, 255);
ellipse(skel.rightHandPos.x, skel.rightHandPos.y, skel.rightHandPos.z*80,skel.rightHandPos.z*80); ellipse(skel.rightHandPos.x, skel.rightHandPos.y, skel.rightHandPos.z*80, skel.rightHandPos.z*80);


// DEBUGGING // DEBUGGING
fill(255); fill(255);
textSize(24); textSize(24);
text("y diff / angle = " + handElbowDir.y + " / " + degrees(yangle), 10, 25*skel.id); text("y diff / angle = " + handElbowDir.y + " / " + degrees(yangle), 10, 25*skel.id);


} }
// end of drawing skeleton stuff // end of drawing skeleton stuff
} }


drawSwarms(); drawSwarms();

} }




Expand Down Expand Up @@ -221,53 +223,60 @@ void keyReleased()
} }




int lastShootTime = 0; // last time we shot a fireball
int fireBallInterval = 300; // in milliseconds


void newSwarm(GLTexture tex, PVector startPos, PVector direction) void newSwarm(GLTexture tex, PVector startPos, PVector direction)
{ {
// number of fireballs in this swarm int timeDiff = millis()-lastShootTime;
int numFireballs = int( random(2, 6) ); if (timeDiff > fireBallInterval)
{
lastShootTime = millis();


// a bit of randomness to their position // number of fireballs in this swarm
float w = width/60.0f; int numFireballs = int( random(2, 6) );
float h = height/60.0f;


ArrayList<PVector> fireballCoords = new ArrayList<PVector>(); // a bit of randomness to their position
float w = width/60.0f;
float h = height/60.0f;


// add some coordinates for our fireballs ArrayList<PVector> fireballCoords = new ArrayList<PVector>();
for (int i=0; i < numFireballs; i++)
{
fireballCoords.add( new PVector( startPos.x + random(-w, w), startPos.y + random(-h, h), startPos.z ) );
}


ImageParticleSwarm swarm = new ImageParticleSwarm(this, tex); // add some coordinates for our fireballs
for (int i=0; i < numFireballs; i++)
{
fireballCoords.add( new PVector( startPos.x + random(-w, w), startPos.y + random(-h, h), startPos.z ) );
}


if (swarm.makeModel( fireballCoords )) ImageParticleSwarm swarm = new ImageParticleSwarm(this, tex);
{
swarms.add( swarm ); if (swarm.makeModel( fireballCoords ))
{
swarms.add( swarm );


// now create object to move this swarm of fireballs // now create object to move this swarm of fireballs
ParticleMover particleBehaviour = new ParticleMover( fireballCoords.size() ); ParticleMover particleBehaviour = new ParticleMover( fireballCoords.size() );


float vel = random(10, 40); float vel = random(10, 40);


particleBehaviour.noisiness = 0.3; particleBehaviour.noisiness = 0.3;


particleBehaviour.setVelocities( PVector.mult(direction, vel ) ); particleBehaviour.setVelocities( PVector.mult(direction, vel ) );


particleMovers.add( particleBehaviour ); particleMovers.add( particleBehaviour );

// DEBUG:
//println("*****ADDED NEW SWARM****");

}


// DEBUG:
//println("*****ADDED NEW SWARM****");
}


if (swarms.size() > MAX_SWARMS)
{
ImageParticleSwarm first = swarms.removeFirst();
first.destroy();


particleMovers.removeFirst(); if (swarms.size() > MAX_SWARMS)
{
ImageParticleSwarm first = swarms.removeFirst();
first.destroy();

particleMovers.removeFirst();
}
} }
} }


Expand Down Expand Up @@ -296,4 +305,3 @@ void drawSwarms()
renderer.endGL(); renderer.endGL();
} }



12 changes: 9 additions & 3 deletions Examples/SkeletonObjectsExample/BoxRenderer.pde
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ public class BoxRenderer implements BodyPartRenderer
app = _app; app = _app;
gfx=new ToxiclibsSupport(app); gfx=new ToxiclibsSupport(app);
mSkeleton = null; mSkeleton = null;
origMesh =(TriangleMesh)new AABB(new Vec3D(), 1).toMesh(); //origMesh =(TriangleMesh)new AABB(new Vec3D(), 1).toMesh();
origMesh.transform(new Matrix4x4().translateSelf(0, 0, 1));
// load a mesh from a 3D STL file
STLReader reader = new STLReader();
origMesh = (TriangleMesh) reader.loadBinary(dataPath("head.stl"), TriangleMesh.class);
//origMesh.transform(new Matrix4x4().translateSelf(0, 0, 1));
origMesh.scale(0.05);
} }


public BoxRenderer(PGraphics g) public BoxRenderer(PGraphics g)
Expand Down Expand Up @@ -107,15 +112,16 @@ public class BoxRenderer implements BodyPartRenderer


// scale from point to point // scale from point to point
mesh = origMesh.getScaled(new Vec3D(w, h, h)); mesh = origMesh.getScaled(new Vec3D(w, h, h));

gfx.translate(p1); gfx.translate(p1);
gfx.rotate(millis()*0.01f);


if (tex != null) if (tex != null)
{ {
gfx.texturedMesh(mesh, tex, false); gfx.texturedMesh(mesh, tex, false);
} }
else else
{ {

gfx.mesh(mesh, false, 10); gfx.mesh(mesh, false, 10);
} }
if (obp.depthDisabled) if (obp.depthDisabled)
Expand Down
Binary file added Examples/SkeletonObjectsExample/data/head.stl
Binary file not shown.
Loading

0 comments on commit 84e447c

Please sign in to comment.