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.
Multiple sceGumTranslate's
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.
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
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();
Code: Select all
// draw eagle some place else and make it spin
sceGumPushMatrix();
sceGumLoadIdentity(); <-----------------REMOVE
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();
-_- 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 ;)
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