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

#include <sphere.h>

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

Public Member Functions

 sphere (const vec3 &Center, float Radius, int Slices)
 
 ~sphere () 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 sphere object class.

Definition at line 16 of file sphere.h.

Constructor & Destructor Documentation

◆ sphere()

scl::topology::sphere::sphere ( const vec3 Center,
float  Radius,
int  Slices 
)
  • Sphere topolgy obejct constructor by center point and radius.
Parameters
Center- sphere center point.
Radius- sphere radius.
Slices- sphere mesh slices count.

Definition at line 12 of file sphere.cpp.

12 :
13 grid(Slices, Slices)
14{
15 for (int i = 0; i <= Slices; i++)
16 {
17 float theta = (float)i / Slices * math::PI;
18 for (int j = 0; j <= Slices; j++)
19 {
20 float phi = (float)j / Slices * 2 * math::PI;
21 float x = sin(phi) * sin(theta);
22 float y = cos(phi);
23 float z = sin(phi) * cos(theta);
24 float x_tbn = sin(phi) * cos(theta);
25 float y_tbn = cos(phi) * cos(theta);
26 vec3 position { x, y, z };
27 vec3 tangent = position.Cross({ x_tbn, 0, y_tbn }).Normalized();
28 vec3 bitangent = tangent.Cross(position).Normalized();
29 vec2 texture_coordinates { (float)i / Slices, (float)j / Slices };
30
31 Vertices.emplace_back(
32 position * Radius + Center, position,
33 tangent, bitangent,
34 texture_coordinates
35 );
36 }
37 }
38
39 Min = -vec3(Radius), Max = vec3(Radius);
40}
vec3 Normalized() const
Definition: vec3.h:190
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
const float PI
Definition: math_common.h:33
math::vec3< float > vec3
Definition: base.h:38
math::vec2< float > vec2
Definition: base.h:37

◆ ~sphere()

scl::topology::sphere::~sphere ( )
overridedefault

Sphere topology object default destructor.


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