public aVertex cross(aVertex operand) { aVertex toReturn = new aVertex(); toReturn.set(y * operand.z - z * operand.y, z * operand.x - x * operand.z, x * operand.y - y * operand.x); return(toReturn); }
public static aVertex operator +(aVertex o1, aVertex o2) { aVertex toReturn = new aVertex(); toReturn.set(o1.x + o2.x, o1.y + o2.y, o1.z + o2.z); return(toReturn); }
public static aVertex operator *(aVertex o1, float o2) { aVertex toReturn = new aVertex(); toReturn.set(o1.x * o2, o1.y * o2, o1.z * o2); return(toReturn); }
public aVertex norm() { aVertex toReturn = new aVertex(); float mag = this.mag(); toReturn.set(x / mag, y / mag, z / mag); return(toReturn); }
public bool loadSphere(float size, int numFaces) { // Loads vertices defining sphere with radius size and the given number of faces clear(); int nPhi = (int)(Math.Sqrt(numFaces / 2.0f)); int nTht = nPhi * 2; float phi0, tht0, phi1, tht1; _numVertices = 6 * nPhi * nTht; // Create triangles by rotating about sphere for (int i = 0; i < nPhi; i++) { // Construct vertices for each latitude for (int j = 0; j < nTht; j++) { // Redeclare to avoid reference crossover aVertex vert0 = new aVertex(); aVertex vert1 = new aVertex(); aVertex vert2 = new aVertex(); aVertex vert3 = new aVertex(); // Construct vertices for each longitude, beginning with spherical coordinates phi0 = (((float)i) / ((float)nPhi)) * (float)Math.PI; phi1 = (((float)(i + 1)) / ((float)nPhi)) * (float)Math.PI; tht0 = (((float)j) / ((float)nTht)) * 2 * (float)Math.PI; tht1 = (((float)(j + 1)) / ((float)nTht)) * 2 * (float)Math.PI; // Create vertices in cartesian from spherical coordinates vert0.set(size * (float)Math.Sin(phi0) * (float)Math.Cos(tht0), size * (float)Math.Cos(phi0), -1 * size * (float)Math.Sin(phi0) * (float)Math.Sin(tht0)); vert1.set(size * (float)Math.Sin(phi1) * (float)Math.Cos(tht0), size * (float)Math.Cos(phi1), -1 * size * (float)Math.Sin(phi1) * (float)Math.Sin(tht0)); vert2.set(size * (float)Math.Sin(phi1) * (float)Math.Cos(tht1), size * (float)Math.Cos(phi1), -1 * size * (float)Math.Sin(phi1) * (float)Math.Sin(tht1)); vert3.set(size * (float)Math.Sin(phi0) * (float)Math.Cos(tht1), size * (float)Math.Cos(phi0), -1 * size * (float)Math.Sin(phi0) * (float)Math.Sin(tht1)); // Specify triangles _vertices.Add(vert0); _vertices.Add(vert2); _vertices.Add(vert1); _vertices.Add(vert0); _vertices.Add(vert3); _vertices.Add(vert2); _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi0 / Math.PI))); _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi1 / Math.PI))); _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi1 / Math.PI))); _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi0 / Math.PI))); _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi0 / Math.PI))); _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi1 / Math.PI))); } } refreshNormals(); return(true); }