Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
引擎的场景这块我一直是写了,删除,再写,一直感觉不太满意
本想着做成irr那种父节点-子场景的形式
一是感觉过于复杂
二则都这个不是理解的很到位
所以感觉写还是简单吧
修改起来也比较容易

具体的Renderable如下:

 1 ///////////////////////////////////////////////////////
 2 /// 定义引擎可渲染对象基类
 3 ///////////////////////////////////////////////////////
 4 class Renderable : public Object 
 5 {
 6 public:
 7     ///////////////////////////////////////////////////////
 8     ///  构造,析构可渲染对象
 9     ///////////////////////////////////////////////////////    
10     Renderable();
11     Renderable(bool visible,bool auto_culling = false):
12          visible(visible),
13          auto_culling(auto_culling)
14          {
15          }
16     virtual ~Renderable(){}
17 public:     
18     ///////////////////////////////////////////////////////
19     /// 设置,获取是否渲染(显示)场景
20     ///////////////////////////////////////////////////////        
21     void SetVisible(bool visible){this->visible = visible;}
22     void EnableVisible(){visible = true;}
23     void DisableVisible(){visible = false;}
24     bool IsVisible()const{return visible;}
25     
26     ///////////////////////////////////////////////////////
27     /// 设置,获取是否自动调用视锥体剔除
28     ///////////////////////////////////////////////////////        
29     void SetAutoCulling(bool auto_cull){this->auto_culling = auto_cull;}
30     bool IsAutoCulling()const{return auto_culling;}
31   
32     ///////////////////////////////////////////////////////
33     /// 设置,获取对象的平移 
34     ///////////////////////////////////////////////////////        
35     /*void     SetTranslate(const Vector3f &offset){this->offset = offset;}
36     Vector3f GetTranslate()const{return offset;}
37     
38     ///////////////////////////////////////////////////////
39     /// 设置,获取对象的平旋转(角度) 
40     ///////////////////////////////////////////////////////        
41     void     SetRotate(const Vector3f &rot){this->rotate = rot;}
42     Vector3f GetRotate()const{return rotate;}    
43     
44     ///////////////////////////////////////////////////////
45     /// 设置,获取对象的缩放 
46     ///////////////////////////////////////////////////////        
47     void     SetScale(const Vector3f &scale){this->scale = scale;}
48     Vector3f GetScale()const{return scale;}*/ 
49         
50     ///////////////////////////////////////////////////////
51     /// 获取可渲染物体是否在视锥体内
52     ///////////////////////////////////////////////////////        
53     virtual bool IsInFrustum()const{return true;}
54     
55     ///////////////////////////////////////////////////////
56     /// 渲染函数
57     ///////////////////////////////////////////////////////            
58     //! virtual void BeginRender() = 0;
59     virtual void Render() = 0;  
60     //! virtual void AfterRender() = 0; 
61 protected
62     bool     visible;
63     bool     auto_culling; 
64     //Vector3f offset;
65     //Vector3f scale;
66     //Vector3f rotate;
67         
68     DECLARE_OBJECT(Renderable)    
69 };
70 

Renderable是一切可渲染对象的基类
它提供了以下几个功能:
1.渲染
2.检测对象是否在视锥体内(默认总是true)
3.设置对象的可视状态和检索
4.设置是否自动调用自剔除功能

然后在具体的场景对象中可以处理如下:
1.如果是天空盒之类则其总是视锥体内的
2.如果是光材质雾之类的对象则其可显示变为启用
3.如果对象为md2模型之类则从Renderable下面再弄一个子类

posted on 2010-04-02 21:45 ccsdu2009 阅读(176) 评论(0)  编辑 收藏 引用 所属分类: Game引擎

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理