引擎的場景這塊我一直是寫了,刪除,再寫,一直感覺不太滿意
本想著做成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下面再弄一個子類