⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpolygonobject.h

📁 一个基于symbian s60 3rd 的3D汽车游戏演示程序,模拟器上编译通过。
💻 H
字号:
   /*
============================================================================
    * Name : CPolygonObject.h
    * Part of : Example3D
    * Description : Definition of CPolygonObject
    * Copyright (c) 2007 Nokia Corporation
============================================================================
    */

#ifndef __CPOLYGONOBJECT_H__
#define __CPOLYGONOBJECT_H__


// INCLUDES
#include <e32base.h>
#include "C3DBase.h"
#include "M3dObject.h"
#include "TBitmap.h"
#include "GLES/egl.h"
#include "GLES/gl.h"

// FORWARD DECLARATIONS
class C3DBase;
class C3DRenderer;
class CPolygonObject;

// HELPER CLASSES

/// type of vertex used in drawlist
class TDrawVertex
    {
    public:
        inline TDrawVertex() {}

        inline TDrawVertex( TInt aX, TInt aY, TInt aZ, TInt aTx, TInt aTy )
            : iX( aX ), iY( aY ), iZ( aZ ), iTx( aTx ), iTy( aTy )
            {}

        inline TDrawVertex( const TVertex& aV, TInt aTx, TInt aTy )
            : iX( aV.iX ), iY( aV.iY ), iZ( aV.iZ ), iTx( aTx ), iTy( aTy )
            {}


    public:

        TInt iX;
        TInt iY;
        TInt iZ;

        TInt iTx;
        TInt iTy;
    };

/// type of face used in drawlist
class TDrawFace
    {
    public:
        inline TDrawFace() {}

        inline TDrawFace( const TDrawVertex& aV1, const TDrawVertex& aV2, const TDrawVertex& aV3 )
            : iV1( aV1 ), iV2( aV2 ), iV3( aV3 )
            {}

    public:

        TDrawVertex iV1;
        TDrawVertex iV2;
        TDrawVertex iV3;
    };


// CLASS DECLARATION

/**
*  CPolygonObject is example type of M3DObject
*  this object contains one sided textured triangles
*  which are clipped against view frustum
*  M3DObjects are arranged and drawn by C3DRenderer
*/

class CPolygonObject 
    : public CBase
    , public M3dObject
    {
    public:

        /// Two-phased constructor
        /// @param a3DBase pointer to constructed C3DBase
        /// @param aNumVertex maximum number of vertices handled
        /// @param aNumFace maximum number of faces handled
        static CPolygonObject* NewL( C3DBase* a3DBase, TInt aNumVertex, TInt aNumFace );

        /// Destructor
        ~CPolygonObject();

    private:

        /// Second-phase constructor
        void ConstructL();

        /// Default constructor
        /// @param a3DBase pointer to constructed C3DBase
        /// @param aNumVertex maximum number of vertices handled
        /// @param aNumFace maximum number of faces handled
        CPolygonObject( C3DBase* a3DBase, TInt aNumVertex, TInt aNumFaces );

    public: // M3dObject

        /// Draws this 3D object to given bitmap with given parameters
        /// @param aScreen bitmap to draw to
        /// @param aRotateMatrix object rotation matrix used
        void Draw( const TBitmap& aScreen, TMatrix* aRotateMatrix );

    public: // new methods

        /// Sets texture used by textured triangle draw
        /// @param aTexture handle to OpenGL bitmap object with size of 256x256
        void SetTexture( TInt aTextureObjectHandle );

        /// Clears all object data
        /// Reserves memory for faces and vertices
        /// @param aNumVertex maximum number of vertices handled
        /// @param aNumFace maximum number of faces handled
        void Reset( TInt aNumVertices, TInt aNumFaces );
        
        /// adds a vertex to facelist
        /// @param aVertex vertex to add
        /// @return number of vertices in list
        TInt AddVertex( const TVertex& aVertex );
        
        /// change a vertex in vertexlist
        /// doesn't "add" a vertex, there must already be a vertex with this index
        /// @param aIndex vertex index
        /// @param aVertex replacing vertex
        void SetVertex( TInt aIndex, const TVertex& aVertex );
        
        /// adds a face to facelist
        /// @param aFace triangle face to add
        /// @return number of faces in list
        TInt AddFace( const TFace& aFace );
        
        /// this should be called if vertices has been added or changed
        /// updates bounding sphere for object
        void Init();
        
    private: // Private methods:
        
        /// rotates object's all vertices
        void Rotate();

        /// projects drawlist's faces to screen
        /// @param aFaceList list of triangle faces to project
        /// @param aNumFaces number of faces in list
        void Project( TDrawFace* aFaceList, TInt aNumFaces );
        
        /// draws textured triangle
        /// drawvertices can be in any order
        /// @param aV1 first vertex of triangle
        /// @param aV2 second vertex of triangle
        /// @param aV3 third vertex of triangle
        void DrawTexTri( TDrawVertex* aV1, TDrawVertex* aV2, TDrawVertex* aV3 );

        /// Swaps two longword sized parameters
        void Swap( TAny* aV1, TAny* aV2 );


    private: // Data:
        C3DBase*    i3DBase;            // pointer to 3DBase

        TBitmap     iScreen;            // bitmap to draw to

        TMatrix*    iRotateMatrix;      // used by Rotate, given by Renderer

        TVertex*    iVertex;            // list of vertices
        TVertex*    iRVertex;           // list of rotated vertices
        TInt        iMaxNumVertices;    // maximum number of vertices
        TInt        iNumVertices;       // real number of vertices

        TFace*      iFace;              // list of faces
        TInt        iMaxNumFaces;       // maximum number of faces
        TInt        iNumFaces;          // real number of faces

        TUint16*    iTexture;           // this object's texture, always 256x256 bitmap

        TInt16*     iCos;               // pointer to cosine table
        TInt16*     iSin;               // pointer to sinus table

        ///
        TDrawFace*  iDrawList;          // list of clipped triangles to draw
        TInt*       iFaceZ;             // list of face's distance from view plane
        TInt*       iFaceN;             // list of draw order indexes

        GLuint      iTextureObject;
        GLfixed*    iGlVerts;
        GLfixed*    iGlTexCoords;
        TInt        iGlTriCount;        // Actually index count (ie. 3 times the tricount)
        GLushort*   iGlTris;
    };

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -