Commit bec66d87 authored by Thomas Jund's avatar Thomas Jund

modif pour rendu

parent 91087979
......@@ -9,7 +9,7 @@
//#define SECURED
#define EXPORTING_AGENT
//#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#ifdef SECURED
......@@ -76,22 +76,23 @@ public:
#endif
#ifdef EXPORTING_OBJ
PFP2::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
// PFP2::MAP map;
// VertexAttribute<VEC3> position;
// VertexAttribute<VEC3> normal;
VEC3 previousPos;
float previousRot;
Geom::Matrix44f m_transfo;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
// Algo::Render::GL2::MapRender* m_render;
// Utils::VBO* m_positionVBO;
// Utils::VBO* m_normalVBO;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::VBO* m_texcoordVBO;
ShaderCustomTex* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
// Utils::Texture<2,Geom::Vec3uc>* m_texture;
// Utils::VBO* m_texcoordVBO;
// ShaderCustomTex* m_shaderTex;
// Algo::Surface::Import::OBJModel<PFP2> m_obj;
// unsigned int m_nbIndices;
#endif
#ifdef SPATIAL_HASHING
......
......@@ -13,10 +13,10 @@
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "shaderCustomTex.h"
#include "Algo/Import/importObjTex.h"
using namespace std;
//#define EXPORTING2
......
......@@ -8,7 +8,7 @@
#include <set>
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
//#define EXPORTING_BOXES
#define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
......
......@@ -7,6 +7,7 @@
#include "Utils/clippingShader.h"
#include "Utils/textures.h"
#include "Utils/gl_def.h"
#include "Geometry/matrix.h"
using namespace CGoGN;
......@@ -57,6 +58,8 @@ public:
unsigned int setAttributeTexCoord(Utils::VBO* vbo);
void setBaseColor(Geom::Vec4f col);
void setTransformation(Geom::Matrix44f t);
};
#endif
......@@ -2,12 +2,13 @@
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec2 VertexTexCoord;
uniform mat4 TransformationMatrix;
uniform mat4 ModelViewProjectionMatrix;
VARYING_VERT vec2 texCoord;
INVARIANT_POS;
void main ()
{
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
gl_Position = ModelViewProjectionMatrix * TransformationMatrix * vec4 (VertexPosition, 1.0);
texCoord = VertexTexCoord;
}
......@@ -116,6 +116,22 @@ public:
Utils::ShaderFlat* m_flatShader_scenary;
#endif
#ifdef EXPORTING_OBJ
PFP2::MAP mapAgent;
VertexAttribute<VEC3> positionAgent;
VertexAttribute<VEC3> normalAgent;
Algo::Render::GL2::MapRender* m_renderAgent;
Utils::VBO* m_positionVBOAgent;
Utils::VBO* m_normalVBOAgent;
Utils::Texture<2,Geom::Vec3uc>* m_textureAgent;
Utils::VBO* m_texcoordVBOAgent;
ShaderCustomTex* m_shaderTexAgent;
Algo::Surface::Import::OBJModel<PFP2> m_objAgent;
unsigned int m_nbIndicesAgent;
#endif
//agents
Utils::VBO* m_agentsVBO;
Utils::PointSprite* m_sprite;
......
This diff is collapsed.
......@@ -17,6 +17,7 @@ float Agent::averageMaxSpeed_ = 2.0f ;
// float Agent::neighborDist_ = 10.0f ;
float Agent::neighborDist_ = 20.0f ;
float Agent::neighborDistSq_ = neighborDist_ * neighborDist_ ;
//float Agent::radius_ = 8.0f ;
float Agent::radius_ = 1.5f ;
//float Agent::timeHorizon_ = 10.0f ;
float Agent::timeHorizon_ = 100.0f ;
......@@ -27,9 +28,9 @@ float Agent::rangeSq_ = range_ * range_ ;
unsigned int Agent::cptAgent = 0 ;
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) :
#ifdef EXPORTING_OBJ
m_obj(map),
#endif
//#ifdef EXPORTING_OBJ
// m_obj(map),
//#endif
#ifdef SPATIAL_HASHING
pos(position),
#else
......@@ -47,9 +48,9 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) :
}
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) :
#ifdef EXPORTING_OBJ
m_obj(map),
#endif
//#ifdef EXPORTING_OBJ
// m_obj(map),
//#endif
#ifdef SPATIAL_HASHING
pos(position),
#else
......@@ -68,11 +69,23 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) :
void Agent::init(const VEC3& start, const VEC3& goal)
{
#ifdef EXPORTING_OBJ
std::vector<std::string> attrNames ;
m_obj.import("./meshRessources/Mexicainlowres.obj",attrNames);
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
#endif
//#ifdef EXPORTING_OBJ
// std::vector<std::string> attrNames ;
// m_obj.import("./meshRessources/Mexicainlowres2.obj",attrNames);
//// m_obj.import("./meshRessources/Mexicainhighres.obj",attrNames);
// position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
//
//// Geom::BoundingBox<PFP::VEC3> bb ;
//// bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
//// std::cout << "bb agent " << bb << std::endl;
//
// TraversorV<PFP2::MAP> tV(map);
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
// position[d] /= 12.0f;
// position[d] *= radius_;
// }
//#endif
#ifdef SPATIAL_HASHING
sim->envMap_.addAgentInGrid(this) ;
......@@ -110,44 +123,45 @@ void Agent::initGL()
// registerShader(m_ghost_shader);
#endif
#ifdef EXPORTING_OBJ
m_texcoordVBO = new Utils::VBO();
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (m_texture->load("./meshRessources/sombrero2lowres_grp.png"))
m_texture->update();
else
std::cout << "problem : loading texture" << std::endl;
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
m_shaderTex = new ShaderCustomTex();
m_shaderTex->setAttributePosition(m_positionVBO);
m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
m_shaderTex->setTextureUnit(GL_TEXTURE0);
m_shaderTex->setTexture(m_texture);
glEnable(GL_TEXTURE_2D);
if (!m_obj.hasNormals())
{
normal = map.getAttribute<VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
m_obj.setNormalAttribute(normal);
}
map.setBrowser(NULL);
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
previousPos = VEC3(0,0,0);
#endif
//#ifdef EXPORTING_OBJ
// m_texcoordVBO = new Utils::VBO();
// m_positionVBO = new Utils::VBO();
// m_normalVBO = new Utils::VBO();
//
// m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
//
//// if (m_texture->load("./meshRessources/sombrero2lowres_grp.png"))
// if (m_texture->load("./meshRessources/sombrero2_grp.png"))
// m_texture->update();
// else
// std::cout << "problem : loading texture" << std::endl;
//
// m_texture->setWrapping(GL_CLAMP_TO_EDGE);
//
// m_shaderTex = new ShaderCustomTex();
// m_shaderTex->setAttributePosition(m_positionVBO);
// m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
// m_shaderTex->setTextureUnit(GL_TEXTURE0);
// m_shaderTex->setTexture(m_texture);
//
// glEnable(GL_TEXTURE_2D);
//
// if (!m_obj.hasNormals())
// {
// normal = map.getAttribute<VEC3, VERTEX>("normal") ;
// if(!normal.isValid())
// normal = map.addAttribute<VEC3, VERTEX>("normal") ;
//
// Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
// m_obj.setNormalAttribute(normal);
// }
//
// map.setBrowser(NULL);
//
// m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
//
// previousPos = VEC3(0,0,0);
//#endif
}
void Agent::draw()
......@@ -168,16 +182,17 @@ void Agent::draw()
m_ghost_shader->disableVertexAttribs();
#endif
#ifdef EXPORTING_OBJ
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_shaderTex->activeTexture();
m_shaderTex->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_shaderTex->disableVertexAttribs();
#endif
//#ifdef EXPORTING_OBJ
//// Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
// m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//
// m_shaderTex->setTransformation(m_transfo);
// m_shaderTex->activeTexture();
// m_shaderTex->enableVertexAttribs();
// glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
// m_shaderTex->disableVertexAttribs();
//#endif
}
......@@ -457,16 +472,22 @@ void Agent::update()
VEC3 axisRot = base ^ dir ;
int sign = axisRot[2] > 0 ? 1 : -1 ;
//57,2957795 : conversion from radian to degree
float myRot = acos(-dir[1])+M_PI;
float myRot = acos(-dir[1]);
const VEC3 displ = getPosition();
// TraversorV<PFP2::MAP> tV(map);
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
// position[d] += rotate(position[d], previousPos, -previousRot);
// position[d] = position[d]+displ;
// position[d] += rotate(position[d], getPosition(), myRot);
// }
m_transfo.identity();
Geom::rotateZ(myRot,m_transfo);
Geom::translate(displ[0],displ[1],displ[2],m_transfo);
m_transfo.transpose();
const VEC3 displ = -previousPos+getPosition();
TraversorV<PFP2::MAP> tV(map);
for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
{
position[d] += rotate(position[d], previousPos, -previousRot);
position[d] = position[d]+displ;
position[d] += rotate(position[d], getPosition(), myRot);
}
previousPos = getPosition();
previousRot = myRot;
......
......@@ -27,7 +27,8 @@ constrainedV(map)
float area = Algo::Surface::Geometry::convexFaceArea<PFP>(envMap.map, d, envMap.position);
scaleValue = std::max(area/1400.0f,10.0f);
std::cout << "scaleVal " << scaleValue << std::endl;
scale(scaleValue/1.8f);
// scale(scaleValue/1.8f);
scale(scaleValue);
// Geom::Matrix44f m;
// m.identity();
......
......@@ -134,7 +134,7 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, -5.0f) ;
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, -10.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
......
......@@ -75,6 +75,11 @@ m_col(1)
m_unif_unit = glGetUniformLocation(this->program_handler(), "textureUnit");
setBaseColor(m_col);
Geom::Matrix44f id;
id.identity();
setTransformation(id);
}
void ShaderCustomTex::setTextureUnit(GLenum texture_unit)
......@@ -101,6 +106,15 @@ void ShaderCustomTex::setBaseColor(Geom::Vec4f col)
unbind();
}
void ShaderCustomTex::setTransformation(Geom::Matrix44f t)
{
bind();
CGoGNGLuint m_transf;
*m_transf = glGetUniformLocation(program_handler(),"TransformationMatrix");
glUniformMatrix4fv(*m_transf, 1, false, &t(0,0));
unbind();
}
void ShaderCustomTex::activeTexture()
{
glActiveTexture(GL_TEXTURE0 + m_unit);
......
......@@ -590,8 +590,8 @@ void Simulator::setupScenario(unsigned int nbMaxAgent, bool pedWay)
TraversorF<PFP::MAP> tF(envMap_.map);
Dart d = tF.begin() ;
unsigned int nbx = 4 ;
unsigned int nby = 4 ;
unsigned int nbx = 1 ;
unsigned int nby = 1 ;
unsigned int bMax = nbx * nby > 0 ? nbMaxAgent / (nbx * nby) : nbMaxAgent ;
......@@ -616,7 +616,7 @@ void Simulator::setupScenario(unsigned int nbMaxAgent, bool pedWay)
if (found)
{
float ecart = 3.0f ;
float ecart = 2.0f*Agent::radius_;
VEC3 posinit = VEC3(pos[0] - (float(nbx) / 2.0f * ecart),
pos[1] - (float(nby) / 2.0f * ecart), pos[2]) ;
for (unsigned int curx = 0 ; curx < nbx ; ++curx)
......
......@@ -36,6 +36,9 @@ SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned i
frames(0),
nextUpdate(0),
simulator(config, minSize, nbAgent, nbObst),
#ifdef EXPORTING_OBJ
m_objAgent(mapAgent),
#endif
render_anim(false),
drawEnvLines(false),
drawEnvFaces(true),
......@@ -115,7 +118,7 @@ void SocialAgents::cb_initGL()
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ)/5.0f ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ)/10.0f ;
setParamObject(gWidthObj, gPosObj.data()) ;
// choose to use GL version 2
......@@ -325,14 +328,70 @@ void SocialAgents::initRendering()
registerShader(simulator.envMap_.m_shaderTex_Export[j]);
#endif
#if defined(EXPORTING_AGENT) || defined(EXPORTING_OBJ)
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
simulator.agents_[i]->initGL();
#ifdef EXPORTING_OBJ
registerShader(simulator.agents_[i]->m_shaderTex);
std::vector<std::string> attrNames ;
m_objAgent.import("./meshRessources/Mexicainlowres2.obj",attrNames);
// m_objAgent.import("./meshRessources/Mexicainhighres.obj",attrNames);
positionAgent = mapAgent.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
// Geom::BoundingBox<PFP::VEC3> bb ;
// bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
// std::cout << "bb agent " << bb << std::endl;
TraversorV<PFP2::MAP> tV(mapAgent);
for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
{
positionAgent[d] /= 12.0f;
positionAgent[d] *= Agent::radius_;
}
m_texcoordVBOAgent = new Utils::VBO();
m_positionVBOAgent = new Utils::VBO();
m_normalVBOAgent = new Utils::VBO();
m_textureAgent = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
// if (m_textureAgent->load("./meshRessources/sombrero2lowres_grp.png"))
if (m_textureAgent->load("./meshRessources/sombrero2_grp.png"))
m_textureAgent->update();
else
std::cout << "problem : loading texture" << std::endl;
m_textureAgent->setWrapping(GL_CLAMP_TO_EDGE);
m_shaderTexAgent = new ShaderCustomTex();
m_shaderTexAgent->setAttributePosition(m_positionVBOAgent);
m_shaderTexAgent->setAttributeTexCoord(m_texcoordVBOAgent);
m_shaderTexAgent->setTextureUnit(GL_TEXTURE0);
m_shaderTexAgent->setTexture(m_textureAgent);
glEnable(GL_TEXTURE_2D);
if (!m_objAgent.hasNormals())
{
normalAgent = mapAgent.getAttribute<VEC3, VERTEX>("normal") ;
if(!normalAgent.isValid())
normalAgent = mapAgent.addAttribute<VEC3, VERTEX>("normal") ;
Algo::Surface::Geometry::computeNormalVertices<PFP2>(mapAgent, m_objAgent.m_positions, normalAgent) ;
m_objAgent.setNormalAttribute(normalAgent);
}
mapAgent.setBrowser(NULL);
m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);
registerShader(m_shaderTexAgent);
#endif
#if EXPORTING_AGENT
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
// simulator.agents_[i]->initGL();
//
//#ifdef EXPORTING_OBJ
// registerShader(simulator.agents_[i]->m_shaderTex);
//#endif
#ifdef EXPORTING_AGENT
registerShader(simulator.agents_[i]->m_ghost_shader);
#endif
......@@ -560,21 +619,35 @@ void SocialAgents::cb_redraw()
if (drawAgents)
{
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
VEC3 p = simulator.agents_[i]->getPosition();
data[i] = p;
}
m_agentsVBO->releasePtr();
#ifdef EXPORTING_OBJ
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_shaderTexAgent->setTransformation(simulator.agents_[i]->m_transfo);
m_shaderTexAgent->activeTexture();
m_shaderTexAgent->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndicesAgent);
m_shaderTexAgent->disableVertexAttribs();
}
#else
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
VEC3 p = simulator.agents_[i]->getPosition();
data[i] = p;
}
m_agentsVBO->releasePtr();
m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
m_sprite->enableVertexAttribs();
glDrawArrays(GL_POINTS, 0, simulator.agents_.size());
m_sprite->disableVertexAttribs();
m_sprite->postdraw();
m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
m_sprite->enableVertexAttribs();
glDrawArrays(GL_POINTS, 0, simulator.agents_.size());
m_sprite->disableVertexAttribs();
m_sprite->postdraw();
#endif
#if defined(EXPORTING_AGENT) || defined(EXPORTING_OBJ)
#ifdef EXPORTING_AGENT
for (unsigned int i=0; i< simulator.agents_.size(); ++i)
{
simulator.agents_[i]->draw();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment