From 32117d0bf27e0a72165707fe4e56d231136e734b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 16 Jan 2010 17:50:43 +0100 Subject: Use index buffers to render tiles --- src/de/gamezock/metacraft/data/Triangle.java | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/de/gamezock/metacraft/data/Triangle.java') diff --git a/src/de/gamezock/metacraft/data/Triangle.java b/src/de/gamezock/metacraft/data/Triangle.java index bcfce9d..2049c6f 100644 --- a/src/de/gamezock/metacraft/data/Triangle.java +++ b/src/de/gamezock/metacraft/data/Triangle.java @@ -3,9 +3,10 @@ package de.gamezock.metacraft.data; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; -public class Triangle { +public class Triangle implements Cloneable { private Point3f[] vertices; private Vector3f[] normals; + private Vector3f normal; public Triangle(Point3f v1, Point3f v2, Point3f v3) { @@ -15,16 +16,15 @@ public class Triangle { vertices[1] = v2; vertices[2] = v3; - normals = new Vector3f[3]; - Vector3f edge1 = new Vector3f(), edge2 = new Vector3f(); edge1.sub(v1, v2); edge2.sub(v3, v2); - Vector3f normal = new Vector3f(); + normal = new Vector3f(); normal.cross(edge1, edge2); normal.normalize(); + normals = new Vector3f[3]; normals[0] = new Vector3f(normal); normals[1] = new Vector3f(normal); normals[2] = new Vector3f(normal); @@ -34,7 +34,27 @@ public class Triangle { return vertices[i]; } - public Vector3f getNormal(int i) { + public Vector3f getVertexNormal(int i) { return normals[i]; } + + public Vector3f getNormal() { + return normal; + } + + public void translate(Vector3f v) { + for(Point3f p : vertices) { + p.add(v); + } + } + + public Object clone() { + Triangle t = new Triangle((Point3f)vertices[0].clone(), (Point3f)vertices[1].clone(), (Point3f)vertices[2].clone()); + + for(int i = 0; i < 3; ++i) { + t.normals[i] = (Vector3f)normals[i].clone(); + } + + return t; + } } -- cgit v1.2.3