|
|
@@ -25,7 +25,7 @@ namespace Polycode {
|
|
|
loadMesh(fileName);
|
|
|
vertexBuffer = NULL;
|
|
|
useVertexColors = false;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
Mesh::Mesh(int meshType) {
|
|
|
for(int i=0; i < 16; i++) {
|
|
|
@@ -49,7 +49,15 @@ namespace Polycode {
|
|
|
delete polygons[i];
|
|
|
}
|
|
|
polygons.clear();
|
|
|
- delete vertexBuffer;
|
|
|
+ if(vertexBuffer)
|
|
|
+ delete vertexBuffer;
|
|
|
+
|
|
|
+ for(int i=0; i < 16; i++) {
|
|
|
+ if(renderDataArrays[i]) {
|
|
|
+ free(renderDataArrays[i]->arrayPtr);
|
|
|
+ delete renderDataArrays[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
VertexBuffer *Mesh::getVertexBuffer() {
|
|
|
@@ -61,9 +69,9 @@ namespace Polycode {
|
|
|
meshHasVertexBuffer = true;
|
|
|
}
|
|
|
|
|
|
- float Mesh::getRadius() {
|
|
|
- float hRad = 0;
|
|
|
- float len;
|
|
|
+ Number Mesh::getRadius() {
|
|
|
+ Number hRad = 0;
|
|
|
+ Number len;
|
|
|
for(int i=0; i < vertices.size(); i++) {
|
|
|
len = vertices[i]->length();
|
|
|
if(len > hRad)
|
|
|
@@ -72,59 +80,52 @@ namespace Polycode {
|
|
|
return hRad;
|
|
|
}
|
|
|
|
|
|
- void Mesh::saveToFile(OSFILE *outFile) {
|
|
|
- unsigned int numVertices = vertices.size();
|
|
|
- OSBasics::write(&numUVs, sizeof(unsigned int), 1, outFile);
|
|
|
- OSBasics::write(&numVertices, sizeof(unsigned int), 1, outFile);
|
|
|
-
|
|
|
- Vector3_struct pos;
|
|
|
- Vector3_struct nor;
|
|
|
-
|
|
|
- for(int i=0; i < vertices.size(); i++) {
|
|
|
- pos.x = vertices[i]->x;
|
|
|
- pos.y = vertices[i]->y;
|
|
|
- pos.z = vertices[i]->z;
|
|
|
-
|
|
|
- nor.x = vertices[i]->normal->x;
|
|
|
- nor.y = vertices[i]->normal->y;
|
|
|
- nor.z = vertices[i]->normal->z;
|
|
|
+ void Mesh::saveToFile(OSFILE *outFile) {
|
|
|
+ unsigned int numFaces = polygons.size();
|
|
|
|
|
|
- OSBasics::write(&pos, sizeof(Vector3_struct), 1, outFile);
|
|
|
- OSBasics::write(&nor, sizeof(Vector3_struct), 1, outFile);
|
|
|
+ OSBasics::write(&meshType, sizeof(unsigned int), 1, outFile);
|
|
|
+ OSBasics::write(&numFaces, sizeof(unsigned int), 1, outFile);
|
|
|
+ for(int i=0; i < polygons.size(); i++) {
|
|
|
+
|
|
|
+ Vector3_struct pos;
|
|
|
+ Vector3_struct nor;
|
|
|
+ Vector4_struct col;
|
|
|
+ Vector2_struct tex;
|
|
|
|
|
|
- unsigned int hasWeights = 0;
|
|
|
- OSBasics::write(&hasWeights, sizeof(unsigned int), 1, outFile);
|
|
|
+ for(int j=0; j < polygons[i]->getVertexCount(); j++) {
|
|
|
+
|
|
|
+ pos.x = polygons[i]->getVertex(j)->x;
|
|
|
+ pos.y = polygons[i]->getVertex(j)->y;
|
|
|
+ pos.z = polygons[i]->getVertex(j)->z;
|
|
|
|
|
|
- }
|
|
|
+ nor.x = polygons[i]->getVertex(j)->normal->x;
|
|
|
+ nor.y = polygons[i]->getVertex(j)->normal->y;
|
|
|
+ nor.z = polygons[i]->getVertex(j)->normal->z;
|
|
|
|
|
|
- unsigned int numFaces = polygons.size();
|
|
|
- OSBasics::write(&numFaces, sizeof(unsigned int), 1, outFile);
|
|
|
-
|
|
|
- Face_struct poly;
|
|
|
- for(int i=0; i < polygons.size(); i++) {
|
|
|
- poly.nx = polygons[i]->getFaceNormal().x;
|
|
|
- poly.ny = polygons[i]->getFaceNormal().y;
|
|
|
- poly.nz = polygons[i]->getFaceNormal().z;
|
|
|
- poly.v1 = getVertexIndex(polygons[i]->getVertex(0));
|
|
|
- poly.v2 = getVertexIndex(polygons[i]->getVertex(1));
|
|
|
- poly.v3 = getVertexIndex(polygons[i]->getVertex(2));
|
|
|
- poly.uvs[0].x = polygons[i]->getTexCoord(0)->x;
|
|
|
- poly.uvs[0].y = polygons[i]->getTexCoord(0)->y;
|
|
|
- poly.uvs[1].x = polygons[i]->getTexCoord(1)->x;
|
|
|
- poly.uvs[1].y = polygons[i]->getTexCoord(1)->y;
|
|
|
- poly.uvs[2].x = polygons[i]->getTexCoord(2)->x;
|
|
|
- poly.uvs[2].y = polygons[i]->getTexCoord(2)->y;
|
|
|
- OSBasics::write(&poly, sizeof(Face_struct), 1, outFile);
|
|
|
- if(numUVs == 2) {
|
|
|
- Vector2_struct uv2s[3];
|
|
|
- uv2s[0].x = polygons[i]->getTexCoord2(0)->x;
|
|
|
- uv2s[0].y = polygons[i]->getTexCoord2(0)->y;
|
|
|
- uv2s[1].x = polygons[i]->getTexCoord2(1)->x;
|
|
|
- uv2s[1].y = polygons[i]->getTexCoord2(1)->y;
|
|
|
- uv2s[2].x = polygons[i]->getTexCoord2(2)->x;
|
|
|
- uv2s[2].y = polygons[i]->getTexCoord2(2)->y;
|
|
|
- OSBasics::write(uv2s, sizeof(Vector2_struct), 3, outFile);
|
|
|
+ col.x = polygons[i]->getVertex(j)->vertexColor.r;
|
|
|
+ col.y = polygons[i]->getVertex(j)->vertexColor.g;
|
|
|
+ col.z = polygons[i]->getVertex(j)->vertexColor.b;
|
|
|
+ col.w = polygons[i]->getVertex(j)->vertexColor.a;
|
|
|
+
|
|
|
+ tex.x = polygons[i]->getVertex(j)->getTexCoord()->x;
|
|
|
+ tex.y = polygons[i]->getVertex(j)->getTexCoord()->y;
|
|
|
+
|
|
|
+ OSBasics::write(&pos, sizeof(Vector3_struct), 1, outFile);
|
|
|
+ OSBasics::write(&nor, sizeof(Vector3_struct), 1, outFile);
|
|
|
+ OSBasics::write(&col, sizeof(Vector4_struct), 1, outFile);
|
|
|
+ OSBasics::write(&tex, sizeof(Vector2_struct), 1, outFile);
|
|
|
+
|
|
|
+ unsigned int numBoneWeights = polygons[i]->getVertex(j)->getNumBoneAssignments();
|
|
|
+ OSBasics::write(&numBoneWeights, sizeof(unsigned int), 1, outFile);
|
|
|
+ for(int b=0; b < numBoneWeights; b++) {
|
|
|
+ BoneAssignment *a = polygons[i]->getVertex(j)->getBoneAssignment(b);
|
|
|
+ unsigned int boneID = a->boneID;
|
|
|
+ float weight = a->weight;
|
|
|
+ OSBasics::write(&boneID, sizeof(unsigned int), 1, outFile);
|
|
|
+ OSBasics::write(&weight, sizeof(float), 1, outFile);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -137,71 +138,131 @@ namespace Polycode {
|
|
|
}
|
|
|
|
|
|
void Mesh::loadFromFile(OSFILE *inFile) {
|
|
|
- int i;
|
|
|
+
|
|
|
+ unsigned int meshType;
|
|
|
+ OSBasics::read(&meshType, sizeof(unsigned int), 1, inFile);
|
|
|
+ setMeshType(meshType);
|
|
|
|
|
|
- Vertex *newVertex;
|
|
|
- Polygon *polygon;
|
|
|
- unsigned int numVertices, numFaces, hasWeights, numWeights, numUVs;
|
|
|
+ int verticesPerFace;
|
|
|
+ switch(meshType) {
|
|
|
+ case TRI_MESH:
|
|
|
+ verticesPerFace = 3;
|
|
|
+ break;
|
|
|
+ case QUAD_MESH:
|
|
|
+ verticesPerFace = 4;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ verticesPerFace = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- unsigned int boneID;
|
|
|
- float boneWeight;
|
|
|
+ unsigned int numFaces;
|
|
|
+ OSBasics::read(&numFaces, sizeof(unsigned int), 1, inFile);
|
|
|
|
|
|
- OSBasics::read(&numUVs, sizeof(unsigned int), 1, inFile);
|
|
|
- OSBasics::read(&numVertices, sizeof(unsigned int), 1, inFile);
|
|
|
Vector3_struct pos;
|
|
|
Vector3_struct nor;
|
|
|
- Face_struct face;
|
|
|
+ Vector4_struct col;
|
|
|
+ Vector2_struct tex;
|
|
|
|
|
|
- for(i=0; i<numVertices; i++) {
|
|
|
- OSBasics::read(&pos, sizeof(Vector3_struct), 1, inFile);
|
|
|
- OSBasics::read(&nor, sizeof(Vector3_struct), 1, inFile);
|
|
|
-
|
|
|
- newVertex = new Vertex(pos.x, pos.y, pos.z, nor.x, nor.y,nor.z);
|
|
|
+ for(int i=0; i < numFaces; i++) {
|
|
|
+ Polygon *poly = new Polygon();
|
|
|
|
|
|
- OSBasics::read(&hasWeights, sizeof(unsigned int), 1, inFile);
|
|
|
- if(hasWeights == 1) {
|
|
|
- OSBasics::read(&numWeights, sizeof(unsigned int), 1, inFile);
|
|
|
- for(int j=0; j < numWeights; j++) {
|
|
|
- OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile);
|
|
|
- OSBasics::read(&boneWeight, sizeof(float), 1, inFile);
|
|
|
- newVertex->addBoneAssignment(boneID, boneWeight);
|
|
|
- }
|
|
|
- newVertex->normalizeWeights();
|
|
|
+ for(int j=0; j < verticesPerFace; j++) {
|
|
|
+ OSBasics::read(&pos, sizeof(Vector3_struct), 1, inFile);
|
|
|
+ OSBasics::read(&nor, sizeof(Vector3_struct), 1, inFile);
|
|
|
+ OSBasics::read(&col, sizeof(Vector4_struct), 1, inFile);
|
|
|
+ OSBasics::read(&tex, sizeof(Vector2_struct), 1, inFile);
|
|
|
+
|
|
|
+ Vertex *vertex = new Vertex(pos.x, pos.y, pos.z);
|
|
|
+ vertex->setNormal(nor.x,nor.y, nor.z);
|
|
|
+ vertex->restNormal.set(nor.x,nor.y, nor.z);
|
|
|
+ vertex->vertexColor.setColor(col.x,col.y, col.z, col.w);
|
|
|
+ vertex->setTexCoord(tex.x, tex.y);
|
|
|
+
|
|
|
+ unsigned int numBoneWeights;
|
|
|
+ OSBasics::read(&numBoneWeights, sizeof(unsigned int), 1, inFile);
|
|
|
+ for(int b=0; b < numBoneWeights; b++) {
|
|
|
+ float weight;
|
|
|
+ unsigned int boneID;
|
|
|
+ OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile);
|
|
|
+ OSBasics::read(&weight, sizeof(float), 1, inFile);
|
|
|
+ vertex->addBoneAssignment(boneID, weight);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ poly->addVertex(vertex);
|
|
|
}
|
|
|
- vertices.push_back(newVertex);
|
|
|
+ addPolygon(poly);
|
|
|
}
|
|
|
|
|
|
- OSBasics::read(&numFaces, sizeof(unsigned int), 1, inFile);
|
|
|
+ arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
|
|
|
+ arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;
|
|
|
+ arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;
|
|
|
+ arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;
|
|
|
|
|
|
- for(i=0; i<numFaces; i++) {
|
|
|
- OSBasics::read(&face, sizeof(Face_struct), 1, inFile);
|
|
|
- polygon = new Polygon();
|
|
|
- polygon->addVertex(vertices[face.v1]);
|
|
|
- polygon->addVertex(vertices[face.v2]);
|
|
|
- polygon->addVertex(vertices[face.v3]);
|
|
|
-
|
|
|
- polygon->setNormal(Vector3(face.nx,face.ny,face.nz));
|
|
|
-
|
|
|
- vertices[face.v1]->setTexCoord(face.uvs[0].x,face.uvs[0].y);
|
|
|
- vertices[face.v2]->setTexCoord(face.uvs[1].x,face.uvs[1].y);
|
|
|
- vertices[face.v3]->setTexCoord(face.uvs[2].x,face.uvs[2].y);
|
|
|
-
|
|
|
- polygon->addTexCoord(face.uvs[0].x,face.uvs[0].y);
|
|
|
- polygon->addTexCoord(face.uvs[1].x,face.uvs[1].y);
|
|
|
- polygon->addTexCoord(face.uvs[2].x,face.uvs[2].y);
|
|
|
- polygon->setUseFaceUV(true);
|
|
|
-
|
|
|
- if(numUVs == 2) {
|
|
|
- Vector2_struct uv2s[3];
|
|
|
- OSBasics::read(uv2s, sizeof(Vector2_struct), 3, inFile);
|
|
|
- polygon->addTexCoord2(uv2s[0].x,uv2s[0].y);
|
|
|
- polygon->addTexCoord2(uv2s[1].x,uv2s[1].y);
|
|
|
- polygon->addTexCoord2(uv2s[2].x,uv2s[2].y);
|
|
|
- }
|
|
|
-
|
|
|
- polygons.push_back(polygon);
|
|
|
- }
|
|
|
- this->numUVs = numUVs;
|
|
|
+
|
|
|
+// int i;
|
|
|
+//
|
|
|
+// Vertex *newVertex;
|
|
|
+// Polygon *polygon;
|
|
|
+// unsigned int numVertices, numFaces, hasWeights, numWeights, numUVs;
|
|
|
+//
|
|
|
+// unsigned int boneID;
|
|
|
+// Number boneWeight;
|
|
|
+//
|
|
|
+// OSBasics::read(&numUVs, sizeof(unsigned int), 1, inFile);
|
|
|
+// OSBasics::read(&numVertices, sizeof(unsigned int), 1, inFile);
|
|
|
+// Vector3_struct pos;
|
|
|
+// Vector3_struct nor;
|
|
|
+// Face_struct face;
|
|
|
+//
|
|
|
+// for(i=0; i<numVertices; i++) {
|
|
|
+// OSBasics::read(&pos, sizeof(Vector3_struct), 1, inFile);
|
|
|
+// OSBasics::read(&nor, sizeof(Vector3_struct), 1, inFile);
|
|
|
+//
|
|
|
+// newVertex = new Vertex(pos.x, pos.y, pos.z, nor.x, nor.y,nor.z);
|
|
|
+//
|
|
|
+// OSBasics::read(&hasWeights, sizeof(unsigned int), 1, inFile);
|
|
|
+// if(hasWeights == 1) {
|
|
|
+// OSBasics::read(&numWeights, sizeof(unsigned int), 1, inFile);
|
|
|
+// for(int j=0; j < numWeights; j++) {
|
|
|
+// OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile);
|
|
|
+// OSBasics::read(&boneWeight, sizeof(Number), 1, inFile);
|
|
|
+// newVertex->addBoneAssignment(boneID, boneWeight);
|
|
|
+// }
|
|
|
+// newVertex->normalizeWeights();
|
|
|
+// }
|
|
|
+// vertices.push_back(newVertex);
|
|
|
+// }
|
|
|
+//
|
|
|
+// OSBasics::read(&numFaces, sizeof(unsigned int), 1, inFile);
|
|
|
+//
|
|
|
+// for(i=0; i<numFaces; i++) {
|
|
|
+// OSBasics::read(&face, sizeof(Face_struct), 1, inFile);
|
|
|
+// polygon = new Polygon();
|
|
|
+// polygon->setNormal(Vector3(face.nx,face.ny,face.nz));
|
|
|
+//
|
|
|
+// vertices[face.v1]->setTexCoord(face.uvs[0].x,face.uvs[0].y);
|
|
|
+// vertices[face.v2]->setTexCoord(face.uvs[1].x,face.uvs[1].y);
|
|
|
+// vertices[face.v3]->setTexCoord(face.uvs[2].x,face.uvs[2].y);
|
|
|
+//
|
|
|
+// polygon->addTexCoord(face.uvs[0].x,face.uvs[0].y);
|
|
|
+// polygon->addTexCoord(face.uvs[1].x,face.uvs[1].y);
|
|
|
+// polygon->addTexCoord(face.uvs[2].x,face.uvs[2].y);
|
|
|
+// polygon->setUseFaceUV(true);
|
|
|
+//
|
|
|
+// if(numUVs == 2) {
|
|
|
+// Vector2_struct uv2s[3];
|
|
|
+// OSBasics::read(uv2s, sizeof(Vector2_struct), 3, inFile);
|
|
|
+// polygon->addTexCoord2(uv2s[0].x,uv2s[0].y);
|
|
|
+// polygon->addTexCoord2(uv2s[1].x,uv2s[1].y);
|
|
|
+// polygon->addTexCoord2(uv2s[2].x,uv2s[2].y);
|
|
|
+// }
|
|
|
+//
|
|
|
+// polygons.push_back(polygon);
|
|
|
+// }
|
|
|
+// this->numUVs = numUVs;
|
|
|
}
|
|
|
|
|
|
void Mesh::loadMesh(String fileName) {
|
|
|
@@ -218,12 +279,12 @@ namespace Polycode {
|
|
|
|
|
|
}
|
|
|
|
|
|
- void Mesh::createPlane(float w, float h) {
|
|
|
+ void Mesh::createPlane(Number w, Number h) {
|
|
|
Polygon *imagePolygon = new Polygon();
|
|
|
- imagePolygon->addVertex(0,0,0,0,0);
|
|
|
- imagePolygon->addVertex(w,0,0, 1, 0);
|
|
|
- imagePolygon->addVertex(w,h,0, 1, 1);
|
|
|
- imagePolygon->addVertex(0,h,0,0,1);
|
|
|
+ imagePolygon->addVertex(0,0,0,0,1);
|
|
|
+ imagePolygon->addVertex(w,0,0, 1, 1);
|
|
|
+ imagePolygon->addVertex(w,h,0, 1, 0);
|
|
|
+ imagePolygon->addVertex(0,h,0,0,0);
|
|
|
addPolygon(imagePolygon);
|
|
|
|
|
|
for(int i=0; i < polygons.size(); i++) {
|
|
|
@@ -257,14 +318,67 @@ namespace Polycode {
|
|
|
return vertices[index];
|
|
|
}
|
|
|
|
|
|
+ Vector3 Mesh::recenterMesh() {
|
|
|
+ Vector3 positiveOffset;
|
|
|
+ Vector3 negativeOffset;
|
|
|
+
|
|
|
+ for(int i=0; i < polygons.size(); i++) {
|
|
|
+ for(int j=0; j < polygons[i]->getVertexCount(); j++) {
|
|
|
+ positiveOffset.x = max(positiveOffset.x,polygons[i]->getVertex(j)->x);
|
|
|
+ positiveOffset.y = max(positiveOffset.y,polygons[i]->getVertex(j)->y);
|
|
|
+ positiveOffset.z = max(positiveOffset.z,polygons[i]->getVertex(j)->z);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i=0; i < polygons.size(); i++) {
|
|
|
+ for(int j=0; j < polygons[i]->getVertexCount(); j++) {
|
|
|
+ negativeOffset.x = min(negativeOffset.x,polygons[i]->getVertex(j)->x);
|
|
|
+ negativeOffset.y = min(negativeOffset.y,polygons[i]->getVertex(j)->y);
|
|
|
+ negativeOffset.z = min(negativeOffset.z,polygons[i]->getVertex(j)->z);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector3 finalOffset;
|
|
|
+
|
|
|
+ finalOffset.x = (positiveOffset.x + negativeOffset.x)/2.0f;
|
|
|
+ finalOffset.y = (positiveOffset.y + negativeOffset.y)/2.0f;
|
|
|
+ finalOffset.z = (positiveOffset.z + negativeOffset.z)/2.0f;
|
|
|
+
|
|
|
+ vector<Vertex*> done;
|
|
|
+ for(int i=0; i < polygons.size(); i++) {
|
|
|
+ for(int j=0; j < polygons[i]->getVertexCount(); j++) {
|
|
|
+
|
|
|
+ bool alreadyDone = false;
|
|
|
+ for(int k=0; k < done.size(); k++) {
|
|
|
+ if(done[k] == polygons[i]->getVertex(j))
|
|
|
+ alreadyDone = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!alreadyDone) {
|
|
|
+ polygons[i]->getVertex(j)->x = polygons[i]->getVertex(j)->x - finalOffset.x;
|
|
|
+ polygons[i]->getVertex(j)->y = polygons[i]->getVertex(j)->y - finalOffset.y;
|
|
|
+ polygons[i]->getVertex(j)->z = polygons[i]->getVertex(j)->z - finalOffset.z;
|
|
|
+ done.push_back(polygons[i]->getVertex(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
|
|
|
+
|
|
|
+ return finalOffset;
|
|
|
+ }
|
|
|
+
|
|
|
Vector3 Mesh::calculateBBox() {
|
|
|
Vector3 retVec;
|
|
|
|
|
|
for(int i=0; i < polygons.size(); i++) {
|
|
|
for(int j=0; j < polygons[i]->getVertexCount(); j++) {
|
|
|
- retVec.x = max(retVec.x,fabsf(polygons[i]->getVertex(j)->x));
|
|
|
- retVec.y = max(retVec.y,fabsf(polygons[i]->getVertex(j)->y));
|
|
|
- retVec.z = max(retVec.z,fabsf(polygons[i]->getVertex(j)->z));
|
|
|
+ retVec.x = max(retVec.x,fabs(polygons[i]->getVertex(j)->x));
|
|
|
+ retVec.y = max(retVec.y,fabs(polygons[i]->getVertex(j)->y));
|
|
|
+ retVec.z = max(retVec.z,fabs(polygons[i]->getVertex(j)->z));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -272,20 +386,20 @@ namespace Polycode {
|
|
|
return retVec*2;
|
|
|
}
|
|
|
|
|
|
- void Mesh::createSphere(float radius, float numRings, float numSegments) {
|
|
|
+ void Mesh::createSphere(Number radius, Number numRings, Number numSegments) {
|
|
|
|
|
|
- float fDeltaRingAngle = (PI / numRings);
|
|
|
- float fDeltaSegAngle = (2 * PI / numSegments);
|
|
|
+ Number fDeltaRingAngle = (PI / numRings);
|
|
|
+ Number fDeltaSegAngle = (2 * PI / numSegments);
|
|
|
|
|
|
for(int i=0; i < numRings; i++) {
|
|
|
- float r0 = radius * sinf (i * fDeltaRingAngle);
|
|
|
- float y0 = radius * cosf (i * fDeltaRingAngle);
|
|
|
+ Number r0 = radius * sinf (i * fDeltaRingAngle);
|
|
|
+ Number y0 = radius * cosf (i * fDeltaRingAngle);
|
|
|
for(int j=0; j < numSegments; j++) {
|
|
|
- float x0 = r0 * sinf(j * fDeltaSegAngle);
|
|
|
- float z0 = r0 * cosf(j * fDeltaSegAngle);
|
|
|
+ Number x0 = r0 * sinf(j * fDeltaSegAngle);
|
|
|
+ Number z0 = r0 * cosf(j * fDeltaSegAngle);
|
|
|
|
|
|
- float tx0 = (float) j / (float) numSegments;
|
|
|
- float tx1 = (float) i / (float) numRings;
|
|
|
+ Number tx0 = (Number) j / (Number) numSegments;
|
|
|
+ Number tx1 = (Number) i / (Number) numRings;
|
|
|
|
|
|
Vector3 nor = Vector3(x0, y0, z0);
|
|
|
nor.Normalize();
|
|
|
@@ -302,7 +416,7 @@ namespace Polycode {
|
|
|
|
|
|
}
|
|
|
|
|
|
- void Mesh::createBox(float w, float d, float h) {
|
|
|
+ void Mesh::createBox(Number w, Number d, Number h) {
|
|
|
Polygon *polygon = new Polygon();
|
|
|
polygon->addVertex(w,0,h, 1, 1);
|
|
|
polygon->addVertex(0,0,h, 1, 0);
|