-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProceduralConeGenerator.cs
187 lines (163 loc) · 7.86 KB
/
ProceduralConeGenerator.cs
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
-----------------------------------------------------------------------------
This source file is part of mogre-procedural
For the latest info, see http://code.google.com/p/mogre-procedural/
my blog:http://hi.baidu.com/rainssoft
this is overwrite ogre-procedural c++ project using c#, look ogre-procedural c++ source http://code.google.com/p/ogre-procedural/
Copyright (c) 2013-2020 rains soft
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 PROCEDURAL_CONE_GENERATOR_INCLUDED
#define PROCEDURAL_CONE_GENERATOR_INCLUDED
// write with new std .... ok
namespace Mogre_Procedural
{
using System;
using System.Collections.Generic;
using System.Text;
using Mogre;
using Math = Mogre.Math;
//*
// * \ingroup objgengrp
// * Generates a cone mesh along Y-axis
// * \image html primitive_cone.png
//
//C++ TO C# CONVERTER WARNING: The original type declaration contained unconverted modifiers:
//ORIGINAL LINE: class _ProceduralExport ConeGenerator : public MeshGenerator<ConeGenerator>
public class ConeGenerator : MeshGenerator<ConeGenerator>
{
private uint mNumSegBase;
private uint mNumSegHeight;
private float mRadius = 0f;
private float mHeight = 0f;
/// Contructor with arguments
public ConeGenerator(float radius, float height, uint numSegBase)
: this(radius, height, numSegBase, 1) {
}
public ConeGenerator(float radius, float height)
: this(radius, height, 16, 1) {
}
public ConeGenerator(float radius)
: this(radius, 1.0f, 16, 1) {
}
public ConeGenerator()
: this(1.0f, 1.0f, 16, 1) {
}
//
//ORIGINAL LINE: ConeGenerator(Ogre::float radius = 1.0f, Ogre::float height = 1.0f, uint numSegBase = 16, uint numSegHeight = 1) : mNumSegBase(numSegBase), mNumSegHeight(numSegHeight), mRadius(radius), mHeight(height)
public ConeGenerator(float radius, float height, uint numSegBase, uint numSegHeight) {
mNumSegBase = numSegBase;
mNumSegHeight = numSegHeight;
mRadius = radius;
mHeight = height;
}
// *
// * Builds the mesh into the given TriangleBuffer
// * @param buffer The TriangleBuffer on where to append the mesh.
//
//
//ORIGINAL LINE: void addToTriangleBuffer(TriangleBuffer& buffer) const
public override void addToTriangleBuffer(ref TriangleBuffer buffer) {
buffer.rebaseOffset();
buffer.estimateVertexCount((mNumSegHeight + 1) * (mNumSegBase + 1) + mNumSegBase + 2);
buffer.estimateIndexCount(mNumSegHeight * mNumSegBase * 6 + 3 * mNumSegBase);
float deltaAngle = (Math.TWO_PI / mNumSegBase);
float deltaHeight = mHeight / (float)mNumSegHeight;
int offset = 0;
Vector3 refNormal = new Vector3(mRadius, mHeight, 0.0f);
Quaternion q = new Quaternion();
for (uint i = 0; i <= mNumSegHeight; i++) {
float r0 = mRadius * (1 - i / (float)mNumSegHeight);
for (uint j = 0; j <= mNumSegBase; j++) {
float x0 = r0 * cosf(j * deltaAngle);
float z0 = r0 * sinf(j * deltaAngle);
q.FromAngleAxis(new Radian(-deltaAngle * j), Vector3.UNIT_Y);
addPoint(ref buffer, new Vector3(x0, i * deltaHeight, z0), q * refNormal, new Vector2(j / (float)mNumSegBase, i / (float)mNumSegHeight));
if (i != mNumSegHeight && j != mNumSegBase) {
buffer.index(offset + (int)mNumSegBase + 2);
buffer.index(offset);
buffer.index(offset + (int)mNumSegBase + 1);
buffer.index(offset + (int)mNumSegBase + +2);
buffer.index(offset + 1);
buffer.index(offset);
}
offset++;
}
}
//low cap
int centerIndex = offset;
addPoint(ref buffer, Vector3.ZERO, Vector3.NEGATIVE_UNIT_Y, Vector2.UNIT_Y);
offset++;
for (uint j = 0; j <= mNumSegBase; j++) {
float x0 = mRadius * cosf(j * deltaAngle);
float z0 = mRadius * sinf(j * deltaAngle);
addPoint(ref buffer, new Vector3(x0, 0.0f, z0), Vector3.NEGATIVE_UNIT_Y, new Vector2(j / (float)mNumSegBase, 0.0f));
if (j != mNumSegBase) {
buffer.index(centerIndex);
buffer.index(offset);
buffer.index(offset + 1);
}
offset++;
}
}
// *
// Sets the number of segments on the side of the base (default=16)
// \exception Ogre::InvalidParametersException Minimum of numSegBase is 1
//
public ConeGenerator setNumSegBase(uint numSegBase) {
if (numSegBase == 0)
OGRE_EXCEPT("Ogre::Exception::ERR_INVALIDPARAMS", "There must be more than 0 segments", "Procedural::ConeGenerator::setNumSegBase(unsigned int)");
;
mNumSegBase = numSegBase;
return this;
}
// *
// Sets the number of segments on the height (default=1)
// \exception Ogre::InvalidParametersException Minimum of numSegHeight is 1
//
public ConeGenerator setNumSegHeight(uint numSegHeight) {
if (numSegHeight == 0)
OGRE_EXCEPT("Ogre::Exception::ERR_INVALIDPARAMS", "There must be more than 0 segments", "Procedural::ConeGenerator::setNumSegHeight(unsigned int)");
;
mNumSegHeight = numSegHeight;
return this;
}
// *
// Sets the base radius (default=1)
// \exception Ogre::InvalidParametersException Radius must be larger than 0!
//
public ConeGenerator setRadius(float radius) {
if (radius <= 0.0f)
OGRE_EXCEPT("Ogre::Exception::ERR_INVALIDPARAMS", "Radius must be larger than 0!", "Procedural::ConeGenerator::setRadius(Ogre::Real)");
;
mRadius = radius;
return this;
}
// *
// Sets the height of the cone (default=1)
// \exception Ogre::InvalidParametersException Height must be larger than 0!
//
public ConeGenerator setHeight(float height) {
if (height <= 0.0f)
OGRE_EXCEPT("Ogre::Exception::ERR_INVALIDPARAMS", "Height must be larger than 0!", "Procedural::ConeGenerator::setHeight(Ogre::Real)");
;
mHeight = height;
return this;
}
}
}