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