lolitrain / marisa

2 stars 0 forks source link

manual rotation? #12

Open laochailan opened 13 years ago

laochailan commented 13 years ago

I didn't get it to run here, but what you do there to rotate your sprites seems a bit strange to me. Is there any reason you don't use OpenGL's capabilities for rotation/matrix manipulation? would be faster and easier (no need for a vector/matrix implemntation)

Just try something like:

glPushMatrix(); // gl's matrices work like a stack

// the order of these manipulations is important, by the way.

glTranslatef(x, y, 0); // translate to the position of your object (so now you are working relatively to that position) glRotatef(angle, 0, 0, 1); // the last three numbers are a vector for the rotation axis glScalef(texw/2.0, texh/2.0, 1); // mostly i also do this to make the following part clearer

glBegin(GL_QUADS); glVertex3f(-1,-1,0); glVertex3f(-1,1,0); glVertex3f(1, 1, 0); glVertex3f(1,-1,0); glEnd(); glPopMatrix(); // pop our modified matrix again

this way you can improve performance and simplicity. and matrix manipulation is a feature every implementation of opengl has. further hints for performance:

i don't know if this is a help, i just felt like writing it when reading your code.

lolitrain commented 13 years ago

Thanks for looking at my small project I really appreciate it.

I am unsure whats the best way to implement rotation, so I implemented with manual matrix multiplication. The original Python code used PyOpenGL and worked the way you describe it. But it was way too slow and I had to switch to vertex buffer objects and shaders, but it was too slow anyway. The C rewrite of the code is the direct translation of the Python vertex buffer/shader code, minus the actual buffers and shaders :) (if that makes any sense). After rewriting everything in C the way you see it, the performance issues disappeared, so I left the code as is for now.

Depending on how things go performance wise later after I add more objects and effects, I'll most likely rewrite sprite rotation using vertex shaders so the manual matrix multiplication will be removed.

As to your other points:

laochailan commented 13 years ago

i don't think the manual matrix manipulation is faster at all. graphics cards can do that stuff way faster so the only thing you get is messy, less dynamical code. i do it the way i described in my project and i do it with really a lot of vertices every frame with blending enabled without having any performance problems (also with pretty old hardware). that's most probably not your bottleneck.

concerning the other points:

oh and i think relying on shaders for a simple thing like rotation is a bad idea. there are still some machines which don't support them.