Package ch.blackspirit.graphics

Examples of ch.blackspirit.graphics.Triangle


    GL2 gl = drawable.getGL().getGL2();
    Vector2f p;
    if(useColors) {
      Color4f c;
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
     
        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
      }
      // reset color;
      applyColor();
    } else {
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
       
        p = t.getPoint(0);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(1);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(1);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(2);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(2);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(0);
          gl.glVertex2f(p.x, p.y);
      }
    }
  }
View Full Code Here


    startPrimitive(Primitive.TRIANGLE, null);

    if(useColors) {
      Color4f c = null;
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;

        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
      }
      // reset color;
      applyColor();
    } else {
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
        p = t.getPoint(0);
            gl.glVertex2f(p.x, p.y);
        p = t.getPoint(1);
            gl.glVertex2f(p.x, p.y);
        p = t.getPoint(2);
            gl.glVertex2f(p.x, p.y);
      }
    }
  }
View Full Code Here

    TextureCoords coords = joglImage.texture.getImageTexCoords();
   
    if(useColors) {
      Color4f c;
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;

        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
   
        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
   
        }
    } else {
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
 
        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");

        p = t.getPoint(0);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
   
View Full Code Here

   * @param scale The amount of scale applied at the textures center. 1 = normal.
   */
  public static void mapTexture(Area shape, Image texture, float x, float y, float rotationAngle, float scale) {
    float rad = (float)Math.toRadians(rotationAngle);
    for(int i = 0; i < shape.getTriangles().length; i++) {
      Triangle area = shape.getTriangles()[i];
      for(int j = 0; j < 3; j++) {
        Vector2f textureCoordinate = area.getTextureCoordinate(j);
        if(textureCoordinate == null) {
          textureCoordinate = new Vector2f();
          area.setTextureCoordinate(j, textureCoordinate);
        }
       
        // Get corresponding shape coordinate
        textureCoordinate.set(area.getPoint(j));
       
        // Rotate, scale, translate results in translation first, then scaling and then rotation
        Transformations.rotate(textureCoordinate, rad);
        textureCoordinate.scale(scale);
        textureCoordinate.x += x;
View Full Code Here

    GL gl = drawable.getGL();
    Vector2f p;
    if(useColors) {
      Color4f c;
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
     
        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
          gl.glVertex2f(p.x, p.y);
      }
      // reset color;
      applyColor();
    } else {
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
       
        p = t.getPoint(0);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(1);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(1);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(2);
          gl.glVertex2f(p.x, p.y);

        p = t.getPoint(2);
          gl.glVertex2f(p.x, p.y);
 
          p = t.getPoint(0);
          gl.glVertex2f(p.x, p.y);
      }
    }
  }
View Full Code Here

    startPrimitive(Primitive.TRIANGLE, null);

    if(useColors) {
      Color4f c = null;
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;

        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
            gl.glVertex2f(p.x, p.y);
      }
      // reset color;
      applyColor();
    } else {
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
        p = t.getPoint(0);
            gl.glVertex2f(p.x, p.y);
        p = t.getPoint(1);
            gl.glVertex2f(p.x, p.y);
        p = t.getPoint(2);
            gl.glVertex2f(p.x, p.y);
      }
    }
  }
View Full Code Here

    TextureCoords coords = joglImage.texture.getImageTexCoords();
   
    if(useColors) {
      Color4f c;
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;

        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
   
        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
   
        }
    } else {
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
 
        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");

        p = t.getPoint(0);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
   
View Full Code Here

TOP

Related Classes of ch.blackspirit.graphics.Triangle

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.