Sin Function problem.

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ShUr1k3n
Posts: 42
Joined: Sun Oct 16, 2005 9:04 pm

Sin Function problem.

Post by ShUr1k3n »

Hi guys,

i need to make a sin curve.

In LuaPlayer i use this code:

Code: Select all

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: Select all


#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
memon
Posts: 63
Joined: Mon Oct 03, 2005 10:51 pm

Post by memon »

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).
ShUr1k3n
Posts: 42
Joined: Sun Oct 16, 2005 9:04 pm

Post by ShUr1k3n »

thks a lot.. Its working =)
Post Reply