/** * Return the x,y positions of a 3D location projected onto a given * reference. The Z axis is the angle (in radians) given by the rotation of * the positionToFind. * * @param positionToFind * @param reference * @return */ public PVector projectPositionTo2D(PMatrix3D positionToFind, PMatrix3D reference, float referenceHeight) { PMatrix3D referenceInv = reference.get(); referenceInv.invert(); PMatrix3D relative = positionToFind.get(); relative.preApply(referenceInv); PMatrix3D positionToFind2 = positionToFind.get(); positionToFind2.translate(100, 0, 0); PMatrix3D relative2 = positionToFind2.get(); relative2.preApply(referenceInv); PVector out = new PVector(); float x = relative.m03 - relative2.m03; float y = relative.m13 - relative2.m13; out.z = PApplet.atan2(x, y); out.x = relative.m03; out.y = referenceHeight - relative.m13; return out; }
/** * Return the x,y positions of a 3D location projected onto a given * reference. The Z axis is the angle (in radians) given by the rotation of * the positionToFind. * * @param positionToFind * @param reference * @return */ public PVector projectPositionTo(PMatrix3D positionToFind, PaperScreen reference) { PMatrix3D referenceInv = reference.getLocation().get(); referenceInv.invert(); PMatrix3D relative = positionToFind.get(); relative.preApply(referenceInv); PMatrix3D positionToFind2 = positionToFind.get(); positionToFind2.translate(100, 0, 0); PMatrix3D relative2 = positionToFind2.get(); relative2.preApply(referenceInv); PVector out = new PVector(); float x = relative.m03 - relative2.m03; float y = relative.m13 - relative2.m13; out.z = PApplet.atan2(x, y); out.x = relative.m03; out.y = reference.drawingSize.y - relative.m13; return out; }
public void drawOnTable() { if (!isDrawingOnDisplay) { return; } // PMatrix3D location = this.getLocation().get(); // PMatrix3D t = tableInv.get(); // t.apply(location); // PVector tableRelativePos = new PVector(t.m03, t.m13, t.m23); PVector p2 = getRelativePos(new PVector(20, 20, 0)); PVector tableRelativePos = getRelativePos(new PVector(0, 0, 0)); float r = PApplet.atan2(p2.y - tableRelativePos.y, p2.x - tableRelativePos.x); PMatrix3D locationInv = this.getLocation().get(); locationInv.invert(); currentGraphics.scale(1, -1, 1); currentGraphics.translate(0, -getSize().y, 0); currentGraphics.applyMatrix(locationInv); currentGraphics.applyMatrix(table); currentGraphics.translate(tableRelativePos.x, tableRelativePos.y); currentGraphics.rotate(r); currentGraphics.scale(1, -1, 1); }