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

The following examples show how to use processing.core.PVector#copy() . 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: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param position in mm in the paper screen
 * @return position in px in the cameratracking.
 */
public PVector computePxPosition(PVector position) {

    PVector p = position.copy();

    // Invert Y
    p.y = p.y - drawingSize.y;
    p.y = -p.y;
    // get a copy of the position
    PMatrix3D mat = this.getLocation(getCameraTracking()).get();
    mat.translate(p.x, p.y, 0);

    PVector pos3D = new PVector(mat.m03, mat.m13, mat.m23);
    PVector camCoord = cameraTracking.getProjectiveDevice().worldToPixelCoord(pos3D);
    return camCoord;
}
 
Example 2
Source File: LineTrail.java    From haxademic with MIT License 6 votes vote down vote up
public void update(PGraphics pg, PVector newPos, int colorStart, int colorEnd) {
	// init points to start point
	if(trail == null) {
		trail = new PVector[size];
		for (int i = 0; i < size; i++) trail[i] = newPos.copy();
	}
	
	// copy all positions towards tail end each step
	for (int i = size - 1; i > 0; i--) {
		trail[i].set(trail[i-1]);
	}
	trail[0].set(newPos);
	
	// render
	for (int i = 0; i < size - 1; i++) {
		PVector curSegment = trail[i]; 
		PVector nexSegment = trail[i+1]; 
		if(curSegment.dist(nexSegment) != 0) {
			if(colorStart != NO_FILL) {
				float progress = (float) i / (float) size;
				pg.stroke(P.p.lerpColor(colorStart, colorEnd, progress));
			}
			pg.line(curSegment.x, curSegment.y,  curSegment.z, nexSegment.x, nexSegment.y, nexSegment.z);
		}
	}
}
 
Example 3
Source File: MarchingCubes.java    From haxademic with MIT License 6 votes vote down vote up
/**
 * constructor:
 * you must define the world bounds, the number of points that will make the grid (in a PVector),
 * and the isoLevel.
 * @param _p5
 * @param _aabbMin
 * @param _aabbMax
 * @param _numPoints
 * @param _isoLevel
 */

public MarchingCubes(PApplet _p5, PVector _aabbMin, PVector _aabbMax, PVector _numPoints, float _isoLevel){
	p5 = _p5;
	aabbMin = _aabbMin.copy();
	aabbMax = _aabbMax.copy();
	worldSize = aabbMax.copy().sub(aabbMin);
	numPoints = _numPoints.copy();
	cubeSize = new PVector(worldSize.x / (numPoints.x-1), worldSize.y / (numPoints.y-1), worldSize.z / (numPoints.z-1));
	voxelValues = new float[(int)numPoints.x][(int)numPoints.y][(int)numPoints.z];
	voxels = new PVector[(int)numPoints.x][(int)numPoints.y][(int)numPoints.z];

	_internalReset();
	isoLevel = _isoLevel;

	vertList = new PVector[12];
	triangles = new ArrayList<MCTriangle>();
}
 
Example 4
Source File: SideScroller.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
public void resizeWindow(int width, int height) {
		windowSize = new PVector(width, height);
		gameResolution = windowSize.copy();
		stage.setWidth(width); // sceneWidth is not bound, so doesn't change
		stage.setHeight(height);
//		stage.setScene(new Scene(new StackPane(canvas), width, height)); // TODO
	}
 
Example 5
Source File: Camera.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tells the camera which object to track/follow, given a new offset.
 * 
 * @param o      Object to track.
 * @param offset Offset with which the camera will follow the given object.
 */
public void setFollowObject(EditableObject o, PVector offset) {
	followObject = o;
	followObjectOffset = offset.copy();
	following = true;
	rotationTarget = 0;
}
 
Example 6
Source File: AttractRepel.java    From haxademic with MIT License 4 votes vote down vote up
public Particle() {
	radius = MathUtil.randRange(20, 50);
	position = new PVector(p.random(p.width), p.random(p.height));
	positionTarget = position.copy();
	velocity = new PVector();
}
 
Example 7
Source File: MarchingCubes.java    From haxademic with MIT License 4 votes vote down vote up
MCTriangle(PVector _a, PVector _b, PVector _c){
	a = _a.copy();
	b = _b.copy();
	c = _c.copy();
	normal = new PVector();
}
 
Example 8
Source File: MarchingCubes.java    From haxademic with MIT License 4 votes vote down vote up
MCTriangle(PVector _a, PVector _b, PVector _c, PVector _norm){
	a = _a.copy();
	b = _b.copy();
	c = _c.copy();
	normal = _norm.copy();
}
 
Example 9
Source File: Camera.java    From Project-16x16 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Constructor. Specify both the object to track and the translation offset with
 * which to track it from initialisation.
 * 
 * @param applet       Target applet ({@link SideScroller}).
 * @param followObject Object the camera will follow.
 * @param followOffset Offset with which the camera will follow the given
 *                     object.
 */
public Camera(SideScroller applet, EditableObject followObject, PVector followOffset) {
	super(applet);
	this.applet = applet;
	this.followObject = followObject;
	following = true;
	followObjectOffset = followOffset.copy();
}
 
Example 10
Source File: Camera.java    From Project-16x16 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Defines the screen region in which the tracked object can move without the
 * camera following. When the tracked object exits the region, the camera will
 * track the object until it returns within the region.
 * 
 * @param point1 Coordinate 1 (Screen coordinate)
 * @param point2 Coordinate 2 (Screen coordinate - the point opposite point1)
 * @see {@link #setWorldDeadZone(PVector, PVector) setWorldDeadZone()}
 */
public void setScreenDeadZone(PVector point1, PVector point2) {
	deadZoneScreen = true;
	deadZoneWorld = false;
	deadZoneTypeLast = 0;
	deadZoneP1 = point1.copy();
	deadZoneP2 = point2.copy();
}
 
Example 11
Source File: Camera.java    From Project-16x16 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Defines the game world region in which the tracked object can move without
 * the camera following. When the tracked object exits the region, the camera
 * will track the object until it returns within the region.
 * 
 * @param point1 Coordinate 1 (Screen coordinate)
 * @param point2 Coordinate 2 (Screen coordinate - the point opposite point1)
 * @see {@link #setScreenDeadZone(PVector, PVector) setScreenDeadZone()}
 */
public void setWorldDeadZone(PVector point1, PVector point2) {
	deadZoneWorld = true;
	deadZoneScreen = false;
	deadZoneTypeLast = 1;
	deadZoneP1 = point1.copy();
	deadZoneP2 = point2.copy();
}
 
Example 12
Source File: Camera.java    From Project-16x16 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Modify the existing object tracking offset.
 * 
 * @param followObjectOffset new offset
 */
public void setFollowObjectOffset(PVector followObjectOffset) {
	this.followObjectOffset = followObjectOffset.copy();
}