Class Triangle

java.lang.Object
com.ijurnove.cpu3d.Triangle
All Implemented Interfaces:
Rotatable, Scalable, Translatable, Comparable<Triangle>

public class Triangle extends Object implements Comparable<Triangle>, Translatable, Rotatable, Scalable
A Triangle holds three Point3ds, three point normals, three UV coordinates, and one surface normal. Point normals define the direction each vertex is facing. The surface normal defines the direction the entire Triangle is facing. UV coordinates define the texture coordinates at each vertex.

Texture and Material data is taken from the parent Shape3d.

  • Constructor Details

    • Triangle

      public Triangle(Point3d v1, Point3d v2, Point3d v3, Vector3d pn1, Vector3d pn2, Vector3d pn3)
      Constructs a new Triangle with the given vertices and point normals.
      Parameters:
      v1 - the first vertex
      v2 - the second vertex
      v3 - the third vertex
      pn1 - the first point normal
      pn2 - the second point normal
      pn3 - the third point normal
    • Triangle

      protected Triangle(Point3d v1, Point3d v2, Point3d v3)
    • Triangle

      protected Triangle(Point3d[] vertices)
  • Method Details

    • setParent

      protected void setParent(Shape3d parent)
    • getParent

      public Shape3d getParent()
      Returns the parent Shape3d of this Triangle.
      Returns:
      the parent Shape3d of this Triangle
    • copy

      public Triangle copy()
      Returns a copy of this Triangle.
      Returns:
      an identical Triangle
    • maybeCalculatePointNormals

      protected void maybeCalculatePointNormals()
    • getPointNormals

      public Vector3d[] getPointNormals()
      Returns the direction the Triangle is facing at each vertex.
      Returns:
      the point normals
    • getVertices

      public Point3d[] getVertices()
      Returns the vertices.
      Returns:
      the vertices
    • getTextureCoords

      public UV[] getTextureCoords()
      Returns the UV coordinates at each vertex.
      Returns:
      the UV coordinates of each vertex
    • vrtx1

      public Point3d vrtx1()
      Returns the first vertex.
      Returns:
      the first vertex
    • vrtx2

      public Point3d vrtx2()
      Returns the second vertex.
      Returns:
      the second vertex
    • vrtx3

      public Point3d vrtx3()
      Returns the third vertex.
      Returns:
      the third vertex
    • getTexture

      public BufferedImage getTexture()
      Returns the parent Shape3d's texture.
      Returns:
      the texture of the parent Shape3d
    • getMaterial

      public Material getMaterial()
      Returns the parent Shape3d's Material.
      Returns:
      the Material of the parent Shape3d
    • getCenter

      public Point3d getCenter()
      Returns the center of this Triangle.
      Returns:
      the center
    • getSurfNorm

      public Vector3d getSurfNorm()
      Returns the direction the Triangle is facing.
      Returns:
      the direction the Triangle is facing
    • isShown

      protected boolean isShown()
    • setShown

      protected void setShown(boolean shown)
    • flip

      protected void flip()
    • point3dFromBary

      protected Point3d point3dFromBary(double[] weights)
    • markForPointNormalCalculation

      protected void markForPointNormalCalculation()
    • setPointNormals

      public void setPointNormals(Vector3d v1Norm, Vector3d v2Norm, Vector3d v3Norm)
      Sets the point normals at each vertex.
      Parameters:
      v1Norm - the first point normal to set
      v2Norm - the second point normal to set
      v3Norm - the third point normal to set
    • setTextureCoords

      public void setTextureCoords(UV v1coords, UV v2coords, UV v3coords)
      Sets the UV coordinates at each vertex.
      Parameters:
      v1coords - the first UV to set
      v2coords - the second UV to set
      v3coords - the third UV to set
    • updateValues

      protected void updateValues()
    • isFacingViewer

      protected boolean isFacingViewer()
    • shiftOnX

      protected void shiftOnX(double distance)
    • shiftOnY

      protected void shiftOnY(double distance)
    • shiftOnZ

      protected void shiftOnZ(double distance)
    • translate

      public void translate(double x, double y, double z)
      Description copied from interface: Translatable
      Shifts this object's X, Y, and Z position by the given values.
      Specified by:
      translate in interface Translatable
      Parameters:
      x - how far the object should be translated along the X axis
      y - how far the object should be translated along the Y axis
      z - how far the object should be translated along the Z axis
    • compareTo

      public int compareTo(Triangle o)
      Specified by:
      compareTo in interface Comparable<Triangle>
    • updateBaryCache

      protected void updateBaryCache()
    • barycentricCoords

      protected double[] barycentricCoords(double pX, double pY)
    • overlapsWithRect

      protected boolean overlapsWithRect(int minX, int minY, int maxX, int maxY)
    • perspProjectionForPointShadowMap

      protected void perspProjectionForPointShadowMap(Camera c)
    • perspProjection

      protected void perspProjection(Camera c)
    • orthoProjection

      protected void orthoProjection(Camera c)
    • rotate

      public void rotate(int axis, double theta, Point3d point)
      Description copied from interface: Rotatable
      Rotates this object about a given point on a specified axis. 0 corresponds to the X axis, 1 corresponds to the Y axis, and 2 corresponds to the Z axis.
      Specified by:
      rotate in interface Rotatable
      Parameters:
      axis - the axis to rotate around
      theta - the radians to rotate by
      point - the center point to rotate around
    • scale

      public void scale(double size, Point3d point)
      Description copied from interface: Scalable
      Scales this object by a given amount from a point.
      Specified by:
      scale in interface Scalable
      Parameters:
      size - the scale multiplier
      point - the point that this object should be scaled from