//! Création de la grille
void CalibrationUtils::setGrid(int x, int y)
{
	//Nombre de points de calibration sur chaque cercle de calibration - 1
	GRID_X = x;
	//Nombre de cercle de calibration - 1
	GRID_Y = y;
	//Nombre de points de calibration
    GRID_POINTS = GRID_X+1;
	for (int i=2; i<= GRID_Y+1; i++) GRID_POINTS += i*GRID_X;
    //printf("\nX : %d\nY : %d\n",x,y);
    //printf("GRID_POINTS : %d\n",GRID_POINTS);

	//Initialisation des listes de points, et des zones de calibration
	screenPoints = new calibrationPoint[GRID_POINTS];
	cameraPoints = new calibrationPoint[GRID_POINTS];
	triangles	 = new std::vector<triangle*>();

	//Si les deux listes de points sont crées
	if(bscreenPoints && bcameraPoints)
	{
		//Initialisation des points à afficher
		initScreenPoints();
		//Initialisation des points à lire
		initCameraPoints(_camWidth, _camHeight);
        //Initialisation des triangles
        initTriangles();
	}
}
Esempio n. 2
0
File: Mesh.cpp Progetto: Booley/nbis
		bool Mesh::intersectsAABB(Vector3f from2, Vector3f to2) {
			if (triangles.count()==0) initTriangles();
			return
					    (from.x() < to2.x()) && (to.x() > from2.x()) &&
						(from.y() < to2.y()) && (to.y() > from2.y()) &&
						(from.z() < to2.z()) && (to.z() > from2.z());
		};
Esempio n. 3
0
File: Mesh.cpp Progetto: Booley/nbis
		bool Mesh::intersectsRay(RayInfo* ri) {
			if (triangles.count()==0) initTriangles();	

			for (int i = 0; i < triangles.count(); i++) {
				if (triangles[i].intersectsRay(ri)) return true;
			}
			return false;
		};
Esempio n. 4
0
void CalibrationUtils::setGrid(int x, int y)
{
	GRID_Y = y;
	GRID_X = x;

	GRID_POINTS = ((GRID_X+1) * (GRID_Y+1));
    GRID_INDICES = (GRID_X * GRID_Y * 3 * 2);

	screenPoints = new vector2df[GRID_POINTS];
	cameraPoints = new vector2df[GRID_POINTS];
	triangles    = new int[GRID_INDICES];

	initTriangles();

	if(bscreenPoints && bcameraPoints){
	initScreenPoints();
	initCameraPoints(_camWidth, _camHeight);
	}
}
int main(int argc, char *argv[])
{
	//start context
	if (!glfwInit())
	{
		fprintf(stderr, "Error, could not start GLFW3\n");
		return 1;
	}
	else
	{
		fprintf(stderr, "GLFW initialized properly.");
	}

	//Forward compatibility from version 3.2.
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_SAMPLES, 4); //Anti aliasing (4 passes)
	
	//start logs
	Logger::restartLog(GL_LOG_FILE);
	glfwSetErrorCallback(glfwErrorCallback);

	GLFWmonitor* monitor = glfwGetPrimaryMonitor();
	const GLFWvidmode* mode = glfwGetVideoMode(monitor);

	//init window with primary monitor resolution
	//Set these modes for a fullscreen window and don't for classic fullscreen:
	/*glfwWindowHint(GLFW_RED_BITS, mode->redBits);
	glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
	glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
	glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);*/
	//------------------------------------------------

	//GLFWwindow * window = glfwCreateWindow(mode->width, mode->height, "Tutorial 1: Draw a triangle", monitor, NULL); //Fullscreen
	GLFWwindow * window = glfwCreateWindow(800, 600, "Tutorial 1: Draw a triangle", NULL, NULL); //Not Fullscreen

	//if window initialisation failed
	if (!window)
	{
		fprintf(stderr, "Could not open window with GLFW3\n");
		glfwTerminate();
		return 1;
	}

	glfwMakeContextCurrent(window);
	glfwSetWindowSizeCallback(window, glfwWindowSizeCallback);

	//start glew extension handler;
	glewExperimental = GL_TRUE;
	glewInit();

	//get version info
	const GLubyte * renderer = glGetString(GL_RENDERER);
	const GLubyte * version = glGetString(GL_VERSION);

	//Log informations
	Logger::printToLog(GL_LOG_FILE, "Starting GLFW: %s \n", glfwGetVersionString());
	logGlParams();

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	//draw triangle
	initTriangles();

	Shader vertex = Shader("vertex.vert", GL_VERTEX_SHADER);
	Shader frag_1 = Shader("frag1.frag", GL_FRAGMENT_SHADER);
	Shader frag_2 = Shader("frag2.frag", GL_FRAGMENT_SHADER);

	Shader shaders_1[2] = { vertex, frag_1 };
	Shader shaders_2[2] = { vertex, frag_2 };

	ShaderProgram shader_programme_1 = ShaderProgram(shaders_1, VERT_FRAG);
	ShaderProgram shader_programme_2 = ShaderProgram(shaders_2, VERT_FRAG);

	while (!glfwWindowShouldClose(window)) {
		updateFpsCounter(window);

		// wipe the drawing surface clear 
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, g_gl_width, g_gl_height);

		glClearColor(0.1f, 0.1f, 0.1f, 0.0f);

		glUseProgram(shader_programme_1.get_program());
		glBindVertexArray(vao_1);

		// draw points 0-5 from the currently bound VAO with current in-use shader 
		glDrawArrays(GL_TRIANGLES, 0, 6);

		glUseProgram(shader_programme_2.get_program());
		glBindVertexArray(vao_2);

		// draw points 0-5 from the currently bound VAO with current in-use shader 
		glDrawArrays(GL_TRIANGLES, 0, 3);

		// update other events like input handling 
		glfwPollEvents();
		// put the stuff we've been drawing onto the display 
		glfwSwapBuffers(window);

		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) 
		{
			glfwSetWindowShouldClose(window, 1);
		}
	}

	//close gl context and other glfw resources
	glfwTerminate();

	return 0;
}