forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rotating a 2D sprite in libGU?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Kinsman



Joined: 18 Jul 2005
Posts: 15
Location: Canada

PostPosted: Sun Jul 24, 2005 2:23 am    Post subject: Rotating a 2D sprite in libGU? Reply with quote

I've been looking through the libGU samples, and while rotating a billboard sprite in a 3D world seems easy enough, I'm not sure how you could rotate a sprite using the GU_TRANSFORM_2D setup. Does anyone know how it's done?

-Sean Givan
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Jul 24, 2005 8:21 am    Post subject: Reply with quote

Well, if you're using GU_TRANSFORM_2D, you have to deal with it yourself. Either, you could setup a Ortho-matrix (2D projection) and use GU_TRANSFORM_3D, or use the following formula
Code:

x = cos(a)*x - sin(a)*y
y = sin(a)*x + cos(a)*y

to rotate you coordinates before displaying them.

Or, you could use matrix-math to transform coordinates, but then I'd suggest you setup a ortho-matrix anyway.

I should perhaps do a small example on doing 2D projections, as people seem to want to know how to do them.
_________________
GE Dominator
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Sun Jul 24, 2005 8:42 am    Post subject: Reply with quote

chp wrote:



I should perhaps do a small example on doing 2D projections, as people seem to want to know how to do them.


Yes I would love to see this :)
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Sun Jul 24, 2005 2:49 pm    Post subject: Reply with quote

Code:

   float width = right-left;
   float height = bottom-top;
   float depth = near-far; //depth is reversed on psp
   m[0*4+0] = 2.0f/width;
   m[1*4+1] = 2.0f/height;
   m[2*4+2] = 2.0f/depth;
   m[3*4+0] = -(left+right)/width;
   m[3*4+1] = -(top+bottom)/height;
   m[3*4+2] = -(near+far)/depth;
   m[3*4+3] = 1.0f;


My orthogonal projection matrix calculation function. Works fine for me :P
You may want to negate the Y axis though depending on your preference.
Back to top
View user's profile Send private message
dctrvenkman



Joined: 02 Aug 2005
Posts: 4

PostPosted: Tue Aug 02, 2005 3:23 am    Post subject: Reply with quote

I'm looking for more information on using GU_TRANSFORM_2D also. Altho I'm not trying to rotate just simple translations. I've been trying to translate by updating the x and y coords in my vertices but I've been getting weird reactions. For example save in my vertices array I have 12 vertices (4 triangles) and I update the x member for all of them (thinking all 4 triangles should move horizontally). Only some of the vertices will update in the display (not even necessarily all verts in a triangle). Another issuse is when I attach the x or y transforms to key presses (dpad) its like the view doest update in real time tho the code works fine if I use GU_TRANSFORM_3D. maybe I'd doing something really stupid. A nice little demo using GU_TRANSFORM_2D and some simple transforms might be nice.
Back to top
View user's profile Send private message
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Tue Aug 02, 2005 5:32 pm    Post subject: Reply with quote

dctrvenkman wrote:
Only some of the vertices will update in the display (not even necessarily all verts in a triangle).


Sounds like you aren't flushing the D cache after updating the vertex array - either do that, or use uncached memory for your array (add 0x40000000 to your pointer).
Back to top
View user's profile Send private message Visit poster's website
dctrvenkman



Joined: 02 Aug 2005
Posts: 4

PostPosted: Wed Aug 03, 2005 2:57 am    Post subject: Reply with quote

is there a function to flush the cache or a way to allocate uncached memory rather than changing the address for my pointer. if not thanks anyway and I'll try adding 0x40000000 to my pointer in the meantime
Back to top
View user's profile Send private message
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Wed Aug 03, 2005 5:20 am    Post subject: Reply with quote

Use sceKernelDcacheWritebackAll() (defined in <pspuser.h>) to write the whole data cache.
Back to top
View user's profile Send private message Visit poster's website
dctrvenkman



Joined: 02 Aug 2005
Posts: 4

PostPosted: Wed Aug 03, 2005 5:35 am    Post subject: Reply with quote

thanks I already found it. Took me a while cuz the docs seem fairly non-intuitive and the minimum documentation leaves a lil to be desired (which is prob why there are so many beginner questions). I'll test it later.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group