📄 scenegraph.h
字号:
// ==========================================================================================================
//
// BREW v2.0+ OPENGLES MICROENGINE
//
// ----------------------------------------
//
// Written by Vander Nunes
//
// ==========================================================================================================
#ifndef __SCENEGRAPH_H__
#define __SCENEGRAPH_H__
// TORUS
#include "../defines.h"
#include "../mobmodel.h"
#include "../math3d.h"
#include "../texture.h"
#include "../camera.h"
#include "../torus.h"
// BREW
#include "AEEAppGen.h"
#include "AEEModGen.h"
#include "AEEStdLib.h"
#include "AEEFile.h"
#include "AEEImage.h"
// ------------------------------------------------------------------------------------
//
// SCENEITEM
// Scenegraph linked list class (may be node or item within a node)
//
// ------------------------------------------------------------------------------------
class CSceneGraph; // forward declaration
#define ENVMAPMODE_NONE 0 // disabled
#define ENVMAPMODE_REPLACE 1 // will just replace default texture
#define ENVMAPMODE_ADD 2 // will add to the default texture
#define ENVMAPMODE_MULTIPLY 3 // will multitply to the default texture
class CSceneItem
{
private:
//
// item/node properties
//
boolean m_bIsNode; // flag if this item represents a node
CSceneItem* m_pParent; // parent node (or NULL if root)
CSceneItem* m_pPrevious; // previous item in the same node (or NULL if first item)
CSceneItem* m_pNext; // next item in the same node (or NULL if last item)
CSceneItem* m_pChild; // child node (or NULL if leaf node)
//
// model data
//
short m_iModelIndex; // model mesh index within model gallery
dword m_dwBSphere; // bounding sphere for culling and collision detection
vec3_t m_BBMin; // minimum bbox coordinates
vec3_t m_BBMax; // maximum bbox coordinates
vec3_t m_OBBMin; // rotated minimum bbox coordinates
vec3_t m_OBBMax; // rotated maximum bbox coordinates
vec3_t m_Position; // model position
vec3_t m_Rotation; // model rotation
vec3_t m_Direction; // model direction
short m_iTextureIndex;// model texture pointer within model gallery
short m_iEnvMapIndex;
BYTE m_jEnvMapMode; // environment map rendering mode
void UpdateBBox();
public:
CSceneItem();
CSceneItem(CSceneGraph* pScene, short iModelIndex, short iTextureIndex, short iEnvMapIndex = -1, BYTE jEnvMapMode = ENVMAPMODE_ADD);
~CSceneItem();
//
// item/node manipulation
//
void TranslateTo(int Px, int Py, int Pz);
void AddTranslation(int Px, int Py, int Pz);
void RotateTo(int Rx, int Ry, int Rz);
void AddRotation(int Rx, int Ry, int Rz);
void Render(CSceneGraph* pScene);
void UpdateDirection(void);
int* Position();
int* Rotation();
int* Direction();
void SetNode(boolean bIsNode);
boolean IsNode();
void SetNext(CSceneItem* pNext);
CSceneItem* Next();
void SetPrevious(CSceneItem* pPrevious);
CSceneItem* Previous();
void SetParent(CSceneItem* pParent);
CSceneItem* Parent();
void SetChild(CSceneItem* pChild);
CSceneItem* Child();
short ModelIndex();
short TextureIndex();
int* OBBMin();
int* OBBMax();
void SetEnvMapMode(byte jEnvMapMode);
byte EnvMapMode();
};
// ------------------------------------------------------------------------------------
//
// SCENEGRAPH
//
// ------------------------------------------------------------------------------------
class CSceneGraph
{
private:
CEngine* m_pEngine;
//
// scenegraph data
//
// root of the scenegraph tree
CSceneItem* m_pRoot;
// a sky box slot that may or may not be used by the user
CSceneItem* m_pSkyBox[6];
boolean m_bSkyBoxLoaded;
// model mesh library
unsigned short m_wModelCount;
CMobModel** m_pModelLibrary;
// texture library
unsigned short m_wTextureCount;
CTexture** m_pTextureLibrary;
public:
CSceneGraph(CEngine* pEngine);
~CSceneGraph();
//
// node/item management
//
void AddItem(CSceneItem* pNode, CSceneItem* pItem);
void RemoveItem(CSceneItem* pItem);
void AddChild(CSceneItem* pNode, CSceneItem* pItem);
void RemoveNode(CSceneItem* pItem);
CSceneItem* Root();
//
// model library management
//
// do not add if you're loading from file
CMobModel* AddEmptyModel();
// loading will call AddEmptyModel() by itself.
boolean LoadModel(char *szFile, float fXScale, float fYScale, float fZScale);
unsigned short ModelCount();
CMobModel* Model(unsigned short wModel);
//
// texture library management
//
// create an empty texture
CTexture* CreateTexture(void);
// create a texture, load an image and upload to the card
boolean LoadTexture(char *szFile, boolean bGenMipMap = FALSE);
unsigned short TextureCount();
CTexture* Texture(unsigned short wTexture);
//
// sky box generation
//
boolean GenSkyBox(char *szFile, int32 iSize);
//
// scenegraph rendering
//
void Render(CSceneItem* pItem, CCamera* pCam, boolean bFrustum = TRUE);
void RecursiveRender(CSceneItem* pItem, CCamera* pCam, boolean bFrustum = TRUE);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -