|
void S_PicXZ(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)//
7 f# k# b0 G( ~3 d{ 3 X' w5 d7 R* u4 ^% l' u, J- N
if(angle>180)angle=360-angle; 7 ~) D6 G3 E! W) [+ I0 p7 b
if(angle<-180)angle=360+angle; 6 b1 g4 y; S6 ^0 W; }/ o8 d! h- t
float radians=(2*3.1416*angle)/360;
* U2 s# | k8 k" i, E5 P# ?& Dfloat cosine=(float)cos(radians);
/ F2 \% F# x0 K# R0 F* P; Tfloat sine=(float)sin(radians); ; s: _: c( M7 B& Q/ F+ n# [
float Point1x=(-Source->Height*sine);
2 s9 G' I# x; Cfloat Point1y=(Source->Height*cosine);
U: n3 I" E2 Qfloat Point2x=(Source->Width*cosine-Source->Height*sine); ) R K: R0 [! A9 y; a' V
float Point2y=(Source->Height*cosine+Source->Width*sine);
; [2 T- x3 N6 G' k7 G( q9 g- Xfloat Point3x=(Source->Width*cosine);
& G8 a. W6 v$ ]4 A, vfloat Point3y=(Source->Width*sine);
5 C1 @' M- ^" g# D& ifloat minx=min((float)0,min(Point1x,min(Point2x,Point3x)));
, r$ b: @% g9 ^, D3 Z& e4 Jfloat miny=min((float)0,min(Point1y,min(Point2y,Point3y)));
$ I/ Z( N d9 z& M( ]) h5 ufloat maxx=max(Point1x,max(Point2x,Point3x));
) Q: e2 B' T, ?8 Xfloat maxy=max(Point1y,max(Point2y,Point3y)); ( y1 z7 M6 N- \6 X1 O6 o
int DestBitmapWidth,DestBitmapHeight;
& c- [/ i% q5 `7 S0 |' c7 V( aif(angle>90&&angle<180) ; E# u9 W$ u0 f+ {0 {( j
DestBitmapWidth=(int)ceil(-minx);
6 ~( U+ n' t5 @( Xelse ! g3 [6 H( ?8 p6 b& s, f
DestBitmapWidth=(int)ceil(maxx-minx); ; C& B- n. f) F7 a9 E4 z& G
if(angle>-180&&angle<-90) , [ W8 @2 f% |3 U5 x' o) a! i( ^ h
DestBitmapHeight=(int)ceil(-miny);
2 w# x. l; y% n4 q* i" J9 T6 B' |8 helse % k4 k3 ^! U1 B( ^
DestBitmapHeight=(int)ceil(maxy-miny); * d k# _. }8 v" p4 ]
NewPic->Height=DestBitmapHeight;
( [: p- i( Z( |. P; N+ z8 X$ U' TNewPic->Width=DestBitmapWidth;
5 `2 k. U2 U; L. S- bfor(int x=0;x<DestBitmapWidth;x++)
5 Q) S7 e, Q5 W( p, N2 ~: M$ W/ b{ 0 X* |9 y# t% c! @% _6 ?0 l
for(int y=0;y<DestBitmapHeight;y++){
/ m) N- M( M. T% T2 q+ r/ }int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine);
, U/ U4 \, H# `, ~2 ~) U5 w" |int SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine);
0 n5 J& C& Y/ i bif(SrcBitmapx>=0&&SrcBitmapx<Source->Width&&SrcBitmapy>=0&& , y, t- d; [! K6 {4 @ _1 q
SrcBitmapy<Source->Height)
" o3 N& z$ K; X# L( }& X{
# O6 S" j9 F5 U/ r( _5 fNewPic->Canvas-> ixels[x][y]=
% @2 q$ k: P7 R% [ W. l/ BSource->Canvas-> ixels[SrcBitmapx][SrcBitmapy]; ' v' u9 s9 V0 ^; r% v2 P; m- A
}
' z; _: ?9 z+ |) Y} 7 }( y0 B A# W/ R( s0 A9 D" _& p
} - x7 b+ V3 o' R5 v0 u. a
} |