processing.core.PVector Java Examples
The following examples show how to use
processing.core.PVector.
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: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void addTextureUVToShape(PShape shape, PImage img, float outerExtent, boolean xyMapping) { shape.setStroke(false); // shape.setFill(255); // This seems to jack up vertex shaders shape.setTextureMode(P.NORMAL); for (int i = 0; i < shape.getVertexCount(); i++) { PVector v = shape.getVertex(i); float uX = (xyMapping == true) ? v.x : v.z; shape.setTextureUV( i, P.map(uX, -outerExtent, outerExtent, 0, 1f), P.map(v.y, -outerExtent, outerExtent, 0, 1f) ); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); addTextureUVToShape(subShape, img, outerExtent, xyMapping); } if(img != null) shape.setTexture(img); }
Example #2
Source File: HaxMapDrawingTool.java From haxademic with MIT License | 6 votes |
public void mousePressed() { super.mousePressed(); _isPressed = true; // find closest vertex to mouse float closestPoint = 10; PShape curShape = null; PVector curVertex = null; for (int i=0; i < _shapes.size(); i++) { curShape = _shapes.get(i); for (int j = 0; j < curShape.getVertexCount(); j++) { curVertex = curShape.getVertex(j); float mouseDistToVertex = MathUtil.getDistance(p.mouseX, p.mouseY, curVertex.x, curVertex.y); if( mouseDistToVertex < closestPoint ) { // set z to 1 so that we know that we're dragging (this is a silly hack) curShape.setVertex(j, curShape.getVertex(j).x, curShape.getVertex(j).y, 1); _draggingShapes.add( curShape ); } } } }
Example #3
Source File: TwoFingersRST.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
protected void twoFingerMovement() { if (!getValidTouchs()) { emptyUpdate(); return; } // System.out.println("Full Update"); // Every values needs to be divided by 2... for some reason. float rot = computeRotation(touchs[0], touchs[1]); if (!Float.isNaN(rot)) // && abs(rot) > PI / 90f) { addRotation(rot / 2f); } float scale = computeScale(touchs[0], touchs[1]); if (!Float.isNaN(scale)) // && abs(scale) > 0.8) { float halfScale = (scale - 1f) / 2f + 1; multScale(halfScale); } PVector translate = computeTranslate(touchs[0], touchs[1]); translate.mult(0.5f); addTranslation(translate); }
Example #4
Source File: TouchDetectionColor.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean checkPoint(int offset, int currentPoint) { // TODO: not sure if the distance is relevant in this context. int x1 = offset % imgSize.getWidth(); int y1 = (int) (offset / imgSize.getWidth()); int x2 = currentPoint % imgSize.getWidth(); int y2 = (int) (currentPoint / imgSize.getWidth()); float dist = PVector.dist(new PVector(x1, y1), new PVector(x2, y2)); return !assignedPoints[offset] // not assigned && segmentedImage[offset] == segmentedImage[currentPoint] // is the same color/compo. && dist < calib.getMaximumDistance(); }
Example #5
Source File: MultiSimpleCalibrator.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
public static void drawAR(PApplet parent, PGraphicsOpenGL g, MultiSimpleCalibrator multiCalibrator, PVector pt) { // AR rendering, for touch and color tracking (and debug). if (multiCalibrator.getDisplay() instanceof ARDisplay) { ARDisplay display = (ARDisplay) multiCalibrator.getDisplay(); display.drawScreensOver(); parent.noStroke(); PImage img = multiCalibrator.getCameraTracking().getPImage(); if (multiCalibrator.getCameraTracking() != null && img != null) { parent.image(img, 0, 0, parent.width, parent.height); // ((PGraphicsOpenGL) (parent.g)).image(camera.getPImage(), 0, 0, frameWidth, frameHeight); } // TODO: Distorsion problems with higher image space distorisions (useless ?) DrawUtils.drawImage((PGraphicsOpenGL) parent.g, display.render(), 0, 0, parent.width, parent.height); } }
Example #6
Source File: HaxMapDrawingTool.java From haxademic with MIT License | 6 votes |
public void exportVertices() { String export = ""; for( int i=0; i < _shapeGroups.size(); i++ ) { export += "#group#\n"; ArrayList<PShape> curGroup = _shapeGroups.get(i); for( int j=0; j < curGroup.size(); j++ ) { PShape curShape = curGroup.get(j); PVector vertex; export += "#poly#"; for (int k = 0; k < curShape.getVertexCount(); k++) { vertex = curShape.getVertex(k); if( k > 0 ) export += ","; export += vertex.x+","+vertex.y; } export += "\n"; } } FileUtil.writeTextToFile(FileUtil.haxademicDataPath() + "text/mapping/mapping-"+SystemUtil.getTimestamp()+".txt", export); }
Example #7
Source File: QuadSurface.java From sketch-mapper with MIT License | 6 votes |
private void setupCornerPoints(XML xml) { PVector[] points = new PVector[4]; int index = 0; while (index < 4) { for (XML child : xml.getChildren()) { if (!"cornerpoint".equals(child.getName())) { continue; } float x = child.getFloat("x"); float y = child.getFloat("y"); points[index] = new PVector(x, y); index++; } } setCornerPoints( points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points[2].y, points[3].x, points[3].y ); }
Example #8
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void exportMesh(PShape mesh) { StringBuilder verts = new StringBuilder(); StringBuilder faces = new StringBuilder(); final int vertsNum = mesh.getVertexCount(); final PVector v = new PVector(); for(int i=0; i < vertsNum; i+=3) { mesh.getVertex(i, v); verts.append("v " + v.x + " " + v.y + " " + v.z + "\n"); mesh.getVertex(i+1, v); verts.append("v " + v.x + " " + v.y + " " + v.z + "\n"); mesh.getVertex(i+2, v); verts.append("v " + v.x + " " + v.y + " " + v.z + "\n"); faces.append("f " + (i+1) + " " + (i+2) + " " + (i+3) + "\n"); } String outputStr = "o Sphere\n"; outputStr += verts; outputStr += faces; FileUtil.writeTextToFile(FileUtil.haxademicOutputPath() + "text/model-"+SystemUtil.getTimestamp()+".obj", outputStr); }
Example #9
Source File: Demo_RandomUVCoordsConstrained.java From haxademic with MIT License | 6 votes |
public void setRandomTexturePolygonToDestPolygon(PVector[] source, Point center, PVector[] destination, int textureW, int textureH) { // make rotated triangle copyPolygon(source, destination); rotatePolygon(destination, center, MathUtil.randRangeDecimal(0, P.TWO_PI)); Rectangle randomPolyRotatedBB = createBoundingBox(destination); // fit rotated version in texture box float ratioW = (float)textureW / (float)randomPolyRotatedBB.width; float ratioH = (float)textureH / (float)randomPolyRotatedBB.height; float containRatio = (ratioW < ratioH) ? ratioW : ratioH; containRatio *= MathUtil.randRangeDecimal(0.25f, 1.0f); translatePolygon(destination, -randomPolyRotatedBB.x, -randomPolyRotatedBB.y); scalePolygon(destination, containRatio); Rectangle destinationBB = createBoundingBox(destination); // find random position within texture and move triangle & bb float moveX = (textureW - destinationBB.width) * MathUtil.randRangeDecimal(0, 1); float moveY = (textureH - destinationBB.height) * MathUtil.randRangeDecimal(0, 1); destinationBB.x = (int) moveX; destinationBB.y = (int) moveY; translatePolygon(destination, (int) moveX, (int) moveY); }
Example #10
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
private void fillNative(PVector[] objectPoints, PVector[] imagePoints, Mat op, Mat ip) { FloatIndexer opIdx = op.createIndexer(); FloatIndexer ipIdx = ip.createIndexer(); // Fill the object and image matrices. for (int i = 0; i < objectPoints.length; i++) { opIdx.put(i, 0, objectPoints[i].x); opIdx.put(i, 1, objectPoints[i].y); opIdx.put(i, 2, objectPoints[i].z); ipIdx.put(i, 0, imagePoints[i].x); ipIdx.put(i, 1, imagePoints[i].y); } }
Example #11
Source File: MathUtils.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Unsafe do not use unless you are sure. */ public int getColorOccurencesFrom(PVector coord, PImage cameraImage, int radius, int col, int threshold, PaperTouchScreen paperTouchScreen) { int x = (int) coord.x; int y = (int) coord.y; int minX = PApplet.constrain(x - radius, 0, cameraImage.width - 1); int maxX = PApplet.constrain(x + radius, 0, cameraImage.width - 1); int minY = PApplet.constrain(y - radius, 0, cameraImage.height - 1); int maxY = PApplet.constrain(y + radius, 0, cameraImage.height - 1); int k = 0; for (int j = minY; j <= maxY; j++) { for (int i = minX; i <= maxX; i++) { int offset = i + j * cameraImage.width; int pxCol = cameraImage.pixels[offset]; if (colorDistRGB(col, pxCol, threshold)) { k++; } } } return k; }
Example #12
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static float getMaxExtent(PShape shape, float outermostVertex) { // find mesh size extent to responsively scale the mesh for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); if(P.abs(vertex.x) > outermostVertex) outermostVertex = P.abs(vertex.x); if(P.abs(vertex.y) > outermostVertex) outermostVertex = P.abs(vertex.y); if(P.abs(vertex.z) > outermostVertex) outermostVertex = P.abs(vertex.z); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); outermostVertex = getMaxExtent(subShape, outermostVertex); } return outermostVertex; }
Example #13
Source File: MeshSegmentScanners.java From haxademic with MIT License | 6 votes |
public PVector nextSegmentPosition(PVector curTargetVec) { // return randomSegmentPosition().randomPoint(); // was used for testing PVector containsVec; int containsVecCount = 0; int indexToReturn = 0; // find segment with current point (make sure to exclude current segment) for (int i = 0; i < _meshLineSegments.size(); i++) { containsVec = _meshLineSegments.get(i).contains(curTargetVec); if( containsVec != null ) { containsVecCount++; if(MathUtil.randRange(0, 5) > 3) { indexToReturn = i; } } } if(containsVecCount > 0) { return _meshLineSegments.get(indexToReturn).otherPoint(curTargetVec); } return null; }
Example #14
Source File: MeshParticles.java From haxademic with MIT License | 6 votes |
public PVector getOneOfTheClosestVertexToParticle(VectorFlyer2d particle) { float leastDistance = Integer.MAX_VALUE; int closestIndex = MathUtil.randRange(0, _meshVertices.size() - 1); int closestIndex2nd = MathUtil.randRange(0, _meshVertices.size() - 1); for(int i=0; i < _meshVertices.size(); i++) { float checkDist = _meshVertices.get(i).dist(particle.position); if( checkDist < leastDistance && particle.closestIndex != i ) { closestIndex2nd = closestIndex; closestIndex = i; leastDistance = checkDist; } } int randClosestIndex = (MathUtil.randBoolean() == true) ? closestIndex : closestIndex2nd; particle.closestIndex = randClosestIndex; return _meshVertices.get(randClosestIndex); }
Example #15
Source File: KinectUser3dCallback.java From haxademic with MIT License | 6 votes |
void drawLimb(int userId, int jointType1, int jointType2) { PVector jointPos1 = new PVector(); PVector jointPos2 = new PVector(); float confidence; // draw the joint position confidence = context.getJointPositionSkeleton(userId, jointType1, jointPos1); confidence = context.getJointPositionSkeleton(userId, jointType2, jointPos2); stroke(255, 0, 0, confidence * 200 + 55); line(jointPos1.x, jointPos1.y, jointPos1.z, jointPos2.x, jointPos2.y, jointPos2.z); drawJointOrientation(userId, jointType1, jointPos1, 50); }
Example #16
Source File: MathUtils.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
public static PMatrix3D compute3DPos(DetectedMarker detected, float markerWidth, Camera camera) { // We create a pair model ( markersFromSVG) -> observation (markers) if (detected.confidence < 1.0) { return null; } // Build object corners PVector[] object = new PVector[4]; object[0] = new PVector(0, 0); object[1] = new PVector(markerWidth, 0); object[2] = new PVector(markerWidth, -markerWidth); object[3] = new PVector(0, -markerWidth); PVector[] image = detected.getCorners(); ProjectiveDeviceP pdp = camera.getProjectiveDevice(); return pdp.estimateOrientation(object, image); // return pdp.estimateOrientationRansac(objectArray, imageArray); }
Example #17
Source File: TouchDetectionDepth.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
@Deprecated protected void setPrecisionFrom(int firstPoint) { Vec3D currentPoint = depthData.depthPoints[firstPoint]; PVector coordinates = depthData.projectiveDevice.getCoordinates(firstPoint); // Find a point. int x = (int) coordinates.x; int y = (int) coordinates.y; int minX = PApplet.constrain(x - precision, 0, depthData.projectiveDevice.getWidth() - 1); int maxX = PApplet.constrain(x + precision, 0, depthData.projectiveDevice.getWidth() - 1); int minY = PApplet.constrain(y - precision, 0, depthData.projectiveDevice.getHeight() - 1); int maxY = PApplet.constrain(y + precision, 0, depthData.projectiveDevice.getHeight() - 1); for (int j = minY; j <= maxY; j += precision) { for (int i = minX; i <= maxX; i += precision) { Vec3D nearbyPoint = depthData.projectiveDevice.pixelToWorld(i, j, currentPoint.z); // Set the distance. setDistance(currentPoint.distanceTo(nearbyPoint)); return; } } // for i }
Example #18
Source File: PointCloud.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
public void addPoint(DepthPoint pce) { if (pce == null || pce.position == null) { return; } PVector p = pce.position; // float[] vert = vertices[nbToDraw]; verticesJava[currentVertNo++] = p.x; verticesJava[currentVertNo++] = p.y; verticesJava[currentVertNo++] = p.z; verticesJava[currentVertNo++] = 1; int c = pce.colorPt; int c2 = javaToNativeARGB(c); colorsJava[nbColors++] = c2; }
Example #19
Source File: PShapeSolid.java From haxademic with MIT License | 6 votes |
public void updateWithTrigAndNoiseCombo(float progressRadians, float trigAmpScale, float trigSpreadMultiplier, float trigIndexPercentOffset, float noiseFreq, float noiseAmpScale, int noiseOctaves, float noiseFalloff) { // deform from original copy, using vertexIndex as the key to find the shared index P.p.noiseDetail(noiseOctaves, noiseFalloff); int vertexIndex = 0; for (int j = 0; j < shape.getChildCount(); j++) { for (int i = 0; i < shape.getChild(j).getVertexCount(); i++) { int sharedVertexIndex = sharedVertexIndices.get(vertexIndex); PVector vOrig = vertices.get(vertexIndex); float vertexIndexPercent = (float)(sharedVertexIndex + 1) / (float)(sharedVertexIndices.size() + 1); vertexIndexPercent = (vertexIndexPercent + trigIndexPercentOffset) % 1f; float ampTrig = 1.0f + trigAmpScale + trigAmpScale * P.sin((progressRadians) + (trigSpreadMultiplier * P.TWO_PI * vertexIndexPercent)); float ampNoise = 1.0f + noiseAmpScale * 2f * (-0.5f + P.p.noise(vOrig.x + P.cos(progressRadians) * noiseFreq, vOrig.y + P.sin(progressRadians) * noiseFreq, vOrig.z + P.sin(progressRadians) * noiseFreq)); // float comboAmp = P.min(ampTrig, ampNoise); float comboAmp = (ampTrig + ampNoise) / 2f; shape.getChild(j).setVertex(i, vOrig.x * comboAmp, vOrig.y * comboAmp, vOrig.z * comboAmp); vertexIndex++; } } }
Example #20
Source File: CollisionUtil.java From haxademic with MIT License | 5 votes |
public static boolean lineIntersectsPolygon(PVector lineStart, PVector lineEnd, Polygon poly) { // check for point in polygon if(polygonContainsPoint(poly, lineStart)) return true; if(polygonContainsPoint(poly, lineEnd)) return true; // check edge intersections with line segment for (int i = 0; i < poly.edges().size(); i++) { Edge edge1 = poly.edges().get(i); if(linesIntersect(edge1.v1(), edge1.v2(), lineStart, lineEnd)) return true; } return false; }
Example #21
Source File: TrackedView.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
public void setCorners(PVector[] corners) { screenPixelCoordinates.clear(); for (int i = 0; i < corners.length; i++) { screenPixelCoordinates.add(corners[i]); } cornersSet = true; }
Example #22
Source File: MeshShapes.java From haxademic with MIT License | 5 votes |
public PVector Figure8Torus(float u, float v) { float x = 1.5f * P.cos(u) * (params[0] + P.sin(v) * P.cos(u) - P.sin(2*v) * P.sin(u) / 2f); float y = 1.5f * P.sin(u) * (params[0] + P.sin(v) * P.cos(u) - P.sin(2*v) * P.sin(u) / 2f) ; float z = 1.5f * P.sin(u) * P.sin(v) + P.cos(u) * P.sin(2*v) / 2; return new PVector(x, y, z); }
Example #23
Source File: MeshShapes.java From haxademic with MIT License | 5 votes |
public PVector SteinbachScrew(float u, float v) { float x = u * P.cos(v); float y = u * P.sin(params[0] * v); float z = v * P.cos(u); return new PVector(x, y, z); }
Example #24
Source File: SideScroller.java From Project-16x16 with GNU General Public License v3.0 | 5 votes |
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 #25
Source File: BaseMappedPolygon.java From haxademic with MIT License | 5 votes |
protected void rotatePolygon(PVector[] points, Point center, float rotateRadians) { for (int i = 0; i < points.length; i++) { double cosAngle = Math.cos(rotateRadians); double sinAngle = Math.sin(rotateRadians); double dx = (points[i].x-center.x); double dy = (points[i].y-center.y); points[i].x = center.x + (int) (dx*cosAngle-dy*sinAngle); points[i].y = center.y + (int) (dx*sinAngle+dy*cosAngle); } }
Example #26
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void offsetShapeVertices(PShape s, float xOffset, float yOffset, float zOffset) { for (int i = 0; i < s.getVertexCount(); i++) { PVector vertex = s.getVertex(i); s.setVertex(i, vertex.x + xOffset, vertex.y + yOffset, vertex.z + zOffset); } for (int i = 0; i < s.getChildCount(); i++) { PShape subShape = s.getChild(i); offsetShapeVertices(subShape, xOffset, yOffset, zOffset); } }
Example #27
Source File: PaperScreen.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
private PVector getRelativePos(PVector v) { PMatrix3D location = this.getLocation().get(); location.translate(v.x, v.y, v.z); PMatrix3D t = tableInv.get(); t.apply(location); PVector tableRelativePos = new PVector(t.m03, t.m13, t.m23); return tableRelativePos; }
Example #28
Source File: Demo_RandomUVCoordsConstrained.java From haxademic with MIT License | 5 votes |
protected PVector[] createTopLeftTriangleCopy(PVector[] points, Rectangle bb) { PVector[] copied = new PVector[3]; for (int i = 0; i < points.length; i++) { copied[i] = new PVector(points[i].x - bb.x, points[i].y - bb.y); } return copied; }
Example #29
Source File: Player.java From Project-16x16 with GNU General Public License v3.0 | 5 votes |
/** * Constructor * * @param a SideScroller game controller. */ public Player(SideScroller a, GameplayScene g , boolean isMultiplayerPlayer) { super(a, g); pos = new PVector(100, 300); // Spawn LOC. TODO get from current level animation = new AnimationComponent(); // animation.setSFX(Audio.SFX.STEP, 2); swings = new ArrayList<Swing>(); image = Tileset.getTile(0, 258, 14, 14, 4); lifeOn = Tileset.getTile(144, 256, 9, 9, 4); lifeOff = Tileset.getTile(160, 256, 9, 9, 4); // Set life lifeCapacity = 6; life = 3; speedWalk = 7; speedJump = 18; width = 14 * 4; height = 16 * 4; state = new PlayerState(); setAnimation(ACTION.IDLE); this.isMultiplayerPlayer = isMultiplayerPlayer; }
Example #30
Source File: ConstellationAbstractMarker.java From constellation with Apache License 2.0 | 5 votes |
protected boolean isInside(final float checkX, final float checkY, final List<? extends PVector> vectors) { boolean inside = false; for (int i = 0, j = vectors.size() - 1; i < vectors.size(); j = i++) { final PVector pi = vectors.get(i); final PVector pj = vectors.get(j); if ((((pi.y <= checkY) && (checkY < pj.y)) || ((pj.y <= checkY) && (checkY < pi.y))) && (checkX < (pj.x - pi.x) * (checkY - pi.y) / (pj.y - pi.y) + pi.x)) { inside = !inside; } } return inside; }