marijnh 182 Report post Posted March 3, 2003 [this comes from someone who has written a rudimentary software-only 3d engine, but is really new to opengl, bear with me if i say something stupid] My dilemma is that for the collision checking system of a game you will need to at least align your objects/vertices so that their relative positions are correct, so you would need a matrix/transform system outside of opengl. While you are at it you might as well align them correctly relative to the camera too. It seems opengl always runs points though the modelview matrix. So when you are passing already-aligned points to opengl with an identity modelview matrix, does opengl skip the modelview tranformation or does that still cost performance? I have to admit the opengl matrix system is pretty nifty. Is there an (efficient) way to get the transformed points back for evaluation or something so you can cut the internal matrix system? Marijn 0 Share this post Link to post Share on other sites

_walrus 126 Report post Posted March 3, 2003 "Is there an (efficient) way to get the transformed points back for evaluation or something so you can cut the internal matrix system?"not really; i think it''s best for you to do the matrix operations on the cpu side for your collision detection, since pulling data back from the graphics card is slow. I recently did a benchmark on the two methods (product of two matricies) and the cpu one is at least 10 time faster (from what i remember. You might be able to increase performance of your cpu operations using SIMD ( i think there are some good articles here or at gamasutra)class Matrix{double m11, m12, m13, m14, m21, ......, m44;}; void Matrix::gpuTranslateBy (Point translation) //slower because we have to pull data back from the card{ glPushMatrixd (*this); glTranslated (translation.x, translation.y, translation.z); glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble *) *this); glPopMatrix(); }void Matrix:: cpuTranslateBy(Point p){ //insert your matrix multiplication here (this way is faster)}I used a translation example here but the same thing applies to general multiplication of two matricies."It seems opengl always runs points though the modelview matrix. So when you are passing already-aligned points to opengl with an identity modelview matrix, does opengl skip the modelview tranformation or does that still cost performance?"Yeah i''ve wondered about that one too; if there is an identity on the top of one of the stacks, does the graphics card skip this when processing verticies? I''m not sure but from what i''m guessing, it probably doesn''t since it would have to check the values of the matrix to see if it is the identity. So if it is the idenity the multiplication would be skipped, but for every other multiplication where it wasn''t the identity then there is the additional overhead of this identity check. I think there is an extension (correct me if i''m wrong) that allows you to lock your verticies (compiled_vertex_array or something like that) so they dont get transformed again until you unlock them. 0 Share this post Link to post Share on other sites

Lev Povalahev 122 Report post Posted March 3, 2003 quote:It seems opengl always runs points though the modelview matrix. So when you are passing already-aligned points to opengl with an identity modelview matrix, does opengl skip the modelview tranformation or does that still cost performance? Most implementations should be smart enough to skip the modelview transformation, but _you_ make a bad decision if you transform all your vertices in software and use OpenGL as a rasterizer only. Modern hardware is really MUCH (MUCH) faster on this task than the host CPU.quote:I have to admit the opengl matrix system is pretty nifty. Is there an (efficient) way to get the transformed points back for evaluation or something so you can cut the internal matrix system? nope, you''ll have to transform them yourself. BUT: using triangle-triangle collision is not very efficient, if you have very dense meshes (if you have only low-poly models you won''t hit the GPU limit anyway). Hierarchical methods are more useful here, like AABB trees. Using hierarchical methods enables to use optimizations (example: don''t transform the whole AABB tree with modelview if the top box in the tree does not intersect the tested object)Regards-LevP.S. for more information: google is your friend. 0 Share this post Link to post Share on other sites

marijnh 182 Report post Posted March 3, 2003 So a good idea would be to use a collision detection system that doesnt transform all vertices (exept maybe in near-collision situations), and then do all the transformations from scratch when passing the points to opengl? Sounds like it is efficient...Marijn 0 Share this post Link to post Share on other sites

_walrus 126 Report post Posted March 3, 2003 if you have a large mesh that your comparing against, it might be faster to transform the think that your checking the mesh against (vector or point or what ever) into the local cooridnate space of your object. 0 Share this post Link to post Share on other sites