Ejemplo n.º 1
0
void motion_reset(int16_t position)
// Reset the motion buffer to the specified position.  The enabled state is preserved.
{
    // Reset the counter.
    motion_counter = 0;

    // Reset the duration.
    motion_duration = 0;

    // Reset the queue.
    motion_head = 0;
    motion_tail = 0;

    // Reset the keypoint.
    keys[0].delta = 0;
    keys[0].position = int_to_float(position);
    keys[0].in_velocity = 0.0;
    keys[0].out_velocity = 0.0;

    // Initialize an empty hermite curve.  This is a degenerate case for the hermite
    // curve that will always return the position of the curve without velocity.
    curve_init(0, 0, keys[0].position, keys[0].position, 0.0, 0.0);

    // Reset the registers.
    motion_registers_reset();
}
Ejemplo n.º 2
0
float __floatsisf(int i)
{
	float_t res;
	
	res.data = int_to_float(i);
	return res.val;
}
Ejemplo n.º 3
0
	int text_entry::get_cursor_caret_pos(const point& cursor_pos) const {
		int cursor_caret_pos = _visible_pos;

		int text_area_left = get_text_area().get_left();
		if (cursor_pos._x >= text_area_left) {
			
			auto& font = get_font();
			float font_size = get_font_size();

			std::wstring visible_text = _text;
			raw_text_to_visible_text(visible_text);
			
			int text_length = uint_to_int(visible_text.length());
			while (cursor_caret_pos < text_length) {
				float width_a = font.get_text_width(font_size, visible_text.c_str(), _visible_pos, cursor_caret_pos - _visible_pos);
				float width_b = font.get_text_width(font_size, visible_text.c_str(), _visible_pos, cursor_caret_pos - _visible_pos + 1);
				float width_extra = (width_b - width_a) / 2.f;
				if (cursor_pos._x < (int_to_float(text_area_left) + width_a + width_extra)) {
					break;
				}
				cursor_caret_pos++;
			}
		}

	 	return cursor_caret_pos;
	}
Ejemplo n.º 4
0
uint8_t motion_append(void)
// Append a new curve keypoint from data stored in the curve registers.  The keypoint
// is offset from the previous curve by the specified delta.  An error is returned if
// there is no more room to store the new keypoint in the buffer or if the delta is
// less than one (a zero delta is not allowed).
{
    int16_t position;
    int16_t in_velocity;
    int16_t out_velocity;
    uint8_t next;
    uint16_t delta;

    // Get the next index in the buffer.
    next = (motion_head + 1) & MOTION_BUFFER_MASK;

    // Return error if we have looped the head to the tail and the buffer is filled.
    if (next == motion_tail) return 0;

    // Get the position, velocity and time delta values from the registers.
    position = (int16_t) registers_read_word(REG_CURVE_POSITION_HI, REG_CURVE_POSITION_LO);
    in_velocity = (int16_t) registers_read_word(REG_CURVE_IN_VELOCITY_HI, REG_CURVE_IN_VELOCITY_LO);
    out_velocity = (int16_t) registers_read_word(REG_CURVE_OUT_VELOCITY_HI, REG_CURVE_OUT_VELOCITY_LO);
    delta = (uint16_t) registers_read_word(REG_CURVE_DELTA_HI, REG_CURVE_DELTA_LO);

    // Keypoint delta must be greater than zero.
    if (delta < 1) return 0;

    // Fill in the next keypoint.
    keys[next].delta = delta;
    keys[next].position = int_to_float(position);
    keys[next].in_velocity = fixed_to_float(in_velocity);
    keys[next].out_velocity = fixed_to_float(out_velocity);

    // Is this keypoint being added to an empty buffer?
    if (motion_tail == motion_head)
    {
        // Initialize a new hermite curve that gets us from the current position to the new position.
        // We use a velocity of zero at each end to smoothly transition from one to the other.
        curve_init(0, delta, curve_get_p1(), keys[next].position, 0.0, 0.0);
    }

    // Increase the duration of the buffer.
    motion_duration += delta;

    // Set the new head index.
    motion_head = next;

    // Reset the motion registers and update the buffer status.
    motion_registers_reset();

    return 1;
}
Ejemplo n.º 5
0
	bool viewport::try_unproject(vec3& world_position, const mat44& view_projection_transform, const point& screen_position) const {
		if (_width == 0 || _height == 0) {
			return false;
		}

		vec4 in;
		in._x = ((int_to_float(screen_position._x - uint_to_int(_x)) / uint_to_float(_width)) * 2.f) - 1.f;
		in._y = ((int_to_float(screen_position._y - uint_to_int(_y)) / uint_to_float(_height)) * 2.f) - 1.f;
		in._y *= -1.f;
		in._z = 0.f; //0 = near plane, 1 = far plane
		in._w = 1.f;

		vec4 out = in * make_mat44_inverted(view_projection_transform);

		if (is_approx(out._w, 0.f, 0.0001f)) {
			return false;
		}

		world_position._x = out._x / out._w;
		world_position._y = out._y / out._w;
		world_position._z = out._z / out._w;
		return true;
	}
Ejemplo n.º 6
0
	float calculate_best_area_scale(const size& desired_size, const size& current_size) {
		if (
			desired_size._width <= 0 || desired_size._height <= 0 ||
			current_size._width <= 0 || current_size._height <= 0) {
			return 1.f;
		}

		float desired_aspect_ratio = int_to_float(desired_size._width) / int_to_float(desired_size._height);
		float current_aspect_ratio = int_to_float(current_size._width) / int_to_float(current_size._height);

		if (current_aspect_ratio >= desired_aspect_ratio) {
			return int_to_float(current_size._height) / int_to_float(desired_size._height);
		}
		else {
			return int_to_float(current_size._width) / int_to_float(desired_size._width);
		}
	}