   Sorting Renderables front to back
  Hi there,I want to sort some 3d renderables front to back from the viewer every frame in a 3rd person RPG game engine. Each of the renderables is a large group of triangles and has a 3-d vector for its "center". The camera is a standard 3d camera with a view matrix.I read somewhere that the "easiest" way to sort these renderables is in view space because then I can just sort based on the z-component.If this is the case, how can I move them to view space for the purposes of the sort?   
Quote:If this is the case, how can I move them to view space for the purposes of the sort?Just transform the object centers by the camera view matrix.Since it's really only the z value that's of interest, you could also do the following:float view_space_z = dot(object.center - camera.position, camera.forward);;  If you have a view matrix, then you just multiply the center by said matrix and it will be in view space.  Alternatively, if you have a 3D camera, you can use the location and normalized forward vector directly without needing to transform the whole point.  The distance is then d = dot(p,F) - dot(C,F), where 'p' is the test point, 'F' is the normalized forward vector, and 'C' is the camera location.Are you sorting your renderables from front to back to reduce overdraw?  Because sorting isn't technically necessary unless they're transparent.  Plus large objects close together don't sort very well because they overlap, and the sort is based on a center point that doesn't represent the whole volume very well.  Just some things to think about.EDIT: Damn jyk and his ninjafoo :)   ;  Thanks guys, yeah the objects are a bunch of trees with leaves (the botanical variety ;)   