Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there anyway to rotate an image of wheel continuously?

12 views
Skip to first unread message

RaaZ Shrestha

unread,
Mar 22, 2012, 12:27:48 PM3/22/12
to
I want to spin image of an wheel continuously in C++ using C++Builder. I was able to rotate the wheel for only one time. Help needed.
Here is the code:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int angle=45; //45° for example
Graphics::TBitmap *SrcBitmap=new Graphics::TBitmap;
Graphics::TBitmap *DestBitmap=new Graphics::TBitmap;
SrcBitmap->LoadFromFile("image1.bmp");
//Convert degrees to radians
float radians=(2*3.1416*angle)/360;

float cosine=(float)cos(radians);
float sine=(float)sin(radians);

float Point1x=(-SrcBitmap->Height*sine);
float Point1y=(SrcBitmap->Height*cosine);
float Point2x=(SrcBitmap->Width*cosine-SrcBitmap->Height*sine);
float Point2y=(SrcBitmap->Height*cosine+SrcBitmap->Width*sine);
float Point3x=(SrcBitmap->Width*cosine);
float Point3y=(SrcBitmap->Width*sine);

float minx=min(0,min(Point1x,min(Point2x,Point3x)));
float miny=min(0,min(Point1y,min(Point2y,Point3y)));
float maxx=max(Point1x,max(Point2x,Point3x));
float maxy=max(Point1y,max(Point2y,Point3y));

int DestBitmapWidth=(int)ceil(fabs(maxx)-minx);
int DestBitmapHeight=(int)ceil(fabs(maxy)-miny);

DestBitmap->Height=DestBitmapHeight;
DestBitmap->Width=DestBitmapWidth;
Form1->Refresh();
for(int x=0;x<DestBitmapWidth;x++)
{
for(int y=0;y<DestBitmapHeight;y++)
{
int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine);
int SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine);
if(SrcBitmapx>=0&&SrcBitmapx<SrcBitmap->Width&&SrcBitmapy>=0&&
SrcBitmapy<SrcBitmap->Height)
{
DestBitmap->Canvas->Pixels[x][y]=
SrcBitmap->Canvas->Pixels[SrcBitmapx][SrcBitmapy];
}
}
}
//Show the rotated bitmap
Image1->Picture->Bitmap=DestBitmap;
delete DestBitmap;
delete SrcBitmap;
}

Phongphan

unread,
Feb 23, 2016, 8:19:42 AM2/23/16
to
Try to adding some code : making step's parameter in while loop.
Message has been deleted
Message has been deleted
Message has been deleted

Phongphan

unread,
Feb 25, 2016, 3:57:55 AM2/25/16
to
Cos(∆) = e^(i∆) = 1 -(∆^2n)/2! + (-1)^2n-1*(∆^2n)/2n! ; n=1..N

Phongphan

unread,
Feb 25, 2016, 3:38:41 PM2/25/16
to
You may try to make the table of angle.
Message has been deleted

Phongphan

unread,
Feb 29, 2016, 3:19:19 AM2/29/16
to
Or you may show wheel picture by each angle one by one form loaded picture set.

See : making picture... By mauro
0 new messages