void
DpadRestrictorModifier::update(int msec_delta, XboxGenericMsg& msg)
{
  switch(m_mode)
  {
    case kRestrictFourWay:
      if (get_axis(msg, XBOX_AXIS_DPAD_X) && get_axis(msg, XBOX_AXIS_DPAD_Y))
      {
        // a diagonal was pressed, thus we reset the axis that wasn't
        // pressed the last time the dpad was touched
        set_axis(msg, m_last_unpressed_axis, 0);
      }
      else if (get_axis(msg, XBOX_AXIS_DPAD_X))
      {
        m_last_unpressed_axis = XBOX_AXIS_DPAD_Y;
      }
      else if (get_axis(msg, XBOX_AXIS_DPAD_Y))
      {
        m_last_unpressed_axis = XBOX_AXIS_DPAD_X;
      }
      break;

    case kRestrictXAxis:
      set_axis(msg, XBOX_AXIS_DPAD_Y, 0);
      break;

    case kRestrictYAxis:
      set_axis(msg, XBOX_AXIS_DPAD_X, 0);
      break;
  }
}
void
UInputMessageProcessor::send(const XboxGenericMsg& msg_in, int msec_delta)
{
    if (!m_config->empty())
    {
        XboxGenericMsg msg = msg_in;

        if (m_rumble_test)
        {
            log_debug("rumble: " << get_axis(msg, XBOX_AXIS_LT) << " " << get_axis(msg, XBOX_AXIS_RT));

            set_rumble(get_axis(msg, XBOX_AXIS_LT),
                       get_axis(msg, XBOX_AXIS_RT));
        }

        // handling switching of configurations
        if (m_config_toggle_button != XBOX_BTN_UNKNOWN)
        {
            bool last = get_button(m_oldmsg, m_config_toggle_button);
            bool cur  = get_button(msg, m_config_toggle_button);

            if (cur && cur != last)
            {
                // reset old mapping to zero to not get stuck keys/axis
                m_config->get_config()->get_uinput().reset_all_outputs();

                // switch to the next input mapping
                m_config->next_config();

                log_info("switched to config: " << m_config->get_current_config());
            }
        }

        // run the controller message through all modifier
        for(std::vector<ModifierPtr>::iterator i = m_config->get_config()->get_modifier().begin();
                i != m_config->get_config()->get_modifier().end();
                ++i)
        {
            (*i)->update(msec_delta, msg);
        }

        m_config->get_config()->get_uinput().update(msec_delta);

        // send current Xbox state to uinput
        if (memcmp(&msg, &m_oldmsg, sizeof(XboxGenericMsg)) != 0)
        {
            // Only send a new event out if something has changed,
            // this is useful since some controllers send events
            // even if nothing has changed, deadzone can cause this
            // too
            m_oldmsg = msg;

            m_config->get_config()->get_uinput().send(msg);
        }
    }
}
void
FourWayRestrictorModifier::update(int msec_delta, XboxGenericMsg& msg)
{
  // left Stick
  if (abs(get_axis(msg, XBOX_AXIS_X1)) > abs(get_axis(msg, XBOX_AXIS_Y1)))
  {
    set_axis(msg, XBOX_AXIS_Y1, 0);
  }
  else if (abs(get_axis(msg, XBOX_AXIS_Y1)) > abs(get_axis(msg, XBOX_AXIS_X1)))
  {
    set_axis(msg, XBOX_AXIS_X1, 0);
  }
  else
  {
    set_axis(msg, XBOX_AXIS_X1, 0);
  }

  // right stick
  if (abs(get_axis(msg, XBOX_AXIS_X2)) > abs(get_axis(msg, XBOX_AXIS_Y2)))
  {
    set_axis(msg, XBOX_AXIS_Y2, 0);
  }
  else if (abs(get_axis(msg, XBOX_AXIS_Y2)) > abs(get_axis(msg, XBOX_AXIS_X2)))
  {
    set_axis(msg, XBOX_AXIS_X2, 0);
  }
  else
  {
    set_axis(msg, XBOX_AXIS_X2, 0);
  }
}
static int set_display_axis(int recovery)
{
    int fd;
    char *path = "/sys/class/display/axis";
    char str[128];
    int count, i;
    fd = open(path, O_CREAT|O_RDWR | O_TRUNC, 0644);
    if (fd >= 0) {
        if (!recovery) {
            read(fd, str, 128);
            printf("read axis %s, length %d\n", str, strlen(str));
            count = get_axis(str, 8, axis);
        }
        if (recovery) {
            sprintf(str, "0 %d %d %d %d %d %d %d", 
                axis[0],axis[1], axis[2], axis[3], axis[4], axis[5], axis[6], axis[7]);
        } else {
            sprintf(str, "2048 %d %d %d %d %d %d %d", 
                axis[1], axis[2], axis[3], axis[4], axis[5], axis[6], axis[7]);
        }
        write(fd, str, strlen(str));
        close(fd);
        return 0;
    }

    return -1;
}
示例#5
0
void quat::set_angle(float f)
{
    vec3 axis = get_axis();

    s = (float) cos( DEG2RAD( f ) / 2.0 );

    v = axis * (float) sin(DEG2RAD(f) / 2.0);
}
示例#6
0
void Matrix3::orthonormalize() {

	// Gram-Schmidt Process

	Vector3 x=get_axis(0);
	Vector3 y=get_axis(1);
	Vector3 z=get_axis(2);

	x.normalize();
	y = (y-x*(x.dot(y)));
	y.normalize();
	z = (z-x*(x.dot(z))-y*(y.dot(z)));
	z.normalize();

	set_axis(0,x);
	set_axis(1,y);
	set_axis(2,z);

}
示例#7
0
void Basis::orthonormalize() {
	ERR_FAIL_COND(determinant() == 0);

	// Gram-Schmidt Process

	Vector3 x=get_axis(0);
	Vector3 y=get_axis(1);
	Vector3 z=get_axis(2);

	x.normalize();
	y = (y-x*(x.dot(y)));
	y.normalize();
	z = (z-x*(x.dot(z))-y*(y.dot(z)));
	z.normalize();

	set_axis(0,x);
	set_axis(1,y);
	set_axis(2,z);

}
示例#8
0
/* This is the entry-point for the game! */
void c_start(void) {
    /* TODO:  You will need to initialize various subsystems here.  This
     *        would include the interrupt handling mechanism, and the various
     *        systems that use interrupts.  Once this is done, you can call
     *        enable_interrupts() to start interrupt handling, and go on to
     *        do whatever else you decide to do!
     */

    seed_rand_with_time();
    init_interrupts();
    init_keyboard();
    init_timer();
    enable_interrupts();

    int board[BOARD_SIZE][BOARD_SIZE] = { };
    animation_descriptor descriptor = { };
    initialize(board);
    int high_score = current_score(board);
    init_video(high_score);
    draw_board(board);
    
    /* Loop forever, so that we don't fall back into the bootloader code. */
    while (1) {
        if (!isemptyqueue()) {
            key k = dequeue();
            if (k == enter_key) {
                for (int *b = *board; b < *board + BOARD_SIZE * BOARD_SIZE; b++) *b = 0;
                initialize(board);
                init_video(high_score);
                draw_board(board);
                continue;
            } else {
                shift_direction direction = key_to_direction(k);

                // Setup animation
                copy_board(board, descriptor.board);
                descriptor.direction = direction;

                // Only add a box if the pieces actually move
                if (shift(board, direction, descriptor.offsets)) {
                    add_random_box(board);
                    int score = current_score(board);
                    if (score > high_score) high_score = score;
                    init_video(high_score);
                }
            }
            
            int num_frames = frame_count(descriptor.direction);
            int incr = get_axis(descriptor.direction) == horizontal_axis ? 12 : 2;
            int frame = 0;
            while (frame <= num_frames) {
                draw_board_frame(descriptor, frame);
                sleep(30);

                if (frame == num_frames) break;
                else frame = min(frame + incr, num_frames);
            }
            draw_board(board);
            
            if (!move_available(board)) {
                draw_failure_message();
            }
        }
    }
}
示例#9
0
void AnimatedSprite3D::_draw() {

	RID immediate = get_immediate();
	VS::get_singleton()->immediate_clear(immediate);

	if (!frames.is_valid() || !frames->get_frame_count(animation) || frame<0 || frame>=frames->get_frame_count(animation)) {
		return;
	}

	Ref<Texture> texture = frames->get_frame(animation,frame);
	if (!texture.is_valid())
		return; //no texuture no life
	Vector2 tsize = texture->get_size();
	if (tsize.x==0 || tsize.y==0)
		return;

	Size2i s=tsize;
	Rect2i src_rect;

	src_rect.size=s;

	Point2i ofs=get_offset();
	if (is_centered())
		ofs-=s/2;

	Rect2i dst_rect(ofs,s);


	Rect2 final_rect;
	Rect2 final_src_rect;
	if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
		return;


	if (final_rect.size.x==0 || final_rect.size.y==0)
		return;

	Color color=_get_color_accum();
	color.a*=get_opacity();

	float pixel_size=get_pixel_size();

	Vector2 vertices[4]={

		(final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
		(final_rect.pos+final_rect.size) * pixel_size,
		(final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
		final_rect.pos * pixel_size,


	};
	Vector2 uvs[4]={
		final_src_rect.pos / tsize,
		(final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
		(final_src_rect.pos+final_src_rect.size) / tsize,
		(final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
	};

	if (is_flipped_h()) {
		SWAP(uvs[0],uvs[1]);
		SWAP(uvs[2],uvs[3]);
	}
	if (is_flipped_v()) {

		SWAP(uvs[0],uvs[3]);
		SWAP(uvs[1],uvs[2]);
	}


	Vector3 normal;
	int axis = get_axis();
	normal[axis]=1.0;

	RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
	VS::get_singleton()->immediate_set_material(immediate,mat);

	VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());

	int x_axis = ((axis + 1) % 3);
	int y_axis = ((axis + 2) % 3);

	if (axis!=Vector3::AXIS_Z) {
		SWAP(x_axis,y_axis);

		for(int i=0;i<4;i++) {
			//uvs[i] = Vector2(1.0,1.0)-uvs[i];
			//SWAP(vertices[i].x,vertices[i].y);
			if (axis==Vector3::AXIS_Y) {
				vertices[i].y = - vertices[i].y;
			} else if (axis==Vector3::AXIS_X) {
				vertices[i].x = - vertices[i].x;
			}
		}
	}

	AABB aabb;

	for(int i=0;i<4;i++) {
		VS::get_singleton()->immediate_normal(immediate,normal);
		VS::get_singleton()->immediate_color(immediate,color);
		VS::get_singleton()->immediate_uv(immediate,uvs[i]);

		Vector3 vtx;
		vtx[x_axis]=vertices[i][0];
		vtx[y_axis]=vertices[i][1];
		VS::get_singleton()->immediate_vertex(immediate,vtx);
		if (i==0) {
			aabb.pos=vtx;
			aabb.size=Vector3();
		} else {
			aabb.expand_to(vtx);
		}
	}
	set_aabb(aabb);
	VS::get_singleton()->immediate_end(immediate);

}
示例#10
0
int amvideo_utils_set_virtual_position(int32_t x, int32_t y, int32_t w, int32_t h, int rotation)
{
    LOG_FUNCTION_NAME
	//for osd rotation, need convert the axis first
	int osd_rotation = amdisplay_utils_get_osd_rotation();
	if(osd_rotation > 0)
        amvideo_convert_axis(&x,&y,&w,&h,&rotation,osd_rotation);

    int video_fd;
    int dev_fd = -1, dev_w, dev_h, disp_w, disp_h, video_global_offset;
    int dst_x, dst_y, dst_w, dst_h;
    char buf[SYSCMD_BUFSIZE];
    int angle_fd = -1;
    int ret = -1;
    int axis[4];
    char enable_p2p_play[8] = {0};
    int video_on_vpp2 = is_video_on_vpp2();
    int vertical_panel = is_vertical_panel();
    int vertical_panel_reverse = is_vertical_panel_reverse();

    if (video_on_vpp2) {
        int fb0_w, fb0_h, fb2_w, fb2_h;

        amdisplay_utils_get_size(&fb0_w, &fb0_h);
        amdisplay_utils_get_size_fb2(&fb2_w, &fb2_h);

        if (fb0_w > 0 && fb0_h > 0 && fb2_w > 0 && fb2_h > 0) {
            if (vertical_panel) {
                int x1, y1, w1, h1;
                if (vertical_panel_reverse) {
                    x1 = (1.0 * fb2_w / fb0_h) * y;
                    y1 = (1.0 * fb2_h / fb0_w) * x;
                    w1 = (1.0 * fb2_w / fb0_h) * h;
                    h1 = (1.0 * fb2_h / fb0_w) * w;
                } else {
                    x1 = (1.0 * fb2_w / fb0_h) * y;
                    y1 = (1.0 * fb2_h / fb0_w) * (fb0_w - x - w);
                    w1 = (1.0 * fb2_w / fb0_h) * h;
                    h1 = (1.0 * fb2_h / fb0_w) * w;
                }
                x = x1;
                y = y1;
                w = w1;
                h = h1;
            } else {
                int x1, y1, w1, h1;
                x1 = (1.0 * fb2_w / fb0_w) * x;
                y1 = (1.0 * fb2_h / fb0_h) * y;
                w1 = (1.0 * fb2_w / fb0_w) * w;
                h1 = (1.0 * fb2_h / fb0_h) * h;
                x = x1;
                y = y1;
                w = w1;
                h = h1;
            }
        }
    }
    LOGI("amvideo_utils_set_virtual_position:: x=%d y=%d w=%d h=%d\n", x, y, w, h);

    bzero(buf, SYSCMD_BUFSIZE);

    dst_x = x;
    dst_y = y;
    dst_w = w;
    dst_h = h;

    video_fd = open(VIDEO_PATH, O_RDWR);
    if (video_fd < 0) {
        goto OUT;
    }

    dev_fd = open(DISP_DEVICE_PATH, O_RDONLY);
    if (dev_fd < 0) {
        goto OUT;
    }

    read(dev_fd, buf, SYSCMD_BUFSIZE);

    if (sscanf(buf, "%dx%d", &dev_w, &dev_h) == 2) {
        LOGI("device resolution %dx%d\n", dev_w, dev_h);
    } else {
        ret = -2;
        goto OUT;
    }

    if (video_on_vpp2)
        amdisplay_utils_get_size_fb2(&disp_w, &disp_h);
    else
        amdisplay_utils_get_size(&disp_w, &disp_h);

    LOGI("amvideo_utils_set_virtual_position:: disp_w=%d, disp_h=%d\n", disp_w, disp_h);

    video_global_offset = amvideo_utils_get_global_offset();

    int free_scale_enable = 0;
    int ppscaler_enable = 0;
    int freescale_mode_enable = 0;

    if (((disp_w != dev_w) || (disp_h / 2 != dev_h)) &&
        (video_global_offset == 0)) {
        char val[256];

        memset(val, 0, sizeof(val));
        if (video_on_vpp2) {
            if (amsysfs_get_sysfs_str(FREE_SCALE_PATH_FB2, val, sizeof(val)) == 0) {
                /* the returned string should be "free_scale_enable:[0x%x]" */
                free_scale_enable = (val[21] == '0') ? 0 : 1;
            }
        } else {
            if (amsysfs_get_sysfs_str(FREE_SCALE_PATH, val, sizeof(val)) == 0) {
                /* the returned string should be "free_scale_enable:[0x%x]" */
                free_scale_enable = (val[21] == '0') ? 0 : 1;
            }
        }

        memset(val, 0, sizeof(val));
        if (amsysfs_get_sysfs_str(PPSCALER_PATH, val, sizeof(val)) == 0) {
            /* the returned string should be "current ppscaler mode is disabled/enable" */
            ppscaler_enable = (val[25] == 'd') ? 0 : 1;
        }

        memset(val, 0, sizeof(val));
        if (amsysfs_get_sysfs_str(FREE_SCALE_MODE_PATH, val, sizeof(val)) == 0) {
            /* the returned string should be "free_scale_mode:new/default" */
            freescale_mode_enable = (val[16] == 'd') ? 0 : 1;
        }
    }

    angle_fd = open(ANGLE_PATH, O_WRONLY);
    if (angle_fd >= 0) {
        if (video_on_vpp2 && vertical_panel)
            ioctl(angle_fd, PPMGR_IOC_SET_ANGLE, 0);
        else
            ioctl(angle_fd, PPMGR_IOC_SET_ANGLE, (rotation/90) & 3);
        LOGI("set ppmgr angle %d\n", (rotation/90) & 3);
    }

    /* this is unlikely and only be used when ppmgr does not exist
     * to support video rotation. If that happens, we convert the window
     * position to non-rotated window position.
     * On ICS, this might not work at all because the transparent UI
     * window is still drawn is it's direction, just comment out this for now.
     */
#if 0
    if (((rotation == 90) || (rotation == 270)) && (angle_fd < 0)) {
        if (dst_h == disp_h) {
            int center = x + w / 2;

            if (abs(center - disp_w / 2) < 2) {
                /* a centered overlay with rotation, change to full screen */
                dst_x = 0;
                dst_y = 0;
                dst_w = dev_w;
                dst_h = dev_h;

                LOGI("centered overlay expansion");
            }
        }
    }
#endif
    /*if (free_scale_enable == 0 && ppscaler_enable == 0) {

        OSD_DISP_MODE display_mode = OSD_DISP_1080P;
        int x_d=0,y_d=0,w_d=0,h_d=0;
        LOGI("set screen position:x[%d],y[%d],w[%d],h[%d]", dst_x, dst_y, dst_w, dst_h);

        display_mode = get_osd_display_mode();
        get_device_win(display_mode, &x_d, &y_d, &w_d, &h_d);
        if(display_mode==OSD_DISP_720P) {
            if((dst_w >= 1279)||(dst_w==0)) {
                dst_x = x_d;
                dst_y = y_d;
                dst_w = w_d;
                dst_h = h_d;
            }
            else {
                dst_x = dst_x*w_d/1280+x_d;
                dst_y = dst_y*h_d/720+y_d;
                dst_w = dst_w*w_d/1280;
                dst_h = dst_h*h_d/720;
            }
        }
        else if((display_mode==OSD_DISP_1080I)||(display_mode==OSD_DISP_1080P)||(display_mode==OSD_DISP_LVDS1080P)) {
            if((dst_w >= 1919)||(dst_w == 0)) {
                dst_x = x_d;
                dst_y = y_d;
                dst_w = w_d;
                dst_h = h_d;
            }
            else {//scaled to 1080p
                dst_x = dst_x*w_d/1920+x_d;
                dst_y = dst_y*h_d/1080+y_d;
                dst_w = dst_w*w_d/1920;
                dst_h = dst_h*h_d/1080;

                LOGI("after scaled to 1080 ,set screen position:x[%d],y[%d],w[%d],h[%d]", dst_x, dst_y, dst_w, dst_h);
            }
        }
        else if((display_mode==OSD_DISP_480I)||(display_mode==OSD_DISP_480P)) {
            if((dst_w >= 719)||(dst_w == 0)) {
                dst_x = x_d;
                dst_y = y_d;
                dst_w = w_d;
                dst_h = h_d;
            }
            else {//scaled to 480p/480i
                dst_x = dst_x*w_d/720+x_d;
                dst_y = dst_y*h_d/480+y_d;
                dst_w = dst_w*w_d/720;
                dst_h = dst_h*h_d/480;

                LOGI("after scaled to 480,set screen position:x[%d],y[%d],w[%d],h[%d]", dst_x, dst_y, dst_w, dst_h);
            }
        }
        else if((display_mode==OSD_DISP_576I)||(display_mode==OSD_DISP_576P)) {
            if((dst_w >= 719)||(dst_w == 0)) {
                dst_x = x_d;
                dst_y = y_d;
                dst_w = w_d;
                dst_h = h_d;
            }
            else {//scaled to 576p/576i
                dst_x = dst_x*w_d/720+x_d;
                dst_y = dst_y*h_d/576+y_d;
                dst_w = dst_w*w_d/720;
                dst_h = dst_h*h_d/576;

                LOGI("after scaled to 576 ,set screen position:x[%d],y[%d],w[%d],h[%d]", dst_x, dst_y, dst_w, dst_h);
            }
        }
    }*/
    if (free_scale_enable == 0 && ppscaler_enable == 0) {
        char val[256];

        if (freescale_mode_enable == 1) {
            int left = 0, top = 0, right = 0, bottom = 0;
            int x = 0, y = 0, w = 0, h = 0;

            memset(val, 0, sizeof(val));
            if (amsysfs_get_sysfs_str(WINDOW_AXIS_PATH, val, sizeof(val)) == 0) {
                /* the returned string should be "window axis is [a b c d]" */
                if (sscanf(val + 15, "[%d %d %d %d]", &left, &top, &right, &bottom) == 4) {
                    x = left;
                    y = top;
                    w = right - left + 1;
                    h = bottom - top + 1;
                    if ((dst_w >= dev_w - 1) || (dst_w == 0)) {
                        dst_x = 0;
                        dst_w = w;
                    }
                    if ((dst_h >= dev_h - 1) || (dst_h == 0)) {
                        dst_y = 0;
                        dst_h = h;
                    }

                    dst_x = dst_x * w / dev_w + x;
                    dst_y = dst_y * h / dev_h + y;
                    LOGI("after scaled, screen position: %d %d %d %d", dst_x, dst_y, dst_w, dst_h);
                }
            }
        } else {
            int x = 0, y = 0, w = 0, h = 0;
            int fb_w = 0, fb_h = 0;
            int req_2xscale = 0;

            memset(val, 0, sizeof(val));
            if (amsysfs_get_sysfs_str(REQUEST_2XSCALE_PATH, val, sizeof(val)) == 0) {
                /* the returned string should be "a b c" */
                if (sscanf(val, "%d", &req_2xscale) == 1) {
                    if (req_2xscale == 7 || req_2xscale == 16) {
                        if (sscanf(val, "%d %d %d", &req_2xscale, &w, &h) == 3) {
                            if (req_2xscale == 7)
                                w *= 2;
                            get_axis(DISPLAY_AXIS_PATH, &x, &y, &fb_w, &fb_h);
                            if (fb_w == 0 || fb_h == 0) {
                                fb_w = 1280;
                                fb_h = 720;
                            }
                            set_scale(x, y, w, h, &dst_x, &dst_y, &dst_w, &dst_h, fb_w, fb_h);
                            LOGI("after scaled, screen position: %d %d %d %d", dst_x, dst_y, dst_w, dst_h);
                        }
                    }
                }
            }
        }
    } else if (free_scale_enable == 1 && ppscaler_enable == 0) {
        char val[256];
        int left = 0, top = 0, right = 0, bottom = 0;
        int x = 0, y = 0, w = 0, h = 0;
        int freescale_x = 0, freescale_y = 0, freescale_w = 0, freescale_h = 0;

        if (amsysfs_get_sysfs_str(WINDOW_AXIS_PATH, val, sizeof(val)) == 0) {
            /* the returned string should be "window axis is [a b c d]" */
            if (sscanf(val + 15, "[%d %d %d %d]", &left, &top, &right, &bottom) == 4) {
                x = left;
                y = top;
                w = right - left + 1;
                h = bottom - top + 1;

                get_axis(FREE_SCALE_AXIS_PATH, &freescale_x, &freescale_y, &freescale_w, &freescale_h);
                freescale_w = (freescale_w + 1) & (~1);
                freescale_h = (freescale_h + 1) & (~1);

                set_scale(x, y, w, h, &dst_x, &dst_y, &dst_w, &dst_h, freescale_w, freescale_h);
                LOGI("after scaled, screen position: %d %d %d %d", dst_x, dst_y, dst_w, dst_h);
            }
        }
    }

    axis[0] = dst_x;
    axis[1] = dst_y;
    axis[2] = dst_x + dst_w - 1;
    axis[3] = dst_y + dst_h - 1;

    ioctl(video_fd, AMSTREAM_IOC_SET_VIDEO_AXIS, &axis[0]);

    ret = 0;
OUT:
    if (video_fd >= 0) {
        close(video_fd);
    }

    if (dev_fd >= 0) {
        close(dev_fd);
    }

    if (angle_fd >= 0) {
        close(angle_fd);
    }
    LOGI("amvideo_utils_set_virtual_position (corrected):: x=%d y=%d w=%d h=%d\n", dst_x, dst_y, dst_w, dst_h);

    return ret;
}
示例#11
0
文件: sprite_3d.cpp 项目: 9cat/godot
void Sprite3D::_draw() {

	RID immediate = get_immediate();

	VS::get_singleton()->immediate_clear(immediate);
	if (!texture.is_valid())
		return; //no texuture no life
	Vector2 tsize = texture->get_size();
	if (tsize.x==0 || tsize.y==0)
		return;

	Size2i s;
	Rect2i src_rect;

	if (region) {

		s=region_rect.size;
		src_rect=region_rect;
	} else {
		s = texture->get_size();
		s=s/Size2i(hframes,vframes);

		src_rect.size=s;
		src_rect.pos.x+=(frame%hframes)*s.x;
		src_rect.pos.y+=(frame/hframes)*s.y;

	}

	Point2i ofs=get_offset();
	if (is_centered())
		ofs-=s/2;

	Rect2i dst_rect(ofs,s);


	Rect2 final_rect;
	Rect2 final_src_rect;
	if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
		return;


	if (final_rect.size.x==0 || final_rect.size.y==0)
		return;

	Color color=_get_color_accum();
	color.a*=get_opacity();

	float pixel_size=get_pixel_size();

	Vector2 vertices[4]={

		(final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
		(final_rect.pos+final_rect.size) * pixel_size,
		(final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
		final_rect.pos * pixel_size,


	};
	Vector2 uvs[4]={
		final_src_rect.pos / tsize,
		(final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
		(final_src_rect.pos+final_src_rect.size) / tsize,
		(final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
	};

	if (is_flipped_h()) {
		SWAP(uvs[0],uvs[1]);
		SWAP(uvs[2],uvs[3]);
	}
	if (is_flipped_v()) {

		SWAP(uvs[0],uvs[3]);
		SWAP(uvs[1],uvs[2]);
	}


	Vector3 normal;
	int axis = get_axis();
	normal[axis]=1.0;

	RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
	VS::get_singleton()->immediate_set_material(immediate,mat);

	VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());

	int x_axis = ((axis + 1) % 3);
	int y_axis = ((axis + 2) % 3);

	AABB aabb;

	for(int i=0;i<4;i++) {
		VS::get_singleton()->immediate_normal(immediate,normal);
		VS::get_singleton()->immediate_color(immediate,color);
		VS::get_singleton()->immediate_uv(immediate,uvs[i]);

		Vector3 vtx;
		vtx[x_axis]=vertices[i][x_axis];
		vtx[y_axis]=vertices[i][y_axis];
		VS::get_singleton()->immediate_vertex(immediate,vtx);
		if (i==0) {
			aabb.pos=vtx;
			aabb.size=Vector3();
		} else {
			aabb.expand_to(vtx);
		}
	}
	set_aabb(aabb);
	VS::get_singleton()->immediate_end(immediate);


}
示例#12
0
void Sprite3D::_draw() {

	RID immediate = get_immediate();

	VS::get_singleton()->immediate_clear(immediate);
	if (!texture.is_valid())
		return; //no texuture no life
	Vector2 tsize = texture->get_size();
	if (tsize.x == 0 || tsize.y == 0)
		return;

	Size2i s;
	Rect2i src_rect;

	if (region) {

		s = region_rect.size;
		src_rect = region_rect;
	} else {
		s = texture->get_size();
		s = s / Size2i(hframes, vframes);

		src_rect.size = s;
		src_rect.position.x += (frame % hframes) * s.x;
		src_rect.position.y += (frame / hframes) * s.y;
	}

	Point2i ofs = get_offset();
	if (is_centered())
		ofs -= s / 2;

	Rect2i dst_rect(ofs, s);

	Rect2 final_rect;
	Rect2 final_src_rect;
	if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
		return;

	if (final_rect.size.x == 0 || final_rect.size.y == 0)
		return;

	Color color = _get_color_accum();
	color.a *= get_opacity();

	float pixel_size = get_pixel_size();

	Vector2 vertices[4] = {

		(final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size,
		(final_rect.position + final_rect.size) * pixel_size,
		(final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size,
		final_rect.position * pixel_size,

	};

	Vector2 src_tsize = tsize;

	// Properly setup UVs for impostor textures (AtlasTexture).
	Ref<AtlasTexture> atlas_tex = texture;
	if (atlas_tex != NULL) {
		src_tsize[0] = atlas_tex->get_atlas()->get_width();
		src_tsize[1] = atlas_tex->get_atlas()->get_height();
	}

	Vector2 uvs[4] = {
		final_src_rect.position / src_tsize,
		(final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / src_tsize,
		(final_src_rect.position + final_src_rect.size) / src_tsize,
		(final_src_rect.position + Vector2(0, final_src_rect.size.y)) / src_tsize,
	};

	if (is_flipped_h()) {
		SWAP(uvs[0], uvs[1]);
		SWAP(uvs[2], uvs[3]);
	}
	if (is_flipped_v()) {

		SWAP(uvs[0], uvs[3]);
		SWAP(uvs[1], uvs[2]);
	}

	Vector3 normal;
	int axis = get_axis();
	normal[axis] = 1.0;

	RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS);
	VS::get_singleton()->immediate_set_material(immediate, mat);

	VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());

	int x_axis = ((axis + 1) % 3);
	int y_axis = ((axis + 2) % 3);

	if (axis != Vector3::AXIS_Z) {
		SWAP(x_axis, y_axis);

		for (int i = 0; i < 4; i++) {
			//uvs[i] = Vector2(1.0,1.0)-uvs[i];
			//SWAP(vertices[i].x,vertices[i].y);
			if (axis == Vector3::AXIS_Y) {
				vertices[i].y = -vertices[i].y;
			} else if (axis == Vector3::AXIS_X) {
				vertices[i].x = -vertices[i].x;
			}
		}
	}

	AABB aabb;

	for (int i = 0; i < 4; i++) {
		VS::get_singleton()->immediate_normal(immediate, normal);
		VS::get_singleton()->immediate_color(immediate, color);
		VS::get_singleton()->immediate_uv(immediate, uvs[i]);

		Vector3 vtx;
		vtx[x_axis] = vertices[i][0];
		vtx[y_axis] = vertices[i][1];
		VS::get_singleton()->immediate_vertex(immediate, vtx);
		if (i == 0) {
			aabb.position = vtx;
			aabb.size = Vector3();
		} else {
			aabb.expand_to(vtx);
		}
	}
	set_aabb(aabb);
	VS::get_singleton()->immediate_end(immediate);
}
示例#13
0
static int
get_data(gboolean read_data_only, char *filename, char *datachannel_name,
         double *data[], int *dimensions[], char **unit,
         G_GNUC_UNUSED gboolean *scattered)
{
    dataFormat format = UNKNOWN_DATAFORMAT;
    codingTypes coding = UNKNOWN_CODING;
    byteOrder byte_order = UNKNOWN_BYTEORDER;
    int ret, i;
    int state = 0;
    GArray *axes, *names, *units, *axis;
    const xmlChar *name, *value, *read_method_name;
    xmlChar *id;
    xmlTextReaderPtr reader;
    int data_dimension = -1;
    int out_len;
    int max_input_len = 1;

    gwy_debug("read only: %d,  channel name==%s", read_data_only,
              datachannel_name);
    *dimensions = NULL;

    reader = xmlReaderForFile(filename, NULL, 0);

    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
            /* process node */
            name = xmlTextReaderConstName(reader);
            if (name == NULL) {
                /* no datachannels */
                return -1;
            }
            if (state == 0
                && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT
                && strcmp(name, "DataChannel") == 0) {
                id = xmlTextReaderGetAttribute(reader, "name");
                if (id && strcmp(id, datachannel_name) == 0) {
                    format =
                        get_data_format(xmlTextReaderGetAttribute
                                        (reader, "dataFormat"));
                    coding =
                        get_data_coding(xmlTextReaderGetAttribute
                                        (reader, "coding"));
                    byte_order =
                        get_byteorder(xmlTextReaderGetAttribute
                                      (reader, "byteOrder"));
                    if (read_data_only == FALSE) {
                        /* when read_data_only is true, we skip dimensions array to prevent
                           infinite cycle when calling from get_axis to get non equidistant axis from
                           datachannel */
                        read_method_name =
                            xmlTextReaderGetAttribute(reader,
                                                      "channelReadMethodName");
                        if (read_method_name == NULL) {
                            /* sequence of one dimensional values */
                            *dimensions = NULL;
                        }
                        else {
                            g_free((char *)read_method_name);
                            /* get axes */
                            data_dimension =
                                get_axis(filename, datachannel_name, &axes,
                                         &names, &units);
                            if (data_dimension != 2) {
                                g_warning
                                    ("SPML: get_data(): Input data are in %d dimension(s).",
                                     data_dimension);
                            }
                            /* one dimension array */
                            if (data_dimension > 0) {
                                *dimensions =
                                    g_malloc(sizeof(int) * data_dimension);
                                for (i = 0; i < data_dimension; i++) {
                                    axis = g_array_index(axes, GArray *, i);
                                    (*dimensions)[i] = axis[0].len;
                                    max_input_len *= axis[0].len;
                                }
                            }
                            else {
                                *dimensions = NULL;
                            }
                            /* free what get_axis allocated */
                            if (axes) {
                                for (i = 0; i < axes->len; i++) {
                                    g_array_free(g_array_index
                                                 (axes, GArray *, i), TRUE);
                                }
                                g_array_free(axes, TRUE);
                            }
                            if (names)
                                g_array_free(names, TRUE);
                            if (units)
                                g_array_free(units, TRUE);
                        }