Update and render large number of triangles

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

Moderators: cheriff, TyRaNiD

User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

Vincent is absolutely right. But it's better than just saving 2 points per quad. You can consolidate all your sprites into just one call to sceGuDrawArray(as long as they all have the same texture and blending mode) instead of once per quad like in the GU_STRIPS case.

This not only saves the overhead of possibly hundreds to thousands function calls per frame, but it saves space in the display list as every call to a drawing function takes space on the list to store info such as the command and any associated flags and parameters. This is a huge savings!

Getting GU_SPRITES working is probably the easiest way for you to gain lots of speed. After that I would probably work on allocating your particles once into a pool, and using some method to manage these particles. This will one again save you all kinds of overhead not to mention avoiding heap fragmentation.

Anyway, enough proselytizing. I can't wait to see the finished project. Lot's of luck.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

@tacoSunday: Well first what did the trick, first I discovered that the position used the previous model matrix so when I use an identity matrix for the particles the were exactly on the place I wanted them. There was only one problem left, The camera matrix was the same all the time. This was actually not the case but I needed to store the view matrix manually into a new matrix and then I could read the values fine. Then I used your code to align it with the view (changing some values to inverse it for my upsidedown world coordinates) and TADADADADA thanks to yuo guys it works now :D

@tacoSunday & Vincent_M: hmmm I see what you mean, it would be a great speedup indeed, I think i'll will try it once again, it could mean a huge speedup. however one not;

my trianglestrips are rendered like this:

3--4
|\ |
| \|
1--2

(also due to the strange coords system)

so in my case I need the 2 and the 3 right?

EDIT EDIT EDIT EDIT EDIT

well I have tried every combination of the vertices that did the trick for my trianglestrips but non gave the correct to the camera orientation. here are the combinations that worked almost:

Code: Select all

DisplayVertices[j].u = 0.0f;
		DisplayVertices[j].v = 0.0f;
		DisplayVertices[j].color = 0xffffffff;
		DisplayVertices[j].x = particles.at(i)->x + ((this->up_.x + this->right_.x) * size);
		DisplayVertices[j].y = particles.at(i)->y + ((this->up_.y + this->right_.y) * size);
		DisplayVertices[j].z = particles.at(i)->z + ((this->up_.z + this->right_.z) * size);

		DisplayVertices[j+1].u = 1.0f;
		DisplayVertices[j+1].v = 1.0f;
		DisplayVertices[j+1].color = 0xffffffff;
		DisplayVertices[j+1].x = particles.at(i)->x - ((this->up_.x - this->right_.x) * size);
		DisplayVertices[j+1].y = particles.at(i)->y - ((this->up_.y + this->right_.y) * size);
		DisplayVertices[j+1].z = particles.at(i)->z - ((this->up_.z - this->right_.z) * size);
combinations:

++ / -- , the quad is rendered on top so the heigth of both vertices seems the same but Whatever i try I can't get one vertices to go down so that the quad faces the camera correct.

++ / +- , the quad is rendered facing left, in the middle ,only need to rotate this one around the Y axis 90 degrees

-- / -+ , same as above only not in the middle but on the left. So rotating it the same as the one above this will let if face the camera but the position is to the left instead of centered.

++ / -+ , this one is diagonal facing up/right, so just translating a point in only one direction should do the trick but also tried a lot here but can't get it correct :s

+- / -- , same as the one above here only facing up/left.

well these were the best I could get them, it is just puzzling me, and the working code for the quads(using triangle strips):

Code: Select all

float size = (float)particles.at(i)->life / (float)this->maxLife_;

		DisplayVertices[0].u = 0.0f;
		DisplayVertices[0].v = 0.0f;
		DisplayVertices[0].color = 0x9900ffff;
		DisplayVertices[0].x = particles.at(i)->x - (this->right_.x - this->up_.x) * size;
		DisplayVertices[0].y = particles.at(i)->y - (this->right_.y - this->up_.y) * size;
		DisplayVertices[0].z = particles.at(i)->z - (this->right_.z - this->up_.z) * size;

		DisplayVertices[1].u = 1.0f;//particleTexture->textureWidth-1;
		DisplayVertices[1].v = 0.0f;
		DisplayVertices[1].color = 0x9900ffff;
		DisplayVertices[1].x = particles.at(i)->x - (this->right_.x + this->up_.x) * size;
		DisplayVertices[1].y = particles.at(i)->y - (this->right_.y + this->up_.y) * size;
		DisplayVertices[1].z = particles.at(i)->z - (this->right_.z + this->up_.z) * size;

		DisplayVertices[2].u = 0.0f; //particleTexture->textureWidth-1;
		DisplayVertices[2].v = 1.0f; //particleTexture->textureHeight-1;
		DisplayVertices[2].color = 0x9900ffff;
		DisplayVertices[2].x = particles.at(i)->x + (this->right_.x + this->up_.x) * size;
		DisplayVertices[2].y = particles.at(i)->y + (this->right_.y + this->up_.y) * size;
		DisplayVertices[2].z = particles.at(i)->z + (this->right_.z + this->up_.z) * size;

		DisplayVertices[3].u = 1.0f;
		DisplayVertices[3].v = 1.0f; //particleTexture->textureHeight-1;
		DisplayVertices[3].color = 0x9900ffff;
		DisplayVertices[3].x = particles.at(i)->x + (this->right_.x - this->up_.x) * size;
		DisplayVertices[3].y = particles.at(i)->y + (this->right_.y - this->up_.y) * size;
		DisplayVertices[3].z = particles.at(i)->z + (this->right_.z - this->up_.z) * size;
		
		sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 4, 0, DisplayVertices);
User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

Lol, yer fubared transforms strike again! I can see that they will be a source of endless fun for you throughout this project!

Kidding aside, fixing your sprite orientation shouldn't be too bad. I would use one of your off by 90 combinations, then start mucking with your up and right vector extraction routines. A 90 degree rotation should be as simple as swapping say, the x and y axes in the relevant vector. Just keep swapping different axes.

Happy hunting.

EDIT: silly typo
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

How exactly would I 'spin' my billboards? I'm guessing quarternoins?
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

translate vectors on Z for spinwheel
translate vectors on Y for boatflap
translate vectors on X for cool ;)
10011011 00101010 11010111 10001001 10111010
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

so if i wanted to rotate it by 1.5707 radians l, just have to add an x y and a value of 1.5707 to my vertices' positions then?
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Code: Select all

/**
  * Rotate around the X axis
  *
  * @param angle - Angle in radians
**/
void sceGumRotateX(float angle);

/**
  * Rotate around the Y axis
  *
  * @param angle - Angle in radians
**/
void sceGumRotateY(float angle);

/**
  * Rotate around the Z axis
  *
  * @param angle - Angle in radians
**/
void sceGumRotateZ(float angle);

/**
  * Rotate around all 3 axis in order X, Y, Z
  *
  * @param v - Pointer to vector containing angles
**/
void sceGumRotateXYZ(const ScePspFVector3* v);

/**
  * Rotate around all 3 axis in order Z, Y, X
  *
  * @param v - Pointer to vector containing angles
**/
void sceGumRotateZYX(const ScePspFVector3* v);
You would use them (from pspgum.h)
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

<This message was originally posted twice somehow>

Is there a way to delete this current post. The real post is below this one.
Last edited by Vincent_M on Mon Sep 10, 2007 7:08 am, edited 1 time in total.
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

I tried that already. I thought that would work too, but then I remembered that I got my billboards to rotate to face the camera because of the x and y vectors in the camera. I think I'll have to rotate my billboards based on translation, but I'm not sure how. That's what rotation breaks down to anyway. Seeing that I use the camera's x and y vectors, I bet I can't implement quaternions correctly without if conflicting with those vectors until I understand exactly how the view matrix works better. Also, I'm not actually transforming the billboards at all, I'm just plugging in the vertices' actual position first. Now, if I just setup some blit code to set the vertices, and then rotated them via rotation those rotation matrices, I think that'll do it, but in that case, I don't know if the camera's x and y vectors will come in handy then because the x and y vectors are actually transformed vectors, not translation/rotation values to plug into a matrix to get a resultant matrix.

I think that if I wanted this to work, I will have to redo my code. Not actually redoing it from scratch, but redo how I implemented it. This code was originally based on taceSunday's code, and Raphael's explanation. If I can get the vertex positions that I should just by taking this code and reimplementing it differently using matrices to transform it instead of directly plugging in the information, I think I have a shot at getting this to work.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

@taco: Yes i think I am pretty much scr&$%wed, I guess the problem is that the sprite function does something with my view info when using sprites, because otherwise how does the triangle knows what way to face, the reason I guess my trianglestrip works is because I can set the other vertices also so that I can make it right, with sprites maybe the lack of control is the reason why it does not work :S

anyway, I'll stick to my trianglestrips, and at the end I will see how much it hurt me :s, now I will continue with the rest :D

here is a screenshot of how it looks now :D

Image
User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

Best of luck.
Post Reply