Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Игры";
Текущий архив: 2003.08.21;
Скачать: [xml.tar.bz2];

Вниз

Нужен алогритм поворота картинки   Найти похожие ветки 

 
Kolya   (2002-10-21 04:17) [0]

Может кто- нибудь поделиться алгоритмом поворота картинки на произвольный угол? Лень самому велосипед изобретать!
Спасибо!


 
Rouse_   (2002-10-21 04:24) [1]

function TForm1.BmpRot(const B: TBitmap;fi:integer):TBitmap;
type
TRGBTripleArray = array[0..1023] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
x0,y0,i,j,x1,y1,x11,y11,x2,y2:integer;
ht,wd,newht,newwd:integer;
cfi,sfi: double;
sline1,sline2: pRGBTRipleArray;
BEGIN
sfi:=sin(degtorad(fi));
cfi:=cos(degtorad(fi));
ht:=b.height;
wd:=b.width;
newwd:=abs(round(ht*sfi))+abs(round(wd*cfi));
newht:=abs(round(wd*sfi))+abs(round(ht*cfi));
Result:=TBitmap.create;
Result.Width:=newwd;
Result.Height:=newht;
Result.PixelFormat:=pf24bit;
x0:=wd div 2;
y0:=ht div 2;
for j :=newht-1 downto 0 do begin
sline2 := Result.scanline[j];
y1:= 2*(j-(newht-ht) div 2 -y0)+1;
for i := newwd-1 downto 0 do begin
x1:=2*(i-(newwd-wd) div 2 -x0)+1;
x2 :=round(x1 * cfi - y1 * sfi);
y2 :=round(x1 * sfi + y1 * cfi);
x11:=(x2-1) div 2 +x0;
y11:=(y2-1) div 2 +y0;
( x11>=0) function TForm1.BmpRot(const B: TBitmap;fi:integer):TBitmap;
type
TRGBTripleArray = array[0..1023] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
x0,y0,i,j,x1,y1,x11,y11,x2,y2:integer;
ht,wd,newht,newwd:integer;
cfi,sfi: double;
sline1,sline2: pRGBTRipleArray;
BEGIN
sfi:=sin(degtorad(fi));
cfi:=cos(degtorad(fi));
ht:=b.height;
wd:=b.width;
newwd:=abs(round(ht*sfi))+abs(round(wd*cfi));
newht:=abs(round(wd*sfi))+abs(round(ht*cfi));
Result:=TBitmap.create;
Result.Width:=newwd;
Result.Height:=newht;
Result.PixelFormat:=pf24bit;
x0:=wd div 2;
y0:=ht div 2;
for j :=newht-1 downto 0 do begin
sline2 := Result.scanline[j];
y1:= 2*(j-(newht-ht) div 2 -y0)+1;
for i := newwd-1 downto 0 do begin
x1:=2*(i-(newwd-wd) div 2 -x0)+1;
x2 :=round(x1 * cfi - y1 * sfi);
y2 :=round(x1 * sfi + y1 * cfi);
x11:=(x2-1) div 2 +x0;
y11:=(y2-1) div 2 +y0;
if (x11>=0)and(x11<wd)and(y11>=0)and(y11<ht) then begin
sline1 := b.scanline[y11];
sline2[i] := sline1[x11];
end;
end;
end;
end;

Желаю успехов


 
Kolya   (2002-10-21 14:44) [2]

спасибо, но алгоритм не работает :( На строчке sfi:=sin(degtorad(fi)); дает ошибку Undeclared identifier: "degtorad". Странно- смотрю функция DegToRad есть, вроде должна работать.. Не знаете в чем проблема?
У меня Delphi 4.


 
MBo   (2002-10-21 15:10) [3]

Лень посмотреть, что надо uses Math ?


 
Kobik   (2003-02-20 07:01) [4]

procedure tform1.rotate(const t1:ttank;const p:byte;var t2:ttank);
var x1,y1,x2,y2,x3,y3:integer;pp,pp2,r,u,tan1:real;
begin
pp:=p*pi/36;
for y2:=1 to 120 do for x2:=1 to 120 do
begin
x1:=x2-60;y1:=y2-60;
r:={1.1*}sqrt(sqr(x1)+sqr(y1));
if x1=0 then
begin
if y1<=0 then u:=pi/2 else u:=3*pi/2;
end else
begin
tan1:=-y1/x1;
if x1>0 then u:=arctan(tan1) else u:=pi+arctan(tan1);
end;
pp2:=pp+u;
y3:=60+round(r*cos(pp2));
x3:=60+round(r*sin(pp2));
if(y3<=120)and(y3>=1)and(x3>=1)and(x3<=120)and(t1[y3,x3]<>65535)then t2[y2,x2]:=t1[y3,x3];
end;
end;

Поясняю: в моем движке Ttank=array[1..120,1..120]of byte; Но довольно легко переделать этот алгоритм и под TBitmap;
Угол поворота p;



Страницы: 1 вся ветка

Форум: "Игры";
Текущий архив: 2003.08.21;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.008 c
14-68506
Домарощинер
2003-08-05 18:16
2003.08.21
Кто знает, какая это кодировка?


3-68224
М. Дмитрий
2003-07-27 20:01
2003.08.21
Имена таблиц в MSAccess?


7-68572
Pliajnik
2003-06-07 12:35
2003.08.21
Как распечатать на принтере StringGrid c данными?


3-68222
VID
2003-07-26 23:07
2003.08.21
Надо сохранить значение ЛЮБОГО поля TpFIBQuery в поток(Stream)


14-68507
HolACost_
2003-08-05 16:35
2003.08.21
UU, XX, Base64





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский