13.游戏引擎源码 3D物体基类Node3D实现

  Node3D:里面记录了对象的空间信息,矩阵信息,颜色信息之类的。
 

直接贴代码吧

Node3D.h

#pragma once
#include "GLmath.h"
#include "Shape.h"
//#define MESH_RESOLUTION 4.0f							// 每个顶点使用的像素
//#define MESH_HEIGHTSCALE 1.0f							// 高度的缩放比例//#define NO_VBOS								// 如果定义将不使用VBO扩展
 定义VBO扩展它们在glext.h头文件中被定义
//
//#define GL_ARRAY_BUFFER_ARB 0x8892
//#define GL_STATIC_DRAW_ARB 0x88E4
//typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
//typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
//typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
//typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
 VBO 扩展函数的指针
//PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; // 创建缓存名称
//PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; // 绑定缓存
//PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; // 绑定缓存数据
//PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; // 删除缓存
//


namespace U3D
{
	class CNode
	{
		friend class CScene;

	protected:
		CNode *parent;	//父节点
		Matrix3D local_matrix; //自身矩阵
		Matrix3D world_matrix; //世界矩阵
		sColor local_color; //自身颜色
		sColor world_color; //世界颜色
		Vector3D pos;		//坐标偏移
		Vector3D scale;		//缩放
		Vector3D anchor; //锚点
		Vector3D angle;
		bool visible;   //是否可见
		bool flip;		//是否翻转
		bool isUseRotMatrix = false;
		char DirectoryPath[256];
		GLuint	m_nVBOVertices;	// 顶点缓存对象的名称
		GLuint	m_nVBOTexCoords;// 顶点纹理缓存对象的名称
		int nVertexCount; //顶点数
		Vector3D* pVertices;     //定点数据的指针;
		Vector2*pTexCoords;   //大图点纹理坐标;
		Matrix3D rotate_matrix;

	public:
		//set///
		void BuildVBOs(Vector3D *pVertices, Vector2 *pTexCoord);//创建拓展VBO
		void setParent(CNode *parent) { this->parent = parent; }
		void setVisible(bool visible) { this->visible = visible; }
		void setAlpha(float alpha) { local_color.a =alpha; }
		void setPosition(float x, float y, float z) {pos.x = x;pos.y = y; pos.z = z;}
		void setPosition(Vector3D p) {pos = p; }
		void setX(float x) { pos.x = x; }
		void setY(float y) { pos.y = y; }
		void setZ(float z) { pos.z = z; }
		void setScale(float sx, float sy, float sz) {scale.x = sx;scale.y = sy; scale.z= sz; }
		void setFilp(bool flip) { this->flip = flip; }
		void setColor(float r, float g, float b) { local_color.r =r; local_color.g =g; local_color.b =b; }
		void setAnchor(float ox, float oy, float oz) { anchor.x = ox; anchor.y = oy; anchor.z = oz; }
		void setAngle(Vector3D angle) { this->angle = angle; }
		void setAngleX(float angle) { this->angle.x = angle; }
		void setAngleY(float angle) { this->angle.y = angle; }
		void setAngleZ(float angle) { this->angle.z = angle; }
		void setRotateMatrix(Matrix3D mat) { this->rotate_matrix =mat;isUseRotMatrix = true; }
		void UseRotateMatrix() { isUseRotMatrix = true;}
		void setLocalMatrix(Matrix3D m) { local_matrix = m;}
		void setWorldMatrix(Matrix3D m) { world_matrix = m;}

		//get///
		CNode*getPraent() { return parent; }
		sColor &getWorldColor() { return world_color; }
		sColor &getlocalColor() { return local_color; }
		Matrix3D &getWorldMatrix() { return world_matrix; }
		Matrix3D &getlocalMatrix() { return local_matrix; }
		float getAlpha() { return local_color.a; }
		Vector3D getPosition() { return pos; }
		float getX() { return pos.x; }			//返回X偏移值
		float getY() { return pos.y; }			//返回Y偏移值
		float getZ() { return pos.z; }			//返回Z偏移值
		float getScaleX() { return scale.x; }//水平翻转比值
		float getScaleY() { return scale.y; }//垂直翻转比值
		float getScaleZ() { return scale.z; }
		Vector3D getAngle() { return angle; }
		bool getIsUseRotateMatrix() { return isUseRotMatrix; }

		//bool//
		bool isVisible() { return visible; }//是否可见
		bool isFlip() { return flip; }
	
		CNode();
		virtual ~CNode() {};
	};



	class CElement :public CNode
	{
	private:
		char elementName[256];
	public:
		virtual void draw(float deltaTime) {};
		virtual void drawDebug() {};
		virtual GLAABB3D getBoundBox() { return GLAABB3D(Vector3D(-9999, -9999, -9999), Vector3D(9999, 9999, 9999)); }

		char *getElementName() { return elementName; }
		void setElementName(const char *name) { strcpy(elementName, name); }

		virtual ~CElement() {};
	};

	class CNode;
	class CUI;
	class Cobject;
	class CAnimate;
	class CAnimateEx;
	class CAnimation;
	enum MovementEvent;

	typedef void (CNode::*event_selector)(CUI*);
	typedef void (CNode::*animate_selector)(CAnimate*, MovementEvent);
	typedef void (CNode::*animation_selector)(CAnimation*, MovementEvent, char *);
	typedef void (CNode::*collider_selector)(Cobject*);
	
}

猜你喜欢

转载自blog.csdn.net/qq_33531923/article/details/126913239
今日推荐