source: GTP/trunk/App/Demos/Illum/MultipleReflections/Mesh.h @ 2242

Revision 2242, 2.4 KB checked in by szirmay, 18 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        D3DXMATRIXA16 rotation;
21
22public:
23
24        /// Loads the specified .X file
25        /// \param fileName name of the mesh file
26        /// \param texFileName name of the texture file
27        /// \param preferredDiameter final size of the mesh
28        /// \param position initial position of the mesh.
29        /// During rendering, use GetMeshScale() to get the appropriate scaling factor
30        /// to achieve the preferred mesh size.
31        Mesh(LPCWSTR fileName, LPCWSTR texFileName, float preferredDiameter, D3DXVECTOR3 position);
32        /// Destructor. Deletes dynamically created resources.
33        ~Mesh();
34
35        /// \brief LOADS THE SPECIFIED .X FILE
36        /// Eliminates mesh offset (centers the mesh to the origin)
37        /// and determines mesh size (#originalSize, #originalDiameter).
38        void Load(LPCWSTR fileName);
39        /// Adds the specified offset to the mesh position.
40        /// \param bContainerOnly indicates whether the object can leave the room
41        void Move(D3DXVECTOR3 offset, bool bContainerOnly = false);
42        /// Draws the mesh. Before drawing, use GetMeshScale() to get the appropriate scaling factor.
43        HRESULT Draw();
44        /// current mesh size   
45        D3DXVECTOR3 GetMeshSize()   { return GetMeshScale() * originalSize; }
46        /// current mesh scale
47        float GetMeshScale()            { return preferredDiameter / originalDiameter; }
48        /// current mesh position
49        D3DXVECTOR3 GetMeshPosition()   { return position; }
50        /// mesh texture
51        IDirect3DTexture9* GetTexture()         { return pMeshTexture; }
52
53        /// Sets the size of the encapsulating room.
54        void SetContainerSize(D3DXVECTOR3 size) { containerSize = size; }
55        /// Sets mesh position.
56        void SetMeshPosition(D3DXVECTOR3 pos)   { position = pos; }
57        /// Sets preferred mesh size (diameter).
58        void SetPreferredDiameter(float d) {
59                preferredDiameter = d;
60                Move(D3DXVECTOR3(0,0,0),true);          // to stay inside the room
61        }
62
63        void setRotation(D3DXMATRIXA16& rotmatrix){rotation = rotmatrix;}
64        D3DXMATRIXA16& getRotation(){return rotation;}
65
66protected:
67        /// Calculates mesh size and updates #originalSize and #originalDiameter.
68        HRESULT CalculateMeshSize( );
69};
Note: See TracBrowser for help on using the repository browser.