Exemple #1
0
// makes a unit width and length robot
static void vxo_robot_init()
{
    float verts_f[NVERTS*2] = { -DEFAULT_LENGTH/2,   DEFAULT_WIDTH/2,
                                -DEFAULT_LENGTH/2,  -DEFAULT_WIDTH/2,
                                DEFAULT_LENGTH/2,  0.0f
    };

    points = vx_resc_copyf(verts_f, NVERTS*2);

    vx_resc_inc_ref(points); // hold on to these forever
}
Exemple #2
0
static void vxo_rect_init()
{
    float verts_f[NVERTS*2] = {-0.5f,-0.5f,
                                0.5f,-0.5f,
                                0.5f, 0.5f,
                               -0.5f, 0.5f};
    uint32_t ind_i[NIDX] = {0,1,2,2,3,0};
    float norms_f[NVERTS*3] = {0,0,1,
                               0,0,1,
                               0,0,1,
                               0,0,1};


    points = vx_resc_copyf(verts_f, NVERTS*2);
    normals = vx_resc_copyf(norms_f, NVERTS*3);
    indices = vx_resc_copyui(ind_i, NIDX);

    vx_resc_inc_ref(points); // hold on to these references until vx_global_destroy()
    vx_resc_inc_ref(indices);
    vx_resc_inc_ref(normals);
}
Exemple #3
0
static void vxo_grid_init(int npts)
{

    // each iteration we make 2 points, along 2 axis in 2D, so stride = 8
    float all_lines[npts*8];

    for (int i = 0; i < npts/2; i++) {

        float x = i;
        float y = npts/2;


        // Vertical lines
        all_lines[ 16 * i + 0] =  x;
        all_lines[ 16 * i + 1] =  y;
        all_lines[ 16 * i + 2] =  x;
        all_lines[ 16 * i + 3] = -y;


        all_lines[ 16 * i + 4] = -x;
        all_lines[ 16 * i + 5] =  y;
        all_lines[ 16 * i + 6] = -x;
        all_lines[ 16 * i + 7] = -y;

        // Horizontal lines  (swap assignment of x->y)
        all_lines[ 16 * i + 8] =  y;
        all_lines[ 16 * i + 9] =  x;
        all_lines[ 16 * i + 10] = -y;
        all_lines[ 16 * i + 11] =  x;

        all_lines[ 16 * i + 12] =  y;
        all_lines[ 16 * i + 13] = -x;
        all_lines[ 16 * i + 14] = -y;
        all_lines[ 16 * i + 15] = -x;

    }

    grid_vertices = vx_resc_copyf(all_lines, npts*8);
    vx_resc_inc_ref(grid_vertices);
}
Exemple #4
0
static void vxo_box_init()
{
    // for GL_POINTS
    float point_verts[NVERTS*3] =
        {
            -0.5f,-0.5f,-0.5f, // 0
            -0.5f,+0.5f,-0.5f, // 1
            +0.5f,+0.5f,-0.5f, // 2
            +0.5f,-0.5f,-0.5f, // 3
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,+0.5f, // 7
        };

    // for GL_LINES
    uint32_t line_idxs[N_LINE_IDX*2] =
        {
            0,1, 1,2, 2,3, 3,0, // bottom
            4,5, 5,6, 6,7, 7,4, // top
            0,4, 1,5, 2,6, 3,7  // sides
        };

    // for GL_TRIANGLES
    // Note: we could reduce the amount of vertex data
    // by using indices -- e.g. point 0 and 2 are listed twice with the
    // same normal on the bottom face (would save us 16 vertices out of 48)
    // each vertex is listed 6 times, has 3 coords
    float tri_verts[N_TRI_VERT*3] =
        {
            // Bottom Face
            +0.5f,+0.5f,-0.5f, // 2
            -0.5f,-0.5f,-0.5f, // 0
            -0.5f,+0.5f,-0.5f, // 1

            -0.5f,-0.5f,-0.5f, // 0
            +0.5f,+0.5f,-0.5f, // 2
            +0.5f,-0.5f,-0.5f, // 3

            // Top
            -0.5f,+0.5f,+0.5f, // 5
            -0.5f,-0.5f,+0.5f, // 4
            +0.5f,+0.5f,+0.5f, // 6

            +0.5f,+0.5f,+0.5f, // 6
            -0.5f,-0.5f,+0.5f, // 4
            +0.5f,-0.5f,+0.5f, // 7

            // Front
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,+0.5f, // 7
            +0.5f,-0.5f,-0.5f, // 3

            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,-0.5f, // 3
            +0.5f,+0.5f,-0.5f, // 2

            // Back
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,+0.5f, // 5
            -0.5f,+0.5f,-0.5f, // 1

            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,-0.5f, // 1
            -0.5f,-0.5f,-0.5f, // 0

            // Right
            +0.5f,-0.5f,+0.5f, // 7
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,-0.5f,-0.5f, // 0

            +0.5f,-0.5f,+0.5f, // 7
            -0.5f,-0.5f,-0.5f, // 0
            +0.5f,-0.5f,-0.5f, // 3

            // Left
            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,+0.5f,-0.5f, // 2

            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,-0.5f, // 2
            -0.5f,+0.5f,-0.5f, // 1
        };


    float tri_norms[N_TRI_VERT*3] =
    {
        // Bottom
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,

        // Top
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,

        // Front
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,

        // Back
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,

        // Right
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,

        // Left
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f
    };

    // triangles in CCW when viewed from outside the box
    /*
      2,0,1,0,2,3,  // bottom face
      5,4,6,6,4,7,  // top face
      6,7,3,6,3,2,  // front face
      4,5,1,4,1,0,  // back face
      7,4,0,7,0,3,  // right face
      5,6,2,5,2,1   // left face
    */

    vertex_points = vx_resc_copyf(point_verts, NVERTS*3);
    line_indices = vx_resc_copyui(line_idxs, N_LINE_IDX*2);
    tri_points = vx_resc_copyf(tri_verts, N_TRI_VERT*3);
    tri_normals = vx_resc_copyf(tri_norms, N_TRI_VERT*3);

    // hold on to these references until vx_global_destroy()
    vx_resc_inc_ref(vertex_points);
    vx_resc_inc_ref(line_indices);
    vx_resc_inc_ref(tri_points);
    vx_resc_inc_ref(tri_normals);
}