diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CGUIMeshViewer.cpp | 342 |
1 files changed, 171 insertions, 171 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIMeshViewer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIMeshViewer.cpp index d121e34..82e96f1 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIMeshViewer.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIMeshViewer.cpp | |||
@@ -1,171 +1,171 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "CGUIMeshViewer.h" | 5 | #include "CGUIMeshViewer.h" |
6 | #ifdef _IRR_COMPILE_WITH_GUI_ | 6 | #ifdef _IRR_COMPILE_WITH_GUI_ |
7 | 7 | ||
8 | #include "IGUIEnvironment.h" | 8 | #include "IGUIEnvironment.h" |
9 | #include "IVideoDriver.h" | 9 | #include "IVideoDriver.h" |
10 | #include "IAnimatedMesh.h" | 10 | #include "IAnimatedMesh.h" |
11 | #include "IMesh.h" | 11 | #include "IMesh.h" |
12 | #include "os.h" | 12 | #include "os.h" |
13 | #include "IGUISkin.h" | 13 | #include "IGUISkin.h" |
14 | 14 | ||
15 | namespace irr | 15 | namespace irr |
16 | { | 16 | { |
17 | 17 | ||
18 | namespace gui | 18 | namespace gui |
19 | { | 19 | { |
20 | 20 | ||
21 | 21 | ||
22 | //! constructor | 22 | //! constructor |
23 | CGUIMeshViewer::CGUIMeshViewer(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) | 23 | CGUIMeshViewer::CGUIMeshViewer(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) |
24 | : IGUIMeshViewer(environment, parent, id, rectangle), Mesh(0) | 24 | : IGUIMeshViewer(environment, parent, id, rectangle), Mesh(0) |
25 | { | 25 | { |
26 | #ifdef _DEBUG | 26 | #ifdef _DEBUG |
27 | setDebugName("CGUIMeshViewer"); | 27 | setDebugName("CGUIMeshViewer"); |
28 | #endif | 28 | #endif |
29 | } | 29 | } |
30 | 30 | ||
31 | 31 | ||
32 | //! destructor | 32 | //! destructor |
33 | CGUIMeshViewer::~CGUIMeshViewer() | 33 | CGUIMeshViewer::~CGUIMeshViewer() |
34 | { | 34 | { |
35 | if (Mesh) | 35 | if (Mesh) |
36 | Mesh->drop(); | 36 | Mesh->drop(); |
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | //! sets the mesh to be shown | 40 | //! sets the mesh to be shown |
41 | void CGUIMeshViewer::setMesh(scene::IAnimatedMesh* mesh) | 41 | void CGUIMeshViewer::setMesh(scene::IAnimatedMesh* mesh) |
42 | { | 42 | { |
43 | if (mesh) | 43 | if (mesh) |
44 | mesh->grab(); | 44 | mesh->grab(); |
45 | if (Mesh) | 45 | if (Mesh) |
46 | Mesh->drop(); | 46 | Mesh->drop(); |
47 | 47 | ||
48 | Mesh = mesh; | 48 | Mesh = mesh; |
49 | 49 | ||
50 | /* This might be used for proper transformation etc. | 50 | /* This might be used for proper transformation etc. |
51 | core::vector3df center(0.0f,0.0f,0.0f); | 51 | core::vector3df center(0.0f,0.0f,0.0f); |
52 | core::aabbox3d<f32> box; | 52 | core::aabbox3d<f32> box; |
53 | 53 | ||
54 | box = Mesh->getMesh(0)->getBoundingBox(); | 54 | box = Mesh->getMesh(0)->getBoundingBox(); |
55 | center = (box.MaxEdge + box.MinEdge) / 2; | 55 | center = (box.MaxEdge + box.MinEdge) / 2; |
56 | */ | 56 | */ |
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
60 | //! Gets the displayed mesh | 60 | //! Gets the displayed mesh |
61 | scene::IAnimatedMesh* CGUIMeshViewer::getMesh() const | 61 | scene::IAnimatedMesh* CGUIMeshViewer::getMesh() const |
62 | { | 62 | { |
63 | return Mesh; | 63 | return Mesh; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | //! sets the material | 67 | //! sets the material |
68 | void CGUIMeshViewer::setMaterial(const video::SMaterial& material) | 68 | void CGUIMeshViewer::setMaterial(const video::SMaterial& material) |
69 | { | 69 | { |
70 | Material = material; | 70 | Material = material; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | //! gets the material | 74 | //! gets the material |
75 | const video::SMaterial& CGUIMeshViewer::getMaterial() const | 75 | const video::SMaterial& CGUIMeshViewer::getMaterial() const |
76 | { | 76 | { |
77 | return Material; | 77 | return Material; |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | //! called if an event happened. | 81 | //! called if an event happened. |
82 | bool CGUIMeshViewer::OnEvent(const SEvent& event) | 82 | bool CGUIMeshViewer::OnEvent(const SEvent& event) |
83 | { | 83 | { |
84 | return IGUIElement::OnEvent(event); | 84 | return IGUIElement::OnEvent(event); |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | //! draws the element and its children | 88 | //! draws the element and its children |
89 | void CGUIMeshViewer::draw() | 89 | void CGUIMeshViewer::draw() |
90 | { | 90 | { |
91 | if (!IsVisible) | 91 | if (!IsVisible) |
92 | return; | 92 | return; |
93 | 93 | ||
94 | IGUISkin* skin = Environment->getSkin(); | 94 | IGUISkin* skin = Environment->getSkin(); |
95 | video::IVideoDriver* driver = Environment->getVideoDriver(); | 95 | video::IVideoDriver* driver = Environment->getVideoDriver(); |
96 | core::rect<s32> viewPort = AbsoluteRect; | 96 | core::rect<s32> viewPort = AbsoluteRect; |
97 | viewPort.LowerRightCorner.X -= 1; | 97 | viewPort.LowerRightCorner.X -= 1; |
98 | viewPort.LowerRightCorner.Y -= 1; | 98 | viewPort.LowerRightCorner.Y -= 1; |
99 | viewPort.UpperLeftCorner.X += 1; | 99 | viewPort.UpperLeftCorner.X += 1; |
100 | viewPort.UpperLeftCorner.Y += 1; | 100 | viewPort.UpperLeftCorner.Y += 1; |
101 | 101 | ||
102 | viewPort.clipAgainst(AbsoluteClippingRect); | 102 | viewPort.clipAgainst(AbsoluteClippingRect); |
103 | 103 | ||
104 | // draw the frame | 104 | // draw the frame |
105 | 105 | ||
106 | core::rect<s32> frameRect(AbsoluteRect); | 106 | core::rect<s32> frameRect(AbsoluteRect); |
107 | frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1; | 107 | frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1; |
108 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect); | 108 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect); |
109 | 109 | ||
110 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; | 110 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; |
111 | frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1; | 111 | frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1; |
112 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect); | 112 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect); |
113 | 113 | ||
114 | frameRect = AbsoluteRect; | 114 | frameRect = AbsoluteRect; |
115 | frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1; | 115 | frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1; |
116 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); | 116 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); |
117 | 117 | ||
118 | frameRect = AbsoluteRect; | 118 | frameRect = AbsoluteRect; |
119 | frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1; | 119 | frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1; |
120 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); | 120 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); |
121 | 121 | ||
122 | // draw the mesh | 122 | // draw the mesh |
123 | 123 | ||
124 | if (Mesh) | 124 | if (Mesh) |
125 | { | 125 | { |
126 | //TODO: if outside of screen, dont draw. | 126 | //TODO: if outside of screen, dont draw. |
127 | // - why is the absolute clipping rect not already the screen? | 127 | // - why is the absolute clipping rect not already the screen? |
128 | 128 | ||
129 | core::rect<s32> oldViewPort = driver->getViewPort(); | 129 | core::rect<s32> oldViewPort = driver->getViewPort(); |
130 | 130 | ||
131 | driver->setViewPort(viewPort); | 131 | driver->setViewPort(viewPort); |
132 | 132 | ||
133 | core::matrix4 mat; | 133 | core::matrix4 mat; |
134 | 134 | ||
135 | //CameraControl->calculateProjectionMatrix(mat); | 135 | //CameraControl->calculateProjectionMatrix(mat); |
136 | //driver->setTransform(video::TS_PROJECTION, mat); | 136 | //driver->setTransform(video::TS_PROJECTION, mat); |
137 | 137 | ||
138 | mat.makeIdentity(); | 138 | mat.makeIdentity(); |
139 | mat.setTranslation(core::vector3df(0,0,0)); | 139 | mat.setTranslation(core::vector3df(0,0,0)); |
140 | driver->setTransform(video::ETS_WORLD, mat); | 140 | driver->setTransform(video::ETS_WORLD, mat); |
141 | 141 | ||
142 | //CameraControl->calculateViewMatrix(mat); | 142 | //CameraControl->calculateViewMatrix(mat); |
143 | //driver->setTransform(video::TS_VIEW, mat); | 143 | //driver->setTransform(video::TS_VIEW, mat); |
144 | 144 | ||
145 | driver->setMaterial(Material); | 145 | driver->setMaterial(Material); |
146 | 146 | ||
147 | u32 frame = 0; | 147 | u32 frame = 0; |
148 | if(Mesh->getFrameCount()) | 148 | if(Mesh->getFrameCount()) |
149 | frame = (os::Timer::getTime()/20)%Mesh->getFrameCount(); | 149 | frame = (os::Timer::getTime()/20)%Mesh->getFrameCount(); |
150 | const scene::IMesh* const m = Mesh->getMesh(frame); | 150 | const scene::IMesh* const m = Mesh->getMesh(frame); |
151 | for (u32 i=0; i<m->getMeshBufferCount(); ++i) | 151 | for (u32 i=0; i<m->getMeshBufferCount(); ++i) |
152 | { | 152 | { |
153 | scene::IMeshBuffer* mb = m->getMeshBuffer(i); | 153 | scene::IMeshBuffer* mb = m->getMeshBuffer(i); |
154 | driver->drawVertexPrimitiveList(mb->getVertices(), | 154 | driver->drawVertexPrimitiveList(mb->getVertices(), |
155 | mb->getVertexCount(), mb->getIndices(), | 155 | mb->getVertexCount(), mb->getIndices(), |
156 | mb->getIndexCount()/ 3, mb->getVertexType(), | 156 | mb->getIndexCount()/ 3, mb->getVertexType(), |
157 | scene::EPT_TRIANGLES, mb->getIndexType()); | 157 | scene::EPT_TRIANGLES, mb->getIndexType()); |
158 | } | 158 | } |
159 | 159 | ||
160 | driver->setViewPort(oldViewPort); | 160 | driver->setViewPort(oldViewPort); |
161 | } | 161 | } |
162 | 162 | ||
163 | IGUIElement::draw(); | 163 | IGUIElement::draw(); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | } // end namespace gui | 167 | } // end namespace gui |
168 | } // end namespace irr | 168 | } // end namespace irr |
169 | 169 | ||
170 | #endif // _IRR_COMPILE_WITH_GUI_ | 170 | #endif // _IRR_COMPILE_WITH_GUI_ |
171 | 171 | ||