本文整理汇总了C++中RenderBatchTriangle::draw_sprite方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderBatchTriangle::draw_sprite方法的具体用法?C++ RenderBatchTriangle::draw_sprite怎么用?C++ RenderBatchTriangle::draw_sprite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RenderBatchTriangle
的用法示例。
在下文中一共展示了RenderBatchTriangle::draw_sprite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//.........这里部分代码省略.........
target_rotation_hotspot.x = float(pixDestX + target_rotation_hotspot.x * p_scale.x);
target_rotation_hotspot.y = float(pixDestY + target_rotation_hotspot.y * p_scale.y);
// Calculate unit vectors for rotated surface:
// (cached for speed reasons)
static float vect_rotate_x[2] = { 1.0f, 0.0f };
static float vect_rotate_y[2] = { 0.0f, 1.0f };
static Angle last_angle(0, angle_radians);
Angle target_rotate_angle = angle - base_angle;
if (last_angle != target_rotate_angle)
{
float angle_degrees = target_rotate_angle.to_degrees();
if (angle_degrees == 0.0f)
{
vect_rotate_x[0] = 1.0;
vect_rotate_x[1] = 0.0;
vect_rotate_y[0] = 0.0;
vect_rotate_y[1] = 1.0;
}
else if (angle_degrees == 90.0f)
{
vect_rotate_x[0] = 0.0;
vect_rotate_x[1] = 1.0;
vect_rotate_y[0] = -1.0;
vect_rotate_y[1] = 0.0;
}
else if (angle_degrees == 180.0f)
{
vect_rotate_x[0] = -1.0;
vect_rotate_x[1] = 0.0;
vect_rotate_y[0] = 0.0;
vect_rotate_y[1] = -1.0;
}
else if (angle_degrees == 270.0f)
{
vect_rotate_x[0] = 0.0;
vect_rotate_x[1] = -1.0;
vect_rotate_y[0] = 1.0;
vect_rotate_y[1] = 0.0;
}
else
{
float angle_rad = target_rotate_angle.to_radians();
vect_rotate_x[0] = cos(angle_rad);
vect_rotate_x[1] = sin(angle_rad);
vect_rotate_y[0] = cos(PI/2+angle_rad);
vect_rotate_y[1] = sin(PI/2+angle_rad);
}
}
// Calculate final source rectangle points for render:
const Texture2D &texture = frames[current_frame].texture;
float texture_width = texture.get_width();
float texture_height = texture.get_height();
Pointf texture_position[4]; // Scaled to the range of 0.0f to 1.0f
Pointf dest_position[4];
texture_position[0].x = (((float) p_src.left) ) / texture_width;
texture_position[1].x = (((float) p_src.left+src_width) ) / texture_width;
texture_position[2].x = (((float) p_src.left) ) / texture_width;
texture_position[3].x = (((float) p_src.left+src_width) ) / texture_width;
texture_position[0].y = (((float) p_src.top) ) / texture_height;
texture_position[1].y = (((float) p_src.top) ) / texture_height;
texture_position[2].y = (((float) p_src.top+src_height) ) / texture_height;
texture_position[3].y = (((float) p_src.top+src_height) ) / texture_height;
// Calculate final destination rectangle points for surface rectangle:
if (target_rotate_angle.to_radians() == 0.0f)
{
dest_position[0].x = pixDestX;
dest_position[1].x = pixDestX+destWidth;
dest_position[2].x = pixDestX;
dest_position[3].x = pixDestX+destWidth;
dest_position[0].y = pixDestY;
dest_position[1].y = pixDestY;
dest_position[2].y = pixDestY+destHeight;
dest_position[3].y = pixDestY+destHeight;
}
else
{
// Roll
dest_position[0].x = calc_rotate_x(pixDestX, pixDestY, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[0], vect_rotate_y[0]);
dest_position[1].x = calc_rotate_x(pixDestX+destWidth, pixDestY, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[0], vect_rotate_y[0]);
dest_position[2].x = calc_rotate_x(pixDestX, pixDestY+destHeight, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[0], vect_rotate_y[0]);
dest_position[3].x = calc_rotate_x(pixDestX+destWidth, pixDestY+destHeight, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[0], vect_rotate_y[0]);
dest_position[0].y = calc_rotate_y(pixDestX, pixDestY, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[1], vect_rotate_y[1]);
dest_position[1].y = calc_rotate_y(pixDestX+destWidth, pixDestY, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[1], vect_rotate_y[1]);
dest_position[2].y = calc_rotate_y(pixDestX, pixDestY+destHeight, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[1], vect_rotate_y[1]);
dest_position[3].y = calc_rotate_y(pixDestX+destWidth, pixDestY+destHeight, target_rotation_hotspot.x, target_rotation_hotspot.y, vect_rotate_x[1], vect_rotate_y[1]);
}
RenderBatchTriangle *batcher = canvas.impl->batcher.get_triangle_batcher();
batcher->draw_sprite(canvas, texture_position, dest_position, frames[current_frame].texture, color);
}