52 VAO->second->unbind();
54 else {std::cerr<<
"Warning VAO not know in Primitive list "<<_name.c_str()<<
"\n";}
67 vao->second->setMode(_mode);
69 vao->second->unbind();
71 else {std::cerr<<
"Warning VAO not know in Primitive list "<<_name.c_str()<<
"\n";}
115 std::vector <vertData>
data;
118 Real wstep=_width/
static_cast<Real>(_steps);
120 Real ws2=_width/2.0f;
125 Real dstep=_depth/
static_cast<Real>(_steps);
127 Real ds2=_depth/2.0f;
131 for(
int i=0; i<=_steps; ++i)
137 data.push_back(vert);
141 data.push_back(vert);
147 data.push_back(vert);
151 data.push_back(vert);
175 std::vector <vertData>
data;
189 for(
int i = 0; i < _precision/2; ++i )
192 theta2 = (i + 1) *
TWO_PI / _precision - PI2;
194 for(
int j = 0; j <= _precision; ++j )
196 theta3 = j *
TWO_PI / _precision;
198 d.
nx = cosf(theta2) * cosf(theta3);
200 d.
nz = cosf(theta2) * sinf(theta3);
201 d.
x = _radius * d.
nx;
202 d.
y = _radius * d.
ny;
203 d.
z = _radius * d.
nz;
205 d.
u = (j/
static_cast<Real>(_precision));
206 d.
v = 2*(i+1)/static_cast<Real>(_precision);
210 d.
nx = cosf(theta1) * cosf(theta3);
212 d.
nz = cosf(theta1) * sinf(theta3);
213 d.
x = _radius * d.
nx;
214 d.
y = _radius * d.
ny;
215 d.
z = _radius * d.
nz;
217 d.
u = (j/
static_cast<Real>(_precision));
218 d.
v = 2*i/
static_cast<Real>(_precision);
234 std::vector <vertData>
data;
236 Real h = _height / 2;
238 Real sb, cb, sb1, cb1;
239 Real ang = (1.0f / _precision) * static_cast<Real>(M_PI);
240 for (
int i = 0; i < 2 * _precision; ++i)
243 c = _radius * cosf(ang * i);
244 c1= _radius * cosf(ang * (i + 1));
245 s = _radius * sinf(ang * i);
246 s1 =_radius * sinf(ang * (i + 1));
278 for (
int j = 0; j <=_precision; ++j)
280 if (j < _precision / 2)
290 s1 = -sinf(ang * (i + 1));
292 c1 = cosf(ang * (i + 1));
294 sb = _radius * sinf(ang * j);
295 sb1 = _radius * sinf(ang * (j + 1));
296 cb = _radius * cosf(ang * j);
297 cb1 = _radius * cosf(ang * (j + 1));
298 if (j != _precision - 1)
394 io_sint.reset(
new Real[size+1]);
395 io_cost.reset(
new Real[size+1]);
400 for (i=1; i<static_cast<unsigned int>(
size); ++i)
402 io_sint[i] = sinf(angle*i);
403 io_cost[i] = cosf(angle*i);
406 io_sint[
static_cast<unsigned int>(
size)] = io_sint[0];
407 io_cost[
static_cast<unsigned int>(
size)] = io_cost[0];
416 const Real zStep = _height / ( ( _stacks > 0 ) ? _stacks : 1 );
419 std::unique_ptr<Real []> sint;
420 std::unique_ptr<Real []> cost;
427 std::vector <vertData>
data;
433 Real du=1.0f/_stacks;
434 Real dv=1.0f/_slices;
439 for(
unsigned int i=1; i<=_stacks+1; ++i )
445 for(
unsigned int j=0; j<=_slices-1; ++j)
467 d.
x=sint[j+1]*_radius;
468 d.
y=cost[j+1]*_radius;
479 d.
x=sint[j+1]*_radius;
480 d.
y=cost[j+1]*_radius;
501 d.
x=sint[j+1]*_radius;
502 d.
y=cost[j+1]*_radius;
510 z0 = z1; z1 += zStep;
524 const Real zStep = _height / ( ( _stacks > 0 ) ? _stacks : 1 );
525 const Real rStep = _base / ( ( _stacks > 0 ) ? _stacks : 1 );
529 const Real cosn = ( _height / sqrtf ( _height * _height + _base * _base ));
530 const Real sinn = ( _base / sqrtf ( _height * _height + _base * _base ));
533 std::unique_ptr<Real []> sint;
534 std::unique_ptr<Real []> cost;
544 Real du=1.0f/_stacks;
545 Real dv=1.0f/_slices;
550 std::vector <vertData>
data;
552 for(
unsigned int i=0; i<_stacks; i++ )
554 for(
unsigned int j=0; j<=_slices; j++)
559 d.
ny = sint[j] * sinn ;
578 z0 = z1; z1 += zStep;
579 r0 = r1; r1 -= rStep;
590 std::unique_ptr<Real []> sint;
591 std::unique_ptr<Real []> cost;
598 Real du=1.0f/_slices;
603 std::vector <vertData>
data;
617 for (
unsigned int j=0; j<=_slices; ++j)
636 Real iradius = _minorRadius, oradius = _majorRadius, phi, psi, dpsi, dphi;
638 Real spsi, cpsi, sphi, cphi ;
640 if ( _nSides < 1 ) { _nSides = 1; }
641 if ( _nRings < 1 ) { _nRings = 1; }
647 std::unique_ptr<Real []>vertex(
new Real[3 * _nSides * _nRings]);
648 std::unique_ptr<Real []>normal(
new Real[3 * _nSides * _nRings]);
649 std::unique_ptr<Real []>uv(
new Real[2*_nSides*_nRings*2]);
651 dpsi = 2.0f *
static_cast<Real>(M_PI) / (_nRings - 1) ;
652 dphi = -2.0f *
static_cast<Real>(M_PI) / (_nSides - 1) ;
654 Real uStep=1.0f/_nRings;
655 Real vStep=1.0f/_nSides;
659 for(
unsigned int j=0; j<_nRings; ++j )
661 cpsi = cosf ( psi ) ;
662 spsi = sinf ( psi ) ;
664 for(
unsigned int i=0; i<_nSides; ++i )
666 unsigned int offset = 3 * ( j * _nSides + i ) ;
669 vertex[
offset] = cpsi * ( oradius + cphi * iradius ) ;
670 vertex[offset+1] = spsi * ( oradius + cphi * iradius ) ;
671 vertex[offset+2] = sphi * iradius ;
672 normal[
offset] = cpsi * cphi ;
673 normal[offset+1] = spsi * cphi ;
674 normal[offset+2] = sphi ;
694 std::vector <vertData>
data;
696 for(
unsigned int i=0; i<_nSides-1; ++i )
698 for(
unsigned int j=0; j<_nRings-1; ++j )
700 unsigned int offset = 3 * ( j * _nSides + i ) ;
707 d.
ny=normal[offset+1];
708 d.
nz=normal[offset+2];
710 d.
y=vertex[offset+1];
711 d.
z=vertex[offset+2];
720 d.
nx=normal[offset+3];
721 d.
ny=normal[offset+4];
722 d.
nz=normal[offset+5];
723 d.
x=vertex[offset+3];
724 d.
y=vertex[offset+4];
725 d.
z=vertex[offset+5];
733 d.
u=uv[(offset+3*_nSides+3)];
734 d.
v=uv[(offset+3*_nSides+3)+1];
735 d.
nx=normal[(offset + 3 * _nSides + 3)];
736 d.
ny=normal[(offset + 3 * _nSides + 3)+1];
737 d.
nz=normal[(offset + 3 * _nSides + 3)+2];
738 d.
x=vertex[(offset + 3 * _nSides + 3)];
739 d.
y=vertex[(offset + 3 * _nSides + 3)+1];
740 d.
z=vertex[(offset + 3 * _nSides + 3)+2];
751 d.
ny=normal[offset+1];
752 d.
nz=normal[offset+2];
754 d.
y=vertex[offset+1];
755 d.
z=vertex[offset+2];
764 d.
u=uv[(offset+3*_nSides+3)];
765 d.
v=uv[(offset+3*_nSides+3)+1];
766 d.
nx=normal[(offset + 3 * _nSides + 3)];
767 d.
ny=normal[(offset + 3 * _nSides + 3)+1];
768 d.
nz=normal[(offset + 3 * _nSides + 3)+2];
769 d.
x=vertex[(offset + 3 * _nSides + 3)];
770 d.
y=vertex[(offset + 3 * _nSides + 3)+1];
771 d.
z=vertex[(offset + 3 * _nSides + 3)+2];
779 d.
u=uv[(offset+3*_nSides)];
780 d.
v=uv[(offset+3*_nSides)+1];
781 d.
nx=normal[ (offset + 3 * _nSides)];
782 d.
ny=normal[ (offset + 3 * _nSides)+1];
783 d.
nz=normal[ (offset + 3 * _nSides)+2];
784 d.
x=vertex[(offset + 3 * _nSides)];
785 d.
y=vertex[(offset + 3 * _nSides)+1];
786 d.
z=vertex[(offset + 3 * _nSides)+2];
807 Real wStep=_width/_wP;
808 Real dStep=_depth/_dP;
818 std::vector <vertData>
data;
821 for(
Real d=-d2; d<d2; d+=dStep)
823 for(
Real w=-w2;
w<w2;
w+=wStep)
840 vert.
u=u; vert.
v=v+dv; vert.
x=
w; vert.
z=d+dStep;
841 data.push_back(vert);
843 vert.
u=u+du; vert.
v=v+dv; vert.
x=
w+wStep; vert.
z=d+dStep;
844 data.push_back(vert);
846 vert.
u=u; vert.
v=
v; vert.
x=
w; vert.
z=d;
847 data.push_back(vert);
860 vert.
u=u+du; vert.
v=v+dv; vert.
x=
w+wStep; vert.
z=d+dStep;
861 data.push_back(vert);
863 vert.
u=u+du; vert.
v=
v; vert.
x=
w+wStep; vert.
z=d;
864 data.push_back(vert);
866 vert.
u=u; vert.
v=
v; vert.
x=
w; vert.
z=d;
867 data.push_back(vert);
882 std::cerr<<
"clearing VAOs\n";
890 v.second->removeVAO();
893 m_createdVAOs.erase(m_createdVAOs.begin(),m_createdVAOs.end());
void draw(const std::string &_name) noexcept
Draw one of the VBO's created via a name lookup.
some useful definitions and functions
void createVAO(const std::string &_name, const std::vector< vertData > &_data, const GLenum _mode) noexcept
the method to actually create the VAO from the various other methods Note this is used in conjunction...
void createDisk(const std::string &_name, Real _radius, unsigned int _slices) noexcept
create a trinagle fan disk (use as end caps for Cylinder etc)
AbstractVAO * getVAOFromName(const std::string &_name)
get the raw VAO so we can map it etc
void clear() noexcept
clear the VAO elements created (is also called by dtor) This is usefull if you don't want the default...
static AbstractVAO * createVAO(const std::string &_type, GLenum _mode=GL_TRIANGLES)
constexpr Real PI
pre-compute the value for value for PI based on system M_PI
void createLineGrid(const std::string &_name, Real _width, Real _depth, int _steps) noexcept
create a line based grid (like the maya ground plane)
constexpr Real PI2
pre-compute the value for value for PI/2.0
void createTorus(const std::string &_name, Real _minorRadius, Real _majorRadius, unsigned int _nSides, unsigned int _nRings, bool _flipTX=false) noexcept
create a VBO based torus from rings of quads.
GLfloat GLfloat GLfloat v2
void createCylinder(const std::string &_name, const Real _radius, Real _height, unsigned int _slices, unsigned int _stacks) noexcept
create a Quad Cylinder as a vbo with auto generated texture cords
void createDefaultVAOs() noexcept
create the default VAO's this is done by the ctor anyway but can be called if the clear method is cal...
void fghCircleTable(std::unique_ptr< Real[]> &io_sint, std::unique_ptr< Real[]> &io_cost, int _n) noexcept
create the elements of a circle this is borrowed from freeglut
GLint GLenum GLsizei GLint GLsizei const void * data
void createCone(const std::string &_name, Real _base, Real _height, unsigned int _slices, unsigned int _stacks) noexcept
create a Quad Cone as a vao with auto generated texture cords
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
std::unordered_map< std::string, AbstractVAO * > m_createdVAOs
a map to store the VAO by name
implementation files for RibExport class
void setVertexAttributePointer(GLuint _id, GLint _size, GLenum _type, GLsizei _stride, unsigned int _dataOffset, bool _normalise=false)
set the generic vertex attribute pointer data usually this method will do however the user may occasi...
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
base class for all VAO from the VAOFactory this defines the base class type with simple draw / bind b...
constexpr Real TWO_PI
pre-compute the value for value for 2*PI convert to float to suppress windows warning as well ...
GLubyte GLubyte GLubyte GLubyte w
void setNumIndices(size_t _s)
the number of indices to draw in the array. It may be that the draw routine can overide this at anoth...
void createTrianglePlane(const std::string &_name, const Real _width, const Real _depth, const int _wP, const int _dP, const Vec3 &_vN) noexcept
create a triangulated plane as a vbo with auto generated texture cords
void unbind()
unbind the VAO by binding default 0
void bind()
bind the VAO so it can be used.
virtual void setData(const VertexData &_data)=0
this method is used to set the data in the VAO, we have a base data type of VertexData above...
void createVAOFromHeader(const std::string &_name, Real const *_data, unsigned int _Size) noexcept
create a VAO from a static header file of data in the TNV format this will usually be created from th...
GLfloat GLfloat GLfloat GLfloat h
void createSphere(const std::string &_name, Real _radius, int _precision) noexcept
create a triangulated Sphere as a vbo with auto generated texture cords
VAOPrimitives() noexcept
default constructor
void createCapsule(const std::string &_name, const Real _radius=1.0f, const Real _height=2.0f, const int _precision=20) noexcept
create a triangulated capsule (Cylinder with spherical ends)
GLsizei const GLchar *const * string
#define GL_TRIANGLE_STRIP