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

📄 utils3d.h

📁 这是在s60第五版上用Open GL开发的软件
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
 * ==============================================================================
 *  Name        : Utils3d.h
 *
 *  Copyright (c) 2004-2006 Nokia Corporation.
 *  This material, including documentation and any related
 *  computer programs, is protected by copyright controlled by
 *  Nokia Corporation.
 * ==============================================================================
 */

#ifndef __UTILS3D__
#define __UTILS3D__

//  INCLUDE FILES

#include <fbs.h>
#include <e32base.h>
#include <e32std.h>
#include <e32math.h>
#include <w32std.h>
#include <eikenv.h>
#include <GLES/gl.h>      // OpenGL ES header file
#include <ImageConversion.h>

#include "Mathutils.h"
#include "Textureutils.h"

// MACROS

// FORWARD DECLARATIONS
class TCamera;
class TCamerax;

/**
 * 3D vector that is presented by x,y,z coordinates using single-precision floating point math.
 */
class TVector
	{
	public: // Constructors

		/**
		 * Constructs and initializes a TVector to (0,0,0).
		 */
        TVector();

		/**
		 * Constructs and initializes a TVector from the specified x,y and z coordinates.
		 * @param aX Vector x component
		 * @param aY Vector y component
		 * @param aZ Vector z component
		 */
		TVector(GLfloat aX, GLfloat aY, GLfloat aZ );

	public: // New functions

		/**
		 * Computes the sum of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Sum of this vector and the given vector.
		 */
		TVector operator + (TVector aVector) const;

		/**
 		 * Increments this vector by the given vector.
         * @param aVector Vector to be added to this vector.
 		 */
		void operator += (TVector aVector);

		/**
		 * Computes the difference of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Difference of this vector and the given vector.
		 */
		TVector operator - (TVector aVector) const;

		/**
		 * Computes the negation of this vector.
		 * @return Negated vector.
		 */
		TVector operator - () const;

		/**
		 * Computes the scalar product of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Scalar prouduct of this vector and the given vector.
		 */
		GLfloat operator * (TVector aVector) const;

		/**
		 * Computes the product of this vector and the given scalar value.
		 * @param aScalar Scalar value.
		 * @return Multiplied vector.
		 */
		TVector operator * ( GLfloat aScalar ) const;

		/**
		 * Computes the magnitude (length) of this vector.
		 * @return Magnitude of this vector.
		 */
		GLfloat Magnitude();

		/**
		 * Normalizes this vector, Panics if this vector = (0, 0, 0)
		 */
		void Normalize();

        /**
         * Computes the multiplication of this vector with the given matrix.
         * Basically transforms the this vector with the given transformation matrix.
         * @param aMatrix 4 times 4 transformation matrix.
         */
        void MultMatrix4x4(const GLfloat aMatrix[]);

        /**
         * Computes the multiplication of given vector with the given matrix.
         * Basically transforms the vector with the given transformation matrix.
         * @param aVector Vector to be transformed.
         * @param aMatrix 4 times 4 transformation matrix.
         * @return Transformed vector.
         */
        static TVector MultMatrix4x4(const TVector aVector, const GLfloat aMatrix[]);

		/**
		 * Computes the crossproduct of the two given vectors.
		 * @param aVector1 Left hand side vector.
		 * @param aVector2 Right hand side vector.
		 * @return Crossproduct of aVector1 and aVector2.
		 */
		static TVector CrossProduct(const TVector aVector1, const TVector aVector2);

	public: // Data
		/** X coordinate. */
		GLfloat iX;
		/** Y coordinate. */
		GLfloat iY;
		/** Z coordinate. */
		GLfloat iZ;
	};

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

/**
 * 3D vector that is represented by x,y,z coordinates using fixed-point math.
 */
class TVectorx
	{
	public: // Constructors
		/** Constructs and initializes a TVectorx to (0,0,0). */
		TVectorx();

		/** Constructs and initializes a TVectorx from the specified x, y and z coordinates. */
		TVectorx(GLfixed aX, GLfixed aY, GLfixed aZ );
	public: // New functions

		/**
		 * Computes the sum of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Sum of this vector and the given vector.
		 */
		TVectorx operator + (TVectorx aVector) const;

		/**
 		 * Increments this vector by the given vector.
         * @param aVector Vector to be added to this vector.
 		 */
		void operator += (TVectorx aVector);

		/**
		 * Computes the difference of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Difference of this vector and the given vector.
		 */
		TVectorx operator - (TVectorx aVector) const;

		/**
		 * Computes the negation of this vector.
		 * @return Negated vector.
		 */
		TVectorx operator - () const;

		/**
		 * Computes the scalar product of this vector and the given vector.
		 * @param aVector Right hand side vector
		 * @return Scalar prouduct of this vector and the given vector.
		 */
		GLfixed operator * (TVectorx aVector) const;


		/**
		 * Computes the product of this vector and the given scalar value.
		 * @param aScalar Scalar value.
		 * @return Multiplied vector.
		 */
		TVectorx operator * (GLfixed aScalar) const;

		/**
		 * Computes the magnitude (length) of this vector.
		 * @return Magnitude of this vector.
		 */
		GLfixed Magnitude() const;

		/**
		 * Normalizes this vector, Panics if this vector = (0, 0, 0)
		 */
		void Normalize();

		/**
		 * Computes the crossproduct of the two given vectors.
		 * @param aVector1 Left hand side vector.
		 * @param aVector2 Right hand side vector.
		 * @return Crossproduct of aVector1 and aVector2.
		 */
		static TVectorx CrossProduct(TVectorx aVector1, TVectorx aVector2);

	public: // Data
		/** X coordinate. */
		GLfixed iX;
		/** Y coordinate. */
		GLfixed iY;
		/** Z coordinate. */
		GLfixed iZ;
	};

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

/**
 * Class for storing 3D model position and orientation using floating point math.
 * The position vector (a TVector) tells where the pivot point of the model is. The single precision
 * (GLfloat) values yaw, pitch and roll tell the models orientation around the model's pivot point.
 */
class T3DModel
	{
	public: // Constructors
		/**
		 * Constructs and initializes a T3DModel to Position (0,0,0), with orientation [Yaw=0, Pitch=0, Roll=0].
		 */
		T3DModel();

		/**
		 * Constructs and initializes a T3DModel to given position and with given orientation.
		 * @param aPosition Position vector that tells where the model's pivot point is located at.
		 * @param aYaw 輆w of the model around the pivot point.
		 * @param aPitch Pitch of the model around the pivot point.
		 * @param aRoll Roll of the model around the pivot point.
		 */
		T3DModel(TVector aPosition, GLfloat aYaw, GLfloat aPitch, GLfloat aRoll);

	public: // New functions

		/**
		 * Set yaw of the model around the model's pivot point.
		 * @param aYaw Yaw of the model.
		 */
		void SetYaw(GLfloat aYaw);

		/**
		 * Set pitch of the model around the model's pivot point.
		 * @param aPitch Pitch of the model.
		 */
		void SetPitch(GLfloat aPitch);

		/**
		 * Set roll of the model around the model's pivot point.
		 * @param aRoll Roll of the model.
		 */
		void SetRoll(GLfloat aRoll);

		/**
		 * Set position of the model's pivot point.
		 * @param aPosition Position of the model.
		 */
		void SetPosition(TVector aPosition);

		/**
		 * Returns the yaw of the model around the model's pivot point.
		 * @return Yaw of the model.
		 */
		GLfloat GetYaw();

		/**
		 * Returns the pitch of the model around the model's pivot point.
		 * @return Pitch of the model.
		 */
		GLfloat GetPitch();

		/**
		 * Returns the roll of the model around the model's pivot point.
		 * @return Roll of the model.
		 */
		GLfloat GetRoll();

		/**
		 * Returns the position of the model's pivot point.
		 * @return Position of the model.
		 */
		TVector GetPosition();

		/**
		 * Helper method that 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 the object is located at the given
		 * position and has the given yaw, pitch and roll.
		 * @param aCamera Target camera.
		 * @param aPosition Model's position.
		 * @param aYaw Model's yaw.
		 * @param aPitch Model's pitch.
		 * @param aRoll Model's roll.
		 */
		static void MakeWorldViewMatrix( TCamera &aCamera, TVector aPosition,
			GLfloat aYaw = 0.0f, GLfloat aPitch = 0.0f, GLfloat aRoll = 0.0f);
		/**
		 * 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 is located at it's current position and
		 * has the current yaw, pitch and roll.
		 * @param aCamera Target camera.
		 */
		void MakeWorldViewMatrix(TCamera &aCamera);

		/**
		 * Helper method that 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 the object at the given
		 * position always faces the camera.
		 * @param aCamera Target camera.
		 * @param aPosition Model's position.
		 */
		static void MakeBillboardWorldViewMatrix(TCamera &aCamera, TVector aPosition);

		/**
 		* Sets up a billboard matrix, which is a matrix that rotates objects in such a way that they always
		* face the camera.
		* Refer to the billboard example to see how this method is used.
		* Uses member data to position the billboard.
		* @param aCamera Targer camera.
		*/

		/**
		 * 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(TCamera &aCamera);

	protected: // Data
		/** Position of the model's pivot point. */
		TVector iPosition;
		/** Yaw of the model around it's pivot point. */
		GLfloat iYaw;
		/** Pitch of the model around it's pivot point. */
		GLfloat iPitch;
		// Roll.
		/** Roll of the model around it's pivot point. */
		GLfloat iRoll;
	};

// =============================================================================
// =============================================================================
/**
 * Class for storing 3D model position and orientation using fixed-point math.
 * The position vector (a TVectorx) tells where the pivot point of the model is. The fixed-point
 * (GLfixed) values yaw, pitch and roll tell the models orientation around the model's pivot point.
 */
class T3DModelx
	{

	public: // Constructors

		/**
		 * Constructs and initializes a T3DModel to Position (0,0,0), with orientation [Yaw=0, Pitch=0, Roll=0].
		 */
		T3DModelx();

		/**
		 * Constructs and initializes a T3DModelx to given position and with given orientation.
		 * @param aPosition Position vector that tells where the model's pivot point is located at.
		 * @param aYaw 輆w of the model around the pivot point.
		 * @param aPitch Pitch of the model around the pivot point.
		 * @param aRoll Roll of the model around the pivot point.
		 */
		T3DModelx(TVectorx aPosition, GLfixed aYaw, GLfixed aPitch, GLfixed aRoll);

	public: // New functions

		/**
		 * Set yaw of the model around the model's pivot point.
		 * @param aYaw Yaw of the model.
		 */
		void SetYaw(GLfixed aYaw);

		/**
		 * Set pitch of the model around the model's pivot point.
		 * @param aPitch Pitch of the model.
		 */
		void SetPitch(GLfixed aPitch);

		/**
		 * Set roll of the model around the model's pivot point.
		 * @param aRoll Roll of the model.
		 */
		void SetRoll(GLfixed aRoll);

		/**
		 * Set position of the model's pivot point.
		 * @param aPosition Position of the model.
		 */
		void SetPosition(TVectorx aPosition);

		/**
		 * Returns the yaw of the model around the model's pivot point.
		 * @return Yaw of the model.
		 */
		GLfixed GetYaw();

		/**
		 * Returns the pitch of the model around the model's pivot point.
		 * @return Pitch of the model.
		 */
		GLfixed GetPitch();

		/**
		 * Returns the roll of the model around the model's pivot point.
		 * @return Roll of the model.
		 */
		GLfixed GetRoll();

		/**
		 * Returns the position of the model's pivot point.
		 * @return Position of the model.
		 */
		TVectorx GetPosition();

		/**
		 * Helper method that 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 the object is located at the given
		 * position and has the given yaw, pitch and roll.
		 * @param aCamera Target camera.
		 * @param aPosition Model's position.
		 * @param aYaw Model's yaw.
		 * @param aPitch Model's pitch.
		 * @param aRoll Model's roll.
		 */
		static void MakeWorldViewMatrix(TCamerax &aCamera, TVectorx aPosition,
			GLfixed aYaw = INT_2_FIXED(0), GLfixed aPitch = INT_2_FIXED(0),
			GLfixed aRoll = INT_2_FIXED(0));

		/**
		 * 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 is located at it's current position and
		 * has the current yaw, pitch and roll.
		 * @param aCamera Target camera.
		 */
		void MakeWorldViewMatrix(TCamerax &aCamera);

		/**
		 * Helper method that 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 the object at the given

⌨️ 快捷键说明

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