List of usage examples for com.badlogic.gdx.math Matrix3 Matrix3
public Matrix3(float[] values)
From source file:es.eucm.ead.engine.paths.PathFinder.java
License:Open Source License
/** * Finds paths within a given polygon./* w w w .j a va 2s. co m*/ * * @param pathBoundary * the polygon that defines the boundaries of admissible paths * @param viewToWorld * projection matrix to use. If null, no projection is used. See * PathUtils.CENTRAL_ONE_QUARTER_SQUARE for an example * perspective. */ public PathFinder(Polygon pathBoundary, Matrix3 viewToWorld) { // setup projection viewToWorld = viewToWorld != null ? new Matrix3(viewToWorld) : new Matrix3().idt(); this.viewToWorld = viewToWorld; this.worldToView = new Matrix3(viewToWorld).inv(); // store a world-transformed copy of pathBoundary, keep all // boundaryPoints // for segment match pathBoundary = new Polygon(PathUtils.clone(pathBoundary.getVertices())); this.pathBoundary = pathBoundary; PathUtils.transformPolygons(viewToWorld, pathBoundary); this.boundaryPoints = PathUtils.polygonToPointsCircular(pathBoundary); }
From source file:magory.svg.Sovery.java
public Matrix3 getTransformMatrix(String trans) { float matrixNew[] = new float[9]; matrixNew[0] = 1;//from w w w . j a v a2s . c om matrixNew[1] = 0; matrixNew[2] = 0; matrixNew[3] = 0; matrixNew[4] = 1; matrixNew[5] = 0; matrixNew[6] = 0; matrixNew[7] = 0; matrixNew[8] = 1; if (!trans.equals("")) { if (isRotation(trans)) { // if is rotation 3 values if (trans.contains(",")) { // translate(<cx>, <cy>) rotate(<rotate-angle>) translate(-<cx>, -<cy>) float r[] = getRotationFloats(trans); Matrix3 t2 = getTransformMatrix("translate(" + r[1] + "," + r[2] + ")"); Matrix3 rr = getTransformMatrix("rotate(" + r[0] + ")"); Matrix3 t1 = getTransformMatrix("translate(" + (-r[1]) + "," + (-r[2]) + ")"); /*Gdx.app.log("test", "translate("+r[1]+","+r[2]+")"); Gdx.app.log("test", "rotate("+r[0]+")"); Gdx.app.log("test", "translate(-"+r[1]+",-"+r[2]+")");*/ rr.mulLeft(t2); t1.mulLeft(rr); return t1; } else { // -> rotation matrix float r = getRotationFloat(trans); matrixNew[0] = (float) Math.cos(Math.toRadians(r)); matrixNew[1] = (float) Math.sin(Math.toRadians(r)); matrixNew[2] = 0; matrixNew[3] = (float) -Math.sin(Math.toRadians(r)); matrixNew[4] = (float) Math.cos(Math.toRadians(r)); matrixNew[5] = 0; matrixNew[6] = 0; matrixNew[7] = 0; matrixNew[8] = 1; } } else if (isScale(trans)) { // -> scale matrix float fl[] = getScaleFloats(trans); matrixNew[0] = fl[0]; matrixNew[1] = 0; matrixNew[2] = 0; matrixNew[3] = 0; matrixNew[4] = fl[1]; matrixNew[5] = 0; matrixNew[6] = 0; matrixNew[7] = 0; matrixNew[8] = 1; } else if (isTranslate(trans)) { // -> translate matrix matrix(1 0 0 1 x y) float fl[] = getTranslateFloats(trans); matrixNew[0] = 1; matrixNew[1] = 0; matrixNew[2] = 0; matrixNew[3] = 0; matrixNew[4] = 1; matrixNew[5] = 0; matrixNew[6] = fl[0]; matrixNew[7] = fl[1]; matrixNew[8] = 1; } else if (isMatrix(trans)) { // just read matrix float fl[] = getMatrixFloats(trans); matrixNew[0] = fl[0]; matrixNew[1] = fl[1]; matrixNew[2] = 0; matrixNew[3] = fl[2]; matrixNew[4] = fl[3]; matrixNew[5] = 0; matrixNew[6] = fl[4]; matrixNew[7] = fl[5]; matrixNew[8] = 1; } } return new Matrix3(matrixNew); }
From source file:magory.svg.Sovery.java
public Matrix3 translate(float x, float y) { // translate to x,y of the object float[] matrixNew = new float[9]; matrixNew[0] = 1;/* w ww. j a v a2s . co m*/ matrixNew[1] = 0; matrixNew[2] = 0; matrixNew[3] = 0; matrixNew[4] = 1; matrixNew[5] = 0; matrixNew[6] = x; matrixNew[7] = y; matrixNew[8] = 1; return new Matrix3(matrixNew); }
From source file:magory.svg.Sovery.java
public void loadElement(Element el, float[] matrixOld) { String elname = el.getName(); if (elname.equals("svg")) getSVGDimentions(el);/* w w w . j av a2s. com*/ int count = el.getChildCount(); // magic for transforms and matrixes, don't touch unless you know what you are doing String trans = getAttribute(el, "transform", "", false); String title = getTitle(el); float elementX = getFloat(el.getAttribute("x", "0")); float elementY = getFloat(el.getAttribute("y", "0")); float elementWidth = getFloat(getAttribute(el, "width", "", false)); float elementHeight = getFloat(getAttribute(el, "height", "", false)); Vector2 origin = new Vector2(elementWidth / 2, elementHeight / 2); Vector2 scale = new Vector2(1, 1); Vector2 scaleOld = new Vector2(1, 1); Vector2 translate = new Vector2(); float rr; // rotation Matrix3 matrix = getTransformMatrix(trans); float oldR = 0; if (matrixOld != null) // is a matrix { Matrix3 mOld = new Matrix3(matrixOld); oldR = mOld.getRotation(); getScale(mOld, scaleOld); if (scaleOld.y < 0 || scaleOld.x < 0) { origin.rotate(oldR); matrix.mulLeft(translate(-origin.x, -origin.y)); origin.rotate(-oldR); matrix.mulLeft(mOld); matrix.mul(translate(elementX, elementY)); matrix.translate(origin.x, origin.y); } else { origin.rotate(-oldR); matrix.mulLeft(translate(-origin.x, -origin.y)); origin.rotate(oldR); matrix.mulLeft(mOld); matrix.mul(translate(elementX, elementY)); matrix.translate(origin.x, origin.y); } } else { matrix.mulLeft(translate(-origin.x, -origin.y)); matrix.mul(translate(elementX, elementY)); matrix.translate(origin.x, origin.y); } if (count != 0) for (int i = 0; i < count; i++) loadElement(el.getChild(i), matrix.getValues()); // important magic for width,height and x,y // inspired by this: http://stackoverflow.com/questions/16359246/how-to-extract-position-rotation-and-scale-from-matrix-svg // and this: http://www.w3.org/TR/css3-transforms/ matrix.getScale(scale); rr = matrix.getRotation(); // magic which I don't understand getScale(matrix, scale); if (scale.y < 0 && scaleOld.y > 0) { Vector2 det = new Vector2(0, elementHeight * Math.signum(scale.y) * 2); // because y flip uses top border of the image det.rotate(rr); matrix.translate(det); } if (scaleOld.y < 0 || scaleOld.x < 0) { Vector2 det = new Vector2(0, scaleOld.y * elementHeight / scale.y); // because... well, I don't know why if (scale.y < 0) det.rotate(rr + 180); else if (scale.x < 0) det.rotate(rr); else { if (scaleOld.x < 0) det.rotate(-rr + 180); else det.rotate(-rr); } matrix.translate(det); } matrix.getTranslation(translate); float width = elementWidth * scale.x; float height = elementHeight * scale.y; float yyy = SVGHeight - translate.y - height; float xxx = translate.x; if (title.startsWith("testing")) { Gdx.app.log("test", "oldR:" + oldR + " sx:" + scaleOld.x + " sy:" + scaleOld.y); Gdx.app.log("test", ":::" + title + ":" + xxx + "," + yyy + ":" + rr + " " + width + "x" + height + " rr:" + rr + " scalex:" + scale.x + " scaley:" + scale.y); } rr = -rr; if (width < 0) rr = rr + 180; if (rr < 0) rr += 360; if (title.startsWith("testing")) Gdx.app.log("test", ":::newrr:" + rr); if (elname.equals("path")) // path { String d = el.getAttribute("d", ""); newPath(parsePathToArray(d, elementX, elementY, SVGHeight), el, title); } else if (isText(elname)) // text { Element e = getChild(el, "tspan"); if (e == null) return; String text; if (e.getText() == null) text = ""; else text = e.getText().trim(); // font-size as height! - width not set unfortunately // example: font-size:44.03109741px; String style = getAttribute(el, "style", "", false); String styles[] = style.split("\\;"); Color color = new Color(1, 1, 1, 1); if (styles != null && styles.length > 0) { for (int i = 0; i < styles.length; i++) { if (isStyle(styles[i], "font-size")) { String stylesdata[] = styles[i].split("\\:"); stylesdata[1] = stylesdata[1].replace("px", ""); stylesdata[1] = stylesdata[1].replace(";", ""); height = getFloat(stylesdata[1].trim()); } else if (isStyle(styles[i], "fill")) { //fill:#effffa String stylesdata[] = styles[i].split("\\:"); stylesdata[1] = stylesdata[1].replace("#", ""); stylesdata[1] = stylesdata[1].replace(";", ""); color = getColorFromString(stylesdata[1].trim()); } } } newText(text, el, xxx, yyy, width, height, rr, color); } else if (isImage(elname)) // obraz { String name = getImageName(getAttribute(el, "xlink:href", "", false)); newImage(name, el, xxx, yyy, width, height, rr); } else if (isRect(elname)) // obraz { Element title2 = getChild(el, "title"); if (title2 != null) newRect(title2.getText(), el, xxx, yyy, width, height, rr); else newRect("", el, xxx, yyy, width, height, rr); } }
From source file:ve.ucv.ciens.ccg.nxtar.components.GeometryComponent.java
License:Apache License
public GeometryComponent(Vector3 position, Matrix3 rotation, Vector3 scaling) { this.position = new Vector3(position); this.rotation = new Matrix3(rotation); this.scaling = new Vector3(scaling); }