Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgrePose.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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