Skip to main content
gamedev.net
🔒 Locked

Problem defining 3D objects

Started by Vendayan 4 replies 150+ views
Original Post
Vendayan
Vendayan
Class 3D_Object { texture textures[10]; primitive primitives[800]; }; Class Primitive { primitive_type type; vector vectors[3]; }; This is obviously a very rough draft of my problem, but by now you should obviously be able to see where im going wrong. Each of my objects defined in this way will take an insane amount of memory (which is equal to the most complicated object I could possibly make). Can anyone show me how I should define my classes so that they won''t take a constant amount of memory, and offer a description of your method and how it works so that I can understand? ~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Martee
Martee
    
Class 3D_Object
{
texture* textures;
primitive* primitives;
};

3D_Object obj;
obj.textures = new texture[numTextures];
obj.primitives = new primitive[numPrimitives];

Just use pointers, and allocate however much memory you need for a particular object.

Edited by - Martee on November 24, 2001 10:40:59 PM
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Vendayan
Vendayan
Thanks, so then I could simply send the nuber of textures and primitives to the class through its constructor?
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Sepsis
Sepsis
Thats somewhat broad, but I have a hard time getting real specific as well hehehehe. Anyway, here is a more efficent what that should suffice for what your looking for. Try to stick to something along the lines of this.

//---------------------------
// class CMyD3DApplication
//---------------------------

class CMyD3DApplication : public CD3DApplictaion
{
//Create your devices, objects, buffers etc..here
LPDIRECT3D8 g_d3d;
LPDIRECT3DDEVICE8 g_d3dDevice;
LPDIRECT3DVERTEXBUFFER8 g_d3dVb;

//Run ConfirmDevice here
HRESULT ConfirmDevice( D3DCAPS8*, DWORD, D3DFORMAT);

protected:
//Your functions

HRESULT OneTimeSceneInit();
HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
HRESULT Render();
HRESULT FrameMove();
HRESULT FinalCleanup();
//And any others that you desire

public:
CmyD3DApplication();
};

//Then down in the file you can use all these, be sure to set your defaults in your constructor.
Vendayan
Vendayan
Now if that number changes by lowering or raising how do I make the change?

For instance I am hoping to make an engine where the world will be very large and also where it will be one continous level, so the number of objects in every frame will depend on how many objects are within roughly a 500 yard radius of the camera.
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Biggles
Biggles
It sounds to me like you don''t really understand dynamic memory. If this is so, I extremelly highly recommend going and reading up on it, especially pointers. If it isn''t the case, I apologise.


--------------------

Never eat anything bigger than your own head.
--------------------Never eat anything bigger than your own head.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.