Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
lauke

Visual Studio E Open Gl 2

Recommended Posts

Ragazzi ho questi 5 sorgenti



#include <iostream>

#include <GL/gl.h>

#include <GL/glut.h>


#ifndef BEZIER_H

#define BEZIER_H


using std::cin;

using std::cout;

using std::cerr;

using std::endl;

using std::string;



typedef double DCOORD;

typedef DCOORD* DPCOORD; /*Definiamo il tipo DOUBLE POINTER COORD*/


class Bezier_Curve {


public:


	Bezier_Curve();

	Bezier_Curve(int,DPCOORD); /*Costruttore della curva Bezièr*/ /*implementata*/

	int getDegree(); /*Implementata*/

	DPCOORD getCoord(); /*Implementata*/

	DPCOORD get_control_polygon_point(int) throw(int); /*Restituisce un pt del poligono di controllo*/ /*Implementata*/

	DPCOORD get_bezier_point(double) throw(double); /*Restituisce un pt della curva bezier*/ /*Implementata*/


private:


	DPCOORD deCasteljau(double); /*Implementazione dell'algoritmo di deCasteljau*/

	DPCOORD get_control_polygon_point_private(int); /*Procedura privata che restituisce un pt di controllo*/ /*Implementata*/


	int degree; /*Definisce il grado della curva*/

	DPCOORD coord; /*Definisce i punti del poligono di controllo*/


} bezier_curve;


#endif


#include "Bezier.h"



Bezier_Curve::Bezier_Curve() {

	this->degree = 0;

	this->coord = NULL;

}



Bezier_Curve::Bezier_Curve(int d, DPCOORD c):degree(d),coord(c) {;}



int Bezier_Curve::getDegree() {


	return this->degree;


}



DPCOORD Bezier_Curve::getCoord() {


	return this->coord;


}



DPCOORD Bezier_Curve::get_control_polygon_point_private(int i) {


	if(i > this->getDegree()) throw i;


	DPCOORD rcoord = new DCOORD[3];

	DPCOORD P = this->getCoord();

	int n = this->getDegree();


	rcoord[0] = P[0*(n + 1) + i];

	rcoord[1] = P[1*(n + 1) + i];

	rcoord[2] = P[2*(n + 1) + i];


	return rcoord;


}



DPCOORD Bezier_Curve::get_control_polygon_point(int i) throw(int) {


	try {


		return this->get_control_polygon_point_private(i);


	}


	catch(int) {


		cerr << "Exception index error in 'get_control_polygon_point' on 'Bezier_Curve" << endl;


	}


}



DPCOORD Bezier_Curve::deCasteljau(double u_0) {


	if(u_0 < 0 || u_0 > 1) throw u_0;


	DPCOORD C = new DCOORD[3];

	DPCOORD P = this->getCoord();

	int n = this->getDegree();


	DPCOORD Q = new DCOORD[3*(n + 1)];


	for(int i = 0; i <= n; i++) {


		Q[0*(n + 1) + i] = P[0*(n + 1) + i];

		Q[1*(n + 1) + i] = P[1*(n + 1) + i];

		Q[2*(n + 1) + i] = P[2*(n + 1) + i];


	}


	for(int k = 1; k <= n; k++) {

		for(int i = 0; i <= n - k; i++) {


			Q[0*(n + 1) + i] = (1 - u_0)*Q[0*(n + 1) + i] + u_0*Q[0*(n + 1) + i + 1];

			Q[1*(n + 1) + i] = (1 - u_0)*Q[1*(n + 1) + i] + u_0*Q[1*(n + 1) + i + 1];

			Q[2*(n + 1) + i] = (1 - u_0)*Q[2*(n + 1) + i] + u_0*Q[2*(n + 1) + i + 1];


		}

	}


	C[0] = Q[0*(n + 1)];

	C[1] = Q[1*(n + 1)];

	C[2] = Q[2*(n + 2)];


	delete Q;


	return C;


}



DPCOORD Bezier_Curve::get_bezier_point(double u_0) throw(double) {


	try {


		return this->deCasteljau(u_0);


	}


	catch(double) {


		cerr << "Exception: parameter error on 'get_bezier_point' in Bezier_curve" << endl;


	}


}


#include "Bezier.h"

#ifndef GRAPH_BEZIER_H

#define GRAPH_BEZIER_H


void init_bezier_curve();

void display_bezier_curve();


#endif


#include "graphBezier.h"


void init() {


	glClearColor(0.0,0.0,0.0,0.0);


	glMatrixMode(GL_PROJECTION);

	glLoadIdentity();

	glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);


}


void display() {


	glClear(GL_COLOR_BUFFER_BIT);

	glColor3d(1.0,1.0,1.0);


	glBegin(GL_LINE_STRIP);


	  for(double u_0 = 0.0; u_0 <= 1.0; u_0 = u_0 + 0.01) {


		  DPCOORD C = bezier_curve.get_bezier_point(u_0);

		  glVertex3d(C[0],C[1],C[2]);

		  delete C;


	  }


    glEnd();


	glutSwapBuffers();


}


#include "graphBezier.h"


int main(int argc, char** argv) {


	DCOORD P[] = {

		0.3,0.4,0.5,0.6,0.7,

		0.1,0.7,0.3,0.5,0.2,

		0.0,0.0,0.0,0.0,0.0

	};


	int n = 4;


	//Bezier_Curve curve(n,P);

	//bezier_curve = &curve;


	//glutInit(&argc,argv);

	//glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

	//glutInitWindowSize(800,600);

	//glutInitWindowPosition(100,100);

	//glutCreateWindow("Bezier_Curve");


	//init_bezier_curve();

	//glutDisplayFunc(&display_bezier_curve);

	//glutMainLoop();

	return 0;

}

Al di là di quello che c'è scritto nel codice, che poco mi interessa...

non capisco perchè non mi compila uno dei problemi è la viariabile globale nell'header di bezier.h dice che è tipo duplicata... ma non vedo come e dove. Mi aiutate?

Grazie Saluti

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...
Aspetta! x