| View previous topic :: View next topic |
| Author |
Message |
Kinsman
Joined: 18 Jul 2005 Posts: 15 Location: Canada
|
Posted: Sun Jul 24, 2005 2:23 am Post subject: Rotating a 2D sprite in libGU? |
|
|
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 |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Sun Jul 24, 2005 8:21 am Post subject: |
|
|
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 |
|
 |
apache37
Joined: 04 Jun 2004 Posts: 76
|
Posted: Sun Jul 24, 2005 8:42 am Post subject: |
|
|
| 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 |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Sun Jul 24, 2005 2:49 pm Post subject: |
|
|
| 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 |
|
 |
dctrvenkman
Joined: 02 Aug 2005 Posts: 4
|
Posted: Tue Aug 02, 2005 3:23 am Post subject: |
|
|
| 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 |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Tue Aug 02, 2005 5:32 pm Post subject: |
|
|
| 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 |
|
 |
dctrvenkman
Joined: 02 Aug 2005 Posts: 4
|
Posted: Wed Aug 03, 2005 2:57 am Post subject: |
|
|
| 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 |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Wed Aug 03, 2005 5:20 am Post subject: |
|
|
| Use sceKernelDcacheWritebackAll() (defined in <pspuser.h>) to write the whole data cache. |
|
| Back to top |
|
 |
dctrvenkman
Joined: 02 Aug 2005 Posts: 4
|
Posted: Wed Aug 03, 2005 5:35 am Post subject: |
|
|
| 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 |
|
 |
|