sculpto
Public Member Functions | List of all members
scl::topology::cone Class Reference

#include <cone.h>

Inheritance diagram for scl::topology::cone:
scl::topology::grid scl::topology::basis< vertex >

Public Member Functions

 cone (const vec3 &A, float R1, const vec3 &B, float R2, int Slices)
 
 ~cone () override=default
 
- Public Member Functions inherited from scl::topology::grid
int GetWidth () const
 
int GetHeight () const
 
 grid (int Width, int Height)
 
 ~grid () override=default
 
- Public Member Functions inherited from scl::topology::basis< vertex >
const mesh_type GetType () const
 
const std::vector< vertexGetVertices () const
 
const std::vector< u32GetIndices () const
 
const vec3GetBoundMin () const
 
const vec3GetBoundMax () const
 
std::vector< vertex >::const_iterator cbegin () const
 
std::vector< vertex >::const_iterator cend () const
 
 basis (mesh_type MeshType)
 
 basis (mesh_type MeshType, const std::vector< vertex > &Vertices, const std::vector< u32 > &Indices)
 
 basis (mesh_type MeshType, std::vector< vertex > &&Vertices, std::vector< u32 > &&Indices)
 
virtual ~basis ()=default
 

Additional Inherited Members

- Public Attributes inherited from scl::topology::basis< vertex >
mesh_type MeshType
 
std::vector< vertexVertices
 
std::vector< u32Indices
 
vec3 Min
 
vec3 Max
 

Detailed Description

Topology cone object class.

Definition at line 16 of file cone.h.

Constructor & Destructor Documentation

◆ cone()

scl::topology::cone::cone ( const vec3 A,
float  R1,
const vec3 B,
float  R2,
int  Slices 
)
  • Topology cone object class contructor.
Parameters
A- cone bottom base middle point.
R1- cone bottmo base cone
B- cone top base middle point.
R2- cone top base middle point.
Slices- mesh slices count.

Definition at line 12 of file cone.cpp.

12 :
13 grid(1, Slices)
14{
15 float height = (A - B).Length();
16 vec3 height_dir = (A - B).Normalized();
17 vec3 height_dir_90 = vec3 { -height_dir.Y, height_dir.X, height_dir.Z };
18 vec3 guide = height_dir_90 - height_dir;
19 float cos_alpha = height_dir_90.Dot(guide);
20 float sin_alpha = sqrt(1 - cos_alpha * cos_alpha);
21 vec3 normal = vec3(cos_alpha, sin_alpha, 0).Normalized();
22
23 for (int i = 0; i <= Slices; i++)
24 {
25 float t = (float)i / Slices;
26 float phi = 360 * t;
27 float x = sin(phi);
28 float z = cos(phi);
29 matr4 rotation = matr4::Rotate(height_dir, phi);
30 vec3 normal = rotation.TransformVector(normal);
31 vec3 tangent = vec3 { z, 0, -x };
32 vec3 bitangent = tangent.Cross(normal);
33
34 Vertices.emplace_back(
35 A + rotation.TransformVector(height_dir_90 * R1),
36 normal, tangent, bitangent, vec2 { t, 0 }
37 );
38 Vertices.emplace_back(
39 B + rotation.TransformVector(height_dir_90 * R2),
40 normal, tangent, bitangent, vec2 { t, 1 }
41 );
42 }
43}
static matr4 Rotate(vec3< float > Axis, degrees< float > Angle)
Definition: matr4.h:288
vec3 Normalized() const
Definition: vec3.h:190
T Dot(const vec3 &Other) const
Definition: vec3.h:213
vec3 Cross(const vec3 &Other) const
Definition: vec3.h:224
std::vector< vertex > Vertices
Definition: basis.h:22
grid(int Width, int Height)
Definition: grid.cpp:12
math::matr4< float > matr4
Definition: base.h:48
math::vec3< float > vec3
Definition: base.h:38
math::vec2< float > vec2
Definition: base.h:37

◆ ~cone()

scl::topology::cone::~cone ( )
overridedefault

Cone topology object default destructor.


The documentation for this class was generated from the following files: