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

📄 utils3d.h

📁 这是在s60第五版上用Open GL开发的软件
💻 H
📖 第 1 页 / 共 2 页
字号:
		 * position always faces the camera.
		 * @param aCamera Target camera.
		 * @param aPosition Model's position.
		 */
		static void MakeBillboardWorldViewMatrix(TCamerax &aCamera, TVectorx aPosition);

		/**
		 * Sets up the current Open GL's matrix (normally this should be set to be the worldview matrix
		 * for this method to work correctly) so that this object at it's current position always faces
		 * the camera. Note that this method doesn't modify the current yeaw, pitch and roll of this object.
		 * @param aCamera Target camera.
		 */
		void MakeBillboardWorldViewMatrix(TCamerax &aCamera);

	protected: // Data

		/** Position of the model's pivot point. */
		TVectorx iPosition;
		/** Yaw of the model around it's pivot point. */
		GLfixed iYaw;
		/** Pitch of the model around it's pivot point. */
		GLfixed iPitch;
		/** Roll of the model around it's pivot point. */
		GLfixed iRoll;
	};

// =============================================================================
// =============================================================================
/**
 * Helper class that implements a camera in 3D space using single precision floating point math.
 * The camera is represented by an eye point vector, "look-at" direction vector and an up vector.
 * This class is very useful since it provides an implementation of the gluLookAt() method
 * which is not part of the OpenGL ES specification.
 */
class TCamera
	{
	public: // Constructors

		/**
		 * Constructs and initializes TCamera to Position (0,0,0), LookAt (0,0,-1), Up(0,1,0).
		 * This equals the default model view matrix setting of OpenGL (camera located at origo, looking towards
		 * negative Z-axis and up direction towards positive Y-axis).
		 */
		TCamera();

		/**
		 * Constructs and initializes TCamera using the given position, look at direction and up orientation vector.
		 * @param aPosition Position of the camera.
		 * @param aLookAt "Look-at" direction of the camera.
		 * @param aUp "Up" vector of the camera.
		 */
		TCamera(TVector aPosition, TVector aLookAt, TVector aUp);

	public: // New functions

		/**
		 * Returns the position of this camera.
		 * @return Position of this camera.
		 */
		TVector GetPosition();

		/**
		 * Returns the "look-at" direction of this camera.
		 * @return "Look-at" direction of this camera.
		 */
		TVector GetLookAt();

		/**
		 * Returns the "up" direction of this camera.
		 * @return "Up" direction of this camera.
		 */
		TVector GetUp();

		/**
		 * Returns the 4x4 model-view matrix representation of this camera.
		 * @return Pointer to 4x4 model-view matrix representation of this camera.
		 */
		GLfloat * GetViewMatrix();

		/**
		 * Resets the given 4x4 matrix to identity matrix.
		 * @param aMatrix Target matrix to be reset to indentity matrix.
		 */
		static void MakeIdentity(GLfloat * aMatrix);

		/**
		 * Sets the camera to use the given position, look-at direction and up direction vectors.
		 * This is NOT an implementation of the gluLookAt() function. This method DOES NOT place
		 * the translation of the camera position into the view matrix. The position must be applied
		 * separately after applying the view matrix.
		 * E.g. glTranslatef( -iCamera->getPosition().iX, -iCamera->getPosition().iY, -iCamera->getPosition().iZ )
		 *
		 * @param aPosition Position of the camera.
		 * @param aLookAt "Look-at" direction of the camera.
		 * @param aUp "Up" vector of the camera.
		 */
		void LookAt(TVector aPosition, TVector aLookAt, TVector aUp);

	protected: // Data
		/** Position of the camera's eye point. */
		TVector iPosition;
		/** Position of the "look-at" direction point. */
		TVector iLookAt;
		/** Direction of the up vector. */
		TVector iUp;
		/** View matrix. */
		GLfloat iViewMatrix[4][4];


	public: // Friend classes
		friend class T3DModel;
	};


// =============================================================================
// =============================================================================

/**
 * Helper class that implements a camera in 3D space using fixed-point math.
 * The camera is represented by an eye point vector, "looking towards" direction vector and an up vector.
 * This class is very useful since it provides an implementation of the gluLookAt() method
 * which is not part of the OpenGL ES specification.
 */
class TCamerax
	{

	public: // Constructors

		/**
 		 * Constructs and initializes a TCamerax to Position (0,0,0), LookAt (0,0,-1), Up(0,1,0).
		 * This equals the default model view matrix setting of OpenGL (camera located at origo, looking towards
		 * negative Z-axis and up direction towards positive Y-axis).
		 */
		TCamerax();

		/**
		 * Constructs and initializes TCamera using the given position, look at direction and up orientation vector.
		 * @param aPosition Position of the camera.
		 * @param aLookAt "Look-at" direction of the camera.
		 * @param aUp "Up" vector of the camera.
		 */
		TCamerax(TVectorx aPosition, TVectorx aLookAt, TVectorx aUp);

	public: // New functions

		/**
		 * Returns the position of the camera.
		 * @return Position of the camera.
		 */
		TVectorx GetPosition();

		/**
		 * Returns the "look-at" direction of the camera.
		 * @return "Look-at" direction of the camera.
		 */
		TVectorx GetLookAt();

		/**
		 * Returns the "up" direction of the camera.
		 * @return "Up" direction of the camera.
		 */
		TVectorx GetUp();

		/**
		 * Returns the 4x4 model-view matrix representation of this camera.
		 * @return Pointer to 4x4 model-view matrix representation of this camera.
		 */
		GLfixed * GetViewMatrix();

		/**
		 * Resets the given 4x4 matrix to identity matrix.
		 * @param aMatrix Target matrix to be reset to indentity matrix.
		 */
		static void MakeIdentity(GLfixed * aMatrix);

		/**
		 * Sets the camera to use the given position, look-at direction and up direction vectors.
		 * This is NOT an implementation of the gluLookAt() function. This method DOES NOT place
		 * the translation of the camera position into the view matrix. The position must be applied
		 * separately after applying the view matrix.
		 * E.g. glTranslatex( -iCamera->getPosition().iX, -iCamera->getPosition().iY, -iCamera->getPosition().iZ )
		 *
		 * @param aPosition Position of the camera.
		 * @param aLookAt "Look-at" direction of the camera.
		 * @param aUp "Up" vector of the camera.
		 */
		void LookAt(TVectorx aPosition, TVectorx aLookAt, TVectorx aUp);

	protected: // Data

		/** Position of the camera's eye point. */
		TVectorx iPosition;
		/** Position of the "look-at" direction point. */
		TVectorx iLookAt;
		/** Direction of the up vector. */
		TVectorx iUp;
		/** View matrix. */
		GLfixed iViewMatrix[4][4];

	public: // Friend classes
		friend class T3DModelx;
	};


// =============================================================================
// =============================================================================
/**
 *  Structure used internally by the class CParticleEngine.
 *  Represents a single particle.
 */
struct TParticle
	{
	/** Current position of the particle. */
    TVector iPosition;
	/** Current velocity and movement direction of the particle. */
    TVector iVelocity;
	/** Current acceleration vector of the particle. */
    TVector iAcceleration;
	};

// =============================================================================
// =============================================================================

/**
 *  Particle engine that can be used to create special effects like Rain, Smoke, Snow, Sparks, etc...
 */
class CParticleEngine : public CBase
	{
	public: // Destructor

		//Destructor
		virtual ~CParticleEngine();

	public: // New functions

		/**
		* Resets the particle engine
		*/
		void ResetEngine();
		/**
		* Resets the particle at index aIndex
		* @param aIndex Index to particle
		*/
		virtual void ResetParticle(GLint aIndex) = 0;
		/**
		* Updates the engine.
		* @param aElapsedTime Elapsed time.
		*/
		virtual void UpdateEngine(GLfloat aElapsedTime) = 0;
		/**
		* Renders the system.
		* @param aCamera Camera
		*/
		virtual void RenderEngine(TCamera &aCamera) = 0;

		/**
		* Gets the position of the effect
		* @return Position
		*/
		TVector GetPosition();
		/**
		* Get the number of particles
		* @return Number of particles
		*/
		GLint GetParticleCount();

		/**
		* Set the effect position
		* @param aPosition Effect position.
		*/
		void SetPosition( TVector & aPosition );

	protected:
		/**
		 * Default C++ and Symbian ConstructL are placed in protected
		 * area to force the use of NewL when creating an instance.
		 * Does nothing in this implementation.
		 */
		CParticleEngine();

		/**
		 * Symbian 2nd phase constructor that can Leave. Constructs a CParticleEngine
		 * object with given number of particles at given position.
		 * @param aParticlesCount Number of particles this particle engine can have.
		 * @param aPosition Position of the particle source.
		 */
		void ConstructL( TInt aParticlesCount, TVector aPosition);

	protected: // Data
		/** Array of the particles owned by this particle engine. */
		TParticle *iParticles;
		/** Lenght of iParticles. */
		GLint iParticlesCount;
		/** Position of the particle source, where all the particles are emanated from. */
		TVector iPosition;
	};

// =============================================================================
// =============================================================================

/**
 *  A lookup-table class for trigonometric (sin, cos and tan) functions.
 */
class CLookUpTable: public CBase
{
	public:
		enum
			{
			ESin    =  1,
			ECos    =  2,
			ETan    =  4,
			ESinx   =  8,
			ECosx   = 16,
			ETanx   = 32
			};

	public: // Constructors and destructor
        /**
         * Destructor. Destroys all the look-up tables.
         */
		virtual ~CLookUpTable();

		/**
		 * Factory method that constructs and initializes a the look up table object.
		 * @param Bit flags that defines which look-up tables are initialized. Value should be an or'ed value of the enumerated
		 *        values of ESin, ECos, ETan, ESinx, ECosx or ETanx.
		 * @return An instance of the look-up table object that has the given tables initialized.
		 */
		static CLookUpTable* NewL(TInt aFlags);

	protected:
		/*
		 * Default C++ and Symbian ConstructL are placed in protected
		 * area to force the use of NewL when creating an instance.
		 * Does nothing in this implementation.
		 */
		CLookUpTable();

		/**
		 * Constructs and initializes the given look up tables.
		 * @param Bit flags that defines which look-up tables are initialized. Value should be an or'ed value of the enumerated
		 *        values of ESin, ECos, ETan, ESinx, ECosx or ETanx.
		 * @return An instance of the look-up table object that has the given tables initialized.
		 */
		void ConstructL(TInt aFlags);

	public: // New functions

		/**
		* Look up a sine of an angle (floating point)
		* @param aAngle Input angle
		* @return Sine of the angle
		*/
		GLfloat Sin(GLushort aAngle);
		/**
		* Look up a cosine of an angle (floating point)
		* @param aAngle Input angle
		* @return Cosine of the angle
		*/
		GLfloat Cos(GLushort aAngle);
		/**
		* Look up a tan of an angle (floating point)
		* @param aAngle Input angle
		* @return Tan of the angle
		*/
		GLfloat Tan(GLushort aAngle);

		/**
		* Look up a sine of an angle (fixed-point)
		* @param aAngle Input angle
		* @return Sine of the angle
		*/
		GLfixed Sinx(GLfixed aAngle);
		/**
		* Look up a cosine of an angle (fixed-point)
		* @param aAngle Input angle
		* @return Cosine of the angle
		*/
		GLfixed Cosx(GLfixed aAngle);
		/**
		* Look up a tan of an angle (fixed-point)
		* @param aAngle Input angle
		* @return Tan of the angle
		*/
		GLfixed Tanx(GLfixed aAngle);

	protected: // New functions
		/**
		 * Calculates a floating point sine values lookup-table.
		 */
		void ComputeSinTableL();
		/**
		 * Calculates a floating point cosine values lookup-table.
 		 */
		void ComputeCosTableL();
		/**
		 * Calculates a floating point tangent values lookup-table.
		 */
		void ComputeTanTableL();

		/**
		 * Calculates a fixed-point sine values lookup-table.
		 */
		void ComputeSinxTableL();
		/**
		 * Calculates a fixed-point cosine values lookup-table.
 		 */
		void ComputeCosxTableL();
		/**
		 * Calculates a fixed-point tangent values lookup-table.
		 */
		void ComputeTanxTableL();

	protected: // Data

		/** Sine floating point value look-up table. */
		GLfloat * iSinTable;
		/** Cosine floating point value look-up table. */
		GLfloat * iCosTable;
		/** Tangent floating point value look-up table. */
		GLfloat * iTanTable;
		/** Sine fixed-point value look-up table. */
		GLfixed * iSinxTable;
		/** Cosine fixed-point value look-up table. */
		GLfixed * iCosxTable;
		/** Tangent fixed-point value look-up table. */
		GLfixed * iTanxTable;
};

// =============================================================================
// =============================================================================
// Other miscallenous helper functions

/**
 * Outputs a text at a given position with a given color and font.
 * @param aGc Window graphics context.
 * @param aString String to be rendered.
 * @param aPosition xy-position of the text to be rendered.
 * @param aColor RGB color of the text.
 * @param aFont Font to be used in rendering.
 */
void utilOutputText(CWindowGc & aGc, const TDesC &aString,
	const TPoint &aPosition, const TRgb &aColor, const CFont *aFont);
/**
 * Outputs a text at a given position with a given color using the
 * CEikonEnv::Static()->SymbolFont() font.
 * @param aGc Window graphics context.
 * @param aString String to be rendered.
 * @param aPosition xy-position of the text to be rendered.
 * @param aColor RGB color of the text.
 */
void utilOutputText(CWindowGc & aGc, const TDesC &aString,
	const TPoint &aPosition, const TRgb &aColor);


#endif

⌨️ 快捷键说明

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