Esempio n. 1
0
Renderable* Renderable::Lines(const std::vector<Vec3f> &verts, Material *material) {
    Renderable *renderable;
    float *vertexBuffer;
    unsigned int *indexBuffer;
    unsigned int size;
    unsigned int i;

    size = (unsigned int)verts.size();

    renderable = new Renderable();

    vertexBuffer = new float[size * 3];
    indexBuffer = new unsigned int[size];

    for(i=0; i < size; i++) {
        vertexBuffer[3*i  ] = verts[i].x;
        vertexBuffer[3*i+1] = verts[i].y;
        vertexBuffer[3*i+2] = verts[i].z;

        indexBuffer[i] = i;
    }
    
    renderable->setMaterial(material);
    renderable->setAttribBuffer("position", size, GL_FLOAT, 3, &vertexBuffer[0]);
    renderable->setIndexBuffer(size, &indexBuffer[0]);
    renderable->setDrawMode(GL_LINE_STRIP);

    delete vertexBuffer;
    delete indexBuffer;

    return renderable;
}
Esempio n. 2
0
Renderable* Renderable::OrthoBox(const Vec2f &pos, const Vec2f &dims, bool texCoords, bool normals, Material *material, float z) {
    Renderable *renderable = new Renderable();

    Vec2f disp = pos + dims;

    // Incorrect - the view matrix is set by the scene node anytime the scene node's affine matrix changes
    //renderable->setViewMatrix(Matrix4::MakeTranslation(Vec3f(pos.x, pos.y, z)));
    renderable->setMaterial(material);

    // Determine if the vertex order needs to be flipped to preserve proper winding order
    bool flipped = ((dims.x < 0) != (dims.y < 0));

    // Set the verts
    if(flipped) {
        float verts[4 * 3] = {
            pos.x,  disp.y, z,
            disp.x, disp.y, z,
            disp.x, pos.y,   z,
            pos.x,  pos.y,   z
        };
        renderable->setAttribBuffer("position", 4, GL_FLOAT, 3, &verts[0]);
    } else {
        float verts[4 * 3] = {
            pos.x,  pos.y,  z,
            disp.x, pos.y,  z,
            disp.x, disp.y, z,
            pos.x,  disp.y, z
        };
        renderable->setAttribBuffer("position", 4, GL_FLOAT, 3, &verts[0]);
    }

    // Set the texture coordinates
    if(texCoords && flipped) {
        float texCoords[4 * 2] = {
            0, 1,
            1, 1,
            1, 0,
            0, 0
        };
        renderable->setAttribBuffer("texcoord", 4, GL_FLOAT, 2, &texCoords[0]);
    } else if(texCoords) {
        float texCoords[4 * 2] = {
            0, 0,
            1, 0,
            1, 1,
            0, 1
        };
        renderable->setAttribBuffer("texcoord", 4, GL_FLOAT, 2, &texCoords[0]);
    }

    // Set the normals
    if(normals) {
        float normals[4 * 3] = {
            0, 0, 1,
            0, 0, 1,
            0, 0, 1,
            0, 0, 1
        };
        renderable->setAttribBuffer("normal", 4, GL_FLOAT, 2, &normals[0]);
    }

    // Set the indices
    unsigned int indices[4] = { 0, 1, 3, 2 };
    renderable->setIndexBuffer(4, &indices[0]);

    return renderable;
}