QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

C/C++ Programming Help Thread

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; For image rotation you're going to need to use some matrix math. Build a rotation matrix for theta (amount of ...

Reply
 
LinkBack Thread Tools
Old 04-29-2006, 02:00 PM   #211
 
Join Date: Apr 2006
Posts: 4
Trader Feedback: 0
Default

For image rotation you're going to need to use some matrix math. Build a rotation matrix for theta (amount of rotation; remember it's in radians, not degrees), then apply the matrix to your image. The resulting image should be put into the back buffer; storing it as an Image is just an unneeded hassle, unless you plan on saving it.

Granted, this method won't compensate for the origin of your image being in the upper left corner. To do that, you'll need to build an affine transformation using the rotation matrix that you should already have. Translate the image so that the origin lies in the center rather than the corner, apply the rotation matrix, then translate the image back to where it was before.

It can be tricky to keep all of your variables straight, so consider building a struct as a representation of vectors and matrices, and define functions for dot products/linear transformations. This will help to keep your code clean, and a good vector struct with helper functions can be reused in the future.

Have fun, and good luck.

Edit: After I posted this I realized that starting with screen coordinates and moving back to the image via the inverse of the rotation matrix might be more effective. With the method that I posted first you might get "holes" in the image due to rounding; this second method takes care of that problem. By starting with the rotated image and looking up the color on the original image you'll get a filled image. From what I've seen, this is probably what most games use.

Last edited by Kage68; 04-29-2006 at 02:33 PM.. Reason: Thought of a (possibly) better way
Kage68 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 05:33 PM   #212

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Maybe a small example, you lost me therem but i understand some of it.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 07:01 PM   #213
 
Join Date: Apr 2006
Posts: 4
Trader Feedback: 0
Default

I wrote a quick little program to rotate an image earlier today. It uses my Vector2 struct with some helper functions, so you'll have to replace them with your own data type. Here's main():

Code:
SceCtrlData pad;
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
Image* img = loadImage("image.png");
if(!img)
{
	printf("Image failed to load.\n");
	sceKernelSleepThread();
	return 0;
}
Color* vram;
Vector2 rotation[] = {{0,0},{0,0}};
int theta=0;
printf("Entering main loop.\n");
while((pad.Buttons&PSP_CTRL_CIRCLE)==0)
{
	fillScreenRect(RGB(theta,64,224),0,0,480,272);
	vram = getVramDrawBuffer();
	sceCtrlReadBufferPositive(&pad,1);
	if(pad.Buttons&(PSP_CTRL_UP|PSP_CTRL_RIGHT))
		++theta;
	if(pad.Buttons&(PSP_CTRL_DOWN|PSP_CTRL_LEFT))
		--theta;
	float sinTh = sin((float)theta*pi/180),cosTh = cos((float)theta*pi/180);
	rotation[0].x = cosTh;
	rotation[0].y = sinTh;
	rotation[1].x = -sinTh;
	rotation[1].y = cosTh;
	int y;
	for(y=0;y<img->imageHeight;++y)
	{
		int x;
		for(x=0;x<img->imageWidth;++x)
		{
			Vector2 image = V2Create(x-img->imageWidth/2,y-img->imageHeight/2);
			image = V2LinearTransform(rotation,image);
			vram[PSP_LINE_SIZE * ((int)image.y+136) + (int)image.x+240] = img->data[img->imageWidth*y+x];
		}
	}
	flipScreen();
}
freeImage(img);
sceKernelSleepThread();
return 0;
It's not commented, but most of what's going on is pretty self explanatory. This uses the first method I mentioned (rotate the image, put it on the screen) because I haven't looked into the second to see if it's feasible yet. I also wasn't too concerned about efficiency, considering that rotating the image is the only thing that this program does.

I hope you find it useful.
Kage68 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 08:15 PM   #214

Developer
 
Join Date: Oct 2005
Posts: 408
Trader Feedback: 0
Default

It's actually going to be much quicker and cleaner to transform a pair of triangles in a triangle strip (giving you 4 corners) and render the image as a texture on the triangles. Then let the graphics processor do all the work while your original image is intact.
Samstag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 09:30 PM   #215
 
Join Date: Apr 2006
Posts: 4
Trader Feedback: 0
Default

I just found the GU documentation and samples in the pspsdk... I feel like an idiot for doing all of this the hard way. Much of what I've done is already built into the GU, so go ahead and disregard the code I posted earlier.
Thanks for pointing that out, Samstag. Now I just have to start figuring out how to use the sceGu_() functions. Is there another reference for them somewhere? The documentation that came with pspsdk is good, but doesn't give too much information.
Kage68 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 03:49 AM   #216

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

I agree, the SDK isn't 100% infomationalably understandable. But who has the time to comment every part. Especially after looking at the SDK, its huge.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 05:28 AM   #217

Developer
 
Join Date: Oct 2005
Posts: 408
Trader Feedback: 0
Default

Quote:
Originally Posted by Kage68
I just found the GU documentation and samples in the pspsdk... I feel like an idiot for doing all of this the hard way. Much of what I've done is already built into the GU, so go ahead and disregard the code I posted earlier.
Thanks for pointing that out, Samstag. Now I just have to start figuring out how to use the sceGu_() functions. Is there another reference for them somewhere? The documentation that came with pspsdk is good, but doesn't give too much information.
The Luaplayer source seems to be the best way to learn the GU functions. There's alse a lot of good information available at www.ps2dev.org. Here's a very good post that I think will help out.
Samstag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 02:39 PM   #218
 
Devun_06's Avatar
 
Join Date: Feb 2006
Posts: 338
Trader Feedback: 0
Default

can someone tell me where I can findout all about PRX`s and how to use them.
Devun_06 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-01-2006, 05:39 AM   #219

Developer
 
SodR's Avatar
 
Join Date: Sep 2005
Location: Sweden
Posts: 941
Trader Feedback: 0
Default

Quote:
Originally Posted by Devun_06
can someone tell me where I can findout all about PRX`s and how to use them.
You can either check the tutorial at forums.ps2dev.org or just use the sample included in the sdk.
SodR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-01-2006, 11:23 AM   #220
 
Devun_06's Avatar
 
Join Date: Feb 2006
Posts: 338
Trader Feedback: 0
Unhappy

Sorry I wasn't clear about what I was looking for, but I've already looked into the ps2|)ev.org's pinned topic and it helped, but didn't exactly go over all that I was looking for.
It looks like PRX's load up automatically when a program closes or is able to atleast boot when another application closes. Also, the sample lacked comments from my standpoint. Maybe there is a simple tutorial, or should I just find a better way for the sceKernelLoadExec() then coming back to the oginal application. Since I've heard the 2.7 has a camera prx for new functions, could it be that prx's act as dll's?
Devun_06 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-01-2006, 11:58 AM   #221

Developer
 
SodR's Avatar
 
Join Date: Sep 2005
Location: Sweden
Posts: 941
Trader Feedback: 0
Default

Quote:
Originally Posted by Devun_06
Sorry I wasn't clear about what I was looking for, but I've already looked into the ps2|)ev.org's pinned topic and it helped, but didn't exactly go over all that I was looking for.
It looks like PRX's load up automatically when a program closes or is able to atleast boot when another application closes. Also, the sample lacked comments from my standpoint. Maybe there is a simple tutorial, or should I just find a better way for the sceKernelLoadExec() then coming back to the oginal application. Since I've heard the 2.7 has a camera prx for new functions, could it be that prx's act as dll's?
I don't think you exactly know what a prx is. You can use prx's for different purposes; like haveing your program in both user and kernel mode (multi-threading, by having a prx in usermode and have the main app in kernel etc.), unloading your program and then start your own etc. You can simply load a prx with load/startmodule. If you want your program running in the background meanwhile another app is running you can use the same method as a told you before, start the app using load/startmodule. From what I get you want to start a app and when it closes I should return to your app just as many shells do. To do that you need some ram-tweaking and I have no idea how to do that. But you can use the already compiled prx for that; The fileassistans bootloader. Otherwise you can mail the fileassistant team and ask how they did it.
SodR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-01-2006, 02:01 PM   #222
 
Devun_06's Avatar
 
Join Date: Feb 2006
Posts: 338
Trader Feedback: 0
Unhappy

There is a link of a quite small way of obtaining ram data, but even with it, I need to findout how I would go about using a prx. I know prx's are a must to do returns, correct?
http://forums.ps2dev.org/viewtopic.p...6aa1457eef9b5b

Although, I don't exactly see why ram would matter, but who cares...
* I opened FileAssistant before and... I think they're way above my level.

Last edited by Devun_06; 05-01-2006 at 02:06 PM..
Devun_06 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-02-2006, 01:26 AM   #223
 
 
Join Date: Jul 2005
Location: Brampton
Posts: 631
Trader Feedback: 0
Default

if you wanna get into prx stuff use irshell
then you can edit and replace the mp3 prx
http://www.ahman.co.nr/
in the downloads page at the bottom

The source code for it is closed, but you can use the prx to display those memory things you use and compair what he did to the memory. Or just go on from there.

So far there isn't any real help besides me, and I think you know more than I do. He made the prx plugin as a way to shut people up. So if you get anywhere pm me some betas.
__________________
[CENTER]You can hyperlink quotes and the whole box will be a link:
[URL=http://forums.qj.net/showthread.php?t=35215][COLOR=DarkRed][QUOTE=ANTONIO_424][CENTER][COLOR=DarkRed]Go for it, and remember, video tape every moment...........I gotta see this :D[/COLOR][/CENTER][/QUOTE][/COLOR][/URL][SIZE=1][B][U][URL=http://forums.qj.net/showthread.php?t=65979]A Ultimate QJ FAQ[/URL][/U][/B]-[B][U][URL=http://forums.qj.net/search.php?do=finduser&u=13500]Topics I'm in[/URL][/U][/B]-[B][U][URL=http://forums.qj.net/f-psp-development-forum-11/t-pps-game-66613.html]My qj game topic[/URL][/U][/B]-[B][U][URL=http://www.psp-programming.com/dev-forum/viewtopic.php?t=962]My psp-prog topic[/URL][/U][/B]-[B][U][URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi]Old QJ Download site[/URL][/U][/B]-[B][U][URL=http://forums.qj.net/showthread.php?t=46926]Only ISO topic[/URL][/U][/B][/SIZE]
"You stayed up all night trying to make your psp crash? LOLOL!!" - my brother
My PSN name is "icantthinkofone".[/CENTER]
lord pip is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-04-2006, 11:07 PM   #224
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default Check file size

How do you check the size of a file on ms with normal file io commands?
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-05-2006, 02:44 AM   #225

Muppet Magnet
 
Fanjita's Avatar
 
Join Date: Sep 2005
Location: Edinburgh, UK
Posts: 2,388
Trader Feedback: 0
Default

Quote:
Originally Posted by Art
How do you check the size of a file on ms with normal file io commands?
Use sceIoOpen, then sceIoLSeek32 to the end of the file.

The LSeek call returns the current file position - which by definition equals the size of the file.

Or, use sceIoGetstat, which has the file size in the stats structure.

Or, read it directly from an sceIoDirent structure, if you've been using sceIoDread to browse around the directories.
Fanjita is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-05-2006, 03:41 AM   #226
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Any chance of an example of the first method?

If I read a file after it's finished, I just keep reading zeros.
This would be one way to tell most files have ended,
unless the file actually ends with a lot of zeros.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-05-2006, 10:21 AM   #227
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Ok, thnx, I found a working example:
file_size = sceIoLseek32(musac, 0, SEEK_END);
Cheers, Art.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-05-2006, 04:23 PM   #228

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Can anyone tell me how to get the damned OSLib to install properly? I just need the rotation in it, but its being a pain, keep getting errors and what not while installing and setting up a mkaefile to include it, along with undefined errors after installation of the OSLib...
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-06-2006, 02:42 AM   #229

Developer
 
SodR's Avatar
 
Join Date: Sep 2005
Location: Sweden
Posts: 941
Trader Feedback: 0
Default

How does SceKernelSysClock work? Can you somehow use it to display the same time as the clock in the os in your program with printf?? I have tryed to get it to work but no go so far... If someone has an example how how to use it please tell me.

Thanks in Advance!
SodR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-06-2006, 07:00 AM   #230

OMFG
 
Slasher's Avatar
 
Join Date: Jul 2005
Location: Toronto
Posts: 2,816
Trader Feedback: 0
Default

Here's a quick one...

What's the equivalent to string.sub in LUA; but in C?

An example of what string.sub does in LUA:
Code:
string.sub(s, i [, j])
Return a substring of the string passed. The substring starts at i. If the third argument j is not given, the substring will end at the end of the string. If the third argument is given, the substring ends at and includes j. 

> = string.sub("Hello Lua user", 7)      -- from character 7 until the end
Lua user
> = string.sub("Hello Lua user", 7, 9)   -- from character 7 until and including 9
Lua

Last edited by Slasher; 05-06-2006 at 07:36 AM..
Slasher is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-06-2006, 02:42 PM   #231

Developer
 
Join Date: Oct 2005
Posts: 408
Trader Feedback: 0
Default

Quote:
Originally Posted by Slasher
Here's a quick one...

What's the equivalent to string.sub in LUA; but in C?

An example of what string.sub does in LUA:
Code:
string.sub(s, i [, j])
Return a substring of the string passed. The substring starts at i. If the third argument j is not given, the substring will end at the end of the string. If the third argument is given, the substring ends at and includes j. 

> = string.sub("Hello Lua user", 7)      -- from character 7 until the end
Lua user
> = string.sub("Hello Lua user", 7, 9)   -- from character 7 until and including 9
Lua
Code:
char *string = "Hello Lua user";
printf("%s", string[7];
printf(%.*s", 3, string[7]);
Make sure you check that the string has at least 7 characters and is null-teminated.
Samstag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-10-2006, 06:56 AM   #232
 
Devun_06's Avatar
 
Join Date: Feb 2006
Posts: 338
Trader Feedback: 0
Unhappy

I know this is a stupid question, but I've searched go0gle, yahoo and I couldn't findout how to remove the error
const_cast undefined

can someone tell me what the problem is, adding #include <stdio> isn't helping?
Devun_06 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-10-2006, 07:03 AM   #233

Developer
 
SodR's Avatar
 
Join Date: Sep 2005
Location: Sweden
Posts: 941
Trader Feedback: 0
Default

Have you tryed adding
Code:
#include <stdio.h>
Instead of:
Code:
#include <stdio>
SodR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-10-2006, 01:28 PM   #234
 
Devun_06's Avatar
 
Join Date: Feb 2006
Posts: 338
Trader Feedback: 0
Unhappy

Quote:
Originally Posted by SodR
Have you tryed adding
Code:
#include <stdio.h>
Instead of:
Code:
#include <stdio>
That isn't working either...
Devun_06 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 08:31 PM   #235
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Code:
#include <pspgu.h>
#include <png.h>
Could I please have a description of what these two includes do,
If you draw all of your own graphics on the screen, would you ever need png.h?
Cheers, Art.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 08:33 PM   #236
 
Join Date: Jan 2006
Posts: 4,288
Trader Feedback: 0
Default

Quote:
Originally Posted by Art
Code:
#include <pspgu.h>
#include <png.h>
Could I please have a description of what these two includes do,
If you draw all of your own graphics on the screen, would you ever need png.h?
Cheers, Art.
I'm pretty sure that the gu header is connected to hardware somehow, but the I'm pretty sure that if you weren't using PNGs, then you wouldn't need the png header.
__________________
[URL="http://www.newlilwayne.com"]www.NewLilWayne.com[/URL]
soccerPMN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 08:43 PM   #237
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Do you know if pspgu has anything to do with graphics?
I know I'm slack, I should look it up on ps2dev.

BTW, the file size of pngs that can be loaded is limited even if resolution is 480x272.
I tried to use a complicated 73.9 KB (75,684 bytes) png file and it broke my program,
but a smaller file of the same resolution did work.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 08:46 PM   #238
 
Join Date: Jan 2006
Posts: 4,288
Trader Feedback: 0
Default

Quote:
Originally Posted by Art
Do you know if pspgu has anything to do with graphics?
I know I'm slack, I should look it up on ps2dev.

BTW, the file size of pngs that can be loaded is limited even if resolution is 480x272.
I tried to use a complicated 73.9 KB (75,684 bytes) png file and it broke my program,
but a smaller file of the same resolution did work.
Did you look in the png header? Perhaps somewhere in the code the size of the array/buffer to hold the image can be changed to be greater than 480x272.
__________________
[URL="http://www.newlilwayne.com"]www.NewLilWayne.com[/URL]
soccerPMN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 09:03 PM   #239
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

I was talking about filesize. Both pics are 480x272.
A png file size increases with the detail in the picture.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-12-2006, 09:05 PM   #240
 
Join Date: Jan 2006
Posts: 4,288
Trader Feedback: 0
Default

Quote:
Originally Posted by Art
I was talking about filesize. Both pics are 480x272.
A png file size increases with the detail in the picture.
I know, so you mean the memory itself cannot hold more than that? I originally thought it was limited by the buffer in the code, but you're suggesting it's limited in hardware?
__________________
[URL="http://www.newlilwayne.com"]www.NewLilWayne.com[/URL]
soccerPMN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
c or c , c++ , c/c++ , code , coding , c_language , programming , psp , psp programming , thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



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



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us