Package org.mt4j.util.math

Examples of org.mt4j.util.math.Vertex


    case CENTER:
      super.setPositionRelativeToParent(position);
      break;
    case LOWER_LEFT:{
      Vertex[] vertices = this.getVerticesLocal();
      Vertex lowerLeft = new Vertex(vertices[3]);
      lowerLeft.transform(this.getLocalMatrix());
      this.translate(position.getSubtracted(lowerLeft), TransformSpace.RELATIVE_TO_PARENT);
    }break;
    case LOWER_RIGHT:{
      Vertex[] vertices = this.getVerticesLocal();
      Vertex v = new Vertex(vertices[2]);
      v.transform(this.getLocalMatrix());
      this.translate(position.getSubtracted(v), TransformSpace.RELATIVE_TO_PARENT);
    }break;
    case UPPER_LEFT:{
      Vertex[] vertices = this.getVerticesLocal();
      Vertex v = new Vertex(vertices[0]);
      v.transform(this.getLocalMatrix());
      this.translate(position.getSubtracted(v), TransformSpace.RELATIVE_TO_PARENT);
    }break;
    default:
      break;
    }
View Full Code Here


   */
  public void setSizeLocal(float width, float height){
    if (width > 0 && height > 0){
      Vertex[] v = this.getVerticesLocal();
      this.setVertices(new Vertex[]{
          new Vertex(v[0].x,      v[0].y,     v[0].z, v[0].getTexCoordU(), v[0].getTexCoordV(), v[0].getR(), v[0].getG(), v[0].getB(), v[0].getA()),
          new Vertex(v[0].x+width,   v[1].y,     v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
          new Vertex(v[0].x+width,   v[1].y+height,   v[2].z, v[2].getTexCoordU(), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
          new Vertex(v[3].x,      v[0].y+height,  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
          new Vertex(v[4].x,      v[4].y,      v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
      });
    }
  }
View Full Code Here

   * @param height the new height local
   */
  public void setHeightLocal(float height){
    Vertex[] v = this.getVerticesLocal();
    this.setVertices(new Vertex[]{
        new Vertex(v[0].x,  v[0].y,     v[0].z, v[0].getTexCoordU(), v[0].getTexCoordV(), v[0].getR(), v[0].getG(), v[0].getB(), v[0].getA()),
        new Vertex(v[1].x,   v[1].y,     v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
        new Vertex(v[2].x,   v[1].y+height,   v[2].z, v[2].getTexCoordU(), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
        new Vertex(v[3].x,  v[1].y+height,  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
        new Vertex(v[4].x,  v[4].y,      v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
    });
  }
View Full Code Here

   */
  public void setWidthLocal(float width){
    if (width > 0){
      Vertex[] v = this.getVerticesLocal();
      this.setVertices(new Vertex[]{
          new Vertex(v[0].x,      v[0].y, v[0].z, v[0].getTexCoordU(), v[0].getTexCoordV(), v[0].getR(), v[0].getG(), v[0].getB(), v[0].getA()),
          new Vertex(v[0].x+width,   v[1].y, v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
          new Vertex(v[0].x+width,   v[2].y, v[2].z, v[2].getTexCoordU(), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
          new Vertex(v[3].x,      v[3].y,  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
          new Vertex(v[4].x,      v[4].y,  v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
      });
    }
  }
View Full Code Here

        //Create Vertex[] from points
        SVGPointList pointList = polyLineElem.getPoints();
        Vertex[] vertices = new Vertex[pointList.getNumberOfItems()];
        for (int i = 0; i < pointList.getNumberOfItems(); i++) {
        SVGPoint p = pointList.getItem(i);
        vertices[i] = new Vertex(p.getX(), p.getY(),0);
        }
       
        //Create the shape
        AbstractShape comp = createPoly(vertices);
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMRectElement){
        SVGOMRectElement rectElem = (SVGOMRectElement)gfxElem;
        if (isUnderClipPath(rectElem)){
          logger.error("discarding clip-path Rect");
          return null;
        }
       
        float x     = rectElem.getX().getBaseVal().getValue();
        float y     = rectElem.getY().getBaseVal().getValue();
        float width   = rectElem.getWidth().getBaseVal().getValue();
        float height   = rectElem.getHeight().getBaseVal().getValue();
        float rx     = rectElem.getRx().getBaseVal().getValue();
        float ry     = rectElem.getRy().getBaseVal().getValue();
       
        AbstractShape comp;
        //Create a normal rectangle or a round rectangle
        if (rx != 0.0f || ry != 0.0f){
          if (rx > width/2 )
            rx = width/2;
          if (ry > height/2 )
            ry = height/2;
          comp = new MTRoundRectangle(x,y,0, width,height,rx, ry, pa);
        }else{
          comp = new MTRectangle(x,y, width,height, pa);
        }
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMEllipseElement){
        SVGOMEllipseElement ellipseElem = (SVGOMEllipseElement)gfxElem;
        float cx = ellipseElem.getCx().getBaseVal().getValue();
        float cy = ellipseElem.getCy().getBaseVal().getValue();
        float r  = ellipseElem.getRx().getBaseVal().getValue();
        float r2 = ellipseElem.getRy().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
        //or else theyre too small => processing bug?
//        r*=2;
//        r2*=2;
        MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMCircleElement){
        SVGOMCircleElement circleElem = (SVGOMCircleElement)gfxElem;
        float cx = circleElem.getCx().getBaseVal().getValue();
        float cy = circleElem.getCy().getBaseVal().getValue();
        float r = circleElem.getR().getBaseVal().getValue();
        float r2 = circleElem.getR().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
View Full Code Here

            GradientPanel gradPanel = new GradientPanel(size, size, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY(), awtCycleMethod);
//          GradientPanel gradPanel = new GradientPanel(bBoxWidth, bBoxHeight, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY());
            swingTex = new SwingTextureRenderer(app, gradPanel);
            swingTex.scheduleRefresh();
            rectangle = new MTRectangle(new Vertex(boundsVecs[0]), bBoxWidth, bBoxHeight, pa);
            rectangle.setName("Swing texture rendering");
            rectangle.setTexture(swingTex.getTextureToRenderTo());
            rectangle.setNoStroke(true);
            rectangle.setPickable(false);
            rectangle.setFillDrawMode(GL.GL_QUADS);

            //Use displaylist by default for gradientshape
            if (MT4jSettings.getInstance().isOpenGlMode()){
              app.invokeLater(new InvokeLaterAction(rectangle));
            }

            //FIXME REMOVE TEST
            /*//Draw the shape we draw in swing
          MTRectangle rectanglePaintedComp = new MTRectangle(new Vertex(boundsVecs[0]), size, size, pa);
          rectanglePaintedComp.setName("rectanglePaintedComp");
          rectanglePaintedComp.setTexture(swingTex.getTextureToRenderTo());
          rectanglePaintedComp.setFillColor(255, 255, 255, 150);
          shape.addChild(rectanglePaintedComp);
             */
          }else{
            //coordsystemtype = userSpaceOnUse!

            //FIXME Problem at userOnSpace with proportional length (%)
            //seems we have to take the width/height from the viewbox then!? and use bounding box code above? but we have to recalculate absoulte values then..

            //Since we draw the gradient at 0,0 we have to transform the gradient points to there
            AffineTransform Mx = new AffineTransform();
            Mx.translate(-boundsVecs[0].x, -boundsVecs[0].y);
            Mx.concatenate(transform);
            transform = Mx;

            //Transform gradient points with gradientTransform
            transform.transform(c, c);
            transform.transform(f, f);

//          GradientPanel gradPanel = new GradientPanel(size, size, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY());
            GradientPanel gradPanel = new GradientPanel(bBoxWidth, bBoxHeight, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY(), awtCycleMethod);
            swingTex = new SwingTextureRenderer(app, gradPanel);
            swingTex.scheduleRefresh();
            rectangle = new MTRectangle(new Vertex(boundsVecs[0]), bBoxWidth, bBoxHeight, pa);
            final GLTexture tex = swingTex.getTextureToRenderTo();
            rectangle.setName("Swing texture rendering");
            rectangle.setTexture(tex);
            rectangle.setNoStroke(true);
            rectangle.setPickable(false);
View Full Code Here

    //Get copy of shapes vertices
    Vertex[] shapeVertsCopy = Vertex.getDeepVertexArrayCopy(testShape.getGeometryInfo().getVertices());
    //Rotate the vertices in the inverse direction of the gradients vector angle
    shapeVertsCopy = (Vertex[]) Vertex.rotateZVectorArray(shapeVertsCopy, testShape.getCenterPointLocal(), invAngle);
   
    Vertex vP1 = new Vertex((float)p1.getX(), (float)p1.getY(), 0);
    Vertex vP2 = new Vertex((float)p2.getX(), (float)p2.getY(), 0);
    float gradientRectWidth = vP2.getSubtracted(vP1).length();
   
    Vertex[] gradientRectVerts = new Vertex[]{
        vP1,
        new Vertex((float)p2.getX(), (float)p1.getY(),0),
        vP2,
        new Vertex((float)p1.getX(), (float)p2.getY(),0)
        };
    //Rotate the vertices in the inverse direction of the gradients vector angle
    gradientRectVerts = (Vertex[]) Vertex.rotateZVectorArray(gradientRectVerts, testShape.getCenterPointLocal(), invAngle);
   
    //Copy the rotated bounding shape vertices and the rotated gradient rectangle vertices into one array
    Vertex[] shapeAndGradVerts = new Vertex[shapeVertsCopy.length + gradientRectVerts.length];
    System.arraycopy(shapeVertsCopy, 0, shapeAndGradVerts, 0, shapeVertsCopy.length);
    System.arraycopy(gradientRectVerts, 0, shapeAndGradVerts, shapeVertsCopy.length, gradientRectVerts.length);
   
    //Create a temporary polygon with the roated vertices to calc BBox
    MTPolygon inverseRotatedShape = new MTPolygon(shapeAndGradVerts, pa);
    //Calculate a bounding rectangle from the rotated shape
    BoundsZPlaneRectangle inverseRotatedBounds = new BoundsZPlaneRectangle(inverseRotatedShape);
    Vector3D[] invBoundsVecs = inverseRotatedBounds.getVectorsLocal();
   
    //logger.debug("Gradient Rectangle width: " + gradientRectWidth);
   
    //Get the positions where the offsets are on the gradient vector
//    float bBoxWidth  = invBoundsVecs[1].x - invBoundsVecs[0].x;
//    logger.debug("BBox width: " + bBoxWidth);
//    float w = bBoxWidth/*/100*/;
    List<Float> xStops = new ArrayList<Float>();
   
    //- Go through stops
    //- multiply stop offsets with bbox width to get the position on gradient vector
    //logger.debug("->Gradient Vector stop positions:");
    for(Stop stop : stops){
      float offsetStopPosition = gradientRectWidth * stop.offset; //position auf gradient vector, stop(0) = vP1.x + offest
      xStops.add(offsetStopPosition);
      //logger.debug(" Offset-Stop-Position: " + offsetStopPosition);
    }
   
    //Calc new gradient polygon vertices with vertices at the stop locations
    Vertex[] newBounds = new Vertex[(xStops.size()-1) * 4];
    for (int i = 0; i < xStops.size()-1; i++) {
      float offset = xStops.get(i);
      Color stopColor = stops.get(i).color;
     
      float nextOffset = xStops.get(i+1);
      Color nextStopColor = stops.get(i+1).color;
     
      newBounds[i*4]     = new Vertex(vP1.x + offset,     invBoundsVecs[0].y,0,   stopColor.getRed(), stopColor.getGreen(), stopColor.getBlue(), stopColor.getAlpha());
      newBounds[i*4+1= new Vertex(vP1.x + nextOffset, invBoundsVecs[0].y,0,   nextStopColor.getRed(), nextStopColor.getGreen(), nextStopColor.getBlue(), nextStopColor.getAlpha());
      newBounds[i*4+2]   = new Vertex(vP1.x + nextOffset, invBoundsVecs[2].y,0,   nextStopColor.getRed(), nextStopColor.getGreen(), nextStopColor.getBlue(), nextStopColor.getAlpha());
      newBounds[i*4+3= new Vertex(vP1.x + offset,    invBoundsVecs[2].y,0,   stopColor.getRed(), stopColor.getGreen(), stopColor.getBlue(), stopColor.getAlpha());
    }
   
    //Put gradient rectangle quads into a list
    List<Vertex> gradientRectQuads = new ArrayList<Vertex>();
    for (int i = 0; i < newBounds.length; i++) {
      Vertex vertex = newBounds[i];
      gradientRectQuads.add(vertex);
    }
   
    /* Bounding shape with gradient rectangle inside (can also overlap outlines)
     invBoundsVecs[0]       invBoundsVecs[1]
            | _______________ |
           |   |_____|    |
           |   |  G  |     |
           | vp1|____>|vp2 |
           |____|_____|____|
     */
    //Calc rectangle bands (quads) to fill the gradient shape with the gradVect end colors if the gradient vector is smaller than the shape to draw
    List<Vertex> leftQuad = new ArrayList<Vertex>();
    if (vP1.x > invBoundsVecs[0].x){
      //upper left of bounding rect
      Vertex v1 = new Vertex(invBoundsVecs[0].x, invBoundsVecs[0].y, 0, newBounds[0].getR(), newBounds[0].getG(), newBounds[0].getB(), newBounds[0].getA());
      //first stop on gradient vector upper
      Vertex v2 = new Vertex(newBounds[0].x, newBounds[0].y, 0, newBounds[0].getR(), newBounds[0].getG(), newBounds[0].getB(), newBounds[0].getA());
      //first stop on gradient vector lower
      Vertex v3 = new Vertex(newBounds[3].x, newBounds[3].y, 0, newBounds[3].getR(), newBounds[3].getG(), newBounds[3].getB(), newBounds[3].getA());
      //down left of bounding rect
      Vertex v4 = new Vertex(invBoundsVecs[3].x, invBoundsVecs[3].y, 0, newBounds[0].getR(), newBounds[0].getG(), newBounds[0].getB(), newBounds[0].getA());
     
      leftQuad.add(v1);
      leftQuad.add(v2);
      leftQuad.add(v3);
      leftQuad.add(v4);
    }
   
    //Add Right quad if gradient rectangle is smaler than overall bounds
    List<Vertex> rightQuad = new ArrayList<Vertex>();
    if (vP2.x < invBoundsVecs[1].x){
      Vertex gradientRectUpperRight = newBounds[newBounds.length-3];
      Vertex gradientRectLowerRight = newBounds[newBounds.length-2];
     
      Vertex v1 = new Vertex(gradientRectUpperRight.x, gradientRectUpperRight.y, 0, gradientRectUpperRight.getR(), gradientRectUpperRight.getG(), gradientRectUpperRight.getB(), gradientRectUpperRight.getA());
      Vertex v2 = new Vertex(invBoundsVecs[1].x, invBoundsVecs[1].y, 0, gradientRectUpperRight.getR(), gradientRectUpperRight.getG(), gradientRectUpperRight.getB(), gradientRectUpperRight.getA());
      Vertex v3 = new Vertex(invBoundsVecs[2].x, invBoundsVecs[2].y, 0, gradientRectUpperRight.getR(), gradientRectUpperRight.getG(), gradientRectUpperRight.getB(), gradientRectUpperRight.getA());
      Vertex v4 = new Vertex(gradientRectLowerRight.x, gradientRectLowerRight.y, 0, gradientRectUpperRight.getR(), gradientRectUpperRight.getG(), gradientRectUpperRight.getB(), gradientRectUpperRight.getA());
     
      rightQuad.add(v1);
      rightQuad.add(v2);
      rightQuad.add(v3);
      rightQuad.add(v4);
View Full Code Here

      for (int i = 0; i < xStops.size()-1; i++) {
        float offset = xStops.get(i);
        Color stopColor = stops.get(i).color;
        float nextOffset = xStops.get(i+1);
        Color nextStopColor = stops.get(i+1).color;
        newBounds[i*4]     = new Vertex(invBoundsVecs[0].x + offset,     invBoundsVecs[0].y,0,   stopColor.getRed(), stopColor.getGreen(), stopColor.getBlue(), stopColor.getAlpha());
        newBounds[i*4+1= new Vertex(invBoundsVecs[0].x + nextOffset, invBoundsVecs[0].y,0,   nextStopColor.getRed(), nextStopColor.getGreen(), nextStopColor.getBlue(), nextStopColor.getAlpha());
        newBounds[i*4+2]   = new Vertex(invBoundsVecs[0].x + nextOffset, invBoundsVecs[2].y,0,   nextStopColor.getRed(), nextStopColor.getGreen(), nextStopColor.getBlue(), nextStopColor.getAlpha());
        newBounds[i*4+3= new Vertex(invBoundsVecs[0].x + offset,     invBoundsVecs[2].y,0,   stopColor.getRed(), stopColor.getGreen(), stopColor.getBlue(), stopColor.getAlpha());
      }
     
      /*
      logger.debug("->New bounds:");
      for (int i = 0; i < newBounds.length; i++) {
View Full Code Here

    //Create Vertex array from points
      SVGPointList pointList = polyElem.getPoints();
      Vertex[] vertices = new Vertex[pointList.getNumberOfItems()];
      for (int i = 0; i < pointList.getNumberOfItems(); i++) {
      SVGPoint p = pointList.getItem(i);
      vertices[i] = new Vertex(p.getX(), p.getY(),0);
      }
     
      //If polygon isnt closed, close it with the first vertex
      if (!vertices[0].equalsVector(vertices[vertices.length-1])){
        Vertex[] closedVertices = new Vertex[vertices.length+1];
View Full Code Here

    PhysicsHelper.addDragJoint(world, physRect, physRect.getBody().isDynamic(), scale);
    physicsContainer.addChild(physRect);
   
    //Create polygon
    Vertex[] polyVertices = new Vertex[]{
        new Vertex(-10,0,0),
        new Vertex(10,0,0),
        new Vertex(10,50,0),
        new Vertex(60,50,0),
        new Vertex(60,70,0),
        new Vertex(10,70,0),
       
        new Vertex(10,120,0),
        new Vertex(-10,120,0),
        new Vertex(-10,70,0),
        new Vertex(-60,70,0),
        new Vertex(-60,50,0),
        new Vertex(-10,50,0),
        new Vertex(-10,0,0),
    };
    PhysicsPolygon physPoly = new PhysicsPolygon(polyVertices, new Vector3D(250,250), app, world, 1.0f, 0.3f, 0.4f, scale);
    MTColor polyCol = new MTColor(ToolsMath.getRandom(60, 255),ToolsMath.getRandom(60, 255),ToolsMath.getRandom(60, 255));
    physPoly.setFillColor(polyCol);
    physPoly.setStrokeColor(polyCol);
View Full Code Here

TOP

Related Classes of org.mt4j.util.math.Vertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.