Skip to content

Commit e4feefd

Browse files
committed
SpriteHandler.h:
* Applying pre- and post-scaling of r and c axes in VectorSprite.
1 parent dee0741 commit e4feefd

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

SpriteHandler.h

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ class VectorSprite : public Sprite
763763
std::vector<std::unique_ptr<VectorFrame>> vector_frames;
764764

765765
float rot_rad = 0.f;
766+
float r_scale_pre = 1.f;
767+
float c_scale_pre = 1.f;
768+
float r_scale_post = 1.f;
769+
float c_scale_post = 1.f;
766770

767771
VectorFrame* fetch_frame(int anim_frame)
768772
{
@@ -774,16 +778,16 @@ class VectorSprite : public Sprite
774778
std::pair<Vec2, Vec2> calc_seg_world_pos_flt(const LineSeg& line_seg) const
775779
{
776780
const auto aspect_ratio = 1.5f;
777-
auto rr0 = line_seg.pos[0].r;
778-
auto cc0 = line_seg.pos[0].c;
779-
auto rr1 = line_seg.pos[1].r;
780-
auto cc1 = line_seg.pos[1].c;
781+
auto rr0 = r_scale_pre*line_seg.pos[0].r;
782+
auto cc0 = c_scale_pre*line_seg.pos[0].c;
783+
auto rr1 = r_scale_pre*line_seg.pos[1].r;
784+
auto cc1 = c_scale_pre*line_seg.pos[1].c;
781785
float C = std::cos(rot_rad);
782786
float S = std::sin(rot_rad);
783-
auto r0 = pos.r + (C*rr0 - S*cc0);
784-
auto c0 = pos.c + (S*rr0 + C*cc0)*aspect_ratio;
785-
auto r1 = pos.r + (C*rr1 - S*cc1);
786-
auto c1 = pos.c + (S*rr1 + C*cc1)*aspect_ratio;
787+
auto r0 = pos.r + r_scale_post*(C*rr0 - S*cc0);
788+
auto c0 = pos.c + c_scale_post*(S*rr0 + C*cc0)*aspect_ratio;
789+
auto r1 = pos.r + r_scale_post*(C*rr1 - S*cc1);
790+
auto c1 = pos.c + c_scale_post*(S*rr1 + C*cc1)*aspect_ratio;
787791
Vec2 p0 { r0, c0 };
788792
Vec2 p1 { r1, c1 };
789793
return { p0, p1 };
@@ -1064,6 +1068,30 @@ class VectorSprite : public Sprite
10641068
return math::rad2deg(rot_rad);
10651069
}
10661070

1071+
// Applied before rotation.
1072+
void set_rc_scale_pre(float r_s, float c_s)
1073+
{
1074+
r_scale_pre = r_s;
1075+
c_scale_pre = c_s;
1076+
}
1077+
1078+
// Applied before rotation.
1079+
void set_rc_scale_post(float r_s, float c_s)
1080+
{
1081+
r_scale_post = r_s;
1082+
c_scale_post = c_s;
1083+
}
1084+
1085+
std::pair<float, float> get_rc_scale_pre() const
1086+
{
1087+
return { r_scale_pre, c_scale_pre };
1088+
}
1089+
1090+
std::pair<float, float> get_rc_scale_post() const
1091+
{
1092+
return { r_scale_post, c_scale_post };
1093+
}
1094+
10671095
template<int NR, int NC>
10681096
bool draw(ScreenHandler<NR, NC>& sh, int sim_frame)
10691097
{

0 commit comments

Comments
 (0)