Ejemplo n.º 1
0
void * render_loop(void * data)
{
    tinfo_t * tinfo = data;
    state_t * state = tinfo->state;
    char * buffer_name = sprintf_alloc("rot%d", tinfo->id);

    float color[4] = {1.0f, 1.0 - .1f*tinfo->id, .1f*tinfo->id, 1.0f};

    while(state->running) {
        double rad = (tinfo->id*M_PI/5) + (vx_util_mtime() % 2000) * 2* M_PI / 1e3;

        vx_object_t * vo = vxo_chain(vxo_mat_rotate_z(rad),
                                     vxo_mat_translate2(0,10),
                                     vxo_box(vxo_mesh_style(color)));

        vx_buffer_add_back(vx_world_get_buffer(state->world, buffer_name), vo);
        vx_buffer_swap(vx_world_get_buffer(state->world, buffer_name));

        usleep(500);
    }
    printf("Exiting render thread %s\n", buffer_name);
    free(buffer_name);

    return NULL;
}
Ejemplo n.º 2
0
// Returns a unit arrow
vx_object_t * _vxo_arrow_private(vx_style_t * style, ...)
{

    vx_object_t * vc = vxo_chain_create();
    va_list va;
    va_start(va, style);
    for (vx_style_t * sty = style; sty != NULL; sty = va_arg(va, vx_style_t *)) {

        vx_style_inc_ref(sty);

        vxo_chain_add(vc,
                      vxo_chain(
                          vxo_mat_scale3(.75, .06, .06),
                          vxo_mat_translate3(.5,0,0),
                                vxo_box(sty)),
                      vxo_chain(vxo_mat_translate3(0.75,0,0),
                                vxo_mat_rotate_y(M_PI/2),
                                vxo_mat_scale(.25),
                                vxo_square_pyramid(sty)));


        vx_style_dec_destroy(sty);
    }
    va_end(va);


    return vc;
}
Ejemplo n.º 3
0
static int key_event (vx_event_handler_t * vh, vx_layer_t * vl, vx_key_event_t * key)
{
    state_t *state = vh->impl;

    //printf("key pressed %d\n", key->key_code);

    if (key->key_code == 'N') {
        vx_buffer_add_back(vx_world_get_buffer(state->world2, "delayed_buffer"),
                           vxo_box(vxo_mesh_style(vx_green)));
        vx_buffer_swap(vx_world_get_buffer(state->world2, "delayed_buffer"));
        return 1;
    }
    return 0;
}
Ejemplo n.º 4
0
static void* render_thread1(void * data)
{
    state_t * state = data;
    vx_world_t * world = state->world;
    float multcolors[] = {1.0f, 0.0f, 0.0f, 1.0f,
                          0.0f, 1.0f, 0.0f, 1.0f,
                          0.0f, 0.0f, 1.0f, 1.0f,
                          1.0f, 1.0f, 0.0f, 1.0f};

    vx_object_t * solid = vxo_chain(vxo_mat_translate3(3.0,0,0),
                                    vxo_mat_scale3(2,2,2),
                                    vxo_box(vxo_mesh_style(vx_orange)));
    // switch above to vxo_box to get a different bug

    vx_object_inc_ref(solid);

    vx_object_t * multi = vxo_chain(vxo_mat_translate3(3.0,0,0),
                                    vxo_mat_scale3(2,2,2),
                                    vxo_rect(vxo_lines_style_multi_colored(vx_resc_copyf(multcolors,4*4), 2.0)));

    vx_object_inc_ref(multi);

    uint64_t count = 0;
    while(1) {

        //printf("CASE %ld\n", count %4);
        switch(count % 4) {
            case 0: // Draw pattern A
                vx_buffer_add_back(vx_world_get_buffer(world, "thread1"),
                                   solid);
                break;
            case 2: // Draw pattern B
                vx_buffer_add_back(vx_world_get_buffer(world, "thread1"),
                                   multi);
                break;
            case 1: // Do nothing
            case 3:
                break;

        }
        count++;
        // swap every time
        vx_buffer_swap(vx_world_get_buffer(world, "thread1"));

        usleep(1000000);
    }
    pthread_exit(NULL);
}
Ejemplo n.º 5
0
Archivo: vx_demo.c Proyecto: DH-std/A3
void * render_loop(void * data)
{
    state_t * state = data;
    while(state->running) {
        double rad = (vx_util_mtime() % 5000) * 2* M_PI / 5e3;

        vx_object_t * vo = vxo_chain(vxo_mat_rotate_z(rad),
                                     vxo_mat_translate2(0,10),
                                     vxo_box(vxo_mesh_style(vx_blue)));

        vx_buffer_add_back(vx_world_get_buffer(state->world, "rotating-square"), vo);
        vx_buffer_swap(vx_world_get_buffer(state->world, "rotating-square"));
        usleep(5000);
    }

    return NULL;
}
Ejemplo n.º 6
0
void BoundingBox::draw(vx_buffer *buf, const float color[]) {
	float translucentColor[4];

	for (int i = 0; i < 3; i++) {
		translucentColor[i] = color[i];
	}
	translucentColor[3] = 0.3f;

    vx_object_t *box = vxo_chain(
	    // Base
	    vxo_mat_scale3(CM_TO_VX, CM_TO_VX, CM_TO_VX),
	    vxo_mat_translate3(this->getX(), this->getY(), this->getZ()),
	    vxo_mat_scale3(this->getW(), this->getH(), this->getD()),
	    vxo_box(vxo_mesh_style(translucentColor), vxo_lines_style(vx_black, 2.0f))
	);
	
	vx_buffer_add_back(buf, box);
}
Ejemplo n.º 7
0
Archivo: vx_demo.c Proyecto: DH-std/A3
static void draw(state_t * state, vx_world_t * world)
{
    if (1) {
        vx_buffer_add_back(vx_world_get_buffer(world, "grid"),
                           vxo_grid());
        vx_buffer_set_draw_order(vx_world_get_buffer(world, "grid"), -100);
        vx_buffer_swap(vx_world_get_buffer(world, "grid"));
    }

    // Draw from the vx shape library
    if (1) {
        vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"),
                           vxo_chain(vxo_mat_translate3(3.0,0,0),
                                     vxo_mat_scale3(2,2,2),
                                     /* vxo_box(vxo_mesh_style(vx_orange)))); */
                                     vxo_box(vxo_mesh_style_fancy(vx_orange, vx_orange, vx_white, 1.0, 400.0, 2))));


        vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"),
                           vxo_chain(vxo_mat_translate3(0,3.0,0),
                                     vxo_mat_scale3(1,1,1),
                                     vxo_depth_test(0,
                                                    vxo_box(vxo_mesh_style_solid(vx_green)))));
        vx_buffer_swap(vx_world_get_buffer(world, "fixed-cube"));
    }

    if (1) {
        float Tr = .2;
        float amb[] = {0.0,0.0,0.0};
        float diff[] = {0.0,0.0,0.0};
        float spec[] = {1.0,1.0,1.0};
        float specularity = 1.0;

        int type = 2;

        vx_buffer_add_back(vx_world_get_buffer(world, "window"),
                           vxo_chain(vxo_mat_translate3(0,0,2.5),
                                     vxo_mat_rotate_y(-M_PI/7),
                                     vxo_mat_rotate_z(M_PI/5),
                                     vxo_mat_rotate_x(M_PI/2),
                                     vxo_mat_scale3(10,10,1),
                                     vxo_rect(vxo_mesh_style_fancy(amb, diff, spec, Tr, specularity, type),
                                              vxo_lines_style(vx_black,2))));
        vx_buffer_swap(vx_world_get_buffer(world, "window"));
        vx_buffer_set_draw_order(vx_world_get_buffer(world, "window"), 100);
    }


    if (1) {
        // Draw a custom ellipse:
        int npoints = 35;
        float points[npoints*3];
        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = 5.0f*cosf(angle);
            float y = 8.0f*sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "ellipse"), vxo_lines(vx_resc_copyf (points, npoints*3),
                                                                            npoints, GL_LINE_LOOP,
                                                                            vxo_lines_style(vx_purple, 1.0f) ));
        vx_buffer_swap(vx_world_get_buffer(world, "ellipse"));
    }

    if (1) {
        vx_object_t *vt = vxo_text_create(VXO_TEXT_ANCHOR_TOP_RIGHT, "<<right,#0000ff>>Heads Up!\n");
        vx_buffer_t *vb = vx_world_get_buffer(world, "text");
        vx_buffer_add_back(vb, vxo_pix_coords(VX_ORIGIN_TOP_RIGHT,vt));
        vx_buffer_swap(vb);
    }

    // Draw a texture
    if (state->img != NULL){
        image_u32_t * img = state->img;
        vx_object_t * o3 = vxo_image_texflags(vx_resc_copyui(img->buf, img->stride*img->height),
                                              img->width, img->height, img->stride,
                                              GL_RGBA, VXO_IMAGE_FLIPY,
                                              VX_TEX_MIN_FILTER | VX_TEX_MAG_FILTER);

        // pack the image into the unit square
        vx_buffer_t * vb = vx_world_get_buffer(world, "texture");
        vx_buffer_add_back(vb,vxo_chain(
                               vxo_mat_scale(1.0/img->height),
                               vxo_mat_translate3(0, - img->height, 0),
                                        o3));
        vx_buffer_swap(vb);
    }
}
Ejemplo n.º 8
0
static void draw(state_t * state, vx_world_t * world)
{
    // Draw from the vx shape library
    vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"), vxo_chain(vxo_mat_translate3(3.0,0,0),
                       vxo_mat_scale(2),
                       vxo_box(vxo_mesh_style(vx_orange))));
    vx_buffer_swap(vx_world_get_buffer(world, "fixed-cube"));

    // Draw some text
    if (1) {
        vx_object_t *vt = vxo_text_create(VXO_TEXT_ANCHOR_LEFT, "<<right>>hello!\n<<serif-italic-4>>line 2\nfoo<<#ff0000>>red<<sansserif-bold-30,#0000ff80>>blue semi\n<<serif-italic-4>>foo bar baz");
        vx_buffer_t *vb = vx_world_get_buffer(world, "text");
        vx_buffer_add_back(vb, vt);
        vx_buffer_swap(vb);
    }

    // Draw a custom ellipse:
    {
        int npoints = 35;
        float points[npoints*3];
        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = 5.0f*cosf(angle);
            float y = 8.0f*sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "ellipse"), vxo_lines(vx_resc_copyf (points, npoints*3),
                           npoints, GL_LINE_LOOP,
                           vxo_lines_style(vx_purple, 1.0f) ));
        vx_buffer_swap(vx_world_get_buffer(world, "ellipse"));
    }

    // Draw a sin wave
    {
        int npoints = 100;
        float points[npoints*3];

        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = i*.1;
            float y = sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "sin"), vxo_points(vx_resc_copyf (points, npoints*3), npoints,
                           vxo_points_style(vx_purple, 10.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "sin"));

    }

    // Draw a cos wave
    {
        int npoints = 100;
        float points[npoints*3];
        float colors[npoints*4];

        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = i*.1;
            float y = cosf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;

            float r = angle/(2*M_PI);
            float g = 0.3f;
            float b = 1.0f-(angle/(2*M_PI));

            colors[4*i + 0] = r;
            colors[4*i + 1] = g;
            colors[4*i + 2] = b;
            colors[4*i + 3] = 1.0f;

        }

        vx_buffer_add_back(vx_world_get_buffer(world, "cos"), vxo_points(vx_resc_copyf (points, npoints*3), npoints,
                           vxo_points_style_multi_colored(vx_resc_copyf(colors, npoints*4), 10.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "cos"));

    }

    // Draw a rose
    if (1) {
        int npoints = 100;
        float points[npoints*3];
        float colors[npoints*4];
        int k = 3;

        for (int i = 0; i < npoints; i++) {
            float angle = M_PI*i/npoints; // [0, Pi] for Odd

            float x = cosf(k*angle)*sin(angle);
            float y = cosf(k*angle)*cos(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;

            float r = angle/(M_PI);
            float g = 1.0f-(angle/(M_PI));
            float b = 0.3f;

            colors[4*i + 0] = r;
            colors[4*i + 1] = g;
            colors[4*i + 2] = b;
            colors[4*i + 3] = 1.0f;

        }

        vx_buffer_add_back(vx_world_get_buffer(world, "rose"), vxo_lines(vx_resc_copyf (points, npoints*3), npoints,
                           GL_LINE_LOOP,
                           vxo_lines_style_multi_colored(vx_resc_copyf(colors, npoints*4), 1.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "rose"));

    }


    if (1) { // draw a box with all the fixings
        vx_buffer_t * vb = vx_world_get_buffer(world, "rect");

        // should draw purple square, with green lines, all occluded by red corners.
        vx_buffer_add_back(vb, vxo_depth_test(0,vxo_chain(
                vxo_mat_translate2(-5,-5),
                vxo_rect(vxo_mesh_style(vx_purple),
                         vxo_lines_style(vx_green, 6.0f),
                         vxo_points_style(vx_red, 6.0f)))));
        vx_buffer_swap(vb);

    }

    // Draw a texture
    if (state->img != NULL) {
        image_u8_t * img = state->img;
        vx_object_t * o3 = vxo_image(vx_resc_copyub(img->buf, img->width*img->height*img->bpp),
                                     img->width, img->height, img->bpp == 4? GL_RGBA : GL_RGB, VXO_IMAGE_FLIPY);

        // pack the image into the unit square
        vx_buffer_t * vb = vx_world_get_buffer(world, "texture");
        vx_buffer_add_back(vb, vxo_chain(vxo_mat_scale3(1.0/img->width, 1.0/img->height, 1), o3));
        vx_buffer_swap(vb);
    }
}
Ejemplo n.º 9
0
void * camera_loop(void * data)
{
    state_t * state = data;

    sleep(2); // wait for 2 seconds before starting the animation

    matd_t * zaxis = matd_create(3,1);
    zaxis->data[2] = 1;

    vx_buffer_add_back(vx_world_get_buffer(state->world, "cam-circle"), vxo_chain(vxo_mat_scale(CAM_RADIUS),
                       vxo_circle(vxo_lines_style(vx_green, 3))));
    vx_buffer_swap(vx_world_get_buffer(state->world, "cam-circle"));


    int64_t start_mtime =  vx_util_mtime();
    // tell each layer to follow
    pthread_mutex_lock(&state->mutex);
    {
        zhash_iterator_t itr;
        zhash_iterator_init(state->layers, &itr);
        vx_display_t * key;
        vx_layer_t * vl;

        while(zhash_iterator_next(&itr, &key, &vl)) {
            if (1) {
                float eye3[] = {CAM_RADIUS,-CAM_RADIUS,45.0f};
                float lookat3[] = {CAM_RADIUS,0,0.0f};
                float up3[] = {0,1,0};
                vx_layer_camera_lookat(vl, eye3, lookat3, up3, 0);
            }
        }
    }
    pthread_mutex_unlock(&state->mutex);

    while (state->running) {
        // 5 seconds revolutions
        double rad = ( (vx_util_mtime() - start_mtime) % 5000) * 2* M_PI / 5e3;

        // compute the current position and orientation of the "robot"
        matd_t * orientation = matd_angle_axis_to_quat(rad, zaxis);
        matd_t * pos =  matd_create(3,1);
        pos->data[0] = cos(rad) * CAM_RADIUS;
        pos->data[1] = sin(rad) * CAM_RADIUS;

        // tell each layer to follow
        pthread_mutex_lock(&state->mutex);
        {
            zhash_iterator_t itr;
            zhash_iterator_init(state->layers, &itr);
            vx_display_t * key;
            vx_layer_t * vl;

            while(zhash_iterator_next(&itr, &key, &vl)) {
                vx_layer_camera_follow(vl, pos->data, orientation->data, 1);
            }
        }
        pthread_mutex_unlock(&state->mutex);


        vx_buffer_add_back(vx_world_get_buffer(state->world, "robot-proxy"),
                           vxo_chain(vxo_mat_quat_pos(orientation->data, pos->data),
                                     vxo_box(vxo_lines_style(vx_purple, 3))));
        vx_buffer_swap(vx_world_get_buffer(state->world, "robot-proxy"));


        matd_destroy(orientation);
        matd_destroy(pos);

        usleep(100000);
    }

    matd_destroy(zaxis);

    return NULL;
}