/ / practica6 c) draw random shapes in random colors
/ / Christian Durán Jorge Lara
# include # include void timer
(int value); void init (void);
void display(void); void reshape (int w, int h); void mouse(int button, int state, int x, int y);
void timer(int value); void idle();
int opcion=0; void init(void)
{ glClearColor (0.0, 0.0, 0.0, 0.0); glClear (GL_COLOR_BUFFER_BIT);
glShadeModel (GL_FLAT); }
void display(void) { float a,b,c,x,y,ancho,alto;
int i; //glClear (GL_COLOR_BUFFER_BIT);
a=rand()%10; a=a/10; b=rand()%10;
b=b/10; c=rand()%10; c=c/10;
glColor3f (a, b, c); glLoadIdentity ();
gluLookAt (2.0,0.0,6.0,2.0,0.0, 0.0, 0.0, 5, 0.0); //glBegin(GL_TRIANGLES);
glPushMatrix(); glTranslatef(-0.5,-2.3,0.0); switch(opcion)
{ case 0: glBegin(GL_LINE_LOOP);
for (i=0;i glVertex3f(rand()%6,rand()%6,1); glEnd();
break; case 1: glBegin(GL_LINE_LOOP);
for (i=0;i glVertex3f(rand()%6,rand()%6,1); glEnd(); glBegin(GL_LINE_LOOP);
x = rand ()% 6;
y = rand ()% 6;
width = rand ()% 6;
glVertex3f (width , y, 1);
glVertex3f (width, height, 1);
glVertex3f (x, height, 1);
glEnd ();
break;
default:
break;}
glPopMatrix ();
glFlush ();}
void mouse (int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON)
{if (state == GLUT_DOWN)
{option + +;
if (option == 3)
option = 0;
}
}
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void idle()
{
int j;
for(j=0;j
display();
<2;i++)
}
void timer(int value)
{
int j;
<3;i++)
glutTimerFunc(5000,timer,1);
glClear (GL_COLOR_BUFFER_BIT);
for(j=0;j
display();
}
int main (int argc, char ** argv) {
glutInit (& argc, argv);
glutInitDisplayMode (GLUT_SINGLE and
knot vector. The curves and NURBS surfaces are generalizations of B-strip and Bezier curves and surfaces, the primary difference is the loading of the control points which makes NURBS curves rational
(the B-strip non-rational are a special case of rational B-strip). While the NURBS curves are developed in only one direction parametric, usually called
s
or
or
, NURBS surfaces are developed in two parametric directions, called s
and
or
t u v
and
.
Evaluating a NURBS curve at various parameter values, the curve can be represented in two or three-dimensional Cartesian space. Also evaluating a NURBS surface at various values \u200b\u200bof the two parameters, the surface can be represented in Cartesian space.
curves and NURBS surfaces are useful for a number of reasons:
tune
are invariant under transformations as well as its perspectives.
offer a common mathematical form for standard analytical shapes (eg, conics) and free-form shape.
provide the flexibility to design a large variety of ways.
reduce consumption memory when the store is (compared to simpler methods).
can be evaluated reasonably fast by numerically stable and accurate algorithms.
are generalizations of B-strips and non-rational curves and surfaces non-rational and rational Bezier.
<30000000;j++){}
The knot vector is a sequence of parameter values \u200b\u200bthat determine where and how the control points affect the NURBS curve. The number of knots is always equal to the number of control points of the curve degree plus one. Necessary only for internal calculations, knots are not usually helpful to users of modeling software. For So many uses that model nodes are not editable or even visible. More recent versions of NURBS software (eg, Maya and Autodesk 3D rhinoceros) allow interactive editing of knot positions, but it is significantly less intuitive editing of control points.
The knot vector values \u200b\u200bmust be in ascending order, so (0, 0, 1, 2, 3) is valid while (0, 0, 2, 1, 3) is not. Individual values \u200b\u200bare not significant knot themselves, only the ratios of the difference between the knot value the subject. Therefore, the knot vectors (0, 0, 1, 2, 3), (0, 0, 2, 4, 6) and (1, 1, 2, 3, 4) all produce the same curve. Also, do not allow any value of the node having so many duplicates that happens more times than the degree of the curve. For the first-degree NURBS, each knot is paired with a control point.
The order of a NURBS curve defines the number of checkpoints coming that influence any given control point. The curve is represented mathematically by a polynomial of degree one less than the order of the curve. Therefore, the second-order curves (which are represented by linear polynomials) are called linear curves, the third-order curves are called quadratic curves, and the fourth-order curves are called cubic curves. The number of control points must be greater than or equal to the order of the curve.
In practice, cubic curves are the ones used most commonly. The curves of fifth-and sixth-order are sometimes useful, especially for derivatives, but curves of higher orders are almost never used because lead to internal numerical problems and tend to require disproportionately large calculation times.
While non-rational curves are not sufficient to represent a circle, these are the NURBS control points for a uniformed the circle in the xy plane
<30000000;j++){}
:
x y z
weight
1 0 0 1 1 1 0 ? 2 / 2
0 1 0?
1 1 0
- ? 2 / 2
- ?
- 1 0 0
- 1
? 1
? 1 0
? 2 / 2
0
| a ? A | 0 ? 2 / 2 | ||
|---|---|---|---|
| 1 0 0 | a | ||
1
0 comments:
Post a Comment