
void CNew3D::GenerateVertex(Vertex &newVertex, const R3DPoly& poly)
{
newVertex.color[0] = (poly.v[0].color[0] + poly.v[1].color[0] + poly.v[2].color[0] + poly.v[3].color[0]) / 4;
newVertex.color[1] = (poly.v[0].color[1] + poly.v[1].color[1] + poly.v[2].color[1] + poly.v[3].color[1]) / 4;
newVertex.color[2] = (poly.v[0].color[2] + poly.v[1].color[2] + poly.v[2].color[2] + poly.v[3].color[2]) / 4;
newVertex.color[3] = (poly.v[0].color[3] + poly.v[1].color[3] + poly.v[2].color[3] + poly.v[3].color[3]) / 4;
newVertex.normal[0] = (poly.v[0].normal[0] + poly.v[1].normal[0] + poly.v[2].normal[0] + poly.v[3].normal[0]) / 4;
newVertex.normal[1] = (poly.v[0].normal[1] + poly.v[1].normal[1] + poly.v[2].normal[1] + poly.v[3].normal[1]) / 4;
newVertex.normal[2] = (poly.v[0].normal[2] + poly.v[1].normal[2] + poly.v[2].normal[2] + poly.v[3].normal[2]) / 4;
newVertex.pos[0] = (poly.v[0].pos[0] + poly.v[1].pos[0] + poly.v[2].pos[0] + poly.v[3].pos[0]) / 4;
newVertex.pos[1] = (poly.v[0].pos[1] + poly.v[1].pos[1] + poly.v[2].pos[1] + poly.v[3].pos[1]) / 4;
newVertex.pos[2] = (poly.v[0].pos[2] + poly.v[1].pos[2] + poly.v[2].pos[2] + poly.v[3].pos[2]) / 4;
newVertex.texcoords[0] = (poly.v[0].texcoords[0] + poly.v[1].texcoords[0] + poly.v[2].texcoords[0] + poly.v[3].texcoords[0]) / 4;
newVertex.texcoords[1] = (poly.v[0].texcoords[1] + poly.v[1].texcoords[1] + poly.v[2].texcoords[1] + poly.v[3].texcoords[1]) / 4;
}
void CNew3D::AddTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, const R3DPoly& r3dPoly, std::vector<Poly>& polyArray)
{
//=====
Poly p;
//=====
p.p1 = v1;
p.p2 = v2;
p.p3 = v3;
//multiply face attributes with vertex attributes if required
for (int i = 0; i < 4; i++) {
p.p1.color[i] = p.p1.color[i] * r3dPoly.faceColour[i];
p.p2.color[i] = p.p2.color[i] * r3dPoly.faceColour[i];
p.p3.color[i] = p.p3.color[i] * r3dPoly.faceColour[i];
}
polyArray.emplace_back(p);
}
void CNew3D::CopyVertexData(const R3DPoly& r3dPoly, std::vector<Poly>& polyArray)
{
//====================
V3::Vec3 normal;
float dotProd;
bool clockWise;
//====================
V3::createNormal(r3dPoly.v[0].pos, r3dPoly.v[1].pos, r3dPoly.v[2].pos, normal);
dotProd = V3::dotProduct(normal, r3dPoly.faceNormal);
clockWise = dotProd >= 0;
if (r3dPoly.number == 3) {
if (clockWise) {
AddTriangle(r3dPoly.v[0], r3dPoly.v[1], r3dPoly.v[2], r3dPoly, polyArray);
}
else {
AddTriangle(r3dPoly.v[2], r3dPoly.v[1], r3dPoly.v[0], r3dPoly, polyArray);
}
}
else if (r3dPoly.number == 4) {
//=================
Vertex newVertex;
bool clockWise2;
//=================
// check for the evil quads that overlap themselves and change the winding ..
V3::createNormal(r3dPoly.v[0].pos, r3dPoly.v[2].pos, r3dPoly.v[3].pos, normal);
dotProd = V3::dotProduct(normal, r3dPoly.faceNormal);
clockWise2 = dotProd >= 0;
if (clockWise != clockWise2) {
if (clockWise) {
AddTriangle(r3dPoly.v[0], r3dPoly.v[1], r3dPoly.v[2], r3dPoly, polyArray);
}
else {
AddTriangle(r3dPoly.v[2], r3dPoly.v[1], r3dPoly.v[0], r3dPoly, polyArray);
}
if (clockWise2) {
AddTriangle(r3dPoly.v[0], r3dPoly.v[2], r3dPoly.v[3], r3dPoly, polyArray);
}
else {
AddTriangle(r3dPoly.v[0], r3dPoly.v[3], r3dPoly.v[2], r3dPoly, polyArray);
}
return;
}
GenerateVertex(newVertex, r3dPoly);
if (clockWise) {
AddTriangle(r3dPoly.v[0], r3dPoly.v[1], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[1], r3dPoly.v[2], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[2], r3dPoly.v[3], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[3], r3dPoly.v[0], newVertex, r3dPoly, polyArray);
}
else {
AddTriangle(r3dPoly.v[0], r3dPoly.v[3], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[3], r3dPoly.v[2], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[2], r3dPoly.v[1], newVertex, r3dPoly, polyArray);
AddTriangle(r3dPoly.v[1], r3dPoly.v[0], newVertex, r3dPoly, polyArray);
}
}
}
void GenerateVertex(Vertex &newVertex, const R3DPoly& poly);
void AddTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, const R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
Ian wrote:I honestly think that the version where we flipped the split was more accurate
Maybe I could use this method to try that..
Users browsing this forum: No registered users and 1 guest