Figuring out depth buffers...

Started by
1 comment, last by 3cheeseMac 21 years, 9 months ago
Hello all, I am learning DirectX programming after years spent in 3D effects and simulations. At a certain point you just have to know how it all works under the hood. The problem is that curiosity always leads to more questions. So here it is: If I define one cube object (or any other model for that matter)can I then re-use that object many times in a scene? For instance: let''s say that I want the cube to represent cars on a road. Can each vehicle reference the same cube and transform it as needed and then render it to the target and depth buffer surfaces without problems? It looks like it''s possible from what I''ve read in the reference material so far. Is this an idea that is worth pursuing? Are there any good examples out there if it is in fact a valid way of approaching multi-object scenes? Thanks 3CM
Advertisement
If you''re using object oriented programming, you can create a class. One of the would contain a display model function that referenced the cube,car,dragon or whatever, and any associate animations. Then within your main program you simply create instances of that object.


  class car{public:    // your constructors/destructors    int displayModel();    void setLocation(int , int, int);    int get_coordinate_X();    int get_coordinate_Y();    int get_coordinate_Z();private:    //  your object''s location    float locationx;    float locationy;    float locationz;};// create instancescar mustang;car corvette;// Display Modelsmustang.displayModel();corvette.displayModel();  


Anyway, the above is a ROUGH representation of reusing the same "model" in multiple objects.

Hope it helps.

"Why must we always come up with incredibly philosophic signatures?"
I compare it to that Return of the Jedi scene with all the TIE Fighters flying behind the Millenium Falcon towards the Death Star. They are all the same TIE Fighter model. It is done this way, naturally, to reduce the amount of work needed to create the models before they can film them in front of a bluescreen and then add them to the scene.

3D rendering works the same way. You can have 1000 cubes in your scene, but use the exact same model to render each of them, translating and rotating to a different location each time. Once rendered, the API doesn't need the data piped into it for drawing, so rotating and translating after a given render doesn't destroy what you've drawn before. You can reuse that same data as needed for all renderings. Good that it works that way, too. It would be a shame to have to generate 1000 models of cubes in memory.

In my own designs, I would create a cube model and contain it in an object. In the linked list that houses my game objects, each would have a reference the cube model object for purposes of rendering. Each node in the linked list also has a position and orientation that I would use to transform to the correct place before I render the model referenced.


[edited by - Waverider on June 25, 2002 1:21:19 PM]
It's not what you're taught, it's what you learn.

This topic is closed to new replies.

Advertisement