genesis-3d_engine/Engine/foundation/meshbuilder/conebuilder.h

93 lines
4.7 KiB
C
Raw Permalink Normal View History

/****************************************************************************
Copyright (c) 2011-2013,WebJet Business Division,CYOU
http://www.genesis-3d.com.cn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CONE_BUILDER_H__
#define __CONE_BUILDER_H__
#include "meshbuilder/meshbuilder.h"
#include "math/float3.h"
namespace MeshBuilder
{
#define CONE_VERTEX_COUNT(tessellation) tessellation + 2
#define CONE_INDEX_COUNT(tessellation) tessellation * 6//tessellation * 2 * 3;
// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>Բ<EFBFBD>ģ<EFBFBD><C4A3>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ׶<CEAA><D7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><E3A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>˳ʱ<CBB3><CAB1><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>
// <20><>νtessellation<6F><6E><EFBFBD><EFBFBD>˼<EFBFBD><CBBC><EFBFBD><EFBFBD>Բ׶<D4B2>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ı<EFBFBD>Ե<EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class ConeBuilder
{
public:
//tessellation<6F>µĶ<C2B5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static SizeT VertexCount(SizeT tessellation);
//tessellation<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static SizeT IndexCount(SizeT tessellation);
// set indices
static void SetIndices(ushort* buffer, SizeT tessellation);
// buffer: vertex buffer, vertexSize: a vertex element's size, posBias: the starting location(in bytes) of position data in a vertex element
// tessellation: tessellation, r: the radius of bottom, topHeight: the cone's height, center: the centre of bottom
template<typename T>
static void SetPositions(T* buffer, SizeT vertexSize, SizeT posBias, SizeT tessellation, float r, float topHeight, const Math::float3& center);
// buffer: vertex buffer, vertexSize: a vertex element's size, normalBias: the starting location(in bytes) of normal data in a vertex element
// tessellation: tessellation
// posBuffer: vertex buffer, posBufferVertexSize: a vertex element's size of posBuffer, posBias: the starting location(in bytes) of position data in a vertex element of posBuffer
template<typename T1, typename T2>
static void SetNormals(T1* buffer, SizeT vertexSize, SizeT normalBias, SizeT tessellation, const T2* posBuffer, SizeT posBufferVertexSize, SizeT posBias);
private:
static void setPositions(ubyte* buffer, SizeT vertexSize, SizeT posBias, SizeT tessellation, float r, float topHeight, const Math::float3& center);
static void setNormals(ubyte* buffer, SizeT vertexSize, SizeT normalBias, SizeT tessellation, const ubyte* posBuffer, SizeT posBufferVertexSize, SizeT posBias);
static void setCircleVector(float angle, Math::float3& dir);
static void calBottomNormal(elem_iterator_const<Math::float3> begin, SizeT tessellation, Math::float3& bottomNormal);
static void calBottomSidePosNormal(const Math::float3& curPos, const Math::float3& nextPos, const Math::float3& prePos, const Math::float3& topPos, const Math::float3& bottomNormal, Math::float3& normal);
static void calNormal(const Math::float3& point0, const Math::float3& point1, const Math::float3& point2, Math::float3& normal);
ConeBuilder();
};
template<typename T>
inline void ConeBuilder::SetPositions(T* buffer, SizeT vertexSize, SizeT posBias, SizeT tessellation, float r, float topHeight, const Math::float3& center)
{
setPositions(reinterpret_cast<ubyte*>(buffer), vertexSize, posBias, tessellation, r, topHeight, center);
}
template<typename T1, typename T2>
inline void ConeBuilder::SetNormals(T1* buffer, SizeT vertexSize, SizeT normalBias, SizeT tessellation, const T2* posBuffer, SizeT posBufferVertexSize, SizeT posBias)
{
setNormals(reinterpret_cast<ubyte*>(buffer),vertexSize,normalBias,tessellation,
reinterpret_cast<const ubyte*>(posBuffer), posBufferVertexSize, posBias);
}
inline SizeT ConeBuilder::VertexCount(SizeT tessellation)
{
n_assert(tessellation > 2);
return CONE_VERTEX_COUNT(tessellation);
}
inline SizeT ConeBuilder::IndexCount(SizeT tessellation)
{
n_assert(tessellation > 2);
return CONE_INDEX_COUNT(tessellation);
}
}
#endif //__CONE_BUILDER_H__