Controllers.h
资源名称:g.rar [点击查看]
上传用户:laitongbao
上传日期:2021-02-20
资源大小:8176k
文件大小:8k
源码类别:
射击游戏
开发平台:
Visual C++
- //typedef unsigned long DWORD;
- class NodeObject;
- #pragma warning(disable: 4786)
- #include "MeshObject.h"
- #include "SceneTree.h"
- #include "Utility.h"
- #include "Time.h"
- #include "RandGenerator.h"
- #include "VECTOR.h"
- #include "CGLDEF.h"
- #ifndef CONTROLLERS_H
- #define CONTROLLERS_H
- //UI对象边界宽度
- #define BORDER_WIDE 5
- struct Parameter{//通用显示属性结构
- bool Mutisample;
- int MutisampleLevel;
- PAR_FILLMODE fillMode;
- PAR_SHADEMODE shadeMode;
- bool fog;
- float fogStart;
- float fogEnd;
- DWORD fogColor;
- DWORD globalAmbientColor;
- DWORD backgroundColor;
- bool forcedTwoSide;
- bool lighting;
- };
- struct InputStatus{//鼠标键盘当前状态信息(由于没有使用Direct_Input 所以暂时不用,
- //由消息处理函数代为检测用户输入)
- };
- class TransitionController{
- public:
- static void SetPosition(NodeObject* obj,VECTOR3 pos);
- static void SetWorldPosition(NodeObject* obj,VECTOR3 gpos);
- static VECTOR3 GetPosition(NodeObject* obj);
- static VECTOR3 GetWorldPosition(NodeObject* obj);
- static void SetRotation(NodeObject* obj,VECTOR3 rot);
- static VECTOR3 GetRotation(NodeObject* obj);
- static void SetScale(NodeObject* obj,VECTOR3 scale);
- static VECTOR3 GetScale(NodeObject* obj);
- static void UpdateMatrix(NodeObject *obj);//更新物体的转换矩阵(将3个矩阵合成为一个叫转换矩阵的矩阵)
- static D3DXMATRIX* GetMatrix(NodeObject* obj);
- static void ApplyMatrix(NodeObject* obj,Camera* cam);//设置物体在视图中的位置(将转换矩阵*视图矩阵的结果传递给Device)
- };
- class FileController{//管理磁盘文件操作
- public:
- static void LoadSceneFromFile(TCHAR* fileName,SceneTree* scene);
- static void SaveSceneToFile(TCHAR* fileName,SceneTree* scene);
- static void LoadMeshFromFile(TCHAR* fileName,MeshObject* mesh);
- static void SaveMeshToFile(TCHAR* fileName,MeshObject* mesh);
- static void LoadSurfaceFromFile(TCHAR* fileName,Surface*sur,RECT*rect=NULL,DWORD colorKey=0);
- static void SaveSurfaceToFile(TCHAR* fileName,Surface *sur);
- };
- /*
- GraphicController
- 负责管理全局的图像设置
- */
- class GraphicController{//管理全局图像效果,如雾化
- friend class View;
- public:
- GraphicController(Parameter param){SetParameter(param);};
- GraphicController();
- void SetParameter(Parameter param);//改变全局设置
- Parameter GetParameter();
- void SetFog(bool fog,float near,float far,DWORD color=0xffffffff);
- void SetBgColor(DWORD color);
- void SetAmbient(DWORD color);
- void SetTowSideRender(bool towside);
- void Apply();//设置渲染状态
- private:
- Parameter parameter;
- };
- /*
- ShaderController
- 管理单个网格物体显示效果
- */
- class ShaderController{
- public:
- static void RenderSubtree(NodeObject* rootObject,Camera* cam);//渲染子场景树,从root向它的child和next节点遍历子树
- static void ApplyShader(NodeObject* object);//设置顶点着色器
- static void UpdateSubtree(NodeObject* rootObject);
- private:
- static void IteratorRender(NodeObject* object,Camera* cam);//叠代渲染,从root向它的child和next节点遍历子树
- };
- /*
- UIController
- 创建管理用户界面,响应用户输入
- */
- class UIController{
- private:
- //用户UI对象结构
- struct PanelElement{
- DWORD type;
- int x,y;//左上角坐标
- int width,height;
- int indicatorx;
- int indicatory;
- int indicatorw;
- int indicatorh;
- TCHAR text[MAXTEXT];//显示文字
- DWORD align;//摆放文字方式
- int ID;//惟一的标示此对象的ID
- DWORD bg_color;//背景颜色
- DWORD text_color;//字体颜色
- LPDIRECT3DTEXTURE9 texture;//UI贴图
- LPDIRECT3DTEXTURE9 over_texture;//当鼠标在其上时的UI贴图
- LPDIRECT3DTEXTURE9 indicator_texture;//滑竿按钮图片
- IDirect3DVertexBuffer9* vertex_buffer;//长方形顶点缓存
- IDirect3DVertexBuffer9* indicator_buffer;//长方形顶点缓存
- BOOL button;//是否是按钮
- BOOL over;//鼠标是否在其上
- BOOL active;//是否激活
- BOOL visable;//是否可见
- BOOL drag;//是否正在被拖拽
- float min;
- float max;
- float step;
- float currentpos;//当前滑竿位置(逻辑位置)
- };
- enum PE_TYPE{
- PE_LABEL=0,PE_BUTTON=1,PE_SLIDEBAR
- };
- friend class View;
- friend class ShaderController;
- public:
- UIController();
- ~UIController();
- void SetFont( TCHAR* pstrFont, DWORD dwSize ,bool bold=false);
- void GetSelected(NodeObject* objectList,int objectCount)const;
- void GetMousePosition(int& x,int& y)const;
- void SetSelected(NodeObject* objectList,int objectCount);
- void SetMousePosition(int x,int y);
- //使用Windows消息处理机制获得用户输入
- LRESULT MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void AddLabel(int x, int y, int width,int height,
- TCHAR* text,DWORD align,int ID,
- DWORD text_color,DWORD bg_color,
- MEM_FILE*image);
- void AddButton(int x, int y, int width,
- int height,TCHAR* text,DWORD align,int ID,
- DWORD text_color,DWORD bg_color,MEM_FILE*image,
- MEM_FILE*over_image);
- void AddSlideBar(int x,int y,int width,
- int height,int ID,
- DWORD bg_color,MEM_FILE*image,
- MEM_FILE*indicator_image,float min=0,float max=255.f,
- float step=1.f);//indicator_image表示滑竿按钮图片,step表示精度(最少的改变量)
- void HideUI(int id);//隐藏指定UI对象
- void ShowUI(int id);//显示指定UI对象
- void EnableUI(int id);//激活UI对象
- void DisableUI(int id);//冻结UI对象
- void MoveUI(int ID,float x,float y,float width,float height);//修改UI对象的大小位置,大小为0时不修改大小
- void ReloadUI_image(int ID,MEM_FILE*image,MEM_FILE*over_image,
- BOOL resize=FALSE);
- void ReloadUI_image(int ID,TCHAR*image,TCHAR*over_image,
- BOOL resize=FALSE);
- void SetText(int ID,const TCHAR*newText,...);
- void SetColor(int ID,BOOL set_text_color,DWORD color);
- void SetTransparent(int ID,int value,bool background=true);//0完全透明-255完全不透明
- void SetSlidePos(int ID,float value);//设置滑块的逻辑位置,
- //真实位置也会随逻辑位置改变
- float GetSlidePos(int ID);
- void SetButtonClickProc(void(CALLBACK*OnButtonClick)(int buttonID));
- void SetMouseClickProc(void(CALLBACK*OnMouseClick)(InputStatus status));
- void SetKeyDownProc(void(CALLBACK*OnKeyDown)(InputStatus status));
- void SetKeyUpProc(void(CALLBACK*OnKeyUp)(InputStatus status));
- void SetKeyPressProc(void (CALLBACK*OnKeyPress)(InputStatus status));
- void SetMouseMoveProc(void(CALLBACK*OnMouseMove)(InputStatus status));
- void SetMouseButtonDownProc(void(CALLBACK*OnMouseButtonDown)(InputStatus status));
- void SetMouseButtonUpProc(void(CALLBACK*OnMouseButtonUp)(InputStatus status));
- void ClearAll();
- private:
- std::list<PanelElement> m_panelList;
- void DrawPanelElement(PanelElement ele);
- void DrawAll();
- void (CALLBACK*m_OnButtonClick)(int buttonID);//相应按钮被按时间的函数
- LPD3DXFONT font;
- LPD3DXSPRITE ui;
- };
- /*
- AnimationController
- 控制物体运动速度和动画播放速度
- */
- class AnimationController
- {
- public:
- AnimationController();
- void SetSpeed(float factor);
- void MoveObject(NodeObject *obj);
- void Orbit(NodeObject*obj,VECTOR3 center,float radius,float link_speed);
- private:
- Timer*timer;
- };
- /*
- ObjectScatter
- 负责复制并在空间中随意散布物体
- */
- class ObjectScatter
- {
- public:
- ObjectScatter(SceneTree*scene,NodeObject*obj,int count=100,float min=1,float max=1,float xstart=-100,float ystart=-100,float zstart=-100,float xend=100,float yend=100,float zend=100,int seed=1);
- void SetBoundary(float xstart,float ystart,float zstart,float xend,float yend,float zend);
- void SetSize(float min ,float max);
- void SetCount(int count);
- void Scatter();
- private:
- float min;
- float max;
- float xstart;
- float ystart;
- float zstart;
- float xend;
- float yend;
- float zend;
- int count;
- NodeObject*obj;
- SceneTree*scene;
- RandGenerator*gen;
- };
- /*
- LineCreater
- 创建各种线条
- */
- class LineCreater
- {
- public:
- LineCreater(bool _3d);
- void SetColor(DWORD color);
- void SetWidth(float width);
- void SetAntialias(bool antialias);
- void SetPatten(DWORD patten);
- void DrawLine(VECTOR start,VECTOR end);
- void DrawPolyline(VECTOR*pointList,int count);
- void DrawLaydownCircle(VECTOR center,float radius,int step=80);
- private:
- DWORD color;
- bool _3d;
- ID3DXLine* line;
- D3DXMATRIX transform;
- };
- #endif