|
void S_PicXZ(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)// 5 g+ {. g# ?8 e I( ?
{
( _1 r8 P- X) R. pif(angle>180)angle=360-angle; ! |. A2 J0 N. V# D4 o# R5 X
if(angle<-180)angle=360+angle; 7 J: [: c6 W. O' x
float radians=(2*3.1416*angle)/360; $ z! Z+ W* E% r: I" _
float cosine=(float)cos(radians); & y R. d) {, m+ N+ E* n
float sine=(float)sin(radians);
7 v4 ~6 D( d% e8 N7 K" u) A1 j4 q; lfloat Point1x=(-Source->Height*sine);
; Q4 p1 P6 y) x G' H% zfloat Point1y=(Source->Height*cosine);
/ [; w: x' ~( m+ gfloat Point2x=(Source->Width*cosine-Source->Height*sine); 9 {5 b+ C) P2 q* p6 ]- M! h
float Point2y=(Source->Height*cosine+Source->Width*sine);
3 R1 O( D$ M$ i. @float Point3x=(Source->Width*cosine);
; ]* z/ B& I X% K+ Y( Hfloat Point3y=(Source->Width*sine); 8 [, Z1 \- c+ k2 M: V! v; ?" V* S
float minx=min((float)0,min(Point1x,min(Point2x,Point3x))); 6 q7 Q. B! ?; {. B/ o/ Y
float miny=min((float)0,min(Point1y,min(Point2y,Point3y)));
/ S; a; p. K( c5 Q2 r2 ?float maxx=max(Point1x,max(Point2x,Point3x)); / N" e# A h4 b3 u( c
float maxy=max(Point1y,max(Point2y,Point3y)); 1 C. U5 J$ G8 k3 Z
int DestBitmapWidth,DestBitmapHeight; 1 Y* W; b' D% P1 S; w
if(angle>90&&angle<180)
( S. g# m, u2 h1 |' O; |DestBitmapWidth=(int)ceil(-minx); ; \/ [$ g! y. L8 u) y6 q P5 o
else
! S6 ?6 n7 f: I" TDestBitmapWidth=(int)ceil(maxx-minx);
' f+ \3 b: x1 y5 t& _if(angle>-180&&angle<-90) ( [6 n. [1 X* g2 k0 ?/ l! [
DestBitmapHeight=(int)ceil(-miny); - R5 o6 X7 B' f5 p2 Y1 r5 M
else ( h% x; U9 |9 f0 }
DestBitmapHeight=(int)ceil(maxy-miny);
9 f. h& k, A, p/ R) fNewPic->Height=DestBitmapHeight; : Y! Q5 _0 d# p, Y9 T* O
NewPic->Width=DestBitmapWidth; 0 q+ Z$ U, G7 C8 @6 ]2 v
for(int x=0;x<DestBitmapWidth;x++)
0 z- `; O! S5 p' E5 {{
$ m; M) `. a0 {( N A; Xfor(int y=0;y<DestBitmapHeight;y++){ : u! t) R# k0 D
int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine);
. j$ Y: h4 S5 z- e- Gint SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine); 0 V3 X) V* ?( E, }/ I8 A6 G
if(SrcBitmapx>=0&&SrcBitmapx<Source->Width&&SrcBitmapy>=0&& 6 s% g; J3 N' b# m4 j; j2 x5 v
SrcBitmapy<Source->Height) ' m6 a% ~: |0 _/ O5 [' ]2 v9 ^6 Y( S
{ - O- y; F! b4 N# A
NewPic->Canvas-> ixels[x][y]=
/ Z4 v, k* U& ^Source->Canvas-> ixels[SrcBitmapx][SrcBitmapy]; 9 p' e8 y8 P% J7 y( t) M
}
0 I" h5 j- V( J5 D1 W}
0 Z8 t1 q4 v2 ?" q B2 p& @; \} 6 T s7 q6 d' d& E7 K1 u
} |