/
HeavyBag.pde
70 lines (65 loc) · 1.86 KB
/
HeavyBag.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import SimpleOpenNI.*;
import processing.opengl.*;
import saito.objloader.*;
class HeavyBag
{
OBJModel model;
int boxSize = 150;
int maxPoints = 150;
PVector boxCenter = new PVector( 0, 0, 1600 );
boolean drawToHit=false;
int s_factor = 800;
BoundingBox bbox;
HeavyBag(PApplet parent)
{
model = new OBJModel( parent, dataPath("ufc.obj"), "relative", TRIANGLES );
model.translateToCenter();
model.enableTexture();
model.enableMaterial();
model.setupGL();
bbox = new BoundingBox(parent, model);
println( bbox.getWHD());
}
boolean check(PVector currentPoint)
{
return currentPoint.x > boxCenter.x - bbox.getWHD().x * s_factor / 2 && currentPoint.x < boxCenter.x + bbox.getWHD().x * s_factor / 2
&& currentPoint.y > boxCenter.y - bbox.getWHD().y * s_factor / 2 && currentPoint.y < boxCenter.y + bbox.getWHD().y * s_factor / 2
&& currentPoint.z > boxCenter.z - bbox.getWHD().z * s_factor / 2 && currentPoint.z < boxCenter.z + bbox.getWHD().z * s_factor / 2;
}
void setDrawToHit( boolean val )
{
drawToHit = val;
}
void draw(boolean drawWithHit)
{
pushMatrix();
translate( boxCenter.x, boxCenter.y, boxCenter.z );
scale(s_factor);
rotateZ( radians( 180 ) );
if( drawWithHit )
{
float boxAlpha = map( 200, 0, 1000, 0, 255 );
pushMatrix();
translate( boxCenter.x, boxCenter.y, boxCenter.z );
fill( 255, 0, 0, boxAlpha );
stroke( 255, 0, 0 );
box( boxSize );
popMatrix();
setDrawToHit( false );
}
else if( drawToHit )
{
float boxAlpha = map( 200, 0, 1000, 0, 255 );
pushMatrix();
translate( boxCenter.x, boxCenter.y, boxCenter.z );
fill( 0, 0, 255, boxAlpha );
stroke( 0, 255, 0 );
box( boxSize );
popMatrix();
}
else
noStroke();
model.drawGL();
popMatrix();
}
}