~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CGUIMeshViewer.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 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
        frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y;
 
121
        skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect);
 
122
 
 
123
        // draw the mesh
 
124
 
 
125
        if (Mesh)
 
126
        {
 
127
                //TODO: if outside of screen, dont draw.
 
128
                // - why is the absolute clipping rect not already the screen?
 
129
 
 
130
                core::rect<s32> oldViewPort = driver->getViewPort();
 
131
 
 
132
                driver->setViewPort(viewPort);
 
133
 
 
134
                core::matrix4 mat;
 
135
 
 
136
                //CameraControl->calculateProjectionMatrix(mat);
 
137
                //driver->setTransform(video::TS_PROJECTION, mat);
 
138
 
 
139
                mat.makeIdentity();
 
140
                mat.setTranslation(core::vector3df(0,0,0));
 
141
                driver->setTransform(video::ETS_WORLD, mat);
 
142
 
 
143
                //CameraControl->calculateViewMatrix(mat);
 
144
                //driver->setTransform(video::TS_VIEW, mat);
 
145
 
 
146
                driver->setMaterial(Material);
 
147
 
 
148
                u32 frame = 0;
 
149
                if(Mesh->getFrameCount())
 
150
                        frame = (os::Timer::getTime()/20)%Mesh->getFrameCount();
 
151
                const scene::IMesh* const m = Mesh->getMesh(frame);
 
152
                for (u32 i=0; i<m->getMeshBufferCount(); ++i)
 
153
                {
 
154
                        scene::IMeshBuffer* mb = m->getMeshBuffer(i);
 
155
                        driver->drawVertexPrimitiveList(mb->getVertices(),
 
156
                                        mb->getVertexCount(), mb->getIndices(),
 
157
                                        mb->getIndexCount()/ 3, mb->getVertexType(),
 
158
                                        scene::EPT_TRIANGLES, mb->getIndexType());
 
159
                }
 
160
 
 
161
                driver->setViewPort(oldViewPort);
 
162
        }
 
163
 
 
164
        IGUIElement::draw();
 
165
}
 
166
 
 
167
 
 
168
} // end namespace gui
 
169
} // end namespace irr
 
170
 
 
171
#endif // _IRR_COMPILE_WITH_GUI_
 
172