Пример #1
0
void VboCircleRenderer::setup(float w, float h) {
    width = w;
    height = h;
    baseRad = width;
    
    initVbo();
}
Пример #2
0
void VboCircleRenderer::setup() {
    width = ofGetWidth();
    height = ofGetHeight();
    baseRad = width;
    
    initVbo();
}
Пример #3
0
bool OBJ::read(const QString &path)
{
    // Open the file
    QString obj = QString(path);

    QFile file(obj);
    if (!file.open(QFile::ReadOnly | QFile::Text)) return false;
    QTextStream f(&file);
    QString line;

    vertices.clear();
    normals.clear();
	vertexNormals.clear();
	vertexNormalContributions.clear();
    triangles.clear();
    boundingBox = BoundingBox();

    // Read the file
    QRegExp spaces("\\s+");
    Vector3 currKA;
    Vector3 currKD;
    do {
        line = f.readLine().trimmed();
        QStringList parts = line.split(spaces);
        if (parts.isEmpty()) continue;
        if (parts[0] == "ka" && parts.count() >= 4) {
            float x = parts[1].toFloat();
            float y = parts[2].toFloat();
            float z = parts[3].toFloat();
            currKA = Vector3(x,y,z);
		} else if(parts[0] == "kd" && parts.count() >= 4) {
            float x = parts[1].toFloat();
            float y = parts[2].toFloat();
			float z = parts[3].toFloat();
            currKD = Vector3(x,y,z);
		} else if (parts[0] == "v" && parts.count() >= 4) {
            float x = parts[1].toFloat();
            float y = parts[2].toFloat();
            float z = parts[3].toFloat();

            vertices += Vertex(x,y,z,currKA,currKD);
			vertexNormals += Vector3(0,0,0);
			vertexNormalContributions += 0;
            //Bounding box info to position camera correctly
            boundingBox.maxX = max(x, boundingBox.maxX );
            boundingBox.minX = min(x, boundingBox.minX );
            boundingBox.maxY = max(y, boundingBox.maxY );
            boundingBox.minY = min(y, boundingBox.minY );
            boundingBox.maxZ = max(z, boundingBox.maxZ );
            boundingBox.minZ = min(z, boundingBox.minZ );
        } else if (parts[0] == "vn" && parts.count() >= 4) {
            normals += Vector3(parts[1].toFloat(), parts[2].toFloat(), parts[3].toFloat());
        } else if (parts[0] == "f" && parts.count() >= 4) {
            // Convert polygons into triangle fans
            Index a = getIndex(parts[1]);
            Index b = getIndex(parts[2]);
            for (int i = 3; i < parts.count(); i++) {
                Index c = getIndex(parts[i]);
                triangles += Triangle(a, b, c);
                b = c;
            }
        }
    } while (!line.isNull());

    boundingBox.center = Vector3((boundingBox.maxX + boundingBox.minX) / 2,
                                 (boundingBox.maxY + boundingBox.minY) / 2,
                                 (boundingBox.maxZ + boundingBox.minZ) / 2);
	computeNormals();
    initVbo();

    return true;
}