Multiple sceGumTranslate's

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

Moderators: cheriff, TyRaNiD

Post Reply
Ratty
Posts: 18
Joined: Sun Sep 18, 2005 12:04 pm

Multiple sceGumTranslate's

Post by Ratty »

Hi.

I'm using sceGumTranslate and sceGumRotateXYZ to simulate a camera by offseting all my meshes from the camera position, but then i also need to do the same to position them in the world. The problem is it seems i can't use sceGumTranslate twice on the same mesh. How am i ment to accomplish the effect i want.
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

If you have a matrix and you make it a translation matrix, it overwrites the previous settings.

So doing another sceGumTranslate will just overwrite it.

You need to make a new matrix, put hte new translation in it, multiply the two matrices together, and put the result on the matrix stack.
Ratty
Posts: 18
Joined: Sun Sep 18, 2005 12:04 pm

Post by Ratty »

Does this mean i can't use sceGumTranslate for this and have to do it manually using sceGuSetMatrix as in the "sprites" sample?
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

No, that's not true.

sceGumTranslate() & other operations (for the exception of sceGumLoadMatrix()/sceGumLoadIdentity()) are dependant on what you pushed earlier onto the matrix. Every time you call sceGumTranslate(), you multiply this result into the matrix that is already there, so the order in which you do your matrix-operations matter. For example, calling sceGumRotate*() before sceGumTranslate() yields a completely different answer than calling sceGumTranslate() and THEN sceGumRotate*(). If you need hierarchy, you could use sceGumPushMatrix()/sceGumPopMatrix(), which will save your information while you progress the tree. Just be careful because the stack is currently hardcoded to 32 matrices per matrix-type.
GE Dominator
Ratty
Posts: 18
Joined: Sun Sep 18, 2005 12:04 pm

Post by Ratty »

Here's the code i have so far. For the "eagle" it's only applying the last matrix opperation rather than adding them together. So my eagle spins as expected, but is glued to the camera because the first trans/rot doesn't get applied to it.

Code: Select all

sceGuStart(GU_DIRECT, gList);

	// clear screen
	sceGuClearColor(0xff554433);
	sceGuClearDepth(0);
	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

	sceGumMatrixMode(GU_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(75.0f, 16.0f/9.0f, 0.5f, 1000.0f);

	sceGumMatrixMode(GU_VIEW);
	sceGumLoadIdentity();

	sceGumMatrixMode(GU_MODEL);
	sceGumLoadIdentity();

	sceGumPushMatrix();
	
		sceGumLoadIdentity();
		gCamera.setCamera();	// trans/rot world to simulate camera
		
		// draw world at centre
		test3DS.draw();		// drawArray()

		// draw eagle some place else and make it spin
		sceGumPushMatrix();
		
			sceGumLoadIdentity();
			
			ScePspFVector3 rot = { val * 0.79f * (M_PI/180.0f), val * 0.98f * (M_PI/180.0f), val * 1.32f * (M_PI/180.0f) };
			sceGumRotateXYZ(&rot);
			ScePspFVector3 pos = { 30, 0, -10 };
			sceGumTranslate(&pos);
			
			test3DS2.draw();
		
		sceGumPopMatrix();
	
	sceGumPopMatrix();

sceGuFinish();
ashleydb
Posts: 26
Joined: Mon Oct 03, 2005 2:06 am
Location: USA
Contact:

Post by ashleydb »

Code: Select all

      // draw eagle some place else and make it spin
      sceGumPushMatrix();
      
         sceGumLoadIdentity&#40;&#41;; <-----------------REMOVE
         
         ScePspFVector3 rot = &#123; val * 0.79f * &#40;M_PI/180.0f&#41;, val * 0.98f * &#40;M_PI/180.0f&#41;, val * 1.32f * &#40;M_PI/180.0f&#41; &#125;;
         sceGumRotateXYZ&#40;&rot&#41;;
         ScePspFVector3 pos = &#123; 30, 0, -10 &#125;;
         sceGumTranslate&#40;&pos&#41;;
         
         test3DS2.draw&#40;&#41;;
      
      sceGumPopMatrix&#40;&#41;; 
I think this line should be removed...
www.PSP-Files.com - PSP News, Hacks etc.

www.HiAsh.com - My work and stuff
Ratty
Posts: 18
Joined: Sun Sep 18, 2005 12:04 pm

Post by Ratty »

Removing that causes the last matrix to have no effect.

I've been told my code is flawed, and that my code is ok but the gum lib "might" have a bug. I dunno which is true :/
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

-_- lets get somethings straight with
using gl matrices

1.)glLoadIdent() or similar pspfunction
replaces the current matrix with the
identity matrix -- also take note initially
each of the stacks per mode contains one matrix,
an identity matrix ;) <--do not forget this
It is equivalent to calling glLoadMatrix() with
the identity matrix visualized below
==========
| 1 | 0 | 0 | 0 |
----------------
| 0 | 1 | 0 | 0 |
----------------
| 0 | 0 | 1 | 0 |
----------------
| 0 | 0 | 0 | 1 |
==========


2.)The glPushMatrix() function pushes
the current matrix stack down by one,
duplicating the current matrix. That is,
after a glPushMatrix call, the matrix
on the top of the stack is identical to the one below it
(here is where your problem lies)

3.)glPopMatrix() function pops the current top of
matrix stack, replacing the current matrix
with the one below it on the stack

Common Mistakes:It is error to push
a full matrix stack(after all psp only can contain 32
matrices per mode, this is hardcoded as noted above --
so pushing a 33rd matrix will result in an error on psp)

another common mistake - to pop a matrix stack
that contains only a single matrix
all matrices intilize with identity matrix if you try
to pop this matrix out of top of stack
guess what happens --- error

with this information it is possible psp does things
differently or sceGum* functions are in early
stage and bugs are natural in its course

now if everything looks ok and works ok
then looking at your code there are obvious
problems with how your matrixes are
released and which matrices are put on
top of stack :P

what is first problem you see here?

sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
sceGumPushMatrix();

sceGumLoadIdentity();

if its not apparent you first load identity
matrix on top of stack, then you duplicate
that matrix with push and push that matrix
lower in stack with another identity matrix
now on top -- thus far thats 2 identity matrices
in stack of 32, but what is your answer to
counter this ;P

you load identity matrix once more and thus
replace top of stack with new identity matrix on top of
stack -- thus resulting in 2 identical matrices
or identity matrices :P right back where you
started :P

everything before these functions looks about right
and functions after these look about right too

but then you push once more :P

// draw world at centre
test3DS.draw(); // drawArray()

// draw eagle some place else and make it spin
sceGumPushMatrix(); <-- here is problem

so what outcome shall this produce if you
have not used any popping? ...you guessed it
the current top of stack (identity matrix from b4)
is duplicated and old top of stack is pushed
down while duplicate of identity is added
as new top of stack thus creating 3 identical
matrices and thus becoming a mess :P

you do not end it here tho ...more to come ;)

sceGumLoadIdentity();

thats right next line does just what you
did earlier...you take top of stack which is
already a identity matrix and you replace it
with ......another identity matrix so that
results in 3 identity matrices ....this is called
walking in circles and ad you can see
is rather pointless and waste of line of code ;)

i hope that this gives you more insight
as to how or what you should do you remedy
your problem ....ill end at this line

sceGumLoadIdentity();

and ill let you resolve your problem
with simple trial and error and take
the knowledge explained above to
rectify your code ;)
10011011 00101010 11010111 10001001 10111010
Post Reply