示例#1
0
/**
 * Create the STL encoder factory singleton and define the default options.
 */
STLEncoderFactory* STLEncoderFactory::createInstance() {
	prtx::EncoderInfoBuilder encoderInfoBuilder;

	encoderInfoBuilder.setID(STLEncoder::ID);
	encoderInfoBuilder.setName(STLEncoder::NAME);
	encoderInfoBuilder.setDescription(STLEncoder::DESCRIPTION);
	encoderInfoBuilder.setType(prt::CT_GEOMETRY);
	encoderInfoBuilder.setExtension(STL_EXT);

	// optionally we could setup a validator
	// encoderInfoBuilder.setValidator(prtx::EncodeOptionsValidatorPtr(new MyOptionsValidator()));

	prtx::PRTUtils::AttributeMapBuilderPtr amb(prt::AttributeMapBuilder::create());
	amb->setString(EO_BASE_NAME, L"stl_default_name"); // required by CityEngine
	amb->setBool(EO_ERROR_FALLBACK, prtx::PRTX_TRUE); // required by CityEngine
	encoderInfoBuilder.setDefaultOptions(amb->createAttributeMap());

	// CityEngine requires the following annotations to create an UI for an option:
	// label, order, group and description
	prtx::EncodeOptionsAnnotator eoa(encoderInfoBuilder);
	eoa.option(EO_BASE_NAME)
			.setLabel(L"Base Name")
			.setOrder(0.0)
			.setGroup(L"General Settings", 0.0)
			.setDescription(L"Sets the base name of the written STL file.");

	// Hide the error fallback option in the CityEngine UI.
	eoa.option(EO_ERROR_FALLBACK).flagAsHidden();

	return new STLEncoderFactory(encoderInfoBuilder.create());
}
示例#2
0
void Loader::LoadMaterial(const aiScene *pScene, const char *file_name)
{
    //store material
    for(int i = 0 ;i<pScene->mNumMaterials;i++)
    {
        aiColor3D dif(0.f,0.f,0.f);
        aiColor3D amb(0.f,0.f,0.f);
        aiColor3D spec(0.f,0.f,0.f);
        aiMaterial * the_material = pScene->mMaterials[i];
        CMC_Material * material = new CMC_Material();
        the_material->Get(AI_MATKEY_COLOR_AMBIENT,amb);
        the_material->Get(AI_MATKEY_COLOR_DIFFUSE,dif);
        the_material->Get(AI_MATKEY_COLOR_SPECULAR,spec);

        material->ambientColor = QVector3D(amb.r,amb.g,amb.b);
        material->diffuseColor = QVector3D(dif.r,dif.g,dif.b);
        material->specularColor = QVector3D(spec.r,spec.g,spec.b);
        aiString normalPath;
        the_material->GetTexture (aiTextureType_NORMALS,0,&normalPath);
        //now ,we only use the first diffuse texture, will fix it later
        aiString diffuse_Path;
        the_material->GetTexture(aiTextureType_DIFFUSE,0,&diffuse_Path);
        if(diffuse_Path.length == 0 )
        {
            material->diffuseTexturePath = "INVALID";
        }else
        {
            material->diffuseTexturePath = diffuse_Path.C_Str ();
        }
        m_model->addMaterial (material);
    }
}
bool CD3DGraphics11::RenderBumpMapShdaer(D3DXMATRIX world, int numIndices, CMaterialDX11 mat)
{
	CGameScene& scene = SYSTEM::PROJECT::GetScene();
	CGameobjectList l = scene.GetLightList();
	int n_l = l.GetNumObjects();
	CCamera* c = scene.GetCamera(0);

	if (!c)
		return false;

	D3DXVECTOR4 amb(mat.GetAmbientColor().r, mat.GetAmbientColor().g, mat.GetAmbientColor().b, mat.GetAmbientColor().a);
	D3DXVECTOR4 spec(mat.GetSpecularColor().r, mat.GetSpecularColor().g, mat.GetSpecularColor().b, mat.GetSpecularColor().a);
	D3DXVECTOR3 camPos(c->GetTransform().GetTranslation().x, c->GetTransform().GetTranslation().y,
		c->GetTransform().GetTranslation().z);

	ID3D11ShaderResourceView* difTex = mat.GetDiffuseTexture();
	ID3D11ShaderResourceView* specTex = mat.GetSpecularMap();
	ID3D11ShaderResourceView* bumpTex = mat.GetBumpMap();

	if (!difTex)
		difTex = m_pDefaultTexture;
	if (!specTex)
		specTex = m_pDefaultTexture;
	if (!bumpTex)
		bumpTex = m_pDefaultTexture;

	return m_bumpMapShader.Render(*this, numIndices, m_matrices.view, world, m_matrices.projection, difTex, specTex, bumpTex, 
		l, n_l,amb, camPos, spec, 64.0f);

	return true;
}
示例#4
0
int main()
{
	namespace fusion = boost::fusion;

	typedef fusion::vector<int, int, int> value_type;
	std::vector<value_type> vec;

    AMB_BLOCK(ctx) {
        amber& x = amb(ctx, 0, amb1_f);
        amber& y = amb(ctx, 1, amb2_f);
        amber& z = amb(ctx, 2, amb3_f);

        vec.push_back(value_type(x.get(), y.get(), z.get()));
    };

	const std::vector<value_type> expected = boost::assign::list_of<value_type>
		(1, 4, 6)
		(1, 4, 7)
		(1, 4, 8)
		(1, 5, 6)
		(1, 5, 7)
		(1, 5, 8)
		(2, 4, 6)
		(2, 4, 7)
		(2, 4, 8)
		(2, 5, 6)
		(2, 5, 7)
		(2, 5, 8)
		(3, 4, 6)
		(3, 4, 7)
		(3, 4, 8)
		(3, 5, 6)
		(3, 5, 7)
		(3, 5, 8)
		;

	BOOST_TEST(boost::equal(vec, expected));

	return boost::report_errors();
}
示例#5
0
int _main() {
  const char *w1,*w2,*w3,*w4;

  w1 = amb(3, "the", "that", "a");
  w2 = amb(3, "frog", "elephant", "thing");
  w3 = amb(3, "walked", "treaded", "grows");
  w4 = amb(2, "slowly", "quickly");

  if(!joins(w1, w2)) amb(0);
  if(!joins(w2, w3)) amb(0);
  if(!joins(w3, w4)) amb(0);

  printf("%s %s %s %s\n", w1, w2, w3, w4);

  return EXIT_SUCCESS;
}
示例#6
0
void projA(std::complex<double> A[d3][d3], std::complex<double> U[d3][d3]) {
  // A = proj(U), where U is projected on a antihermitian traceless matrix A
  // proj(U) = ( U - U^dag)/2 - i*( U - U^dag)/2 )/3

  std::complex<double> Udag[d3][d3], UmUdag[d3][d3];

  aeb(Udag,U);
  adag(Udag);

  amb(UmUdag, U,Udag);
  za(UmUdag, 0.5, UmUdag);

  aeb(A,UmUdag); 

  std::complex<double> trace;
  trace = UmUdag[0][0] + UmUdag[1][1] + UmUdag[2][2];
  for (int i=0; i<d3; i++) {
    A[i][i] -= trace/(double)3;
  }
}
bool CD3DGraphics11::RenderTextureLightingShader(D3DXMATRIX world, int numIndices, CMaterialDX11 mat)
{
	CGameScene& scene = SYSTEM::PROJECT::GetScene();
	CGameobjectList l = scene.GetLightList();
	int n_l = l.GetNumObjects();
	CCamera* c = scene.GetCamera(0);

	if(!c)
		return false;

	D3DXVECTOR4 amb(mat.GetAmbientColor().r,mat.GetAmbientColor().g,mat.GetAmbientColor().b,mat.GetAmbientColor().a);
	D3DXVECTOR4 spec(mat.GetSpecularColor().r,mat.GetSpecularColor().g,mat.GetSpecularColor().b,mat.GetSpecularColor().a);
	D3DXVECTOR3 camPos(c->GetTransform().GetTranslation().x,c->GetTransform().GetTranslation().y,
		c->GetTransform().GetTranslation().z);

	if (mat.GetDiffuseTexture())
		return m_textureLightingShader.Render(*this, numIndices, m_matrices.view, world, m_matrices.projection, mat.GetDiffuseTexture(),
			l, n_l, amb, camPos, spec, 64.0f);
	else
		return m_textureLightingShader.Render(*this, numIndices, m_matrices.view, world, m_matrices.projection, m_pDefaultTexture,
			l, n_l, amb, camPos, spec, 64.0f);

	return true;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
    ui->tab_2->setEnabled(false);
    ui->pushButton_3->setEnabled(false);
    ui->btnSmooth->setEnabled(false);
    ui->menuExperimenta->setEnabled(false);
    ui->actionSave_Laplace_Matrix->setEnabled(false);
    connect(ui->glWidget, SIGNAL(faceCount(int)), ui->faceCount, SLOT(display(int)));
    connect(ui->glWidget, SIGNAL(vertexCount(int)), ui->vertexCount, SLOT(display(int)));
    connect(ui->radioButton, SIGNAL(toggled(bool)), ui->glWidget, SLOT(Light0State(bool)));
    connect(ui->radioButton_2, SIGNAL(toggled(bool)), ui->glWidget, SLOT(Light1State(bool)));
    connect(ui->radioButton_3, SIGNAL(toggled(bool)), ui->glWidget, SLOT(Light2State(bool)));

    connect(ui->glWidget,SIGNAL(SendVector(VectorXd)), &plotWin, SLOT(getVector(VectorXd)));

    connect(&posLight, SIGNAL(posX(int)), ui->glWidget, SLOT(LightPosX(int)));
    connect(&posLight, SIGNAL(posY(int)), ui->glWidget, SLOT(LightPosY(int)));
    connect(&posLight, SIGNAL(posZ(int)), ui->glWidget, SLOT(LightPosZ(int)));

    connect(&matWin, SIGNAL(amb(QColor)), ui->glWidget, SLOT(glAmb(QColor)));
    connect(&matWin, SIGNAL(diffuse(QColor)), ui->glWidget, SLOT(glDiffuse(QColor)));
    connect(&matWin, SIGNAL(spec(QColor)), ui->glWidget, SLOT(glSpec(QColor)));
    connect(&posLight, SIGNAL(sendLightColor(QColor)), ui->glWidget, SLOT(LightColor(QColor)));


    connect(&selectLaplacian, SIGNAL(selectKind(int)), ui->glWidget, SLOT(SelectLaplace(int)));
    connect(this, SIGNAL(sendEigenIndex(int)), ui->glWidget, SLOT(SeekEigen(int)));
    connect(this, SIGNAL(sendCompressionVolume(int)), ui->glWidget, SLOT(AdjustCompression(int)));
    connect(this, SIGNAL(analyseCurve()), ui->glWidget, SLOT(AnalyseCurve()));
    connect(ui->glWidget, SIGNAL(Status(QString)), this, SLOT(setStatus(QString)));
    connect(this, SIGNAL(shadingMode(int)), ui->glWidget, SLOT(selectShade(int)));
}
示例#9
0
void MyGLWidget::createBuffers ()
{
  // Carreguem el model de l'OBJ - Atenció! Abans de crear els buffers!
  //patr.load("/assig/idi/models/Patricio.obj");
  patr.load("/assig/idi/models/Patricio.obj");

  // Calculem la capsa contenidora del model
  calculaCapsaModel ();
  
  // Creació del Vertex Array Object del Patricio
  glGenVertexArrays(1, &VAO_Patr);
  glBindVertexArray(VAO_Patr);

  // Creació dels buffers del model patr
  // Buffer de posicions
  glGenBuffers(1, &VBO_PatrPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_vertices(), GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  // Buffer de normals
  glGenBuffers(1, &VBO_PatrNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_normals(), GL_STATIC_DRAW);

  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_PatrMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matamb(), GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_PatrMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matdiff(), GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_PatrMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matspec(), GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_PatrMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3, patr.VBO_matshin(), GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);

  // Dades del terra
  // VBO amb la posició dels vèrtexs
  glm::vec3 posterra[12] = {
	glm::vec3(-1.0, -1.0, 1.0),
	glm::vec3(1.0, -1.0, 1.0),
	glm::vec3(-1.0, -1.0, -1.0),
	glm::vec3(-1.0, -1.0, -1.0),
	glm::vec3(1.0, -1.0, 1.0),
	glm::vec3(1.0, -1.0, -1.0),
	glm::vec3(-1.0, -1.0, -1.0),
	glm::vec3(1.0, -1.0, -1.0),
	glm::vec3(-1.0, 1.0, -1.0),
	glm::vec3(-1.0, 1.0, -1.0),
	glm::vec3(1.0, -1.0, -1.0),
	glm::vec3(1.0, 1.0, -1.0)
  }; 

  // VBO amb la normal de cada vèrtex
  glm::vec3 norm1 (0,1,0);
  glm::vec3 norm2 (0,0,1);
  glm::vec3 normterra[12] = {
	norm1, norm1, norm1, norm1, norm1, norm1, // la normal (0,1,0) per als primers dos triangles
	norm2, norm2, norm2, norm2, norm2, norm2  // la normal (0,0,1) per als dos últims triangles
  };

  // Definim el material del terra
  glm::vec3 amb(0,0,1);
  glm::vec3 diff(0,0,1);
  glm::vec3 spec(1,1,1);
  float shin = 100;

  // Fem que aquest material afecti a tots els vèrtexs per igual
  glm::vec3 matambterra[12] = {
	amb, amb, amb, amb, amb, amb, amb, amb, amb, amb, amb, amb
  };
  glm::vec3 matdiffterra[12] = {
	diff, diff, diff, diff, diff, diff, diff, diff, diff, diff, diff, diff
  };
  glm::vec3 matspecterra[12] = {
	spec, spec, spec, spec, spec, spec, spec, spec, spec, spec, spec, spec
  };
  float matshinterra[12] = {
	shin, shin, shin, shin, shin, shin, shin, shin, shin, shin, shin, shin
  };

// Creació del Vertex Array Object del terra
  glGenVertexArrays(1, &VAO_Terra);
  glBindVertexArray(VAO_Terra);

  glGenBuffers(1, &VBO_TerraPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(posterra), posterra, GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  glGenBuffers(1, &VBO_TerraNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(normterra), normterra, GL_STATIC_DRAW);

  // Activem l'atribut normalLoc
  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_TerraMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matambterra), matambterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_TerraMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matdiffterra), matdiffterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_TerraMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matspecterra), matspecterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_TerraMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matshinterra), matshinterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);

  glBindVertexArray(0);
}
示例#10
0
void MyGLWidget::createBuffers ()
{
  // Carreguem el model de l'OBJ - Atenció! Abans de crear els buffers!
  patr.load("./models/Patricio.obj");

  // Calculem la capsa contenidora del model
  calculaCapsaModel ();
  
  // Creació del Vertex Array Object del Patricio
  glGenVertexArrays(1, &VAO_Patr);
  glBindVertexArray(VAO_Patr);

  // Creació dels buffers del model patr
  // Buffer de posicions
  glGenBuffers(1, &VBO_PatrPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_vertices(), GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  // Buffer de normals
  glGenBuffers(1, &VBO_PatrNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_normals(), GL_STATIC_DRAW);

  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_PatrMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matamb(), GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_PatrMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matdiff(), GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_PatrMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3*3, patr.VBO_matspec(), GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_PatrMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_PatrMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*patr.faces().size()*3, patr.VBO_matshin(), GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);

  // Dades del terra
  // VBO amb la posició dels vèrtexs
  glm::vec3 posterra[4] = {
	glm::vec3( 10.0, 0.0, -10.0),
	glm::vec3( 10.0, 0.0,  10.0),
	glm::vec3(-10.0, 0.0, -10.0),
	glm::vec3(-10.0, 0.0,  10.0)
  }; 

  // VBO amb la normal de cada vèrtex
  glm::vec3 norm (0,1,0);
  glm::vec3 normterra[4] = {
	norm, norm, norm, norm
  };

  // Definim el material del terra
  glm::vec3 amb(0.2,0.2,0.0);
  glm::vec3 diff(1.,1.,0.0);
  glm::vec3 spec(0.,0.,0.);
  float shin = 100;

  // Fem que aquest material afecti a tots els vèrtexs per igual
  glm::vec3 matambterra[4] = {
	amb, amb, amb, amb
  };
  glm::vec3 matdiffterra[4] = {
	diff, diff, diff, diff
  };
  glm::vec3 matspecterra[4] = {
	spec, spec, spec, spec
  };
  float matshinterra[4] = {
	shin, shin, shin, shin
  };

// Creació del Vertex Array Object del terra
  glGenVertexArrays(1, &VAO_Terra);
  glBindVertexArray(VAO_Terra);

  glGenBuffers(1, &VBO_TerraPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(posterra), posterra, GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  glGenBuffers(1, &VBO_TerraNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(normterra), normterra, GL_STATIC_DRAW);

  // Activem l'atribut normalLoc
  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_TerraMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matambterra), matambterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_TerraMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matdiffterra), matdiffterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_TerraMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matspecterra), matspecterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_TerraMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matshinterra), matshinterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);


  glm::vec3 colorF(0.8, 0.8, 0.8);
  PosicionEstandarFoco = glm::vec3(5., 3., 5.);
  glUniform3fv(colFocusLoc, 1, &colorF[0]);
  glUniform3fv(posFocusLoc, 1, &PosicionEstandarFoco[0]);
  glUniform3fv(llumAmbiLoc, 1, &colorF[0]);


  glBindVertexArray(0);
}
示例#11
0
文件: pwm.cpp 项目: B-Rich/StochHMM
	/*! Parses a Position Weight Matrices string
	 Parses string containing position weight matrix definitions
	 \param[in] std::string file
	 */
	bool PWM::parse(const std::string& matrix){
		size_t thresh = matrix.find("THRESHOLD DEFINITION");
        size_t track  = matrix.find("TRACK SYMBOL DEFINITIONS");
        size_t ambig  = matrix.find("AMBIGUOUS SYMBOL DEFINITIONS");
        size_t pwm = matrix.find("POSITION WEIGHT DEFINITIONS");
		size_t back = matrix.find("BACKGROUND DEFINITION");
		size_t space = matrix.find("SPACER DEFINITIONS");
		size_t blank;
        size_t nlChar;
		
		if (thresh != std::string::npos){
			blank=matrix.find("\n\n",thresh);
			
			size_t nlCharEq = matrix.rfind("####\n",blank);
			size_t nlCharNum= matrix.rfind("====\n",blank);
			//Check for optional dividing line
			if (nlCharEq!=std::string::npos){
				nlChar=nlCharEq+5;
			}
			else if (nlCharNum!=std::string::npos){
				nlChar=nlCharNum+5;
			}
			else{  //No divider line
				nlChar=matrix.find("\n",thresh);
				nlChar++;
			}
			
			
			std::string thr (matrix.substr(nlChar,blank-nlChar));
			
			if (!_parseThreshold(thr)){
				return false;
			}
			
		}
		
		if (track != std::string::npos){
			blank=matrix.find("\n\n",track);

            size_t nlCharEq = matrix.rfind("####\n",blank);
            size_t nlCharNum= matrix.rfind("====\n",blank);
            //Check for optional dividing line
            if (nlCharEq!=std::string::npos){
                nlChar=nlCharEq+5;
            }
            else if (nlCharNum!=std::string::npos){
                nlChar=nlCharNum+5;
            }
            else{  //No divider line
                nlChar=matrix.find("\n",track);
                nlChar++;
            }


            std::string trck (matrix.substr(nlChar,blank-nlChar));

            if (!_parseTrack(trck)){
                return false;
            }
			
        }
        else{
            std::cerr << "Required section: TRACK SYMBOL DEFINITIONS missing from the model" << std::endl;
            return false;
        }
		
		if (ambig != std::string::npos){
			blank=matrix.find("\n\n",ambig);

            size_t nlCharEq = matrix.rfind("####\n",blank);
            size_t nlCharNum= matrix.rfind("====\n",blank);
            //Check for optional dividing line
            if (nlCharEq!=std::string::npos){
                nlChar=nlCharEq+5;
            }
            else if (nlCharNum!=std::string::npos){
                nlChar=nlCharNum+5;
            }
            else{  //No divider line
                nlChar=matrix.find("\n",ambig);
                nlChar++;
            }

            std::string amb(matrix.substr(nlChar,blank-nlChar));

            if (!_parseAmbiguous(amb)){
                return false;
            }

		}
		
		if (back!= std::string::npos){
			blank=matrix.find("\n\n",back);
			
            size_t nlCharEq = matrix.rfind("####\n",blank);
            size_t nlCharNum= matrix.rfind("====\n",blank);
            //Check for optional dividing line
            if (nlCharEq!=std::string::npos){
                nlChar=nlCharEq+5;
            }
            else if (nlCharNum!=std::string::npos){
                nlChar=nlCharNum+5;
            }
            else{  //No divider line
                nlChar=matrix.find("\n",back);
                nlChar++;
            }
			
            std::string background(matrix.substr(nlChar,blank-nlChar));
			
            if (!_parseBackground(background)){
                return false;
            }
		}
		
		//Parse the positions
		if (pwm != std::string::npos){
			std::string positions = matrix.substr(pwm);
			_parsePositions(positions);
		}
		
		
		//Parse the Spacer Information
		if (space != std::string::npos){
			blank=matrix.find("\n\n",space);
			
            size_t nlCharEq = matrix.rfind("####\n",blank);
            size_t nlCharNum= matrix.rfind("====\n",blank);
            //Check for optional dividing line
            if (nlCharEq!=std::string::npos){
                nlChar=nlCharEq+5;
            }
            else if (nlCharNum!=std::string::npos){
                nlChar=nlCharNum+5;
            }
            else{  //No divider line
                nlChar=matrix.find("\n",space);
                nlChar++;
            }
			
            std::string spacer(matrix.substr(nlChar,blank-nlChar));
			
            if (!_parseSpacer(spacer)){
                return false;
            }
		}
		
		_finalizeTransitions();
		
		return true;
	}
示例#12
0
void MyGLWidget::createBuffers ()
{
  // Carreguem el model de l'OBJ - Atenció! Abans de crear els buffers!
  caps.load("./models/cow.obj");

  // Calculem la capsa contenidora del model
  calculaCapsaModel ();

  // Creació del Vertex Array Object del Patricio
  glGenVertexArrays(1, &VAO_Caps);
  glBindVertexArray(VAO_Caps);

  // Creació dels buffers del model patr
  // Buffer de posicions
  glGenBuffers(1, &VBO_CapsPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3*3, caps.VBO_vertices(), GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  // Buffer de normals
  glGenBuffers(1, &VBO_CapsNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3*3, caps.VBO_normals(), GL_STATIC_DRAW);

  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_CapsMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3*3, caps.VBO_matamb(), GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_CapsMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3*3, caps.VBO_matdiff(), GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_CapsMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3*3, caps.VBO_matspec(), GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_CapsMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_CapsMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps.faces().size()*3, caps.VBO_matshin(), GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);


  // Carreguem el model de l'OBJ - Atenció! Abans de crear els buffers!
  caps2.load("./models/Patricio.obj");

  // Calculem la capsa contenidora del model
  calculaCapsaModel2 ();

  // Creació del Vertex Array Object del Patricio
  glGenVertexArrays(1, &VAO_Caps2);
  glBindVertexArray(VAO_Caps2);

  // Creació dels buffers del model patr
  // Buffer de posicions
  glGenBuffers(1, &VBO_Caps2Pos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Pos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3*3, caps2.VBO_vertices(), GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  // Buffer de normals
  glGenBuffers(1, &VBO_Caps2Norm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Norm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3*3, caps2.VBO_normals(), GL_STATIC_DRAW);

  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_Caps2Matamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Matamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3*3, caps2.VBO_matamb(), GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_Caps2Matdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Matdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3*3, caps2.VBO_matdiff(), GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_Caps2Matspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Matspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3*3, caps2.VBO_matspec(), GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_Caps2Matshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_Caps2Matshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*caps2.faces().size()*3, caps2.VBO_matshin(), GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);



  // Dades del terra
  // VBO amb la posició dels vèrtexs
  glm::vec3 posterra[12] = {
	glm::vec3(-2.0, -1.0, 2.0),
	glm::vec3(2.0, -1.0, 2.0),
	glm::vec3(-2.0, -1.0, -2.0),
	glm::vec3(-2.0, -1.0, -2.0),
	glm::vec3(2.0, -1.0, 2.0),
	glm::vec3(2.0, -1.0, -2.0),
	glm::vec3(-2.0, -1.0, -2.0),
	glm::vec3(2.0, -1.0, -2.0),
	glm::vec3(-2.0, 1.0, -2.0),
	glm::vec3(-2.0, 1.0, -2.0),
	glm::vec3(2.0, -1.0, -2.0),
	glm::vec3(2.0, 1.0, -2.0)
  }; 

  //________________________________________________________________
  //___________________CALCUL MAX I MIN TERRA_______________________

  maxTerra.x = minTerra.x = posterra[0].x;
  maxTerra.y = minTerra.y = posterra[0].y;
  maxTerra.z = minTerra.z = posterra[0].z;

  for (unsigned int i = 0; i < 12; i+=1)
  {
      if (posterra[i].x < minTerra.x)
        minTerra.x = posterra[i].x;
      if (posterra[i].x > maxTerra.x)
        maxTerra.x = posterra[i].x;
      if (posterra[i].y < minTerra.y)
        minTerra.y = posterra[i].y;
      if (posterra[i].y > maxTerra.y)
        maxTerra.y = posterra[i].y;
      if (posterra[i].z < minTerra.z)
        minTerra.z = posterra[i].z;
      if (posterra[i].z > maxTerra.z)
        maxTerra.z = posterra[i].z;
  }
  centreTerra.x = (minTerra.x+maxTerra.x)/2.0;
  centreTerra.y = (minTerra.y+maxTerra.y)/2.0;
  centreTerra.z = (minTerra.z+maxTerra.z)/2.0;

   //________________________________________________________
   //_______________FI CALCUL________________________________





  // VBO amb la normal de cada vèrtex
  glm::vec3 norm1 (0,1,0);
  glm::vec3 norm2 (0,0,1);
  glm::vec3 normterra[12] = {
	norm1, norm1, norm1, norm1, norm1, norm1, // la normal (0,1,0) per als primers dos triangles
	norm2, norm2, norm2, norm2, norm2, norm2  // la normal (0,0,1) per als dos últims triangles
  };

  // Definim el material del terra
  glm::vec3 amb(0.2,0,0.2);
  glm::vec3 diff(0.8,0,0.8);
  glm::vec3 spec(0,0,0);
  float shin = 100;

  // Fem que aquest material afecti a tots els vèrtexs per igual
  glm::vec3 matambterra[12] = {
	amb, amb, amb, amb, amb, amb, amb, amb, amb, amb, amb, amb
  };
  glm::vec3 matdiffterra[12] = {
	diff, diff, diff, diff, diff, diff, diff, diff, diff, diff, diff, diff
  };
  glm::vec3 matspecterra[12] = {
	spec, spec, spec, spec, spec, spec, spec, spec, spec, spec, spec, spec
  };
  float matshinterra[12] = {
	shin, shin, shin, shin, shin, shin, shin, shin, shin, shin, shin, shin
  };

// Creació del Vertex Array Object del terra
  glGenVertexArrays(1, &VAO_Terra);
  glBindVertexArray(VAO_Terra);

  glGenBuffers(1, &VBO_TerraPos);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraPos);
  glBufferData(GL_ARRAY_BUFFER, sizeof(posterra), posterra, GL_STATIC_DRAW);

  // Activem l'atribut vertexLoc
  glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(vertexLoc);

  glGenBuffers(1, &VBO_TerraNorm);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraNorm);
  glBufferData(GL_ARRAY_BUFFER, sizeof(normterra), normterra, GL_STATIC_DRAW);

  // Activem l'atribut normalLoc
  glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(normalLoc);

  // En lloc del color, ara passem tots els paràmetres dels materials
  // Buffer de component ambient
  glGenBuffers(1, &VBO_TerraMatamb);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatamb);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matambterra), matambterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matambLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matambLoc);

  // Buffer de component difusa
  glGenBuffers(1, &VBO_TerraMatdiff);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatdiff);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matdiffterra), matdiffterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matdiffLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matdiffLoc);

  // Buffer de component especular
  glGenBuffers(1, &VBO_TerraMatspec);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatspec);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matspecterra), matspecterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matspecLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matspecLoc);

  // Buffer de component shininness
  glGenBuffers(1, &VBO_TerraMatshin);
  glBindBuffer(GL_ARRAY_BUFFER, VBO_TerraMatshin);
  glBufferData(GL_ARRAY_BUFFER, sizeof(matshinterra), matshinterra, GL_STATIC_DRAW);

  glVertexAttribPointer(matshinLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(matshinLoc);

  glBindVertexArray(0);
}