[DEV] add some cone, sphere, capsule and cylinder at the 3d object element
This commit is contained in:
parent
dbe62ed3d5
commit
1ac5daa456
@ -53,7 +53,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
// set Matrix: translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
@ -62,10 +62,10 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, &_vertices[0], 4*sizeof(float));
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
// Request the draw od the elements:
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
// Request the draw od the elements :
|
||||
// Request the draw od the elements:
|
||||
//glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
//m_GLprogram->UnUse();
|
||||
if (true == _depthtest) {
|
||||
@ -96,7 +96,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
// set Matrix: translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
@ -105,7 +105,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z*/, &_vertices[0], 4*sizeof(float));
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
// Request the draw od the elements:
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
if (true == _depthtest) {
|
||||
@ -136,7 +136,7 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
// set Matrix: translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix;
|
||||
@ -145,7 +145,7 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z*/, &_vertices[0], 4*sizeof(float));
|
||||
// color :
|
||||
m_GLprogram->uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&_color);
|
||||
// Request the draw od the elements :
|
||||
// Request the draw od the elements:
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::line, 0, _vertices.size());
|
||||
m_GLprogram->unUse();
|
||||
if (true == _depthtest) {
|
||||
@ -156,52 +156,9 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::Colored3DObject::drawSphere(float _radius,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
int i, j;
|
||||
std::vector<vec3> EwolVertices;
|
||||
for(i = 0; i <= _lats; i++) {
|
||||
btScalar lat0 = M_PI * (-0.5f + float(i - 1) / _lats);
|
||||
btScalar z0 = _radius*sin(lat0);
|
||||
btScalar zr0 = _radius*cos(lat0);
|
||||
|
||||
btScalar lat1 = M_PI * (-0.5f + float(i) / _lats);
|
||||
btScalar z1 = _radius*sin(lat1);
|
||||
btScalar zr1 = _radius*cos(lat1);
|
||||
|
||||
//glBegin(GL_QUAD_STRIP);
|
||||
for(j = 0; j < _longs; j++) {
|
||||
btScalar lng = 2.0f * M_PI * float(j - 1) / _longs;
|
||||
btScalar x = cos(lng);
|
||||
btScalar y = sin(lng);
|
||||
vec3 v1 = vec3(x * zr1, y * zr1, z1);
|
||||
vec3 v4 = vec3(x * zr0, y * zr0, z0);
|
||||
|
||||
lng = 2 * M_PI * float(j) / _longs;
|
||||
x = cos(lng);
|
||||
y = sin(lng);
|
||||
vec3 v2 = vec3(x * zr1, y * zr1, z1);
|
||||
vec3 v3 = vec3(x * zr0, y * zr0, z0);
|
||||
|
||||
EwolVertices.push_back(v1);
|
||||
EwolVertices.push_back(v2);
|
||||
EwolVertices.push_back(v3);
|
||||
|
||||
EwolVertices.push_back(v1);
|
||||
EwolVertices.push_back(v3);
|
||||
EwolVertices.push_back(v4);
|
||||
}
|
||||
}
|
||||
draw(EwolVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
void ewol::resource::Colored3DObject::drawSquare(const vec3& _size,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor){
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
std::vector<vec3> tmpVertices;
|
||||
static int indices[36] = { 0,1,2, 3,2,1, 4,0,6,
|
||||
6,0,2, 5,1,4, 4,1,0,
|
||||
@ -226,6 +183,265 @@ void ewol::resource::Colored3DObject::drawSquare(const vec3& _size,
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
void ewol::resource::Colored3DObject::drawSphere(float _radius,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
std::vector<vec3> tmpVertices;
|
||||
for(int32_t iii=0; iii<=_lats; ++iii) {
|
||||
float lat0 = M_PI * (-0.5f + float(iii - 1) / _lats);
|
||||
float y0 = _radius*sin(lat0);
|
||||
float yr0 = _radius*cos(lat0);
|
||||
|
||||
float lat1 = M_PI * (-0.5f + float(iii) / _lats);
|
||||
float y1 = _radius*sin(lat1);
|
||||
float yr1 = _radius*cos(lat1);
|
||||
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
float x = cos(lng);
|
||||
float z = sin(lng);
|
||||
vec3 v1 = vec3(x * yr1, y1, z * yr1);
|
||||
vec3 v4 = vec3(x * yr0, y0, z * yr0);
|
||||
|
||||
lng = 2 * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng);
|
||||
z = sin(lng);
|
||||
vec3 v2 = vec3(x * yr1, y1, z * yr1);
|
||||
vec3 v3 = vec3(x * yr0, y0, z * yr0);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v4);
|
||||
}
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
void ewol::resource::Colored3DObject::drawCylinder(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
std::vector<vec3> tmpVertices;
|
||||
// center to border (TOP)
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
|
||||
float y = _size*0.5f;
|
||||
vec3 v1 = vec3(0.0f, y, 0.0f);
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, y, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, y, z);
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v2);
|
||||
}
|
||||
// Cylinder
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
|
||||
float y = _size*0.5f;
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, y, z);
|
||||
vec3 v2b = vec3(x, -y, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, y, z);
|
||||
vec3 v3b = vec3(x, -y, z);
|
||||
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v3b);
|
||||
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3b);
|
||||
tmpVertices.push_back(v2b);
|
||||
}
|
||||
|
||||
// center to border (BUTTOM)
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
|
||||
float y = _size*-0.5f;
|
||||
vec3 v1 = vec3(0.0f, y, 0.0f);
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, y, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, y, z);
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
void ewol::resource::Colored3DObject::drawCapsule(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
std::vector<vec3> tmpVertices;
|
||||
_lats = int32_t(_lats / 2)*2;
|
||||
// center to border (TOP)
|
||||
float offset = _size*0.5f;
|
||||
for(int32_t iii=_lats/2+1; iii<=_lats; ++iii) {
|
||||
float lat0 = M_PI * (-0.5f + float(iii - 1) / _lats);
|
||||
float y0 = _radius*sin(lat0);
|
||||
float yr0 = _radius*cos(lat0);
|
||||
|
||||
float lat1 = M_PI * (-0.5f + float(iii) / _lats);
|
||||
float y1 = _radius*sin(lat1);
|
||||
float yr1 = _radius*cos(lat1);
|
||||
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
float x = cos(lng);
|
||||
float z = sin(lng);
|
||||
vec3 v1 = vec3(x * yr1, y1+offset, z * yr1);
|
||||
vec3 v4 = vec3(x * yr0, y0+offset, z * yr0);
|
||||
|
||||
lng = 2 * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng);
|
||||
z = sin(lng);
|
||||
vec3 v2 = vec3(x * yr1, y1+offset, z * yr1);
|
||||
vec3 v3 = vec3(x * yr0, y0+offset, z * yr0);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v4);
|
||||
}
|
||||
}
|
||||
// Cylinder
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
|
||||
float y = _size*0.5f;
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, y, z);
|
||||
vec3 v2b = vec3(x, -y, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, y, z);
|
||||
vec3 v3b = vec3(x, -y, z);
|
||||
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v3b);
|
||||
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3b);
|
||||
tmpVertices.push_back(v2b);
|
||||
}
|
||||
offset = -_size*0.5f;
|
||||
for(int32_t iii=0; iii<=_lats/2; ++iii) {
|
||||
float lat0 = M_PI * (-0.5f + float(iii - 1) / _lats);
|
||||
float y0 = _radius*sin(lat0);
|
||||
float yr0 = _radius*cos(lat0);
|
||||
|
||||
float lat1 = M_PI * (-0.5f + float(iii) / _lats);
|
||||
float y1 = _radius*sin(lat1);
|
||||
float yr1 = _radius*cos(lat1);
|
||||
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
float x = cos(lng);
|
||||
float z = sin(lng);
|
||||
vec3 v1 = vec3(x * yr1, y1+offset, z * yr1);
|
||||
vec3 v4 = vec3(x * yr0, y0+offset, z * yr0);
|
||||
|
||||
lng = 2 * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng);
|
||||
z = sin(lng);
|
||||
vec3 v2 = vec3(x * yr1, y1+offset, z * yr1);
|
||||
vec3 v3 = vec3(x * yr0, y0+offset, z * yr0);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v4);
|
||||
}
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
void ewol::resource::Colored3DObject::drawCone(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor) {
|
||||
std::vector<vec3> tmpVertices;
|
||||
// center to border (TOP)
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
vec3 v1 = vec3(0.0f, _size/2, 0.0f);
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, -_size/2, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, -_size/2, z);
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v3);
|
||||
tmpVertices.push_back(v2);
|
||||
}
|
||||
// center to border (BUTTOM)
|
||||
for(int32_t jjj=0; jjj<_longs; ++jjj) {
|
||||
float lng = 2.0f * M_PI * float(jjj - 1) / _longs;
|
||||
|
||||
vec3 v1 = vec3(0.0f, -_size/2, 0.0f);
|
||||
|
||||
float x = cos(lng)*_radius;
|
||||
float z = sin(lng)*_radius;
|
||||
vec3 v2 = vec3(x, -_size/2, z);
|
||||
|
||||
lng = 2.0f * M_PI * float(jjj) / _longs;
|
||||
x = cos(lng)*_radius;
|
||||
z = sin(lng)*_radius;
|
||||
vec3 v3 = vec3(x, -_size/2, z);
|
||||
tmpVertices.push_back(v1);
|
||||
tmpVertices.push_back(v2);
|
||||
tmpVertices.push_back(v3);
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string(ewol::resource::Colored3DObject const&) {
|
||||
return "!!ewol::resource::Colored3DObject!ERROR!CAN_NOT_BE_CONVERT!!";
|
||||
|
@ -45,14 +45,32 @@ namespace ewol {
|
||||
bool _updateDepthBuffer=true,
|
||||
bool _depthtest=true);
|
||||
public:
|
||||
void drawSquare(const vec3& _size,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
void drawSphere(float _radius,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
void drawSquare(const vec3& _size, // halph size
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
void drawCylinder(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
void drawCapsule(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
void drawCone(float _radius,
|
||||
float _size,
|
||||
int _lats,
|
||||
int _longs,
|
||||
mat4& _transformationMatrix,
|
||||
const etk::Color<float>& _tmpColor);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user