当前位置: 首页>>代码示例>>C++>>正文


C++ Cube::CreateBuffers方法代码示例

本文整理汇总了C++中Cube::CreateBuffers方法的典型用法代码示例。如果您正苦于以下问题:C++ Cube::CreateBuffers方法的具体用法?C++ Cube::CreateBuffers怎么用?C++ Cube::CreateBuffers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cube的用法示例。


在下文中一共展示了Cube::CreateBuffers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Create


//.........这里部分代码省略.........
        -1.0f, 0, 0, // D-X
        0, 0, -1.0f, // E-Z
        0, -1.0f, 0, // E-Y
        -1.0f, 0, 0, // E-X
        0, 0, -1.0f, // F-Z
        0, -1.0f, 0, // F-Y
        +1.0f, 0, 0, // F+X
        0, 0, -1.0f, // G-Z
        0, +1.0f, 0, // G+Y
        +1.0f, 0, 0, // G+X
        0, 0, -1.0f, // H-Z
        0, +1.0f, 0, // H+Y
        -1.0f, 0, 0  // H-X
    };

    static const int Indices[] = {
        0, 9, 6, // +Z
        0, 3, 6,
        15, 18, 21, // -Z
        15, 12, 21,
        14, 23, 11, // +Y
        14, 2, 11,
        5, 8, 20, // -Y
        5, 17, 20,
        10, 22, 19, // +X
        10, 7, 19,
        1, 13, 16, // -X
        1, 4, 16
    };

    static const Scalar TexCoords[] = {
        0.995f, 0.005f, // A+Z
        0.005f, 0.995f, // A-Y
        0.995f, 0.005f, // A-X
        0.005f, 0.005f, // B+Z
        0.995f, 0.995f, // B-Y
        0.005f, 0.005f, // B+X
        0.005f, 0.995f, // C+Z
        0.995f, 0.005f, // C+Y
        0.005f, 0.995f, // C+X
        0.995f, 0.995f, // D+Z
        0.005f, 0.005f, // D+Y
        0.995f, 0.995f, // D-X
        0.005f, 0.005f, // E-Z
        0.005f, 0.005f, // E-Y
        0.005f, 0.005f, // E-X
        0.995f, 0.005f, // F-Z
        0.995f, 0.005f, // F-Y
        0.995f, 0.005f, // F+X
        0.995f, 0.995f, // G-Z
        0.995f, 0.995f, // G+Y
        0.995f, 0.995f, // G+X
        0.005f, 0.995f, // H-Z
        0.005f, 0.995f, // H+Y
        0.005f, 0.995f  // H-X
    };

    static const Scalar Positions[] = {
        -0.5f, -0.5f, +0.5f,
        -0.5f, -0.5f, +0.5f,
        -0.5f, -0.5f, +0.5f,
        +0.5f, -0.5f, +0.5f,
        +0.5f, -0.5f, +0.5f,
        +0.5f, -0.5f, +0.5f,
        +0.5f, +0.5f, +0.5f,
        +0.5f, +0.5f, +0.5f,
        +0.5f, +0.5f, +0.5f,
        -0.5f, +0.5f, +0.5f,
        -0.5f, +0.5f, +0.5f,
        -0.5f, +0.5f, +0.5f,
        -0.5f, -0.5f, -0.5f,
        -0.5f, -0.5f, -0.5f,
        -0.5f, -0.5f, -0.5f,
        +0.5f, -0.5f, -0.5f,
        +0.5f, -0.5f, -0.5f,
        +0.5f, -0.5f, -0.5f,
        +0.5f, +0.5f, -0.5f,
        +0.5f, +0.5f, -0.5f,
        +0.5f, +0.5f, -0.5f,
        -0.5f, +0.5f, -0.5f,
        -0.5f, +0.5f, -0.5f,
        -0.5f, +0.5f, -0.5f
    };

    Cube* C = new Cube;

    if(C->CreateBuffers() != BGE_SUCCESS) {
        delete C;
        return NULL;
    }

    C->SetPositionData(24, Positions);
    C->SetNormalData(24, Normals);
    C->SetTexCoordData(24, TexCoords);
    C->SetIndexData(36, Indices);

    C->Unbind();

    return C;
}
开发者ID:bakge,项目名称:bakge,代码行数:101,代码来源:Cube.cpp

示例2: Create

Cube* Cube::Create(Scalar Length, Scalar Width, Scalar Height)
{
    Cube* C = new Cube;

    if(C->CreateBuffers() != BGE_SUCCESS) {
        delete C;
        return NULL;
    }

    /* So following changes affect our cube's VAO */
    C->BindVAO();

    /* *
     * A cube has 6 faces, each composed of two triangles.
     * We only need 8 vertices (3 components for each vertex, 24 buffer size)
     * The indices buffer will create our triangles
     * */
    C->NumFaces = 6;
    C->NumVertices = 4 * 6; /* 4 vertices per face */
    C->NumIndices = 36; /* 2 triangles per face, 3 vertices per triangle */
    Scalar* Vertices = new Scalar[72];
    Scalar* Normals = new Scalar[72];
    Scalar* TexCoords = new Scalar[48];
    unsigned int* Indices = new unsigned int[36];

    /* *
     *       H__________G
     *      /|         /|
     *    D/_|_______C/ |         +Y HEIGHT
     *    |  |       |  |         |            MODEL COORDINATE
     *    |  |       |  |         |
     *    |  |E______|__|F        |_____ +X WIDTH
     *    | /        | /         /
     *    |/_________|/         /
     *    A          B         +Z LENGTH
     *
     * Each of A through H corresponds to 3 separate vertices.
     * They are separate so normals can be constant across each
     * of the cube's faces.
     *
     * e.g. A corresponds to vertices A+Z, A-Y and A-X
     *
     * Texcoords
     * Z and X faces: When the face normal is pointing towards you and
     * the Y axis pointing up, texcoords are as follows
     *    BL 0, 0    BR 1, 0
     *    TL 0, 1    TR 1, 1
     *
     *  e.g. +Z face:
     *        A 0, 0
     *        B 1, 0
     *        D 0, 1
     *        C 1, 1
     *
     * Y faces:
     *   +Y:
     *     D 0, 0
     *     C 1, 0
     *     H 0, 1
     *     G 1, 1
     *
     *   -Y:
     *     E 0, 0
     *     F 1, 0
     *     A 0, 1
     *     B 1, 1
     * */

    /* *
     * Convenience. Dimensions are full edge measurements and the cube is
     * formed around the origin (0, 0, 0) anyways
     * */
    Width /= 2;
    Length /= 2;
    Height /= 2;

    memset((void*)Normals, 0, sizeof(Normals[0]) * 72);
    memset((void*)TexCoords, 0, sizeof(TexCoords[0]) * 48);

    /* +Z */
    Indices[0] = 0;
    Indices[1] = 9;
    Indices[2] = 6;
    Indices[3] = 0;
    Indices[4] = 3;
    Indices[5] = 6;

    /* -Z */
    Indices[6] = 15;
    Indices[7] = 18;
    Indices[8] = 21;
    Indices[9] = 15;
    Indices[10] = 12;
    Indices[11] = 21;

    /* -X */
    Indices[12] = 14;
    Indices[13] = 23;
    Indices[14] = 11;
    Indices[15] = 14;
//.........这里部分代码省略.........
开发者ID:jgcoded,项目名称:bakge,代码行数:101,代码来源:Cube.cpp


注:本文中的Cube::CreateBuffers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。