Computer Science Canada sorting attributes of an object |
Author: | shaon [ Fri Apr 11, 2008 8:34 pm ] |
Post subject: | sorting attributes of an object |
When working in 3D, objects in the far back are drawn first with the closest object to camera being the last object to be drawn. I stored the center coordinate of any object in space as it's attribute (ie. self.position = [x,y,z]). I then made an enviroment class that stores(in a list) and transforms this point based on user control. The problem that I havent figured out how to overcome is how to efficiently sort all the objects in 3D space that are held in a list, so that the object with the highest "z" point is first on the list and lowest "z" point object is last on the list. I guess my question is, how do I sort objects in a list based on one of their attributes? I tried to make a modified merge sort, but sorting 1000 integers sucks up 16-17 ms and I can only afford 40 ms total for my game (25 fps). In fact is there a better way to draw objects in a 3D plane correctly rather than sorting? I feel sorting takes too much processing time..... |
Author: | rdrake [ Fri Apr 11, 2008 9:39 pm ] | ||
Post subject: | Re: sorting attributes of an object | ||
You can and it's fairly easy. Read this. In particular, pay attention to this snippet:
|
Author: | shaon [ Fri Apr 11, 2008 10:24 pm ] |
Post subject: | Re: sorting attributes of an object |
thx, I tried to search for the sort techniques in the manual and I couldn't find anything. Thank you oh so very much!!!! One step closer to a full-fledged 3D world.... |