Rotating a 2D sprite in libGU?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Rotating a 2D sprite in libGU?

Post by Kinsman »

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
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

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: Select all

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
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

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 :)
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Code: Select all

	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.
dctrvenkman
Posts: 4
Joined: Tue Aug 02, 2005 3:13 am

Post by dctrvenkman »

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.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

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).
dctrvenkman
Posts: 4
Joined: Tue Aug 02, 2005 3:13 am

Post by dctrvenkman »

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
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Use sceKernelDcacheWritebackAll() (defined in <pspuser.h>) to write the whole data cache.
dctrvenkman
Posts: 4
Joined: Tue Aug 02, 2005 3:13 am

Post by dctrvenkman »

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