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

📄 cpolygonobject.h

📁 symbian 60 3d 的一个很经典的例子
💻 H
字号:
    /*
    *
============================================================================
    *  Name     : CPolygonObject.h
    *  Part of  : Example3D
    *  Created  : 12/14/2003 by Forum Nokia
    *  Description:
    *     This is the project specification file for Example3D.
    *     Initial content was generated by Series 60 AppWizard.
    *
    *  Version  : 1.0.0
    *  Copyright: Forum Nokia
    *
============================================================================
    */

#ifndef __CPOLYGONOBJECT_H__
#define __CPOLYGONOBJECT_H__


// INCLUDES
#include <e32base.h>
#include "C3DBase.h"
#include "M3dObject.h"
#include "TBitmap.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 pointer to bitmap with size of 256x256
		void SetTexture( TUint16* aTexture );
		
		/// 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 );

		/// draws half of textured triangle
		/// called by DrawTexTri
		void DrawTexSlice( TInt aX1, TInt aX2, TInt aX1Add, TInt aX2Add, 
						   TInt aY1, TInt aY2, TInt aTx1, TInt aTy1, 
						   TInt aTxAddX, TInt aTyAddX, TInt aTxAddY, TInt aTyAddY );



	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

		
	};

#endif

⌨️ 快捷键说明

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