source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/EnvMap [DirectX]/Mesh.h @ 3255

Revision 3255, 2.3 KB checked in by szirmay, 15 years ago (diff)
Line 
1#pragma once
2/**
3        \brief Encapsulates a mesh of .X format.
4        \brief Adds helper functions for easier scaling, moving, texturing
5        \see OptimizedMesh DirectX SDK Sample
6*/
7class Mesh
8{
9        ID3DXMesh* pMesh;                                       ///< THE .X MESH OBJECT
10        IDirect3DTexture9* pMeshTexture;
11
12        DWORD numMaterials;
13        D3DXVECTOR3 originalSize;
14        float originalDiameter;
15        float preferredDiameter;
16        D3DXVECTOR3 containerSize;
17
18        HRESULT hr;
19        D3DXVECTOR3 position;
20
21public:
22
23        /// Loads the specified .X file
24        /// \param fileName name of the mesh file
25        /// \param texFileName name of the texture file
26        /// \param preferredDiameter final size of the mesh
27        /// \param position initial position of the mesh.
28        /// During rendering, use GetMeshScale() to get the appropriate scaling factor
29        /// to achieve the preferred mesh size.
30        Mesh(LPCWSTR fileName, LPCWSTR texFileName, float preferredDiameter, D3DXVECTOR3 position);
31        /// Destructor. Deletes dynamically created resources.
32        ~Mesh();
33
34        /// \brief LOADS THE SPECIFIED .X FILE
35        /// Eliminates mesh offset (centers the mesh to the origin)
36        /// and determines mesh size (#originalSize, #originalDiameter).
37        void Load(LPCWSTR fileName);
38        /// Adds the specified offset to the mesh position.
39        /// \param bContainerOnly indicates whether the object can leave the room
40        void Move(D3DXVECTOR3 offset, bool bContainerOnly = false);
41        /// Draws the mesh. Before drawing, use GetMeshScale() to get the appropriate scaling factor.
42        HRESULT Draw();
43        /// current mesh size   
44        D3DXVECTOR3 GetMeshSize()   { return GetMeshScale() * originalSize; }
45        /// current mesh scale
46        float GetMeshScale()            { return preferredDiameter / originalDiameter; }
47        /// current mesh position
48        D3DXVECTOR3 GetMeshPosition()   { return position; }
49        /// mesh texture
50        IDirect3DTexture9* GetTexture()         { return pMeshTexture; }
51
52        /// Sets the size of the encapsulating room.
53        void SetContainerSize(D3DXVECTOR3 size) { containerSize = size; }
54        /// Sets mesh position.
55        void SetMeshPosition(D3DXVECTOR3 pos)   { position = pos; }
56        /// Sets preferred mesh size (diameter).
57        void SetPreferredDiameter(float d) {
58                preferredDiameter = d;
59                Move(D3DXVECTOR3(0,0,0),true);          // to stay inside the room
60        }
61
62protected:
63        /// Calculates mesh size and updates #originalSize and #originalDiameter.
64        HRESULT CalculateMeshSize( );
65};
Note: See TracBrowser for help on using the repository browser.