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!

need help with sprite rotation

This is a discussion on need help with sprite rotation within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hey, I've been gone for a long time because of school and all but I'm trying to get back to ...

Reply
 
LinkBack Thread Tools
Old 01-27-2009, 01:45 PM   #1
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default need help with sprite rotation

Hey, I've been gone for a long time because of school and all but I'm trying to get back to developing games. I refreshed my memory by going through the psp-programming tutorials so I'm using the graphics.c file right now and I have a problem. I need a sprite to rotate by the amount of radians I want it to because I'm making it so he will walk in the direction he is facing(assuming you're at a bird's eye view). I can get the movement fine because I know how to use cosf and sinf but I'm not sure how to get the actual sprite to rotate. I want to modify blitAlphaImageToScreen() function to apply a certain rotation in radians to the sprite so obviously I had to add an extra argument.

here is the function with a new argument for rotation in it(but I never used it):
Code:
void blitAlphaImageToScreenRot(int sx, int sy, int width, int height, Image* source, int dx, int dy,float rad)
{
	if (!initialized) return;

	sceKernelDcacheWritebackInvalidateAll();
	guStart();
	sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data);
	float u = 1.0f / ((float)source->textureWidth);
	float v = 1.0f / ((float)source->textureHeight);
	sceGuTexScale(u, v);
	
	int j = 0;
	while (j < width) {
		Vertex* vertices = (Vertex*) sceGuGetMemory(2 * sizeof(Vertex));
		int sliceWidth = 64;
		if (j + sliceWidth > width) sliceWidth = width - j;
		vertices[0].u = (sx + j);
		vertices[0].v = (sy);
		vertices[0].x = (dx + j);
		vertices[0].y = (dy);
		vertices[0].z = 0;
		vertices[1].u = (sx + j + sliceWidth);
		vertices[1].v = (sy + height);
		vertices[1].x = (dx + j + sliceWidth);
		vertices[1].y = (dy + height);
		vertices[1].z = 0;
		sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
		j += sliceWidth;
	}
	
	sceGuFinish();
	sceGuSync(0, 0);
}
now what should I do to make the sprite rotate from here?

Last edited by pspballer07; 01-27-2009 at 06:15 PM..
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-27-2009, 06:08 PM   #2
No longer a community member.
 
a_noob's Avatar
 
Join Date: Sep 2006
Location: Over there.
Posts: 666
Trader Feedback: 0
Default

Well, to start I advise you to not rotate and strip blit as it causes images to be choppy, second, setup 4 vertices and use a triangle fan. THen from there it is a simple cos/sin to translate the vertices to their proper location. It is just simple trig.
a_noob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-27-2009, 06:28 PM   #3
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

Quote:
Originally Posted by a_noob View Post
Well, to start I advise you to not rotate and strip blit as it causes images to be choppy, second, setup 4 vertices and use a triangle fan. THen from there it is a simple cos/sin to translate the vertices to their proper location. It is just simple trig.
Thanks, can you write how you would do it into that function and comment whatever you add? I'm in high school and we haven't done that much trig. we just finished with quadratic equations and started trig.
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-27-2009, 06:34 PM   #4

Developer
 
Join Date: Aug 2007
Location: Australia
Posts: 657
Trader Feedback: 0
Default

Couldn't you just print with sceGum and rotate with sceGumRotateZ?

Then again I have very little GU experience so it may not be that easy
__________________

Last edited by Xsjado7; 01-27-2009 at 06:45 PM..
Xsjado7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-27-2009, 06:56 PM   #5
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

Quote:
Originally Posted by Xsjado7 View Post
Couldn't you just print with sceGum and rotate with sceGumRotateZ?

Then again I have very little GU experience so it may not be that easy
I tried changing this:
Code:
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
to this :
Code:
sceGumRotateZ(rad);
		sceGumDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
in the graphics.c file and it drew the sprite like normal but it never rotated. for anyone thinking its just a mess-up with the "rad" float value, I already checked it to make sure it had the right value.
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-28-2009, 12:16 AM   #6
Art

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

Looking at this:
http://community.hackingpsp.com/foru.../ShowPost.aspx
would probably give you some idea,
because it's based on graphics.c.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-28-2009, 07:55 AM   #7
No longer a community member.
 
a_noob's Avatar
 
Join Date: Sep 2006
Location: Over there.
Posts: 666
Trader Feedback: 0
Default

NEVER ask for code. Thats a big NO NO. Plus im in High School too, so there is not an excuse there.
a_noob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-28-2009, 08:29 AM   #8
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

Quote:
Originally Posted by a_noob View Post
NEVER ask for code. Thats a big NO NO. Plus im in High School too, so there is not an excuse there.
I asked you to modify the code I had. and I get straight As so if they haven't taught us something, I try to look it up, but sometimes it's hard to get a good explanation.
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-28-2009, 02:27 PM   #9
No longer a community member.
 
a_noob's Avatar
 
Join Date: Sep 2006
Location: Over there.
Posts: 666
Trader Feedback: 0
Default

http://letmegooglethatforyou.com/?q=...right+triangle

First link.
a_noob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-29-2009, 03:56 PM   #10
 
pspballer07's Avatar
 
Join Date: Feb 2007
Posts: 315
Trader Feedback: 0
Default

Quote:
Originally Posted by a_noob View Post
haha nice.
well I already knew all that, I just wasn't sure how to apply it to vertices but it's ok because I'm going to use the lib that you gave me a link to. thanks.
pspballer07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
rotation , sprite

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 10:44 AM.



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