You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

321 lines
10 KiB

/******************************************************
* LEGACY CODE FROM EMBRYO VERY FIRST DRAFT *
* READ AT YOUR OWN RISK *
* I cannot be held responsible for any brain damage *
* resulting caused by the reading of this code *
* It worked at some point, so it should be pretty *
* easy to reimplment it *
******************************************************/
//#include "Scene.h"
//#include <iostream>
//#include "ExternalLib/glm/gtc/matrix_transform.hpp"
//#include "ExternalLib/glm/gtc/type_ptr.hpp"
//using namespace std;
//bool operator==(Coordinates const& lhs, Coordinates const& rhs)
//{
// if ( lhs.xPos == rhs.xPos && lhs.yPos == rhs.yPos && lhs.zPos == rhs.zPos &&
// lhs.xRot == rhs.xRot && lhs.yRot == rhs.yRot && lhs.zRot == rhs.zRot
// )
// return true;
// else
// return false;
//}
//bool operator==(Force const& lhs, Force const& rhs)
//{
// if ( lhs.xPos == rhs.xPos && lhs.yPos == rhs.yPos && lhs.zPos == rhs.zPos &&
// lhs.xRot == rhs.xRot && lhs.yRot == rhs.yRot && lhs.zRot == rhs.zRot
// )
// return true;
// else
// return false;
//}
//bool operator==(OBI const& lhs, OBI const& rhs)
//{
// if ( lhs.obj == rhs.obj &&
// lhs.coords == rhs.coords &&
// lhs.forces == rhs.forces
// )
// return true;
// else
// return false;
//}
//Scene::Scene(ShaderProgram* sp)
// : cam(sp), shaderProgram(sp), obis(std::vector<OBI>())
//{}
//Scene::~Scene()
//{}
/////***********************************************/
////
//// containerTexture
////
//// std::vector<Material> materials; // get id to set texturelayer
////
//// glUniform1i(glGetUniformLocation(shaderProgram->getId(), *** glName ***), 0); /* initialize the "shader variable" called "containerTexture" to the shader Program
////
//// /********* BINDING SEQUENCE *********/
////
//// /* Binding VAO */
//// glBindVertexArray(VAO);
////
//// /* Binding Textures */
//// // Container Texture
//// glActiveTexture(GL_TEXTURE0); /* OpenGL texture system is organized with Texture Units which allow the usage of multiple texture on the same shader
//// * Texture Units can be seen as "Texture Slot". By usingthe glActiveTexture( GL_TEXTUREXXX ) command we're defining
//// * on which slot our code is gonna work / send textures / etc. So typically 1 texture <=> 1 textureUnit / Slot
//// * AfterWards textures are send to the shader as uniform and retrieved in the shader code by a sampler2D
//// * (By default, working on GL_TEXTURE0)
//// */
//// glBindTexture(GL_TEXTURE_2D, container); /* binds container to global GL_TEXTURE_2D describing 2D textures
//// * container set on textureUnit/slot 0 of GL_TEXTURE_2D */
//// // Face Texture
//// glActiveTexture(GL_TEXTURE1);
//// glBindTexture(GL_TEXTURE_2D, face);
//// /********* UPDATE OF CAMERA *********/
////
//// cam.updateCamera();
////
//// /********* RENDERING *********/
////
//// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear Z-Buffer and ColorBuffer before painting
////
//// /*
//// * shenaningans to print multiple cube (TO BE REPLACED BY SCENE)
//// */
////
////
////// for(GLuint i = 0; i < 10; i++)
////// {
////// glm::mat4 model;
////// model = glm::translate(model, cubePositions[i]); // change origin of display of each cube according to cubePositions[]
////// GLfloat angle = 20.0f * i;
////// model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f)); // change initial rotation of each cube
////// model = glm::rotate(model, elapsedTime*5, glm::vec3(0.5f, 1.0f, 0.0f)); // give each cube a time relative spinning
////// GLint modelLoc = glGetUniformLocation(shaderProgram->getId(), "model");
////// glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
//////
////// glDrawArrays(GL_TRIANGLES, 0, 36);/* print what's in the current VAO */
////// /* Use glDrawElements if VAO's vertices are indexed */
////// }
////
//// /********* UNBINDING SEQUENCE *********/
////
//// /* Unbinding VAO */
//// glBindVertexArray(0); // unbind it
////
//// /* Unbinding Textures */
//// // Container Texture
//// glActiveTexture(GL_TEXTURE0);
//// glBindTexture(GL_TEXTURE_2D, 0);
////
//// // Face Texture
//// glActiveTexture(GL_TEXTURE1);
//// glBindTexture(GL_TEXTURE_2D, 0);
///************************************************/
//void Scene::renderScene()
//{
// /**
// * \brief: render every object in the Scene
// */
// /*********************************************************************
// * GL RENDERING *
// *********************************************************************
// * As stated by the convention, it is always preffered to *
// * rebind what we want to print, and unbind it once it's done *
// * to avoid accidental writes on VAO, Textures, etc *
// *********************************************************************/
// for(auto const& curOBI: obis)
// renderOBI(curOBI);
// cam.updateCamera();
//}
//void Scene::renderOBI(OBI o)
//{
// /*
// * Load Object (o.obj)'s ressources (VAO && Materials)
// */
// // Binding Shader
// shaderProgram->enable();
// // Binding VAO
// glBindVertexArray(o.obj.getVAO());
// // Binding Materials
// for (int i=0 ; o.obj.getMaterials().size(); i++)
// {
// // Bind Textures using texture units
// glActiveTexture(GL_TEXTURE0+i);
// glBindTexture(GL_TEXTURE_2D, o.obj.getMaterials()[i].getGlId());
// string GLName = o.obj.getMaterials()[i].getGlName();
// glUniform1i( glGetUniformLocation( shaderProgram->getId(), GLName.c_str() ), i );
// }
// /*
// * Rendering
// */
// //detect if EBO present
// if( o.obj.getEBO() != 0 ) // Object's vertices position indexed using EBO
// {
// cout << "INDEXED EBO NOT SUPPORTED YET" << endl ;
// //TODO render with EBO
// // bind EBO
// }
// else
// {
// glm::mat4 model; // model Matrix to define position of Object
// model = glm::translate( model, glm::vec3( o.coords.xPos, o.coords.yPos, o.coords.zPos ) );
// //TODO apply initial rotation
// //TODO apply force
////// model = glm::translate(model, cubePositions[i]); // change origin of display of each cube according to cubePositions[]
////// GLfloat angle = 20.0f * i;
////// model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f)); // change initial rotation of each cube
////// model = glm::rotate(model, elapsedTime*5, glm::vec3(0.5f, 1.0f, 0.0f)); // give each cube a time relative spinning
// GLint modelLoc = glGetUniformLocation(shaderProgram->getId(), "model");
// glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
// glDrawArrays(GL_TRIANGLES, 0, o.obj.getNbVertices());/* print what's in the current VAO */
// }
// /*
// * UnLoad Object (o.obj)'s ressources
// */
// // UnBinding VAO
// glBindVertexArray(0);
//}
//void Scene::addObject(Object& object, Coordinates& coords_, std::vector<Force>& forces_)
//{
// OBI obi;
// obi.obj= object;
// obi.coords = coords_;
// obi.forces = forces_;
// obis.push_back(obi);
//}
//void Scene::addObject(Object& object, Coordinates& coords_)
//{
// std::vector<Force> foo = std::vector<Force>();
// addObject(object, coords_, foo );
//}
//int Scene::searchObject(Object& object) const
//{
// int rtrnVal = 0;
// for(uint i=0; i<= obis.size(); i++)
// if (obis[i].obj== object)
// rtrnVal++;
// return rtrnVal;
//}
//int Scene::searchObject(Object& object, Coordinates& coords_)
//{
// int rtrnVal = 0;
// for(auto const& curOBI: obis)
// if ( curOBI.obj == object && curOBI.coords == coords_ )
// rtrnVal++;
// return rtrnVal; // return number of times the object has been found ( there could be overlapping instances of an object )
//}
//int Scene::searchObject(Object& object, Coordinates& coords_, std::vector<Force> forces_)
//{
// OBI sOBI; // Searched Object
// sOBI.obj= object;
// sOBI.coords = coords_;
// sOBI.forces = forces_;
// int rtrnVal = 0;
// for(auto const& curOBI: obis)
// if (curOBI == sOBI)
// rtrnVal++;
// return rtrnVal; // return number of times the object has been found ( there could be overlapping instances of an object )
//}
//int Scene::remObject(Object& object)
//{
// int rtrnVal = 0; // number of Object removed from the vector
// for(uint i=0; i<= obis.size(); i++)
// if (obis[i].obj == object)
// {
// obis.erase(obis.begin()+i);
// rtrnVal++;
// }
// return rtrnVal;
//}
//int Scene::remObject(Object& object, Coordinates coords_)
//{
// int rtrnVal = 0; // number of Object removed from the vector
// for(uint i=0; i<= obis.size(); i++)
// if ( obis[i].obj == object && obis[i].coords == coords_)
// {
// obis.erase(obis.begin()+i);
// rtrnVal++;
// }
// return rtrnVal;
//}
//int Scene::remObject(Object& object, Coordinates coords_, std::vector<Force> forces)
//{
// int rtrnVal = 0; // number of Object removed from the vector
// OBI dOBI; // Searched Object // to be deleted Object
// dOBI.obj= object;
// dOBI.coords = coords_;
// dOBI.forces = forces;
// for(uint i=0; i<= obis.size(); i++)
// if (obis[i] == dOBI)
// {
// obis.erase(obis.begin()+i);
// rtrnVal++;
// }
// return rtrnVal;
//}
//ShaderProgram* Scene::getShaderProgram()
//{ return shaderProgram; }