The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Here is a code to draw a filled circle, someone may find it usfull so I thought I'll post it, ...

 Tweet
1. Here is a code to draw a filled circle, someone may find it usfull so I thought I'll post it, it comes from my own graphics c++ class library

Code:
```void Graphics::fillCircle(int x, int y, int radius)
{
int i=0,j;
int p=3 - 2 * radius;
u32 *vptr=(u32 *)pixelFrame(x,y);

// Bottom Part
for (j=0; j<=i; j++) {
*(vptr-j)=fillColor;
*(vptr+j-i-i)=fillColor;
}

// Top Part
for (j=0; j<=i; j++) {
*(vptr-j)=fillColor;
*(vptr+j-i-i)=fillColor;
}

// Middle Part
*(vptr+j)=fillColor;
}

*(vptr+j)=fillColor;
}

if(p < 0) {
p += 4 * i++ + 6;
} else {
p += 4 * (i++ - radius--) + 10;
}
}
}```

2. You might want to post the code for the pixelFrame() function ;)

3. For those who are wondering what the pixelFrame function dose.

pixelFrame just returns the screen drawing frame address for x & y location

it should be strait forward to convert it to be used in your own graphics library.

4. Lines like this worry me:
Code:
`*(vptr-j)=fillColor;`
There is possiblity of under-running the screen buffer here causing it to write into underfined memory.

5. It will never be though, so as long as the radius is a positive value,... Or am i missing something? I didnt thoroughly look through it, just a quick glance at the whie loop...

(i need to go to the bathroom real bad :Argh: *runs*)

6. Originally Posted by SG57
It will never be though, so as long as the radius is a positive value,... Or am i missing something? I didnt thoroughly look through it, just a quick glance at the whie loop...

(i need to go to the bathroom real bad :Argh: *runs*)
*Looks at it again* Ah, so you can't, it's the opposite, you can overrun the buffer.

7. abs(i); for all i's should do it... Unless im missing something again ffs...

8. I know about that issue, I just don't care:Jump: , no I do care, it was just to show you one method of drawing a circle, I am very much working on getting everythink working and transported over to the C++ class from the old C version, and the checks have been left out untill all functions are ported over and benched marked, so when i add the safeguards in I can compare the new benchmarks with the old one.

if you replace *vptr with a pixel(x,y) function with checks then it would be perfectly safe, but could have a efect on speed

9. Originally Posted by xart
if you replace *vptr with a pixel(x,y) function with checks then it would be perfectly safe, but could have a efect on speed
Not really, I can think of a few solutions that don't branch so the effect on speed is very minor.

10. I'm trying to make a .obj loader how ever I'm struggling a bit.
There are more texture vertices than vertices. How can I apply the texture correctly? I'd think I have to modify the vertices in some way, but I don't get how.

Anyone got any tips?

11. In C, How do we continue a long line of code from next line[In vb, it is _]?
!I am not referring to Next line character !

Ex: How Do i split a very long IF statement so that it is 2 lines?

12. Originally Posted by Mr305
In C, How do we continue a long line of code from next line[In vb, it is _]?
!I am not referring to Next line character !

Ex: How Do i split a very long IF statement so that it is 2 lines?
don't think you need one.. the ; indicates a new line..

13. Originally Posted by Mr305
In C, How do we continue a long line of code from next line[In vb, it is _]?
!I am not referring to Next line character !

Ex: How Do i split a very long IF statement so that it is 2 lines?
Code:
```if( blahsajkdjsaljdsadjklsjdsldsa &&
dsfjkklsdfjksdfjdklfjldfjdklfjdlkfdjfl )
{

}```

14. That would be the '\' character:

Code:
```guDrawBullet(BULLET_SIZE, &Bullets[i].pos, Bullets[i].rotZ, \
GU_RGBA(127, 255, 127, Bullets[i].alpha), GU_RGBA(bulletRed, bulletGreen, bulletBlue, Bullets[i].alpha));```
Or you can just put a return in. I think defines requires the '\' however.

15. Originally Posted by Insert_Witty_Name
That would be the '\' character:

Code:
```guDrawBullet(BULLET_SIZE, &Bullets[i].pos, Bullets[i].rotZ, \
GU_RGBA(127, 255, 127, Bullets[i].alpha), GU_RGBA(bulletRed, bulletGreen, bulletBlue, Bullets[i].alpha));```
Or you can just put a return in. I think defines requires the '\' however.
IF Statements don't require them do they?

16. no they don't

if you only want to do one thing , you can use ths
if(blablabla) do; else
if(blobloblo) do; else
......

that makes the code a bit nicer instead of
if(blablabla)
{
do;
}
else if(blobloblo)
{
do;
}
......

17. Originally Posted by Insert_Witty_Name
That would be the '\' character:

Code:
```guDrawBullet(BULLET_SIZE, &Bullets[i].pos, Bullets[i].rotZ, \
GU_RGBA(127, 255, 127, Bullets[i].alpha), GU_RGBA(bulletRed, bulletGreen, bulletBlue, Bullets[i].alpha));```
Or you can just put a return in. I think defines requires the '\' however.
Defines definitely need them. Regular exprressions don't AFAIK and use.
-= Double Post =-
Originally Posted by hallo007
no they don't

if you only want to do one thing , you can use ths
if(blablabla) do; else
if(blobloblo) do; else
......

that makes the code a bit nicer instead of
if(blablabla)
{
do;
}
else if(blobloblo)
{
do;
}
......
Opinion related. I find this more readable:
Code:
```if( something )
{
functionThis();
}
else if( soemthingElse )
{
functionThat();
}```
Then:
Code:
```if( something ) functionThis(); else
if( somethingElse ) functionThat(); else```
One expression per line rule.

18. i agree with yaustar, code shouldn't be small and compact if it makes it harder to follow, you just end up with bugs

a good example of improving the look of some code would of been

Code:
`if (i>0) t=true; else t=false;`
Better written as
Code:
`t=(i>0)?true:false;`
but don't use the ? all over the place as it should only be used were it makes code smaller and easer to understand

19. if(function() != 0) error();

i do all this checks if i write it so

if(function() != 0)
{
error();
}

then the code will be 2 as long , but thats my point on it ;)

20. How would you get the time from flash1?

And when you have that you would just assein that as a function and then say something like printf function?

21. Originally Posted by gameo
How would you get the time from flash1?

And when you have that you would just assein that as a function and then say something like printf function?
Ehhhh.... nani?

22. ## Tip for beginers

Code:
```int done;
...
...
...
done = 0;
while ( !done ) {
}```
is better than

Code:
```for (int done=0; !done;)
{
}```
The second may look good as you are keeping int done !done all at the same place, but what it dose is holds you up when you have to read it to know what this line of code dose.

were while (!done) allows you to quickly move away from reading it as it hits you strait in the face

while note done

apose to

for done=0 do this for loop until not done

depending how you read it, but gets the point over not that clear

also avoid this type
Code:
```for (;;)
{
// using break to exit
}```
may look good at first but using break to exit a loop like this could give you issues

23. Originally Posted by gameo
How would you get the time from flash1?

And when you have that you would just assein that as a function and then say something like printf function?
Code:
```#include <psprtc.h>
#include <psphprm.h>
#include <math.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>

#define printf pspDebugScreenPrintf
int getcurrenthour()
{
/*by hallo007*/
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
int hour = rtime.hour;
return hour;
}
int getCurrentMinutes()
{
/*by hallo007*/
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
int minutes = rtime.minutes;
return minutes;
}
char * printfCurrentTime()
{
/*by hallo007*/
char timeText[200];
sprintf(timeText , "%i : %i" , getCurrentHour() , getcurrentMinutes());
return timetext;
}```
:

24. ## PNG for Mac OS X in Xcode

Files taken from the installation of the Universal PNG for Mac OS X
libpng.zip

1st Add this folder to you Xcode project

2nd
Code:
```#include "libpng/png.h"
#include "libpng/pngconf.h"```
3rd Add to Project... the file libpng.a (this is an alias file that points to libpng12.a file)

Now you should be able to use the LoadPNG code that you use for the PSP for Mac OS X make testing png functions easer.
-= Double Post =-
Originally Posted by hallo007
Code:
```#include <psprtc.h>
#include <psphprm.h>
#include <math.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>

#define printf pspDebugScreenPrintf
int getcurrenthour()
{
/*by hallo007*/
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
int hour = rtime.hour;
return hour;
}
int getCurrentMinutes()
{
/*by hallo007*/
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
int minutes = rtime.minutes;
return minutes;
}
char * printfCurrentTime()
{
/*by hallo007*/
char timeText[200];
sprintf(timeText , "%i : %i" , getCurrentHour() , getcurrentMinutes());
return timetext;
}```
:
I would use
Code:
```/* time example */
#include <stdio.h>
#include <time.h>

int main ()
{
time_t seconds;

seconds = time (NULL);
printf ("%ld hours since January 1, 1970", seconds/3600);

return 0;
}```
Cross platform, makes testing code easer as you don't need a PSP
readup on time.h and you should be able to produce emulator functions for functions like sceRtcGetCurrentClockLoca lTime

25. rand() Should yield decimals in random right?

But when I try rand()% 0.9

It says "Invalid binary % operand"!
Any help?

And also,

Do we have any psp- Programming Hard Books?

26. Originally Posted by Mr305
rand() Should yield decimals in random right?

But when I try rand()% 0.9

It says "Invalid binary % operand"!
Any help?

And also,
Code:
`rand() % x`
x must always be an integer. Try this:
Code:
```float aFloat = static_cast<float>( rand() % 9 ) / 10.0f; // C++
float aFloat = (float)( rand() % 9 ) / 10.0f; // C```
Do we have any psp- Programming Hard Books?
Pardon? If you want to learn 'advance' C++ then start reading Effective C++.

27. the best book I find is the internet, loads of stuff to learn

e.g
http://www.cplusplus.com/reference/

28. mmm, Ok, I need a way to play Mp3's in a file browser, (using a file browser , press x on an mp3, it plays) Ill just use the File browser at the source depository at psp-programming.com, but does any body know how to use the mp3 function?

29. Originally Posted by xart
the best book I find is the internet, loads of stuff to learn

e.g
http://www.cplusplus.com/reference/
Thinking in C++ is a great eBook as well..
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html

30. Originally Posted by yaustar
Code:
`rand() % x`
x must always be an integer. Try this:
Code:
```float aFloat = static_cast<float>( rand() % 9 ) / 10.0f; // C++
float aFloat = (float)( rand() % 9 ) / 10.0f; // C```

Pardon? If you want to learn 'advance' C++ then start reading Effective C++.

I meant real HandHeld books that are written specifically dealing with PSP development not Generic C/C++!

Will try that code...

Code:
```float m;
m= (rand() % 9)/10;```
Wouldn't this work in the same way?
Other ?n, I 've been seeing many 'f' s at the end of number lately... looking at PSP Gu tutorials! What are they used for?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 06:02 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY