 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Mon Sep 07, 2009 12:21 pm Post subject: 2D point rotation problem |
|
|
Hi Guys,
Well I've done my homework on this one,
so I hope I can find some help.
This program spins a line around a point in the centre of the screen,
like a clock hand moving around a clock face.
The program works,
but as I increment the angle from 0-360, the line makes a full circle many times, and only has about 5 or 6 frames per full circle rotation.
If I increment the angle by 0.01, the display looks great, and movement
is fluid, but it only takes 7 or 8 degrees to make a full circle.
Any ideas what I'm doing wrong?
all vars are ints except for theta & thetab.
| Code: |
while (1) {
clearScreen(0);
xx = 240; // set the starting point.
yy = 30;
drawLineScreen(240, 136, xx, yy, white); // draw stationary line for reference
x = xx - 240; // coords X=240,Y=136 is a point in the middle of the screen to spin around
y = yy - 136;
theta = theta + 1; // increment the angle to 360 degrees.
if (theta > 359) {theta = 0;}
thetab = 360 - theta;
sprintf (filler, " %f", theta); // print the current angle
printTextScreen(0,0,filler, white);
xnew = cos(thetab)*x - sin(thetab)*y;
ynew = sin(thetab)*x + cos(thetab)*y;
xnew = xnew + 240; // if I leave this out, the line spins around 0,0 coords, and I only see a quater of the action
ynew = ynew + 136;
drawLineScreen(240, 136, xnew, ynew, white);
sceDisplayWaitVblankStart();
flipScreen();
for(del=0; del<10; del++) {sceDisplayWaitVblankStart();} // delay to see the current frame
}
|
_________________ If not actually, then potentially. |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Sep 07, 2009 12:29 pm Post subject: |
|
|
| Radians? |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Mon Sep 07, 2009 12:30 pm Post subject: |
|
|
Yes :)
NVM, I forgot the conversion.. came back to delete it ;) _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
marksteven
Joined: 21 Sep 2009 Posts: 3
|
Posted: Wed Sep 23, 2009 5:44 pm Post subject: |
|
|
Hi,
i can not find error in this code.It is all right.But if you want to see analog clock then here some code,
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm;
int x=320,y=240,r=200,i,h,m,s,thetamin,thetasec;
struct time t;
char n[12][3]={"3","2","1","12","11","10","9","8","7","6","5","4"};
initgraph(&gd,&gm,"f:\arun\tc");\put the directory which contains
egavga.bgi
circle(x,y,210);
setcolor(4);
settextstyle(4,0,5);
for(i=0;i<12;i++)
{
if(i!=3)
outtextxy(x+(r-14)*cos(M_PI/6*i)-10,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
else
outtextxy(x+(r-14)*cos(M_PI/6*i)-20,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
}
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d
",t.ti_hour, t.ti_min,
t.ti_sec, t.ti_hund);
while(!kbhit())
{
setcolor(5);
setfillstyle(1,5);
circle(x,y,10);
floodfill(x,y,5);
gettime(&t);
if(t.ti_min!=m)
{
setcolor(0);
line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180
)));
circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180))
,10);
line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),10);
}
if(t.ti_hour>12)
t.ti_hour=t.ti_hour-12;
if(t.ti_hour<4)
h=abs(t.ti_hour-3);
else
h=15-t.ti_hour;
m=t.ti_min;
if(t.ti_min<=15)
thetamin=(15-t.ti_min)*6;
else
thetamin=450-t.ti_min*6;
if(t.ti_sec<=15)
thetasec=(15-t.ti_sec)*6;
else
thetasec=450-t.ti_sec*6;
setcolor(4);
line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),10);
line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180
)));
circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180))
,10);
setcolor(15);
line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180
)));
delay(1000);
setcolor(0);
line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180
)));
}
}
Thanks for sharing this information. _________________ fetes des meres |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Thu Sep 24, 2009 11:10 pm Post subject: |
|
|
Yes it dos the same thing.
That clock has been in LUAplayer from the beginning. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|