| View previous topic :: View next topic |
| Author |
Message |
ShUr1k3n
Joined: 16 Oct 2005 Posts: 42
|
Posted: Sun Nov 27, 2005 5:38 am Post subject: Sin Function problem. |
|
|
Hi guys,
i need to make a sin curve.
In LuaPlayer i use this code:
| Code: |
while not Controls.read():start() do
x = x + 1
ang = ang + 1
y = 100 + math.sin(math.rad(ang)) * 50
screen:pixel(x,y,red)
screen.waitVblankStart()
screen.flip()
end
|
and woks perfect.
Now in C i use this:
| Code: |
#define PI 3.1415926535897932
int de2rad(int degrees)
{
return degrees * (PI/180);
}
int main()
{
int x=0,y=0;
int ang = 0;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
InitGraphics();
ScreenFrame(2,0);
ClearScreen(black);
WaitV();
FlipScreenV();
while (1) {
x = x + 1;
ang = ang + 1;
y = 100 + sin(de2rad(ang))*50;
PutPixel(x,y,red);
WaitV();
FlipScreenV();
}
sceKernelExitGame();
return 0;
}
|
And the output is very diferent ( horizontal lines )...
Can u help me plz..
Regards,
ShUr1k3n |
|
| Back to top |
|
 |
memon
Joined: 03 Oct 2005 Posts: 63
|
Posted: Sun Nov 27, 2005 5:48 am Post subject: |
|
|
| Try to change all ints to floats (or doubles). The whole circle in radians is just 0..6.2, which means 6 steps if you use integers. In Lua all numbers are floats (unless it is specified differently in the luaplayer). |
|
| Back to top |
|
 |
ShUr1k3n
Joined: 16 Oct 2005 Posts: 42
|
Posted: Sun Nov 27, 2005 6:04 am Post subject: |
|
|
| thks a lot.. Its working =) |
|
| Back to top |
|
 |
|