Ejemplo n.º 1
0
  /*
   *  Reorders a vertex list organized as a QUAD_STRIP duplets of vertices, so that it forms an outline path instead. The logic is as follows:
   *  <pre>
   *  int u=n/2;
   *  UVertexList tmp=new UVertexList();
   *
   *  for(int i=u-1; i>-1; i--) tmp.add(v[i*2]);
   *  for(int i=0; i<u; i++) tmp.add(v[i*2+1]);
   *  v=tmp.v;
   *  n=tmp.n;
   *  </pre>
   */
  public UVertexList QStoOutline() {
    int u = n / 2;
    UVertexList tmp = new UVertexList();

    for (int i = u - 1; i > -1; i--) tmp.add(v[i * 2]);
    for (int i = 0; i < u; i++) tmp.add(v[i * 2 + 1]);

    v = tmp.v;
    n = tmp.n;

    return this;
  }
Ejemplo n.º 2
0
  /**
   * Convenience method to calculate <code>res</code> vertices along a circle of <code>R</code>
   * radius
   *
   * @param R Radius of circle
   * @param res Number of points to calculate
   * @return
   */
  public static UVertexList getCircle(float R, int res) {
    UVertexList vl = new UVertexList();
    float D = TWO_PI / (float) (res - 1);
    for (int i = 0; i < res; i++)
      vl.add(PApplet.cos(D * (float) i) * R, PApplet.sin(D * (float) i) * R, 0);

    return vl;
  }
Ejemplo n.º 3
0
 /**
  * Adds quad of vertices (order: bottom left, bottom right, top right, top left). if q.length%2==0
  * the array data treated as 2D XY duplets.
  *
  * @param vv Array of XY duplets or XYZ triplets.
  * @return Returns reference to self
  */
 public UVertexList addQuad(float[] q) {
   int id = 0;
   if (q.length == 8) {
     add(q[id++], q[id++]);
     add(q[id++], q[id++]);
     add(q[id++], q[id++]);
     add(q[id++], q[id++]);
     add(q[0], q[1]);
   } else if (q.length == 12) {
     add(q[id++], q[id++], q[id++]);
     add(q[id++], q[id++], q[id++]);
     add(q[id++], q[id++], q[id++]);
     add(q[id++], q[id++], q[id++]);
     add(q[0], q[1], q[2]);
   }
   return this;
 }
Ejemplo n.º 4
0
  /**
   * Adds array of floats as vertices, treating values as XYZ triplets or XY duplets depending on
   * whether vv.length%2==0 or vv.length%3==0.
   *
   * @param vv Array of XY duplets or XYZ triplets.
   * @return Returns reference to self
   */
  public UVertexList add(float[] vv) {
    int id = 0, vn = vv.length;

    if (vn == 2) add(vv[0], vv[1]);
    else if (vn == 3) add(vv[0], vv[1], vv[2]);
    else {
      if (vn % 2 == 0) {
        for (int i = 0; i < vn / 2; i++) add(vv[id++], vv[id++]);
      } else if (vn % 3 == 0) {
        for (int i = 0; i < vn / 1; i++) add(vv[id++], vv[id++], vv[id++]);
      } else {
        Util.logErr(
            "VertexList.add(float[]): Unsure what to do with an array of " + vn + " positions.");
        Util.logErr("Expecting an array of length divisible by 2 or 3.");
      }
    }
    return this;
  }
Ejemplo n.º 5
0
 /** Parses a VertexList from the string produced by VertexList.toDataString(). */
 public UVertexList(String in) {
   String[] tok = PApplet.split(in, "\t");
   v = new UVec3[tok.length];
   for (int i = 0; i < tok.length; i++) add(UVec3.parse(tok[i]));
 }
Ejemplo n.º 6
0
 /**
  * Create new UVertexList by copying the UVertexList given as parameter, leaving the input
  * unchanged.
  *
  * @param _vl UVertexList to copy.
  */
 public UVertexList(UVertexList _vl) {
   n = 0;
   v = new UVec3[_vl.n];
   for (int i = 0; i < _vl.n; i++) add(_vl.v[i]);
 }
Ejemplo n.º 7
0
 /**
  * Adds all vertices from another vertex list. All vertices are copied as new UVec3 instances, so
  * changes in either vertex list will not affect the other
  *
  * @param _vl Input vertex list
  * @return Returns reference to self
  */
 public UVertexList add(UVertexList _vl) {
   for (int i = 0; i < _vl.n; i++) add(_vl.v[i]);
   return this;
 }
Ejemplo n.º 8
0
 /**
  * Adds x,y,z vertex to list
  *
  * @param x
  * @param y
  * @param z
  * @return Returns reference to self
  */
 public UVertexList add(float x, float y, float z) {
   add(new UVec3(x, y, z));
   return this;
 }
Ejemplo n.º 9
0
 /**
  * Convenience method to add X,Y vertices
  *
  * @param x
  * @param y
  * @return Returns reference to self
  */
 public UVertexList add(float x, float y) {
   add(x, y, 0);
   return this;
 }