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 ...
-
04-29-2006, 01:00 PM #211
- Registriert seit
- Apr 2006
- Beiträge
- 4
- Points
- 3.990
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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.
Geändert von Kage68 (04-29-2006 um 01:33 PM Uhr) Grund: Thought of a (possibly) better way
-
04-29-2006, 04:33 PM #212words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Maybe a small example, you lost me therem but i understand some of it.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
04-29-2006, 06:01 PM #213
- Registriert seit
- Apr 2006
- Beiträge
- 4
- Points
- 3.990
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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():
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.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;
I hope you find it useful.
-
04-29-2006, 07:15 PM #214Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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.
-
04-29-2006, 08:30 PM #215
- Registriert seit
- Apr 2006
- Beiträge
- 4
- Points
- 3.990
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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.
-
04-30-2006, 02:49 AM #216words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
04-30-2006, 04:28 AM #217Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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.
Zitat von Kage68
-
04-30-2006, 01:39 PM #218
can someone tell me where I can findout all about PRX`s and how to use them.
-
05-01-2006, 04:39 AM #219Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You can either check the tutorial at forums.ps2dev.org or just use the sample included in the sdk.
Zitat von Devun_06
-
05-01-2006, 10:23 AM #220
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?
-
05-01-2006, 10:58 AM #221Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
Zitat von Devun_06
-
05-01-2006, 01:01 PM #222
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.Geändert von Devun_06 (05-01-2006 um 01:06 PM Uhr)
-
05-02-2006, 12:26 AM #223QJ Gamer Silver
- Registriert seit
- Jul 2005
- Ort
- Brampton
- Beiträge
- 631
- Points
- 6.764
- Level
- 54
- Downloads
- 0
- Uploads
- 0
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.You can hyperlink quotes and the whole box will be a link:
A Ultimate QJ FAQ-Topics I'm in-My qj game topic-My psp-prog topic-Old QJ Download site-Only ISO topic
Zitat von ANTONIO_424
"You stayed up all night trying to make your psp crash? LOLOL!!" - my brother
My PSN name is "icantthinkofone".
-
05-04-2006, 10:07 PM #224Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Check file size
How do you check the size of a file on ms with normal file io commands?
-
05-05-2006, 01:44 AM #225QJ Gamer Platinum

- Registriert seit
- Sep 2005
- Ort
- Edinburgh, UK
- Beiträge
- 2.388
- Points
- 25.089
- Level
- 95
- Downloads
- 0
- Uploads
- 0
Use sceIoOpen, then sceIoLSeek32 to the end of the file.
Zitat von Art
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.Using firmware v2.00-v3.50? Open up a whole world of homebrew here
The PSP Homebrew Database needs YOU!
Your ISP may be illegally wiretapping all your web activity. Stop Phorm Now!
Visiting the Edinburgh Festivals? Get practical advice from experts.
-
05-05-2006, 02:41 AM #226Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
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.
-
05-05-2006, 09:21 AM #227Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Ok, thnx, I found a working example:
file_size = sceIoLseek32(musac, 0, SEEK_END);
Cheers, Art.
-
05-05-2006, 03:23 PM #228words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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...

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
05-06-2006, 01:42 AM #229Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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!
-
05-06-2006, 06:00 AM #230OMFG

- Registriert seit
- Jul 2005
- Ort
- Toronto
- Beiträge
- 2.814
- Points
- 19.453
- Level
- 88
- Downloads
- 0
- Uploads
- 0
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 LuaGeändert von Slasher (05-06-2006 um 06:36 AM Uhr)
-
05-06-2006, 01:42 PM #231Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Zitat von Slasher
Make sure you check that the string has at least 7 characters and is null-teminated.Code:char *string = "Hello Lua user"; printf("%s", string[7]; printf(%.*s", 3, string[7]);
-
05-10-2006, 05:56 AM #232
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?
-
05-10-2006, 06:03 AM #233Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Have you tryed adding
Instead of:Code:#include <stdio.h>
Code:#include <stdio>
-
05-10-2006, 12:28 PM #234
That isn't working either...
Zitat von SodR
-
05-12-2006, 07:31 PM #235Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Could I please have a description of what these two includes do,Code:#include <pspgu.h> #include <png.h>
If you draw all of your own graphics on the screen, would you ever need png.h?
Cheers, Art.
-
05-12-2006, 07:33 PM #236QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
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.
Zitat von Art
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
05-12-2006, 07:43 PM #237Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
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.
-
05-12-2006, 07:46 PM #238QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
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.
Zitat von Art
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
05-12-2006, 08:03 PM #239Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I was talking about filesize. Both pics are 480x272.
A png file size increases with the detail in the picture.
-
05-12-2006, 08:05 PM #240QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
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?
Zitat von Art
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum