public Triangle() : base() { //Right Angle Triangle /| Vertice bottomLeft = new Vertice(); Vertice bottomRight = new Vertice(); Vertice topRight = new Vertice(); bottomLeft.set(-0.5f, -0.5f, 0); bottomRight.set(0.5f, -0.5f, 0); topRight.set(0.5f, 0.5f, 0); this.v0 = bottomLeft; this.v1 = bottomRight; this.v2 = topRight; TextureCoordinate bottomLeftT = new TextureCoordinate(); TextureCoordinate bottomRightT = new TextureCoordinate(); TextureCoordinate topRightT = new TextureCoordinate(); bottomLeftT.set(0.0f, 0.0f); bottomRightT.set(1.0f, 0.0f); topRightT.set(1.0f, 1.0f); this.t0 = bottomLeftT; this.t1 = bottomRightT; this.t2 = topRightT; this.reset(); }
private Triangle(Triangle aThis) : base(aThis) { this.v0 = aThis.v0.clone(); this.v1 = aThis.v1.clone(); this.v2 = aThis.v2.clone(); this.t0 = aThis.t0.clone(); this.t1 = aThis.t1.clone(); this.t2 = aThis.t2.clone(); this.reset(); }
public void generateVBO() { lock (model) { List <Vertice> verts = model.getAllVertices(); List <TextureCoordinate> tcors = model.getAllTextureCoordinates(); this.vSize = verts.Count; this.tSize = tcors.Count; if (this.vSize < 1) { return; } float[] vertices = new float[this.vSize * 3]; for (int i = 0; i < this.vSize; i++) { Vertice v = verts[i]; int j = i * 3; vertices[j + 0] = (float)v.getX(); vertices[j + 1] = (float)v.getY(); vertices[j + 2] = (float)v.getZ(); } float[] coords = new float[this.tSize * 2]; for (int i = 0; i < this.tSize; i++) { TextureCoordinate t = tcors[i]; int j = i * 2; coords[j + 0] = (float)t.getX(); coords[j + 1] = (float)t.getY(); } this.vb = new VertexBuffer(this.vSize, VertexFormat.Float3, VertexFormat.Float2); lock (this.vb) { this.vb.SetVertices(0, vertices); if (this.vSize == this.tSize) { this.vb.SetVertices(1, coords); } } } }
public TextureCoordinate(TextureCoordinate tc) : this(tc.x, tc.y) { }
public override List <Model> loadModels(string data) { String[] lines = removeBlankElements(data.Replace("\r", "\n").Split('\n')); List <Model> models = new List <Model>(); Model m = null; Model g = null; List <Material> materials = new List <Material>(); List <Vertice> loadedVertices = new List <Vertice>(); List <TextureCoordinate> loadedTextureCoords = new List <TextureCoordinate>(); List <Material> loadedMaterials = new List <Material>(); for (int i = 0; i < lines.Length; i++) { String line = lines[i]; BAD_ID = i; if (line.StartsWith("ml")) { line = getLine(line, "ml"); if (m == null) { continue; } Location location = Location.ValueOf(line); m.getLocation().set(location); continue; } if (line.StartsWith("o")) { line = getLine(line, "o"); m = new Model(); m.setName(line); models.Add(m); g = null; continue; } if (line.StartsWith("usemtl")) { line = getLine(line, "usemtl"); Material guess = null; foreach (Material mat in materials) { if (mat.getName() != null && mat.getName().Equals(line)) { guess = mat; break; } } if (guess == null) { guess = new Material(); guess.setName(line); materials.Add(guess); } m.setMaterial(guess); } if (line.StartsWith("s")) { line = getLine(line, "s"); if (g == null) { g = new Model(); models.Add(g); } Material mat = g.getMaterial(); m = new Model(); m.setMaterial(mat); g.addChild(m); continue; } if (line.StartsWith("g")) { line = getLine(line, "g"); g = new Model(); models.Add(g); m = g; continue; } if (line.StartsWith("mtllib")) { continue; } if (line.StartsWith("usemtl")) { continue; } if (line.StartsWith("vt")) { line = getLine(line, "vt"); String[] coords = removeBlankElements(line.Split(' ')); TextureCoordinate tc = new TextureCoordinate(Convert.ToDouble(coords[0]), Convert.ToDouble(coords[1])); loadedTextureCoords.Add(tc); continue; } if (line.StartsWith("vn")) { continue; } if (line.StartsWith("v")) { line = getLine(line, "v"); String[] coordinates = removeBlankElements(line.Split(' ')); Vertice v = new Vertice(); v.set(Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[2])); loadedVertices.Add(v); continue; } if (line.StartsWith("f")) { line = getLine(line, "f"); String[] vertIndexs = removeBlankElements(line.Split(' ')); if (m == null) { m = new Model(); models.Add(m); } List <Vertice> selectedVertices = new List <Vertice>(); List <TextureCoordinate> selectedTextureCoordinates = new List <TextureCoordinate>(); for (int index = 0; index < vertIndexs.Length; index++) { String indexLine = vertIndexs[index]; Vertice selectedVertice = null; TextureCoordinate selectedTextureCoordinate = null; if (indexLine.Contains("//")) { //Form of v1//vn1 String[] parts = indexLine.Split(new String[] { "//" }, StringSplitOptions.RemoveEmptyEntries); selectedVertice = loadedVertices[Convert.ToInt32(parts[0]) - 1]; } else if (indexLine.Contains("/")) { String[] requesting = indexLine.Split('/'); if (requesting.Length == 2) { //Form of v1/vt1 selectedVertice = loadedVertices[Convert.ToInt32(requesting[0]) - 1]; selectedTextureCoordinate = loadedTextureCoords[Convert.ToInt32(requesting[1]) - 1]; } else if (requesting.Length == 3) { //Form of v1/vt1/vn1 selectedVertice = loadedVertices[Convert.ToInt32(requesting[0]) - 1]; selectedTextureCoordinate = loadedTextureCoords[Convert.ToInt32(requesting[1]) - 1]; } } else { //PURE VERTICE GETTING selectedVertice = loadedVertices[Convert.ToInt32(indexLine) - 1]; } //Now to add these things to the face if (selectedVertice != null) { selectedVertices.Add(selectedVertice); } if (selectedTextureCoordinate != null) { selectedTextureCoordinates.Add(selectedTextureCoordinate); } } //Create a Face if (selectedVertices.Count == 3) { //This is a triangle (yay) Face f = new Face(); for (int index = 0; index < selectedVertices.Count; index++) { try { f.addVertice(selectedVertices[index]); }catch (Exception t) {} try { f.addTextureCoordinate(selectedTextureCoordinates[index]); }catch (Exception t) {} } m.addFace(f); } else if (selectedVertices.Count == 4) { //Convert to Triangle and add Quad quad = new Quad(); quad.setVert0(selectedVertices[0]); quad.setVert1(selectedVertices[1]); quad.setVert2(selectedVertices[2]); quad.setVert3(selectedVertices[3]); try { quad.setTextureCoordinate0(selectedTextureCoordinates[0]); }catch (Exception t) {} try { quad.setTextureCoordinate1(selectedTextureCoordinates[1]); }catch (Exception t) {} try { quad.setTextureCoordinate2(selectedTextureCoordinates[2]); }catch (Exception t) {} try { quad.setTextureCoordinate3(selectedTextureCoordinates[3]); }catch (Exception t) {} m.addFaces(quad.toQuadArray()); } else { //Something that isn't a quad or a triangle? } } } //Logging Game.GAME_INSTANCE.getLogger().log("Model loaded."); return(models); }
public void updateFace() { Vertice topLeft = new Vertice(0, 0, 0); Vertice topRight = new Vertice(this.width, 0, 0); Vertice bottomLeft = new Vertice(0, this.height, 0); Vertice bottomRight = new Vertice(this.width, this.height, 0); int lx = 0; int ly = 0; int mx = 1; int my = 1; if (this.xf) { lx = 1; mx = 0; } if (this.yf) { ly = 1; my = 0; } TextureCoordinate topLeftTC = new TextureCoordinate(lx, ly); TextureCoordinate topRightTC = new TextureCoordinate(mx, ly); TextureCoordinate bottomLeftTC = new TextureCoordinate(lx, my); TextureCoordinate bottomRightTC = new TextureCoordinate(mx, my); Face topLeftFace = new Face(); topLeftFace.addVertice(bottomLeft); topLeftFace.addVertice(topRight); topLeftFace.addVertice(topLeft); topLeftFace.addTextureCoordinate(bottomLeftTC); topLeftFace.addTextureCoordinate(topRightTC); topLeftFace.addTextureCoordinate(topLeftTC); Face topRightFace = new Face(); topRightFace.addVertice(bottomRight); topRightFace.addVertice(topRight); topRightFace.addVertice(bottomLeft); topLeftFace.addTextureCoordinate(bottomRightTC); topLeftFace.addTextureCoordinate(topRightTC); topLeftFace.addTextureCoordinate(bottomLeftTC); foreach (Face f in this.getFaces()) { this.removeFace(f); } addFace(topLeftFace); addFace(topRightFace); if (Thread.CurrentThread != Game.GAME_INSTANCE.getMainThread()) { if (this.getVBO() != null) { lock (this.getVBO()) { this.getVBO().Dispose(); } } this.setVBO(null); this.addToVBOList(); while (!this.isOnVBO()) { continue; } } else { if (this.getVBO() != null) { this.getVBO().Dispose(); } this.newVBO(); } }
public void removeTextureCoordinate(TextureCoordinate tc) { this.textureCoordinates.Remove(tc); }
public void addTextureCoordinate(TextureCoordinate tc) { lock (this.textureCoordinates) { this.textureCoordinates.Add(tc); } }
public void setTextureCoordinate3(TextureCoordinate tc) { topRight.setTextureCoordinate2(tc); }
public void setTextureCoordinate2(TextureCoordinate tc) { bottomLeft.setTextureCoordinate2(tc); topRight.setTextureCoordinate1(tc); }
public void setTextureCoordinate1(TextureCoordinate tc) { bottomLeft.setTextureCoordinate1(tc); }
public void setTextureCoordinate2(TextureCoordinate v) { this.t2 = v; this.reset(); }