-
X-Received: by 10.31.3.169 with SMTP id f41mr493586vki.16.1506808084053; Sat, 30 Sep
2017 14:48:04 -0700 (PDT)
X-Received: by 10.31.3.169 with SMTP id f41mr493586vki.16.1506808084053; Sat, 30 Sep
2017 14:48:04 -0700 (PDT)
Path: news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!go
blin3!goblin.stu.neva.ru!news.misty.com!border2.nntp.dca1.giganews.com!nntp.gig
anews.com!d13no108454qta.0!news-out.google.com!s33ni128qtj.1!nntp.google.com!b1
no1938357qtc.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-m
ail
Newsgroups: pl.comp.programming
Date: Sat, 30 Sep 2017 14:48:03 -0700 (PDT)
Complaints-To: g...@g...com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=5.172.255.112;
posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.112
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d...@g...com>
Subject: how 2 speed up rotozoomer
From: fir <p...@g...com>
Injection-Date: Sat, 30 Sep 2017 21:48:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 98
Xref: news-archive.icm.edu.pl pl.comp.programming:211544
[ ukryj nagłówki ]rotozumer is a routine that displays bitmap
on screen (which is also a bitmap so this is like
copying bitmap onto bitmap) but the input bitmap
(you may call it 'sprite') will be rotated by given angle and scaled by given zoom
the method is just to iterate on spirite all pixels, totate them (this is multiply by
rotated base vectors that
sescribes rotation and zoom) and set this roteted zoomed pixels to screen (yet if
zoom is like 2.0 the sampling of the input should be not by +1 step but more like
+0.5 to not make holes in output)
my unoptymised and not much edited for names etc function for this is that
inline void Rotate2d(float* x, float* y, float angle)
{
float xt = (*x) * cos(angle*degree360) - (*y) * sin(angle*degree360);
float yt = (*x) * sin(angle*degree360) + (*y) * cos(angle*degree360);
*x = xt;
*y = yt;
}
void DrawSprite2(float pos_x,
float pos_y,
char* file,
int sprite_bitmap_pos_x,
int sprite_bitmap_pos_y,
int sprite_bitmap_end_x,
int sprite_bitmap_end_y,
float angle = 0 ,
float zoom = 1,
int sprite_centre_bitmap_x = -1,
int sprite_centre_bitmap_y = -1
)
{
if(sprite_centre_bitmap_x<0 || sprite_centre_bitmap_y<0)
{
sprite_centre_bitmap_x = (sprite_bitmap_pos_x + sprite_bitmap_end_x)/2;
sprite_centre_bitmap_y = (sprite_bitmap_pos_y + sprite_bitmap_end_y)/2;
}
float sprite_width = sprite_bitmap_end_x - sprite_bitmap_pos_x + 1 ;
float sprite_height = sprite_bitmap_end_y - sprite_bitmap_pos_y + 1;
float Ax = sprite_bitmap_pos_x - sprite_centre_bitmap_x ;
float Ay = sprite_bitmap_pos_y - sprite_centre_bitmap_y ;
float Bx = sprite_bitmap_end_x - sprite_centre_bitmap_x ;
float By = sprite_bitmap_pos_y - sprite_centre_bitmap_y ;
float Cx = sprite_bitmap_end_x - sprite_centre_bitmap_x ;
float Cy = sprite_bitmap_end_y - sprite_centre_bitmap_y ;
float Dx = sprite_bitmap_pos_x - sprite_centre_bitmap_x ;
float Dy = sprite_bitmap_end_y - sprite_centre_bitmap_y ;
Rotate2d(&Ax,&Ay, angle);
Rotate2d(&Bx,&By, angle);
// Rotate2d(&Cx,&Cy, angle);
Rotate2d(&Dx,&Dy, angle);
float dxdx = (Bx-Ax)/sprite_width;
float dydx = (By-Ay)/sprite_width;
float dxdy = (Dx-Ax)/sprite_height;
float dydy = (Dy-Ay)/sprite_height;
float x, y;
for(float j=sprite_bitmap_pos_y-sprite_centre_bitmap_y;
j<sprite_bitmap_end_y-sprite_centre_bitmap_y; j+=.7/zoom)
{
for(float i=sprite_bitmap_pos_x-sprite_centre_bitmap_x;
i<sprite_bitmap_end_x-sprite_centre_bitmap_x; i+=.7/zoom)
{
unsigned color = sprites_buf_[sprite_centre_bitmap_y +
int(j)][sprite_centre_bitmap_x + int(i)];
x = 0*sprite_centre_bitmap_x + i * dxdx*zoom + j*dxdy*zoom;
y = 0*sprite_centre_bitmap_y + i * dydx*zoom + j*dydy*zoom;
if(color==0) {} else SetPixelSafe(pos_x + x, pos_y + y, color);
}
}
}
the problem is clipping, if sprite is rotated positioned and zoomed often quite large
parts and a lot of pixels destinate out the screen - and here in that routine i clib
them all per pixel (in "SetPixelSafe")
this is much wastefull, and optimistation of this routine is very important as
sprites, esp big sprites or sprites that are zoomed to be big may take real lot of
time on cpu
(rotozuming big screen size or overscreen sprites sadly may take like 40 ms which is
deadly slow (where small ones may take like 1 ms which is ok)
so how to speed it up?
(id someone want to see how it runs i may ulpoad te win32 exe showing how it worx)
Następne wpisy z tego wątku
- 01.10.17 11:51 fir
Najnowsze wątki z tej grupy
- Prezydent SZAP/USONA Trump ułaskawił prezydenta Hondurasu Hernandeza skazanego na 45 lat więzienia
- Rosjanie chwalą się prototypem komputera kwantowego. "Najważniejszy projekt naukowy Rosji"
- A Szwajcarzy kombinują tak: FinalSpark grows human neurons from stem cells and connects them to electrode arrays
- Re: Najgorszy język programowania
- NOWY: 2025-09-29 Alg., Strukt. Danych i Tech. Prog. - komentarz.pdf
- Na grupie comp.os.linux.advocacy CrudeSausage twierdzi, że Micro$lop używa SI do szyfrowania formatu dok. XML
- Błąd w Sofcie Powodem Wymiany 3 Duńskich Fregat Typu Iver Huitfeldt
- Grok zaczął nadużywać wulgaryzmów i wprost obrażać niektóre znane osoby
- Can you activate BMW 48V 10Ah Li-Ion battery, connecting to CAN-USB laptop interface ?
- We Wrocławiu ruszyła Odra 5, pierwszy w Polsce komputer kwantowy z nadprzewodzącymi kubitami
- Ada-Europe - AEiC 2025 early registration deadline imminent
- John Carmack twierdzi, że gdyby gry były optymalizowane, to wystarczyły by stare kompy
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2025
- Linuks od wer. 6.15 przestanie wspierać procesory 486 i będzie wymagać min. Pentium
- ,,Polski przemysł jest w stanie agonalnym" - podkreślił dobitnie, wskazując na brak zamówień.
Najnowsze wątki
- 2026-01-08 Ślad węglowy
- 2026-01-08 Prezydent SZAP/USONA Trump ułaskawił prezydenta Hondurasu Hernandeza skazanego na 45 lat więzienia
- 2026-01-08 Prezydent SZAP/USONA Trump ułaskawił prezydenta Hondurasu Hernandeza skazanego na 45 lat więzienia
- 2026-01-08 Agora zwalnia grupowo, mimo że w firmie pojawiły się zyski, czyli załoga zapracowała na siebie
- 2026-01-08 Agora zwalnia grupowo, mimo że w firmie pojawiły się zyski, czyli załoga zapracowała na siebie
- 2026-01-08 Dlaczego wrzucenie szkolnego krzyża do śmieci to zbrodnia mniejsza od zgaszenia sejmowej menory?
- 2026-01-08 NR 5G -- mity, hity, kity, bez satelity...
- 2026-01-07 Oszustwa w go go
- 2026-01-07 Jaka myjka ultradźwiękowa?
- 2026-01-07 POCO
- 2026-01-07 Kraków => Konsultant Microsoft Dynamics AX/365 SCM Consultant - Servi
- 2026-01-07 Kraków => Microsoft Dynamics AX/365 SCM Consultant - Service & Suppor
- 2026-01-06 I kolejny
- 2026-01-06 Retro organizer ale współcześnie
- 2026-01-06 Bowling




5 Najlepszych Programów do Księgowości w Chmurze - Ranking i Porównanie [2025]