Java Code Examples for processing.core.PVector#set()

The following examples show how to use processing.core.PVector#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinectSilhouetteVectorField.java    From haxademic with MIT License 6 votes vote down vote up
protected void updateField() {
	// draw field
	PG.setDrawCenter(_canvas);
	_canvas.fill(255);
	for (int i = 0; i < _vectorFieldBase.size(); i++) {
		PVector vector = _vectorFieldBase.get(i);
		PVector vectorOffset = _vectorFieldOffset.get(i);
		float noise = P.p.noise(
				vector.x/31f + P.p.noise(P.p.frameCount/100f), 
				vector.y/20f + P.p.noise(P.p.frameCount/80f) 
		);
		vectorOffset.set(vector.x, vector.y, P.sin(noise * 1f) * 1f);
		
		if(SHOW_ATTRACTORS == true) {
			// draw attractors
			_canvas.pushMatrix();
			_canvas.translate(vector.x, vector.y);
			_canvas.rotate( vector.z + vectorOffset.z );	// use z for rotation!
		    _canvas.rect(0, 0, 3, 10);
		    _canvas.popMatrix();
		}
	}
}
 
Example 2
Source File: Demo_VectorField.java    From haxademic with MIT License 5 votes vote down vote up
public FieldParticle() {
	speed = p.random(2,6);
	radians = new EasingFloat(0, p.random(6,20) );
	position = new PVector( p.random(0, p.width), p.random(0, p.height) );
	lastPosition = new PVector();
	lastPosition.set(position);
}
 
Example 3
Source File: PerlinNoise3dParticles.java    From haxademic with MIT License 5 votes vote down vote up
protected void reset() {
	pos.set(
			random(-halfSize,  halfSize), 
			random(-halfSize,  halfSize),
			random(-halfSize,  halfSize)
			);
	
	for (PVector trailPos : trail) {
		trailPos.set(pos);
	}
}
 
Example 4
Source File: KinectUser3d.java    From haxademic with MIT License 5 votes vote down vote up
void getBodyDirection(int userId,PVector centerPoint,PVector dir)
{
  PVector jointL = new PVector();
  PVector jointH = new PVector();
  PVector jointR = new PVector();
  float  confidence;
  
  // draw the joint position
  confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_LEFT_SHOULDER,jointL);
  confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,jointH);
  confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_RIGHT_SHOULDER,jointR);
  
  // take the neck as the center point
  confidence = context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,centerPoint);
  
  /*  // manually calc the centerPoint
  PVector shoulderDist = PVector.sub(jointL,jointR);
  centerPoint.set(PVector.mult(shoulderDist,.5));
  centerPoint.add(jointR);
  */
  
  PVector up = new PVector();
  PVector left = new PVector();
  
  up.set(PVector.sub(jointH,centerPoint));
  left.set(PVector.sub(jointR,centerPoint));
  
  dir.set(up.cross(left));
  dir.normalize();
}
 
Example 5
Source File: TextureVectorFieldEQ.java    From haxademic with MIT License 5 votes vote down vote up
public void updateDraw() {
	// fade out background
	PG.setDrawCorner(_texture);
	_texture.noStroke();
	_texture.fill(0, OVERDRAW_FADE);
	_texture.rect(0,0,width, height);
	
	// update & draw field
	PG.setDrawCenter(_texture);
	_texture.fill(255);
	for (PVector vector : _vectorField) {
		float noise = P.p.noise(
				vector.x/11f + P.p.noise(P.p.frameCount/50f), 
				vector.y/20f + P.p.noise(P.p.frameCount/50f) 
				);
		float targetRotation = noise * 4f * P.TWO_PI;
		vector.set(vector.x, vector.y, P.lerp(vector.z, targetRotation, 0.2f));

		if(DEBUG_VECTORS == true) {
			// draw attractors
			_texture.pushMatrix();
			_texture.translate(vector.x, vector.y);
			_texture.rotate( vector.z );	// use z for rotation!
			_texture.rect(0, 0, 2, 10);
			_texture.popMatrix();
		}
	}
	
	for (int j = 0; j < DRAWS_PER_FRAME; j++) {
		// draw particles
		_texture.strokeWeight(2f);
		PG.setDrawCenter(_texture);
		for( int i = 0; i < _particles.size(); i++ ) {
			_texture.stroke(180 + (i % 75), 200 + (i % 55), 210 + (i % 45));
			_particles.get(i).update( _vectorField, i );
		}
	}
}
 
Example 6
Source File: TextureVectorFieldEQ.java    From haxademic with MIT License 5 votes vote down vote up
public FieldParticle() {
	speed = P.p.random(2,6);
	radians = new EasingFloat(0, P.p.random(6,20) );
	position = new PVector( P.p.random(0, width), P.p.random(0, P.p.height) );
	lastPosition = new PVector();
	lastPosition.set(position);
}
 
Example 7
Source File: Demo_PVector_tests.java    From haxademic with MIT License 4 votes vote down vote up
protected void getPerp(PVector p1, PVector p2, PVector pDest) {
	pDest.set(p2).sub(p1).normalize();
	pDest.set(-pDest.y, pDest.x);
}
 
Example 8
Source File: Demo_VectorField.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawApp() {
		if( p.frameCount == 1 ) p.background(0);

//		OpenGLUtil.setBlending(p.g, true);
//		OpenGLUtil.setBlendMode(p.g, OpenGLUtil.Blend.ADDITIVE);
		
//		feedback(4, 0.2f);
		
		// fade out background
		PG.setDrawCorner(p);
		p.noStroke();
		p.fill(0, OVERDRAW_FADE);
		p.rect(0,0,p.width, p.height);
		
		// draw field
		PG.setDrawCenter(p);
		p.fill(0);
		for (PVector vector : _vectorField) {
			float noise = p.noise(
					vector.x/15f + p.noise(p.frameCount/50f), 
					vector.y/10f + p.noise(p.frameCount/50f) 
					);
			float targetRotation = noise * 6f * P.TWO_PI;
			vector.set(vector.x, vector.y, P.lerp(vector.z, targetRotation, 0.2f));
			
			// draw attractors
			p.pushMatrix();
			p.translate(vector.x, vector.y);
			p.rotate( vector.z );	// use z for rotation!
			// p.rect(0, 0, 1, 10);
			p.popMatrix();
		}
		
		updateVectors();

		for (int j = 0; j < DRAWS_PER_FRAME; j++) {
			// draw particles
			p.strokeWeight(2f);
			PG.setDrawCenter(p);
			for( int i = 0; i < _particles.size(); i++ ) {
//				p.fill((i % 150 + 55 / 10), i % 155 + 100, i % 100 + 100); // blue/green
				p.stroke(180 + (i % 75), 200 + (i % 55), 210 + (i % 45));
				_particles.get(i).update( _vectorField, i );
			}
		}
		
//		postProcessForRendering();
	}
 
Example 9
Source File: Demo_Polygon.java    From haxademic with MIT License 4 votes vote down vote up
public Polygon createNeighborTriangle(Polygon parentPoly) {
		// get available edge
		// and find a reasonable new vertex for a neighbor 
		Edge edge = parentPoly.availableNeighborEdge();
		PVector newNeighborVertex = parentPoly.newNeighbor3rdVertex(edge, MathUtil.randRangeDecimal(0.5f, 1.8f), 0.25f, 0.75f);
		
		// new triangle off the Edge, but lerp the shared edge away a tiny bit to prevent overlap check
		tempTriangle.setVertex(0, edge.v1());
		tempTriangle.setVertex(1, edge.v2());
		tempTriangle.setVertex(2, newNeighborVertex);
		tempTriangle.shrink(0.001f);
		
		// if offscreen, bail
		if(polygonOffscreen(tempTriangle)) return null;
		
		// check to see if we're overlapping with another polygon
		Polygon overlappedPoly = null;
		for (int i = 0; i < polygons.size(); i++) {
			if(overlappedPoly == null) {
				if(CollisionUtil.polygonsIntersect(polygons.get(i), tempTriangle)) {
					overlappedPoly = polygons.get(i);
//					log.update("overlappedPoly");
				}
			}
		}
		
		// if we're overlapping another poly, try to move the new vertex to the closest vertex of the overlapped triangle, then see if the two triangles share an edge
		if(overlappedPoly != null) {
			PVector closestOverlappedVert = overlappedPoly.closestVertexToVertex(newNeighborVertex);
			newNeighborVertex.set(closestOverlappedVert);
//			log.update("OVERLAP SNAP!");
		} else {
			// if we're not overlapped, but close to another vertex, let's try to snap
			boolean snapped = false;
			for (int i = 0; i < polygons.size(); i++) {
				for (int j = 0; j < polygons.get(i).vertices().size(); j++) {
					if(snapped == false && polygons.get(i) != parentPoly) {		// don't snap to parent, or we get overlaps that don't get cleaned up below
						PVector vertex = polygons.get(i).vertices().get(j);
						if(newNeighborVertex.dist(vertex) < SNAP_RADIUS) {
							newNeighborVertex.set(vertex);
							overlappedPoly = polygons.get(i);	// ensures that the neighbors are connected below
							snapped = true;
							log.update("SNAP!");
						}
					}
				}
			}
		}
		
//		// TODO: Do we need to check for overlap again, based on "SNAP" above??
//		if(overlappedPoly != null) {
//			
//		}
		
		// new triangle to attach
		Polygon newNeighbor = new Polygon(new float[] {
				edge.v1().x, edge.v1().y, edge.v1().z,
				edge.v2().x, edge.v2().y, edge.v2().z,
				newNeighborVertex.x, newNeighborVertex.y, newNeighborVertex.z
		});
		
		// if not overlapping another, add to collection
		if(overlappedPoly == null && newNeighbor.area() < MAX_POLY_AREA) { // && newNeighborArea > 800) {
			// tell polys about their shared edges
			parentPoly.findNeighbor(newNeighbor);
			newNeighbor.findNeighbor(parentPoly);
			return newNeighbor;
		} else {
			// TODO: put this in an object pool for recycling
			return null;
		}
	}
 
Example 10
Source File: ParticleAlphaShape.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawVoxels() {
		JoonsWrapper joons = Renderer.instance().joons;
		
		ArrayList<PVector> voxelPositions = new ArrayList<PVector>();
		ArrayList<Integer> voxelDecay = new ArrayList<Integer>();
		float resolution = 50;
		
		PVector checkVector;
		PVector roundedPos = new PVector();
		for( int i=0; i < _numParticles; i++ ) {
			checkVector = boxes.get(i).position();
			roundedPos.set(
					Math.round(checkVector.x / resolution) * resolution, 
					Math.round(checkVector.y / resolution) * resolution, 
					Math.round(checkVector.z / resolution) * resolution
					);
			
			boolean foundMatch = false;
			for( int j=0; j < voxelPositions.size(); j++ ) {
				if( roundedPos.equals(voxelPositions.get(j))) {
					foundMatch = true;
				}
			}
			if( foundMatch == false ) {
				voxelPositions.add( new PVector( roundedPos.x, roundedPos.y, roundedPos.z ) );
				voxelDecay.add(1);
			}
				
		}
		
		for( int i=0; i < voxelPositions.size(); i++ ) {
			// PVector worldCenter = new PVector();
			PVector voxel = voxelPositions.get(i);
			// P.println(i+"  "+voxel.x+"  "+ Math.abs(Math.round(voxel.x / resolution)));
//			if( Math.abs(Math.round(voxel.x / resolution)) == 0 &&  Math.abs(Math.round(voxel.y / resolution)) == 0 ) { 
//				p.fill(255, 255, 255);
//				_jw.jr.fill(JoonsWrapper.MATERIAL_LIGHT, 255, 255, 255, 4);
//			} else 
			if( Math.abs(Math.round(voxel.x / resolution)) % 2 == 0 ||  Math.abs(Math.round(voxel.y / resolution)) % 2 == 0 ) {
				p.fill( Math.abs(voxel.x)/4, Math.abs(voxel.y)/3, Math.abs(voxel.z)/2);
				joons.jr.fill(JoonsWrapper.MATERIAL_SHINY, Math.abs(voxel.x)/3, Math.abs(voxel.y)/3, Math.abs(voxel.z)/2);
			} else { 
				p.fill(20, 20, 20);
				joons.jr.fill(JoonsWrapper.MATERIAL_SHINY, 20, 20, 20, 1);
			}
			
			p.pushMatrix();
//			p.rotateZ(p.frameCount / 130f);
			p.translate(voxelPositions.get(i).x, voxelPositions.get(i).y, voxelPositions.get(i).z);
//			p.sphere(resolution/2f);
			p.box(resolution);
			p.popMatrix();
		}
	}
 
Example 11
Source File: TextureSphere.java    From haxademic with MIT License 4 votes vote down vote up
void addVertex(PVector p, PVector n, PVector t) {
	positions.add(p);
	normals.add(n);
	t.set(1.0f-t.x, 1.0f-t.y, t.z);
	texCoords.add(t);
}
 
Example 12
Source File: MathUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void rotateAroundPoint(PVector point, PVector anchor, float rads) {
	float radius = getDistance(point.x, point.y, anchor.x, anchor.y);
	float destRads = getRadiansToTarget(0, 0, point.x - anchor.x, point.y - anchor.y) + rads;
	point.set(anchor.x + radius * P.cos(destRads), anchor.y + radius * P.sin(destRads), point.z);
}
 
Example 13
Source File: Polygon.java    From haxademic with MIT License 4 votes vote down vote up
protected void getPerp(PVector p1, PVector p2, PVector pDest) {
	pDest.set(p2).sub(p1).normalize();
	pDest.set(-pDest.y, pDest.x);
}
 
Example 14
Source File: Icosahedron.java    From haxademic with MIT License 4 votes vote down vote up
void addVertex(PVector p, PVector n, PVector t) {
	positions.add(p);
	normals.add(n);
	t.set(1.0f-t.x, 1.0f-t.y, t.z);
	texCoords.add(t);
}