Пример #1
0
void draw_point(const Vertex &pt, scalar_t size) {

    Vector3 p = pt.pos;

    Vector3 cam_pos = Vector3(0,0,0).transformed(inv_view_matrix);

    Basis basis;
    basis.k = -(cam_pos - p).normalized();
    basis.j = Vector3(0, 1, 0);
    basis.i = cross_product(basis.j, basis.k);
    basis.j = cross_product(basis.k, basis.i);

    world_matrix.set_translation(p);
    world_matrix = world_matrix * Matrix4x4(basis.create_rotation_matrix());
    load_xform_matrices();

    Vertex quad[] = {
        Vertex(Vector3(-size, -size, 0), 0.0, 0.0, pt.color),
        Vertex(Vector3(-size, size, 0), 0.0, 1.0, pt.color),
        Vertex(Vector3(size, size, 0), 1.0, 1.0, pt.color),
        Vertex(Vector3(size, -size, 0), 1.0, 0.0, pt.color)
    };

    set_lighting(false);
    set_primitive_type(QUAD_LIST);
    draw(VertexArray(quad, 4));
    set_primitive_type(TRIANGLE_LIST);
    set_lighting(true);

}
Пример #2
0
/* draw_line(start_vertex, end_vertex, start_width, end_width)
 * Draws a line as a cylindrically billboarded elongated quad.
 */
void draw_line(const Vertex &v1, const Vertex &v2, scalar_t w1, scalar_t w2) {
    if(w2 < 0.0) w2 = w1;

    Vector3 p1 = v1.pos;
    Vector3 p2 = v2.pos;

    Vector3 cam_pos = Vector3(0,0,0).transformed(inv_view_matrix);

    Vector3 vec = p2 - p1;
    scalar_t len = vec.length();

    Basis basis;
    basis.k = -(cam_pos - ((p2 + p1) / 2)).normalized();
    basis.j = vec / len;
    basis.i = cross_product(basis.j, basis.k).normalized();
    basis.k = cross_product(basis.i, basis.j).normalized();

    world_matrix.set_translation(p1);
    world_matrix = world_matrix * Matrix4x4(basis.create_rotation_matrix());
    load_xform_matrices();

    Vertex quad[] = {
        Vertex(Vector3(-w1, 0, 0), 0.0, v1.tex[0].u),
        Vertex(Vector3(-w2, len, 0), 0.0, v2.tex[0].u),
        Vertex(Vector3(w2, len, 0), 1.0, v2.tex[0].u),
        Vertex(Vector3(w1, 0, 0), 1.0, v1.tex[0].u)
    };

    set_lighting(false);
    set_primitive_type(QUAD_LIST);
    draw(VertexArray(quad, 4));
    set_primitive_type(TRIANGLE_LIST);
    set_lighting(true);
}