Commit 8bd8a582 authored by pitiot's avatar pitiot

merging

parents c20f9b48 56ab7f86
......@@ -45,6 +45,7 @@ add_executable( socialAgentsD
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
../src/shaderPhongTexCust.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -46,6 +46,7 @@ add_executable( socialAgents
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
../src/shaderPhongTexCust.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -8,11 +8,16 @@
#include "spatialHashing.h"
//#define SECURED
#define SECURED
//#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#define ARASH
#define SMOOTHING_BUFFER_SIZE 200
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
#else
......@@ -156,7 +161,7 @@ public:
VEC3 velocity_ ;
VEC3 newVelocity_ ;
VEC3 prefVelocity_ ;
VEC3 meanVelocity_[4] ;
VEC3 meanVelocity_[SMOOTHING_BUFFER_SIZE] ;
VEC3 meanDirection_ ;
Simulator* sim_;
......
......@@ -33,8 +33,10 @@ class ArticulatedObstacle;
#include "pfp.h"
#define EXPORTING3
#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
......
......@@ -18,7 +18,7 @@
using namespace std;
//#define EXPORTING2
#define EXPORTING2
float get_angle3D(VEC3 v1, VEC3 v2);
......@@ -59,8 +59,8 @@ public:
Utils::VBO* m_texcoordVBO;
ShaderCustomTex* m_shaderTex;
// Utils::ShaderPhongTexture* m_shaderTex;
// ShaderCustomTex* m_shaderTex;
Utils::ShaderPhongTexture* m_shaderTex;
// Utils::ShaderSimpleTexture* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
......
......@@ -14,7 +14,7 @@
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#endif
#define EXPORTING_BOXES
// #define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
......
// ShaderPhongTexCust::fragmentShaderText
PRECISON;
VARYING_FRAG vec3 EyeVector, Normal, LightDir;
VARYING_FRAG vec2 texCoord;
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform float ambientCoef;
uniform float shininess;
uniform sampler2D textureUnit;
FRAG_OUT_DEF;
void main()
{
vec3 N = normalize (Normal);
vec3 L = normalize (LightDir);
float lambertTerm = dot(N,L);
vec4 finalColor = ambientCoef * texture2D(textureUnit,texCoord);
#ifdef DOUBLE_SIDED
if (lambertTerm < 0.0)
{
N = -1.0*N;
lambertTerm = -1.0*lambertTerm;
#else
if (lambertTerm > 0.0)
{
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
vec3 diffuse = (1.0 - ambientCoef) * texture2D(textureUnit,texCoord).rgb;
finalColor += vec4(diffuse*lambertTerm,0.0) + materialSpecular*specular;
}
gl_FragColor=finalColor;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef SHADER_PHONG_TEXTURE__CUST
#define SHADER_PHONG_TEXTURE__CUST
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/textures.h"
#include "Utils/gl_def.h"
#include "Geometry/matrix.h"
using namespace CGoGN;
class ShaderPhongTexCust : public Utils::ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
CGoGNGLuint m_unif_unit;
int m_unit;
Utils::GTexture* m_tex_ptr;
// flag color per vertex or not
bool m_with_eyepos;
// uniform locations
CGoGNGLuint m_unif_ambient;
CGoGNGLuint m_unif_specular;
CGoGNGLuint m_unif_shininess;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
//values
float m_ambient;
Geom::Vec4f m_specular;
float m_shininess;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboNormal;
Utils::VBO* m_vboTexCoord;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderPhongTexCust(bool doubleSided = false, bool withEyePosition=false);
/**
* choose the texture unit engine to use for this texture
*/
void setTextureUnit(GLenum texture_unit);
/**
* set the texture to use
*/
void setTexture(Utils::GTexture* tex);
/**
* activation of texture unit with set texture
*/
void activeTexture();
/**
* activation of texture unit with texture id
*/
void activeTexture(CGoGNGLuint texId);
// inviduals parameter setting functions
void setAmbient(float ambient);
void setSpecular(const Geom::Vec4f& specular);
void setShininess(float shininess);
void setLightPosition(const Geom::Vec3f& lp);
/// set eye position for VR environement
void setEyePosition(const Geom::Vec3f& ep);
float getAmbiant() const { return m_ambient; }
const Geom::Vec4f& getSpecular() const { return m_specular; }
float getShininess() const { return m_shininess; }
const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
/**
* set all parameter in on call (one bind also)
*/
void setParams(float ambient, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos);
unsigned int setAttributePosition(Utils::VBO* vbo);
unsigned int setAttributeNormal(Utils::VBO* vbo);
unsigned int setAttributeTexCoord(Utils::VBO* vbo);
void setTransformation(Geom::Matrix44f t);
};
#endif /* SHADER_PHONG_TEXTURE__CUST */
// ShaderPhongTexCust::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexNormal;
ATTRIBUTE vec2 VertexTexCoord;
uniform mat4 TransformationMatrix;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 NormalMatrix;
uniform vec3 lightPosition;
VARYING_VERT vec3 EyeVector, Normal, LightDir;
VARYING_VERT vec2 texCoord;
#ifdef WITH_EYEPOSITION
uniform vec3 eyePosition;
#endif
INVARIANT_POS;
void main ()
{
Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * TransformationMatrix *vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
texCoord = VertexTexCoord;
gl_Position = ModelViewProjectionMatrix * TransformationMatrix *vec4 (VertexPosition, 1.0);
}
......@@ -54,10 +54,11 @@
#include "Utils/pointSprite.h"
#include "shaderCustom.h"
#include "shaderPhongTexCust.h"
//#define EXPORTING
//#define ONERING
#define SHADOWSHELL
//#define SHADOWSHELL
using namespace CGoGN ;
......@@ -133,7 +134,8 @@ public:
Utils::Texture<2,Geom::Vec3uc>* m_textureAgent;
Utils::VBO* m_texcoordVBOAgent;
ShaderCustomTex* m_shaderTexAgent;
// ShaderCustomTex* m_shaderTexAgent;
ShaderPhongTexCust* m_shaderTexAgent;
Algo::Surface::Import::OBJModel<PFP2> m_objAgent;
unsigned int m_nbIndicesAgent;
#endif
......@@ -173,7 +175,9 @@ public:
// ARASH : camera input file
std::ifstream cam_input_file;
bool cif_exists;
unsigned int cif_begin, cif_end;
VEC3 *cif_lookfrom;
VEC3 *cif_lookat;
VEC3 *cif_upvector;
......
......@@ -21,12 +21,12 @@ float Agent::averageMaxSpeed_ = 2.0f ;
//float Agent::neighborDist_ = 20.0f ;
float Agent::neighborDistSq_ = neighborDist_ * neighborDist_ ;
//float Agent::radius_ = 8.0f ;
//float Agent::radius_ = 3.0f ;
float Agent::radius_ = 1.5f ;
float Agent::radius_ = 3.0f ;
// float Agent::radius_ = 1.5f ;
float Agent::timeHorizon_ = 10.0f ;
//float Agent::timeHorizon_ = 100.0f ;
float Agent::timeHorizonObst_ = 10.0f ;
float Agent::range_ = 2*timeHorizonObst_ * averageMaxSpeed_ + radius_ ;
float Agent::range_ = 4*timeHorizonObst_ * averageMaxSpeed_ + radius_ ;
float Agent::rangeSq_ = range_ * range_ ;
unsigned int Agent::cptAgent = 0 ;
......@@ -123,7 +123,7 @@ void Agent::init(const VEC3& start, const VEC3& goal)
// color1=0;
// color2 = 1.0f;
// }
for (unsigned int i=0 ; i<4 ; ++i)
for (unsigned int i=0 ; i<SMOOTHING_BUFFER_SIZE ; ++i)
meanVelocity_[i].set(0) ;
agentNeighbors_.reserve(maxNeighbors_ * 2) ;
......@@ -506,11 +506,11 @@ void Agent::update()
#endif
meanDirection_.set(0) ;
for (unsigned int i=0 ; i<4 ; ++i) {
for (unsigned int i=0 ; i<SMOOTHING_BUFFER_SIZE ; ++i) {
meanDirection_ += meanVelocity_[i] ;
meanVelocity_[i] = meanVelocity_[(i+1)%4] ;
meanVelocity_[i] = meanVelocity_[(i+1)%SMOOTHING_BUFFER_SIZE] ;
}
meanVelocity_[3] = velocity_ ;
meanVelocity_[SMOOTHING_BUFFER_SIZE-1] = velocity_ ;
meanDirection_.normalize() ;
}
......@@ -751,7 +751,7 @@ void Agent::computeNewVelocity()
VEC3 normFace = VEC3 (0,0,1);
#endif
double collision_softening_factor;
float ag_ambient_damping = 10.0;
float ag_ambient_damping = 50.0;
// double mass_var = 0.95;
// double average_mass = 1.0;
......@@ -765,7 +765,7 @@ void Agent::computeNewVelocity()
double rand = 2.0*drand48()-1.0; // compris entre -1 et 1
// double ag_mass = average_mass*(1 + rand*mass_var); // valeurs uniformement réparties entre min et max
double ag_mass = 50.0;
double ag_mass = 200.0;
/*
rand = 2.0*drand48()-1.0; // compris entre -1 et 1
radius_ = average_radius + rand*radius_var; // valeurs uniformement réparties entre min et max
......@@ -805,7 +805,7 @@ void Agent::computeNewVelocity()
obst_radius_infl = 100.; // scenario 0
else
obst_radius_infl = 40.; // scenario 1 et 3
float force_value;
float force_value=0.0;
int nobst=0;
......@@ -881,13 +881,14 @@ void Agent::computeNewVelocity()
// double fixed_obst_stiffness = 50000.0; // agent-obstacle interaction stiffness
double fixed_obst_stiffness = 5000.0; // agent-obstacle interaction stiffness
// double fixed_obst_damping = 1.0; // agent-obstacle interaction damping
int fixed_obst_power = 1; // the power to which elevate the agent-obstacle distance
int fixed_obst_power = 4.0; // the power to which elevate the agent-obstacle distance
Obstacle* fixed_obst ;
for(std::vector<std::pair<float, Obstacle*> >::iterator it = obstacleNeighbors_.begin() ;
it != obstacleNeighbors_.end() ;
++it)
{
double dist = it->first;
// cerr << "nobst=" << nobst << "dist=" << dist << endl;
// double effective_range = 50*range_;
......@@ -900,29 +901,33 @@ void Agent::computeNewVelocity()
}
fixed_obst=it->second ;
if(fixed_obst->mo!=NULL)
cerr << "Collision avec limace !!!" << endl;
VEC3 p1=fixed_obst->p1 ;
VEC3 p2=fixed_obst->p2 ;
vec=p2-p1;
vec.normalize();
norm= normFace ^vec;
forces -= force_value * norm;
// cerr << "obstacles fixes : nobst=" << nobst << " dist=" << dist << " force=" << force_value*norm << endl;
nobst++;
}
//----- forces dues à la répulsion des autres agents -------
double ag_stiffness = 400.0; // agent-agent interaction stiffness
double ag_damping = 1.0; // agent-agent interaction damping
// double ag_power = 1; // the power to which elevate the agent-agent distance
double ag_power = 4.0; // the power to which elevate the agent-agent distance
rand = 2.0*drand48()-1.0; // compris entre -1 et 1
double radius_var = 0.5;
double ag_phys_radius_coef = 2.0*(1 + rand*radius_var); // valeurs uniformement réparties entre min et max
unsigned int nbA = 0 ;
for (std::vector<std::pair<float, Agent*> >::iterator it = agentNeighbors_.begin() ;
......@@ -950,8 +955,7 @@ void Agent::computeNewVelocity()
if(dist < combinedRadius)
{
// collision_softening_factor = pow(1-dist/combinedRadius,ag_power);
collision_softening_factor = 1;
collision_softening_factor = pow(1-dist/combinedRadius,ag_power);
float force_value = - ag_stiffness*collision_softening_factor*(combinedRadius-dist)
- ag_damping * (dist - previous_dist) / sim_->timeStep_;
......
......@@ -262,6 +262,7 @@ void EnvMap::initGL()
std::vector<std::string> texturenames;
std::string dir("./meshRessources/PlaneteRessource/");
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
......@@ -314,6 +315,7 @@ void EnvMap::initGL()
position_nmap.push_back(position_Export);
TraversorV<PFP2::MAP> tV(*nmap);
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
//// {
//// position_Export[d] *= 100.0f;
......@@ -321,6 +323,7 @@ void EnvMap::initGL()
//// }
Geom::BoundingBox<PFP::VEC3> bbTest2 = Algo::Geometry::computeBoundingBox<PFP>(*nmap, position_Export) ;
bbTest.addPoint(bbTest2.min());
bbTest.addPoint(bbTest2.max());
......
......@@ -56,22 +56,24 @@ void MovingMesh::initGL()
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (m_texture->load("./meshRessources/limace.png"))
// if (m_texture->load("./meshRessources/scenario3/limace_occ.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 = new ShaderCustomTex();
m_shaderTex = new Utils::ShaderPhongTexture();
// m_shaderTex = new Utils::ShaderSimpleTexture();
m_shaderTex->setAttributePosition(m_positionVBO);
m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
// m_shaderTex->setAttributeNormal(m_normalVBO);
m_shaderTex->setAttributeNormal(m_normalVBO);
m_shaderTex->setTextureUnit(GL_TEXTURE0);
m_shaderTex->setTexture(m_texture);
// m_shaderTex->setShininess(10.0f);
// m_shaderTex->setAmbient(0.1f);
// m_shaderTex->setSpecular(Geom::Vec4f(0.5));
m_shaderTex->setShininess(0.1f);
m_shaderTex->setAmbient(0.5f);
m_shaderTex->setSpecular(Geom::Vec4f(0.05));
glEnable(GL_TEXTURE_2D);
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <GL/glew.h>
#include "shaderPhongTexCust.h"
#include "shaderPhongTexCust.vert"
#include "shaderPhongTexCust.frag"
ShaderPhongTexCust::ShaderPhongTexCust(bool doubleSided, bool withEyePosition):
m_with_eyepos(withEyePosition),
m_ambient(0.1f),
m_specular(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f)),
m_shininess(100.0f),
m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
m_vboPos(NULL),
m_vboNormal(NULL),
m_vboTexCoord(NULL)
{
m_nameVS = "ShaderPhongTexCust_vs";
m_nameFS = "ShaderPhongTexCust_fs";
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(*GLSLShader::DEFINES_GL);
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
// and get and fill uniforms
getLocations();
sendParams();
Geom::Matrix44f id;
id.identity();
setTransformation(id);
}
void ShaderPhongTexCust::getLocations()
{
bind();
*m_unif_unit = glGetUniformLocation(this->program_handler(), "textureUnit");
*m_unif_ambient = glGetUniformLocation(this->program_handler(), "ambientCoef");
*m_unif_specular = glGetUniformLocation(this->program_handler(), "materialSpecular");
*m_unif_shininess = glGetUniformLocation(this->program_handler(), "shininess");
*m_unif_lightPos = glGetUniformLocation(this->program_handler(), "lightPosition");
if (m_with_eyepos)
*m_unif_eyePos = glGetUniformLocation(this->program_handler(), "eyePosition");
unbind();
}
void ShaderPhongTexCust::sendParams()
{
bind();
glUniform1i (*m_unif_unit,m_unit);
glUniform1f(*m_unif_ambient, m_ambient);
glUniform4fv(*m_unif_specular, 1, m_specular.data());
glUniform1f (*m_unif_shininess, m_shininess);
glUniform3fv(*m_unif_lightPos, 1, m_lightPos.data());
if (m_with_eyepos)
glUniform3fv(*m_unif_eyePos, 1, m_eyePos.data());
unbind();
}
void ShaderPhongTexCust::setTextureUnit(GLenum texture_unit)
{
bind();
int unit = texture_unit - GL_TEXTURE0;
glUniform1iARB(*m_unif_unit, unit);
m_unit = unit;
unbind();
}
void ShaderPhongTexCust::setTexture(Utils::GTexture* tex)
{
m_tex_ptr = tex;
}
void ShaderPhongTexCust::activeTexture()
{
glActiveTexture(GL_TEXTURE0 + m_unit);
m_tex_ptr->bind();
}
void ShaderPhongTexCust::activeTexture(CGoGNGLuint texId)
{
glActiveTexture(GL_TEXTURE0 + m_unit);
glBindTexture(GL_TEXTURE_2D, *texId);
}
void ShaderPhongTexCust::setAmbient(float ambient)
{
bind();
glUniform1f(*m_unif_ambient, ambient);
m_ambient = ambient;
unbind();
}
void ShaderPhongTexCust::setSpecular(const Geom::Vec4f& specular)
{
bind();
glUniform4fv(*m_unif_specular,1,specular.data());
m_specular = specular;
unbind();
}
void ShaderPhongTexCust::setShininess(float shininess)
{
bind();
glUniform1f (*m_unif_shininess, shininess);
m_shininess = shininess;
unbind();
}
void ShaderPhongTexCust::setLightPosition(const Geom::Vec3f& lightPos)
{
bind();
glUniform3fv(*m_unif_lightPos,1,lightPos.data());
m_lightPos = lightPos;
unbind();
}
void ShaderPhongTexCust::setEyePosition(const Geom::Vec3f& eyePos)
{
if (m_with_eyepos)
{
bind();
glUniform3fv(*m_unif_eyePos,1,eyePos.data());
m_eyePos = eyePos;
unbind();
}
}
void ShaderPhongTexCust::setParams(float ambient, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos)
{
m_ambient = ambient;
m_specular = specular;
m_shininess = shininess;
m_lightPos = lightPos;
sendParams();
}
void ShaderPhongTexCust::restoreUniformsAttribs()
{
getLocations();
sendParams();
bind();
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexNormal", m_vboNormal);
bindVA_VBO("VertexTexCoord", m_vboTexCoord);