Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. public class Pair {
  2. public double u, v;
  3.  
  4. public Pair(double u, double v) {
  5. this.u = u;
  6. this.v = v;
  7. }
  8. }
  9.  
  10. public class Vertex extends Point3 {
  11. public Vector3 vn = null;
  12. public Pair vt = null;
  13.  
  14. public Vertex(double x, double y, double z) {
  15. super(x, y, z);
  16. }
  17. }
  18.  
  19. public class Face {
  20. public Vertex p0;
  21. public Vertex p1;
  22. public Vertex p2;
  23.  
  24. public Face(Vertex p0, Vertex p1, Vertex p2) {
  25. this.p0 = p0;
  26. this.p1 = p1;
  27. this.p2 = p2;
  28. }
  29. }
  30.  
  31. public class Triangle implements Object {
  32. public Face face; //public for debugging
  33. private final double epsilon = 0.00001;
  34. private Vector3 normal;
  35. private boolean smoothShaded = false;
  36.  
  37. public Material material;
  38.  
  39. // constructor with smooth shaded boolean for defining a normal
  40. public Triangle(Vertex v1, Vertex v2, Vertex v3, boolean smoothShaded) {
  41. face = new Face(v1, v2, v3);
  42. this.smoothShaded = smoothShaded;
  43. }
  44.  
  45. ..........................
  46.  
  47. //in format: v/vt/vn
  48. String[] aEls = a.split("/");
  49. String[] bEls = b.split("/");
  50. String[] cEls = c.split("/");
  51. Vertex v1 = vertexList.get(Integer.parseInt(aEls[0]) - 1);
  52. Vertex v2 = vertexList.get(Integer.parseInt(bEls[0]) - 1);
  53. Vertex v3 = vertexList.get(Integer.parseInt(cEls[0]) - 1);
  54. v1.vt = vtList.get(Integer.parseInt(aEls[1]) - 1);
  55. v2.vt = vtList.get(Integer.parseInt(bEls[1]) - 1);
  56. v3.vt = vtList.get(Integer.parseInt(cEls[1]) - 1);
  57. v1.vn = normals.get(Integer.parseInt(aEls[2]) - 1);
  58. v2.vn = normals.get(Integer.parseInt(bEls[2]) - 1);
  59. v3.vn = normals.get(Integer.parseInt(cEls[2]) - 1);
  60. Triangle t = new Triangle(v1, v2, v3, true);
  61. t.material = currentMtl;
  62. if (currentTexture != null) {
  63. t.material.texture = currentTexture;
  64. }
  65. System.out.println("unlisted!");
  66. System.out.println("vt 0 a: " + t.face.p0.vt.u + ", vt b: " + t.face.p0.vt.v);
  67. System.out.println("vt 1 a: " + t.face.p1.vt.u + ", vt b: " + t.face.p1.vt.v);
  68. System.out.println("vt 2 a: " + t.face.p2.vt.u + ", vt b: " + t.face.p2.vt.v);
  69. addTriangle(t);
  70. System.out.println("Current triangles: ");
  71. for (Triangle tr : triangleList) {
  72. System.out.println("vt 0 a: " + tr.face.p0.vt.u + ", vt b: " + tr.face.p0.vt.v);
  73. System.out.println("vt 1 a: " + tr.face.p1.vt.u + ", vt b: " + tr.face.p1.vt.v);
  74. System.out.println("vt 2 a: " + tr.face.p2.vt.u + ", vt b: " + tr.face.p2.vt.v);
  75. }
  76.  
  77. private void addTriangle(Triangle t){
  78. if(triangleList != null){
  79. int newSize = triangleList.length + 1;
  80. Triangle[] temp = new Triangle[newSize];
  81. for(int i = 0; i < triangleList.length;i++){
  82. temp[i] = triangleList[i];
  83. }
  84. temp[newSize-1] = t;
  85. triangleList = temp;
  86. }else{
  87. triangleList = new Triangle[]{t};
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement