Wednesday, 15 June 2011

opengl - Casteljau c++ Vector2D Spline -



opengl - Casteljau c++ Vector2D Spline -

i doesent decasteljau run. wrote comments in code doesent check.

here pseudocode decasteljau:

decasteljau(anz, p[], t){ for(j=anz-2; j>=0; j--) for(i=0; i<=j; i++) p[i]=(1-t) * p[i] + t * p[i+1]; }

i must utilize vector2d.

#include <stdlib.h> #include <gl\glut.h> #include <iostream> #include <cmath> #include "vector2d.h" using namespace std; #define pi 3.14159265 int w = 600; int h = 600; int array[][2] = { { 0, 0 }, { 2, 4 }, { 3 ,5 } }; vector2d p0(0,0); vector2d p1(0,0); vector2d p2(0,0); float decasteljau(float t){ vector2d x; vector2d y; p0.setxy(array[0][0], array[0][1]); p1.setxy(array[1][0], array[1][1]); p2.setxy(array[2][0], array[2][1]); (int j=3-2;j>=0;j--) (int i=0; i<=j; i++) { //how write this: p[i]=(1-t) * p[i] + t * p[i+1] } homecoming p[0]; //and here } void display(void) { /* clear pixels */ glclear(gl_color_buffer_bit); glcolor3f(1.0, 1.0, 0.0); glbegin(gl_points); //how code draw spline? glend(); glflush(); } void init(void) { /* select clearing color */ glclearcolor(0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glortho(0, w, 0, h, -1, 1); } int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode(glut_single | glut_rgb); glutinitwindowsize(w + 100, h + 100); glutinitwindowposition(100, 0); glutcreatewindow("aufgabe7"); for(int t=0; t<=1;t=t+0.01){ decasteljau(t); } init(); glutdisplayfunc(display); glutmainloop(); homecoming 0; /* ansi c requires main homecoming int. */ }

you can write this

//how write this: p[i]=(1-t) * p[i] + t * p[i+1]

as

p[i].x= (1-t) * p[i].x + t * p[i+1].x; p[i].y= (1-t) * p[i].y + t * p[i+1].y;

c++ opengl vector bezier-curve splines

No comments:

Post a Comment