|
void S_PicXZ(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)//
2 E8 d- x( n% V; ~' \8 l$ u{ / z1 d( \3 Q0 B
if(angle>180)angle=360-angle; / i) Y# B2 v7 ~
if(angle<-180)angle=360+angle;
# H5 Q9 z5 y* n) ]float radians=(2*3.1416*angle)/360;
. c5 [4 R7 H2 yfloat cosine=(float)cos(radians); , L0 I& R; r! d1 M* d; s
float sine=(float)sin(radians); ' V( Q9 [, {9 o6 s( Y8 f
float Point1x=(-Source->Height*sine);
) ]8 c8 y. W/ U4 p8 pfloat Point1y=(Source->Height*cosine); 0 @) D* S4 i( a4 K w2 {
float Point2x=(Source->Width*cosine-Source->Height*sine); ' H( m, ~3 i1 Y
float Point2y=(Source->Height*cosine+Source->Width*sine);
9 Z, A4 M0 O9 u& cfloat Point3x=(Source->Width*cosine);
; J6 h3 U- G) ~+ E, qfloat Point3y=(Source->Width*sine);
- a" ^6 q: p1 C; s; c1 afloat minx=min((float)0,min(Point1x,min(Point2x,Point3x)));
5 K* U+ Q* o. T- q- ^' bfloat miny=min((float)0,min(Point1y,min(Point2y,Point3y))); : f1 _0 G4 x5 j6 I5 X- O/ K, o5 a
float maxx=max(Point1x,max(Point2x,Point3x)); 3 r5 K/ k) ^( w$ {0 h6 }
float maxy=max(Point1y,max(Point2y,Point3y)); 3 [& P; y; @$ o# e4 j
int DestBitmapWidth,DestBitmapHeight;
2 x5 I1 V5 T, kif(angle>90&&angle<180)
% M( U3 y, [1 e$ n! ^# ~4 n( hDestBitmapWidth=(int)ceil(-minx);
- q5 n+ S; N2 N8 o/ f* c/ N/ [' B. celse ( \) Y+ V9 B0 t2 \
DestBitmapWidth=(int)ceil(maxx-minx); 1 O J" T( S& h0 e' j" t( @; d( w
if(angle>-180&&angle<-90) 8 ]+ d5 f$ B" p) z
DestBitmapHeight=(int)ceil(-miny); * G) j8 J! v+ L7 Z" l
else
, I0 l5 I/ N0 w- r6 {+ l$ xDestBitmapHeight=(int)ceil(maxy-miny);
4 w, W, M; h8 q2 j# GNewPic->Height=DestBitmapHeight; 7 @$ Q/ _7 ]& ~& t2 [% ~9 J. P) g
NewPic->Width=DestBitmapWidth;
& ]9 e# g) T9 e6 _4 \1 O* f0 Z3 efor(int x=0;x<DestBitmapWidth;x++)
0 q8 l3 t7 T D{ ; X' o) \1 `1 y* N3 K
for(int y=0;y<DestBitmapHeight;y++){ [* H9 `# E7 K- a" W% q
int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine); 5 k. F: ]: o5 Y% q
int SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine); 7 v" O4 i7 h8 L- @
if(SrcBitmapx>=0&&SrcBitmapx<Source->Width&&SrcBitmapy>=0&& 5 ] P% y* t. ^$ b7 U
SrcBitmapy<Source->Height)
; A; z( H( u) e( r& @! |4 v! [$ f{
! J* l& q. A, H) q( t& A& TNewPic->Canvas-> ixels[x][y]= : } R- Y3 `& S* l
Source->Canvas-> ixels[SrcBitmapx][SrcBitmapy];
8 x/ ?: \) _0 s- S/ R `2 ^* M} ; K- |5 |# c( }$ l
}
4 Z/ D2 e& n8 ]3 Y K}
/ s1 {. x. t9 g) _6 ?/ E1 F} |