| View previous topic :: View next topic |
| Author |
Message |
Ratty
Joined: 18 Sep 2005 Posts: 18
|
Posted: Mon Oct 03, 2005 1:11 pm Post subject: Multiple sceGumTranslate's |
|
|
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. |
|
| Back to top |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Mon Oct 03, 2005 1:29 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Ratty
Joined: 18 Sep 2005 Posts: 18
|
Posted: Mon Oct 03, 2005 1:40 pm Post subject: |
|
|
| Does this mean i can't use sceGumTranslate for this and have to do it manually using sceGuSetMatrix as in the "sprites" sample? |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Mon Oct 03, 2005 6:54 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Ratty
Joined: 18 Sep 2005 Posts: 18
|
Posted: Mon Oct 03, 2005 11:49 pm Post subject: |
|
|
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: |
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();
|
|
|
| Back to top |
|
 |
ashleydb
Joined: 03 Oct 2005 Posts: 26 Location: USA
|
Posted: Tue Oct 04, 2005 3:56 am Post subject: |
|
|
| Code: |
// 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(); |
I think this line should be removed... _________________ www.PSP-Files.com - PSP News, Hacks etc.
www.HiAsh.com - My work and stuff |
|
| Back to top |
|
 |
Ratty
Joined: 18 Sep 2005 Posts: 18
|
Posted: Tue Oct 04, 2005 4:10 am Post subject: |
|
|
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 :/ |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Tue Oct 04, 2005 6:15 am Post subject: |
|
|
-_- 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 |
|
| Back to top |
|
 |
|