/** * Divide a vector by a scalar and store the result in another vector. * @param target PVector in which to store the result */ static public PVector div(PVector v, float n, PVector target) { if (target == null) { target = new PVector(v.x/n, v.y/n, v.z/n); } else { target.set(v.x/n, v.y/n, v.z/n); } return target; }
/** * @param target Set to null to create a new vector * @return a new vector (if target was null), or target */ public PVector normalize(PVector target) { if (target == null) { target = new PVector(); } float m = mag(); if (m > 0) { target.set(x/m, y/m, z/m); } else { target.set(x, y, z); } return target; }
/** * Sets the magnitude of this vector, storing the result in another vector. * @param target Set to null to create a new vector * @param len the new length for the new vector * @return a new vector (if target was null), or target */ public PVector setMag(PVector target, float len) { target = normalize(target); target.mult(len); return target; }
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; }
protected float computeRotation(Touch touch0, Touch touch1) { PVector currentDirection = PVector.sub(touch0.pposition, touch1.pposition); PVector previousDirection = PVector.sub(touch0.position, touch1.position); currentDirection.normalize(); previousDirection.normalize(); float cos = currentDirection.dot(previousDirection); float angle = acos(cos); PVector sin = currentDirection.cross(previousDirection); if (sin.z < 0) { angle = -angle; } return angle; }
/** * ( begin auto-generated from PVector_limit.xml ) * * Limit the magnitude of this vector to the value used for the <b>max</b> parameter. * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @param max the maximum magnitude for the vector * @brief Limit the magnitude of the vector */ public void limit(float max) { if (magSq() > max*max) { normalize(); mult(max); } }
velocity= new PVector(1, 1); acceleration= new PVector( random(-0.01, 0.01), random(-0.01, 0.01)); acceleration.normalize(); PVector moverPos = new PVector(x, y); dir.normalize(); // Normalize dir.mult(4); // Scale acceleration = dir; velocity = new PVector(0,0); acceleration = new PVector(random(-1,1),random(-1,1));//random initial acceleration topspeed = 4;
/** * Update the position of this element according to the parameter. Updates * the position, previous position, confidence and speed. * * @param tp */ private void updatePosition(TrackedElement tp) { // save the previous position previousPosition = position.get(); this.position.set(tp.position); this.confidence = tp.confidence; // this.setSource(tp.source); speed.set(this.position); speed.sub(this.previousPosition); }
PVector originP = new PVector(0, 0, 0); PVector viewedPtP = getProjectiveDeviceP().pixelToWorldNormalized(px, py); PVector originC = originP.copy(); PVector viewedPtC = viewedPtP.copy(); if (hasExtrinsics()) { originC = new PVector(); viewedPtC = new PVector(); proCamExtrinsics.mult(originP, originC); proCamExtrinsics.mult(viewedPtP, viewedPtC); viewedPtC.sub(originC); return new PVector(inter.x(), inter.y(), inter.z());
/** * Set the position of the capture in millimeter. * * @param x * @param y */ public void setCaptureOffset(float x, float y) { this.captureOffset.set(x, y); }
/** * ( begin auto-generated from PVector_normalize.xml ) * * Normalize the vector to length 1 (make it a unit vector). * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @brief Normalize the vector to a length of 1 */ public void normalize() { float m = mag(); if (m != 0 && m != 1) { div(m); } }
/** * Multiply a vector by a Matrix. * * @param mat source matrix * @param source vector to multiply * @param target output, will be created if null. * @return */ public static PVector mult(PMatrix3D mat, PVector source, PVector target) { if (target == null) { target = new PVector(); } target.x = mat.m00 * source.x + mat.m01 * source.y + mat.m02 * source.z + mat.m03; target.y = mat.m10 * source.x + mat.m11 * source.y + mat.m12 * source.z + mat.m13; target.z = mat.m20 * source.x + mat.m21 * source.y + mat.m22 * source.z + mat.m23; float tw = mat.m30 * source.x + mat.m31 * source.y + mat.m32 * source.z + mat.m33; if (tw != 0 && tw != 1) { target.div(tw); } return target; }
public void start( float posx, float posy, float posz, float dirx, float diry, float dirz, float upx, float upy, float upz) { this.pgl = app.beginPGL(); if (this.stereoType == StereoType.SIDE_BY_SIDE) { this.aspectRatio = (float) (width / 2.0f) / (float) height; } else { this.aspectRatio = (float) width / (float) height; } this.widthdiv2 = nearPlane * (float) Math.tan(this.fovy / 2); // aperture in radians this.posx = posx; this.posy = posy; this.posz = posz; this.dirx = dirx; this.diry = diry; this.dirz = dirz; this.upx = upx; this.upy = upy; this.upz = upz; PVector cdir = new PVector(this.dirx, this.diry, this.dirz); PVector cup = new PVector(this.upx, this.upy, this.upz); PVector cright = cdir.cross(cup); this.rightx = cright.x * eyeSeparation / 2.0f; this.righty = cright.y * eyeSeparation / 2.0f; this.rightz = cright.z * eyeSeparation / 2.0f; }
/** * @param v the vector to multiply by the scalar */ static public PVector mult(PVector v, float n) { return mult(v, n, null); }
/** * @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; }