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