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

The following examples show how to use processing.core.PVector#add() . 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: TwoFingersRST.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected PVector computeTranslate(Touch touch0, Touch touch1) {
        PVector previousCenter = PVector.add(touch0.pposition, touch1.pposition);
        previousCenter.mult(0.5f);
        PVector currentCenter = PVector.add(touch0.position, touch1.position);
        currentCenter.mult(0.5f);
        PVector diff = PVector.sub(currentCenter, previousCenter);
//        diff.mult(0.5f);
        return diff;
    }
 
Example 2
Source File: Polygon.java    From haxademic with MIT License 5 votes vote down vote up
public void translate(float x, float y, float z) {
	for (int i = 0; i < vertices.size(); i++) {
		PVector v = vertices.get(i);
		v.add(x, y, z);
	}
	calcCentroid();
	calcBounds();
}
 
Example 3
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Init VR rendering. The VR rendering creates a 3D "screen". It is used to
 * create 3D pop-up effects.
 *
 * @param cam Rendering origin.
 * @param userPos Position of the user, relative to the PaperScreen
 * @param nearPlane Close disance for OpengL in millimeters.
 * @param farPlane Far distance for OpenGL in millimeters.
 * @param isAnaglyph Use Anaglyph.
 * @param isLeft When analygph is it left or right, ignored otherwise.
 */
public void initDraw(Camera cam, PVector userPos, float nearPlane, float farPlane, boolean isAnaglyph, boolean isLeft) {

    PGraphicsOpenGL graphics = getGraphics();

    if (initPosM == null) {
        this.isOpenGL = true;
        // Transformation  Camera -> Marker

        initPosM = this.getLocation(cam);

        initPosM.translate(this.getRenderingSizeX() / 2, this.getRenderingSizeY() / 2);
        // All is relative to the paper's center. not the corner. 
        initPosM.scale(-1, 1, 1);

    }

    // get the current transformation... 
    PMatrix3D newPos = this.getLocation(cam);

    newPos.translate(this.getRenderingSizeX() / 2, this.getRenderingSizeY() / 2);
    newPos.scale(-1, 1, 1);

    newPos.invert();
    newPos.apply(initPosM);

    PVector user = new PVector();

    if (isAnaglyph && isLeft) {
        userPos.add(-halfEyeDist * 2, 0, 0);
    }
    newPos.mult(userPos, user);
    PVector paperCameraPos = user;

    // Camera must look perpendicular to the screen. 
    graphics.camera(paperCameraPos.x, paperCameraPos.y, paperCameraPos.z,
            paperCameraPos.x, paperCameraPos.y, 0,
            0, 1, 0);

    // http://www.gamedev.net/topic/597564-view-and-projection-matrices-for-vr-window-using-head-tracking/
    float nearFactor = nearPlane / paperCameraPos.z;

    float left = nearFactor * (-drawingSize.x / 2f - paperCameraPos.x);
    float right = nearFactor * (drawingSize.x / 2f - paperCameraPos.x);
    float top = nearFactor * (drawingSize.y / 2f - paperCameraPos.y);
    float bottom = nearFactor * (-drawingSize.y / 2f - paperCameraPos.y);

    graphics.frustum(left, right, bottom, top, nearPlane, farPlane);
    graphics.projection.m11 = -graphics.projection.m11;

    // No detection?
    PMatrix3D transformation = this.getLocation(cam);
    if (transformation.m03 == 0 && transformation.m13 == 0 && transformation.m23 == 0) {
        resetPos();
    }
}
 
Example 4
Source File: Demo_PVector_tests.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawApp() {
	p.background(0);
	p.stroke(255);
	PG.setDrawCenter(p);
	mouse.set(Mouse.xEased * p.width, Mouse.yEased * p.height);
	
	// line to mouse
	p.line(center.x, center.y, mouse.x, mouse.y);
	
	// get perpendicular location from mouse
	// from: https://twitter.com/mattdesl/status/1140218255069646848
	p.stroke(0, 255, 0);
	float perpLength = 70f + 20f * P.sin(p.frameCount * 0.03f);
	perp.set(mouse).sub(center).normalize();
	perp.set(-perp.y, perp.x);
	perp.mult(perpLength).add(mouse);
	p.line(mouse.x, mouse.y, perp.x, perp.y);
	p.ellipse(perp.x, perp.y, 10, 10);
	
	// average perpendiculars between line segments
	for (int i = 0; i < lineSegments.length; i++) {
		PVector point = lineSegments[i];
		point.add(1.5f * P.sin(i + p.frameCount * 0.05f), 1.5f * P.cos(i + p.frameCount * 0.04f));
		p.noStroke();
		p.ellipse(point.x, point.y, 10, 10);
		if(i > 0) {
			PVector pointLast = lineSegments[i-1];
			p.stroke(255);
			p.line(point.x, point.y, pointLast.x, pointLast.y);
		}
	}
	getPerp(lineSegments[0], lineSegments[1], perp1);
	getPerp(lineSegments[1], lineSegments[2], perp2);
	perp1.lerp(perp2, 0.5f);
	
	// draw averaged perpendicular
	perp1.mult(50).add(lineSegments[1]);
	p.stroke(0, 255, 0);
	p.line(lineSegments[1].x, lineSegments[1].y, perp1.x, perp1.y);
	p.ellipse(perp1.x, perp1.y, 10, 10);
}
 
Example 5
Source File: TextureSphere.java    From haxademic with MIT License 4 votes vote down vote up
PVector midpointOnSphere(PVector a, PVector b) {
	PVector midpoint = PVector.add(a, b);
	midpoint.mult(0.5f);
	midpoint.normalize();
	return midpoint;
}
 
Example 6
Source File: Icosahedron.java    From haxademic with MIT License 4 votes vote down vote up
PVector midpointOnSphere(PVector a, PVector b) {
	PVector midpoint = PVector.add(a, b);
	midpoint.mult(0.5f);
	midpoint.normalize();
	return midpoint;
}