Seite 8 von 340 ErsteErste 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 58 108 ... LetzteLetzte
Zeige Ergebnis 211 bis 240 von 10174

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 ...

  
  1. #211
    Points: 3.990, Level: 40
    Level completed: 20%, Points required for next Level: 160
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Beiträge
    4
    Points
    3.990
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    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

  2. #212
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    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


  3. #213
    Points: 3.990, Level: 40
    Level completed: 20%, Points required for next Level: 160
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Beiträge
    4
    Points
    3.990
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    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.

  4. #214
    Developer
    Points: 7.058, Level: 55
    Level completed: 54%, Points required for next Level: 92
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    408
    Points
    7.058
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    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.

  5. #215
    Points: 3.990, Level: 40
    Level completed: 20%, Points required for next Level: 160
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Beiträge
    4
    Points
    3.990
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    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.

  6. #216
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    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


  7. #217
    Developer
    Points: 7.058, Level: 55
    Level completed: 54%, Points required for next Level: 92
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    408
    Points
    7.058
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.

  8. #218
    QJ Gamer Bronze
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Beiträge
    338
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    can someone tell me where I can findout all about PRX`s and how to use them.

  9. #219
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.

  10. #220
    QJ Gamer Bronze
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Beiträge
    338
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    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?

  11. #221
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.

  12. #222
    QJ Gamer Bronze
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Beiträge
    338
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    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.
    Geändert von Devun_06 (05-01-2006 um 01:06 PM Uhr)

  13. #223
    QJ Gamer Silver
    Points: 6.764, Level: 54
    Level completed: 7%, Points required for next Level: 186
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Brampton
    Beiträge
    631
    Points
    6.764
    Level
    54
    Downloads
    0
    Uploads
    0

    Standard

    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:
    Zitat Zitat von ANTONIO_424
    Go for it, and remember, video tape every moment...........I gotta see this :D
    A Ultimate QJ FAQ-Topics I'm in-My qj game topic-My psp-prog topic-Old QJ Download site-Only ISO topic
    "You stayed up all night trying to make your psp crash? LOLOL!!" - my brother
    My PSN name is "icantthinkofone".

  14. #224
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard Check file size

    How do you check the size of a file on ms with normal file io commands?

  15. #225
    QJ Gamer Platinum
    Points: 25.089, Level: 95
    Level completed: 74%, Points required for next Level: 261
    Overall activity: 18,0%

    Registriert seit
    Sep 2005
    Ort
    Edinburgh, UK
    Beiträge
    2.388
    Points
    25.089
    Level
    95
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.

  16. #226
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    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.

  17. #227
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    Ok, thnx, I found a working example:
    file_size = sceIoLseek32(musac, 0, SEEK_END);
    Cheers, Art.

  18. #228
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    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


  19. #229
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    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!

  20. #230
    OMFG
    Points: 19.453, Level: 88
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Toronto
    Beiträge
    2.814
    Points
    19.453
    Level
    88
    Downloads
    0
    Uploads
    0

    Standard

    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
    Geändert von Slasher (05-06-2006 um 06:36 AM Uhr)

  21. #231
    Developer
    Points: 7.058, Level: 55
    Level completed: 54%, Points required for next Level: 92
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    408
    Points
    7.058
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.

  22. #232
    QJ Gamer Bronze
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Beiträge
    338
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    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?

  23. #233
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Have you tryed adding
    Code:
    #include <stdio.h>
    Instead of:
    Code:
    #include <stdio>

  24. #234
    QJ Gamer Bronze
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Beiträge
    338
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    0

    Unhappy

    Zitat Zitat von SodR
    Have you tryed adding
    Code:
    #include <stdio.h>
    Instead of:
    Code:
    #include <stdio>
    That isn't working either...

  25. #235
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    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.

  26. #236
    QJ Gamer Green
    Points: 25.223, Level: 95
    Level completed: 88%, Points required for next Level: 127
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    4.289
    Points
    25.223
    Level
    95
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.
    QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days

  27. #237
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    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.

  28. #238
    QJ Gamer Green
    Points: 25.223, Level: 95
    Level completed: 88%, Points required for next Level: 127
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    4.289
    Points
    25.223
    Level
    95
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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.
    QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days

  29. #239
    Art
    Art ist offline
    Bush Programmer
    Points: 60.149, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Nov 2005
    Beiträge
    3.658
    Points
    60.149
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    I was talking about filesize. Both pics are 480x272.
    A png file size increases with the detail in the picture.

  30. #240
    QJ Gamer Green
    Points: 25.223, Level: 95
    Level completed: 88%, Points required for next Level: 127
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    4.289
    Points
    25.223
    Level
    95
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von 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?
    QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days


 
Seite 8 von 340 ErsteErste 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 58 108 ... LetzteLetzte

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .