Show 40 post(s) from this thread on one page
• 03-14-2007, 02:40 PM
xart
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);       while(i <= radius) {       // Bottom Part       vptr=(u32 *)pixelFrame(x+i,y+radius);       for (j=0; j<=i; j++) {         *(vptr-j)=fillColor;         *(vptr+j-i-i)=fillColor;       }             // Top Part       vptr=(u32 *)pixelFrame(x+i,y-radius);       for (j=0; j<=i; j++) {         *(vptr-j)=fillColor;         *(vptr+j-i-i)=fillColor;       }             // Middle Part       vptr=(u32 *)pixelFrame(x-radius,y+i);       for (j=0; j<=radius; j++) {         *(vptr+j)=fillColor;         *(vptr+radius+radius-j)=fillColor;       }             vptr=(u32 *)pixelFrame(x-radius,y-i);       for (j=0; j<=radius; j++) {         *(vptr+j)=fillColor;         *(vptr+radius+radius-j)=fillColor;       }             if(p < 0) {         p += 4 * i++ + 6;       } else {         p += 4 * (i++ - radius--) + 10;       }   } }```
• 03-14-2007, 02:41 PM
Bronx
You might want to post the code for the pixelFrame() function ;)
• 03-14-2007, 02:55 PM
xart
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.
• 03-14-2007, 03:06 PM
yaustar
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.
• 03-14-2007, 03:25 PM
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*)
• 03-14-2007, 03:37 PM
yaustar
Quote:

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.
• 03-14-2007, 04:48 PM
SG57
abs(i); for all i's should do it... Unless im missing something again ffs...
• 03-14-2007, 04:51 PM
xart
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
• 03-15-2007, 12:50 AM
yaustar
Quote:

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.
• 03-15-2007, 11:15 AM
Waterbottle
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?
• 03-15-2007, 01:01 PM
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?
• 03-15-2007, 01:04 PM
MiG
Quote:

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..
• 03-15-2007, 01:11 PM
yaustar
Quote:

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 ) { }```
• 03-15-2007, 01:12 PM
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.
• 03-15-2007, 01:19 PM
BlackShark
Quote:

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?
• 03-15-2007, 01:26 PM
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;
}
......
• 03-15-2007, 01:35 PM
yaustar
Quote:

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 =-
Quote:

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.
• 03-15-2007, 05:33 PM
xart
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
• 03-15-2007, 11:31 PM
hallo007
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 ;)
• 03-16-2007, 11:35 AM
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?
• 03-16-2007, 01:37 PM
Raphael
Quote:

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?
• 03-16-2007, 02:30 PM
xart
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
• 03-16-2007, 02:47 PM
hallo007
Quote:

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; }```
:icon_cool:
• 03-16-2007, 03:00 PM
xart
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 =-
Quote:

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; }```
:icon_cool:

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
• 03-16-2007, 03:59 PM
Mr305
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?
• 03-16-2007, 04:57 PM
yaustar
Quote:

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```
Quote:

Do we have any psp- Programming Hard Books?
Pardon? If you want to learn 'advance' C++ then start reading Effective C++.
• 03-16-2007, 05:38 PM
xart
the best book I find is the internet, loads of stuff to learn

e.g
http://www.cplusplus.com/reference/
• 03-16-2007, 05:53 PM
BlackShark
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?
• 03-16-2007, 06:15 PM
yaustar
Quote:

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
• 03-16-2007, 06:54 PM
Mr305
Quote:

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?
Show 40 post(s) from this thread on one page