1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright © 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgrePose.h"
|
---|
27 | #include "OgreHardwareBufferManager.h"
|
---|
28 |
|
---|
29 | namespace Ogre {
|
---|
30 | //---------------------------------------------------------------------
|
---|
31 | Pose::Pose(ushort target, const String& name)
|
---|
32 | : mTarget(target), mName(name)
|
---|
33 | {
|
---|
34 | }
|
---|
35 | //---------------------------------------------------------------------
|
---|
36 | Pose::~Pose()
|
---|
37 | {
|
---|
38 | }
|
---|
39 | //---------------------------------------------------------------------
|
---|
40 | void Pose::addVertex(size_t index, const Vector3& offset)
|
---|
41 | {
|
---|
42 | mVertexOffsetMap[index] = offset;
|
---|
43 | mBuffer.setNull();
|
---|
44 | }
|
---|
45 | //---------------------------------------------------------------------
|
---|
46 | void Pose::removeVertex(size_t index)
|
---|
47 | {
|
---|
48 | VertexOffsetMap::iterator i = mVertexOffsetMap.find(index);
|
---|
49 | if (i != mVertexOffsetMap.end())
|
---|
50 | {
|
---|
51 | mVertexOffsetMap.erase(i);
|
---|
52 | mBuffer.setNull();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | //---------------------------------------------------------------------
|
---|
56 | void Pose::clearVertexOffsets(void)
|
---|
57 | {
|
---|
58 | mVertexOffsetMap.clear();
|
---|
59 | mBuffer.setNull();
|
---|
60 | }
|
---|
61 | //---------------------------------------------------------------------
|
---|
62 | Pose::ConstVertexOffsetIterator
|
---|
63 | Pose::getVertexOffsetIterator(void) const
|
---|
64 | {
|
---|
65 | return ConstVertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
|
---|
66 | }
|
---|
67 | //---------------------------------------------------------------------
|
---|
68 | Pose::VertexOffsetIterator
|
---|
69 | Pose::getVertexOffsetIterator(void)
|
---|
70 | {
|
---|
71 | return VertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
|
---|
72 | }
|
---|
73 | //---------------------------------------------------------------------
|
---|
74 | const HardwareVertexBufferSharedPtr& Pose::_getHardwareVertexBuffer(size_t numVertices) const
|
---|
75 | {
|
---|
76 | if (mBuffer.isNull())
|
---|
77 | {
|
---|
78 | // Create buffer
|
---|
79 | mBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
|
---|
80 | VertexElement::getTypeSize(VET_FLOAT3),
|
---|
81 | numVertices, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
82 |
|
---|
83 | float* pFloat = static_cast<float*>(
|
---|
84 | mBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
85 | // initialise
|
---|
86 | memset(pFloat, 0, mBuffer->getSizeInBytes());
|
---|
87 | // Set each vertex
|
---|
88 | for (VertexOffsetMap::const_iterator i = mVertexOffsetMap.begin();
|
---|
89 | i != mVertexOffsetMap.end(); ++i)
|
---|
90 | {
|
---|
91 | float* pDst = pFloat + (3 * i->first);
|
---|
92 | *pDst++ = i->second.x;
|
---|
93 | *pDst++ = i->second.y;
|
---|
94 | *pDst++ = i->second.z;
|
---|
95 | }
|
---|
96 | mBuffer->unlock();
|
---|
97 | }
|
---|
98 | return mBuffer;
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|