[DEV] add sphere in usable shape

This commit is contained in:
Edouard DUPIN 2017-05-22 21:44:21 +02:00
parent c25f125dee
commit 3f22081ced
7 changed files with 152 additions and 16 deletions

View File

@ -176,6 +176,18 @@ void ege::physics::Component::generate() {
EGE_ERROR(" Sphere ==> can not cast in Sphere");
continue;
}
// Create the box shape
rp3d::SphereShape* shape = new rp3d::SphereShape(tmpElement->getRadius());
rp3d::Vector3 position(it->getOrigin().x(),
it->getOrigin().y(),
it->getOrigin().z());
rp3d::Quaternion orientation(it->getQuaternion().x(),
it->getQuaternion().y(),
it->getQuaternion().z(),
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
m_listProxyShape.push_back(proxyShape);
/*
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
if (tmpShape != nullptr) {
@ -404,18 +416,12 @@ void ege::physics::Component::drawShape(ememory::SharedPtr<ewol::resource::Color
EGE_ERROR(" Sphere ==> can not cast in Sphere");
continue;
}
/*
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
if (tmpShape != nullptr) {
if (outputShape == nullptr) {
return tmpShape;
} else {
vec4 qqq = tmpElement->getQuaternion();
const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin());
outputShape->addChildShape(localTransform, tmpShape);
}
}
*/
etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation());
transformLocal.getOpenGLMatrix(mmm);
mat4 transformationMatrixLocal(mmm);
transformationMatrixLocal.transpose();
transformationMatrixLocal = transformationMatrix * transformationMatrixLocal;
_draw->drawSphere(tmpElement->getRadius(), 10, 10, transformationMatrixLocal, tmpColor);
break;
}
case ege::PhysicsShape::convexHull : {

View File

@ -37,6 +37,14 @@ namespace ege {
static ememory::SharedPtr<ege::resource::Mesh> createCube(float _size=1.0f,
const std::string& _materialName="basics",
const etk::Color<float>& _color=etk::color::green);
static ememory::SharedPtr<ege::resource::Mesh> createSphere(float _size=1.0f,
const std::string& _materialName="basics",
const etk::Color<float>& _color=etk::color::green,
int32_t _lats = 10,
int32_t _longs = 10);
static ememory::SharedPtr<ege::resource::Mesh> createCylinder(float _size=1.0f,
const std::string& _materialName="basics",
const etk::Color<float>& _color=etk::color::green);
public:
/**
* @not_in_doc

View File

@ -8,7 +8,7 @@
#include <ege/resource/Mesh.hpp>
ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createCube(float _size, const std::string& _materialName, const etk::Color<float>& _color) {
EGE_ERROR(" create a cube _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
EGE_VERBOSE(" create a cube _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:color3.prog");
if (out != nullptr) {
ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();

View File

@ -0,0 +1,39 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ege/debug.hpp>
#include <ege/resource/Mesh.hpp>
ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createCylinder(float _size, const std::string& _materialName, const etk::Color<float>& _color) {
EGE_VERBOSE(" create a cube _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:color3.prog");
if (out != nullptr) {
ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
// set the element material properties :
material->setAmbientFactor(vec4(1,1,1,1));
material->setDiffuseFactor(vec4(0,0,0,1));
material->setSpecularFactor(vec4(0,0,0,1));
material->setShininess(1);
material->setRenderMode(gale::openGL::renderMode::triangle);
out->addMaterial(_materialName, material);
out->addFaceIndexing(_materialName);
out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1, 1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1,-1,-1)*_size, _color);
out->addQuad(_materialName, vec3(-1, 1, 1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, _color);
out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3(-1, 1,-1)*_size, _color);
out->addQuad(_materialName, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1, 1, 1)*_size, _color);
out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1,-1,-1)*_size, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, _color);
out->addQuad(_materialName, vec3(-1, 1,-1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color);
out->setNormalMode(ege::resource::Mesh::normalMode::face);
out->calculateNormaleFace(_materialName);
// generate the VBO
out->generateVBO();
} else {
EGE_ERROR("can not create the basic mesh interface");
}
return out;
}

View File

@ -0,0 +1,59 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ege/debug.hpp>
#include <ege/resource/Mesh.hpp>
ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createSphere(float _radius, const std::string& _materialName, const etk::Color<float>& _color, int32_t _lats, int32_t _longs) {
EGE_VERBOSE(" create a sphere _size=" << _radius << " _materialName=" << _materialName << " _color=" << _color);
ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:color3.prog");
if (out != nullptr) {
ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
// set the element material properties :
material->setAmbientFactor(vec4(1,1,1,1));
material->setDiffuseFactor(vec4(0,0,0,1));
material->setSpecularFactor(vec4(0,0,0,1));
material->setShininess(1);
material->setRenderMode(gale::openGL::renderMode::triangle);
out->addMaterial(_materialName, material);
out->addFaceIndexing(_materialName);
for(int32_t iii=0; iii<=_lats; ++iii) {
float lat0 = M_PI * (-0.5f + float(iii - 1) / _lats);
float z0 = _radius*sin(lat0);
float zr0 = _radius*cos(lat0);
float lat1 = M_PI * (-0.5f + float(iii) / _lats);
float z1 = _radius*sin(lat1);
float zr1 = _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 y = sin(lng);
vec3 v1 = vec3(x * zr1, y * zr1, z1);
vec3 v4 = vec3(x * zr0, y * zr0, z0);
lng = 2 * M_PI * float(jjj) / _longs;
x = cos(lng);
y = sin(lng);
vec3 v2 = vec3(x * zr1, y * zr1, z1);
vec3 v3 = vec3(x * zr0, y * zr0, z0);
out->addTriangle(_materialName, v1, v3, v2, _color);
out->addTriangle(_materialName, v1, v4, v3, _color);
}
}
out->setNormalMode(ege::resource::Mesh::normalMode::face);
out->calculateNormaleFace(_materialName);
// generate the VBO
out->generateVBO();
} else {
EGE_ERROR("can not create the basic mesh interface");
}
return out;
}

View File

@ -52,6 +52,8 @@ def configure(target, my_module):
'ege/resource/MeshEmf.cpp',
'ege/resource/MeshGird.cpp',
'ege/resource/MeshCube.cpp',
'ege/resource/MeshSphere.cpp',
'ege/resource/MeshCylinder.cpp',
'ege/resource/MeshObj.cpp',
'ege/resource/ParticuleMesh.cpp',
'ege/resource/tools/icoSphere.cpp',

View File

@ -137,7 +137,7 @@ void appl::Windows::init() {
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
physic->setSize(vec3(3.2,3.2,3.2));
physic->setSize(vec3(3.01,3.01,3.01));
physic->setMass(300000);
componentPhysics->addShape(physic);
componentPhysics->generate();
@ -159,7 +159,7 @@ void appl::Windows::init() {
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
physic->setSize(vec3(3.2,3.2,3.2));
physic->setSize(vec3(3.01,3.01,3.01));
physic->setMass(50000);
componentPhysics->addShape(physic);
componentPhysics->generate();
@ -167,6 +167,28 @@ void appl::Windows::init() {
// add it ..
m_env->addElement(element);
}
myMesh = ege::resource::Mesh::createSphere(4, "basics", etk::color::blue);
if (myMesh != nullptr) {
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(m_env);
// add all component:
// 1st Position component:
etk::Transform3D transform(vec3(-20,10,10), etk::Quaternion::identity());
//ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
//element->addComponent(componentPosition);
// 2nd something to diplay:
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
element->addComponent(componentRender);
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::PhysicsSphere> physic = ememory::makeShared<ege::PhysicsSphere>();
physic->setRadius(4.01);
physic->setMass(500000);
componentPhysics->addShape(physic);
componentPhysics->generate();
element->addComponent(componentPhysics);
// add it ..
m_env->addElement(element);
}
m_env->propertyStatus.set(ege::gameStart);
}
/*
@ -207,7 +229,7 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
physic->setSize(vec3(1.1,1.1,1.1));
physic->setSize(vec3(1.01,1.01,1.01));
physic->setMass(1000);
componentPhysics->setType(ege::physics::Component::type::bodyDynamic);
componentPhysics->addShape(physic);