forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sin Function problem.

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ShUr1k3n



Joined: 16 Oct 2005
Posts: 42

PostPosted: Sun Nov 27, 2005 5:38 am    Post subject: Sin Function problem. Reply with quote

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
View user's profile Send private message Send e-mail
memon



Joined: 03 Oct 2005
Posts: 63

PostPosted: Sun Nov 27, 2005 5:48 am    Post subject: Reply with quote

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
View user's profile Send private message
ShUr1k3n



Joined: 16 Oct 2005
Posts: 42

PostPosted: Sun Nov 27, 2005 6:04 am    Post subject: Reply with quote

thks a lot.. Its working =)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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