[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

## curve3.c Example C Language Program

```/*
Example: curve3.c```
```This program draw a Bezier curve segment using curveit().  The
Cardinal spline and B-spline curve segments could be drawn in a
similar manner (only the basis matrix would be different).
*/```
```#include <gl/gl.h>
#include <gl/device.h>```
`#define BEZIER 1`
```Matrix beziermatrix = {
{ -1.0,  3.0, -3.0,  1.0 } ,
{  3.0, -6.0,  3.0,  0.0 },
{ -3.0,  3.0,  0.0,  0.0 },
{  1.0,  0.0,  0.0,  0.0 }};```
```Matrix geom1 = {
{ 50.0, 150.0, 0.0, 1.0},
{ 150.0, 225.0, 0.0, 1.0},
{ 150.0, 075.0, 0.0, 1.0},
{ 250.0, 150.0, 0.0, 1.0}};```
```Matrix precisionmatrix = {
{ 6.0/8000.0,       0.0,    0.0, 0.0},
{ 6.0/8000.0, 2.0/400.0,    0.0, 0.0},
{ 1.0/8000.0, 1.0/400.0, 1/20.0, 0.0},
{        0.0,       0.0,    0.0, 1.0}};```
```main()
{
int dev,val;    ```
`  initialize();    `
```  while (TRUE) {
if (qtest()) {
if (dev == ESCKEY) {
gexit();
exit();
}
else if (dev == REDRAW) {
reshapeviewport();
drawcurve();
}
}
}```
`}`
```initialize()
{
int gid;    ```
```  prefposition(200, 500, 100, 400);
gid = winopen("curve3");
winconstraints();
qdevice(ESCKEY);
qdevice(REDRAW);
qenter(REDRAW,gid);
}```
```drawcurve()
{
int i,xx,yy;```
```  color(BLACK);
clear();
pushmatrix();                /* the current transformation
* matrix on the matrix stack is
* saved */```
```  multmatrix(geom1);           /* the product of the current
* transformation matrix and the
* matrix containing the
* control points becomes the new
* current transformation matrix */```
```  multmatrix(beziermatrix);    /* the product of the basis
* matrix and the current
* transformation matrix becomes
* the new current transformation
* matrix */```
```  multmatrix(precisionmatrix); /* the product of the precision
* matrix and the current
* transformation matrix
* becomes the new current
* transformation matrix */```
```  move(0.0,0.0,0.0);           /* this command must be issued
* so that the correct first
* point is generated by the
* curveit command */```
```  color(RED);
curveit(20);                 /* a curve consisting of 20 line
* segments is drawn */```
```  popmatrix();                 /* the original transformation
* matrix is restored */```
```    /* show the control points */
color(WHITE);
for ( i = 0 ; i < 4 ; i++ )  {
for ( xx = -2 ; xx < 2 ; xx++) {
for ( yy = -2 ; yy < 2 ; yy++) {
pnt2( geom1[i][0] + (Coord) xx , geom1[i][1] + (Coord) yy);
}
}
}```
`}`
```/*
Changes:
- the control points are drawn on the screen
- added winconstraints() so the window could be resized
- changes the geometry so it would be centered
from:
Matrix geom1 = {
{ 100.0, 100.0, 0.0, 1.0},
{ 200.0, 200.0, 0.0, 1.0},
{ 200.0,   0.0, 0.0, 1.0},
{ 300.0, 100.0, 0.0, 1.0}};
to:
Matrix geom1 = {
{ 100.0, 150.0, 0.0, 1.0},
{ 200.0, 225.0, 0.0, 1.0},
{ 200.0, 075.0, 0.0, 1.0},
{ 300.0, 150.0, 0.0, 1.0}};
*/```

### Related Information

The curveit subroutine, the multmatrix subroutine.

Drawing Curves in GL3.2 Version 4 for AIX: Programming Concepts.

[ Previous | Next | Contents | Glossary | Home | Search ]