home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src-glu / nurbs.h < prev    next >
C/C++ Source or Header  |  1996-05-27  |  6KB  |  239 lines

  1. /* nurbs.h */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: nurbs.h,v 1.5 1996/02/20 20:48:43 brianp Exp $
  26.  
  27. $Log: nurbs.h,v $
  28.  * Revision 1.5  1996/02/20  20:48:43  brianp
  29.  * applied Bogdan's February 20th patches (fixes patch cracks)
  30.  *
  31.  * Revision 1.4  1996/01/26  15:32:08  brianp
  32.  * added Bogdan Sikorski's January 25th and 26th patches
  33.  *
  34.  * Revision 1.3  1995/11/03  14:13:19  brianp
  35.  * Bogdan's November 3, 1995 updates
  36.  *
  37.  * Revision 1.2  1995/07/28  21:36:49  brianp
  38.  * changed all GLUenum to GLenum
  39.  *
  40.  * Revision 1.1  1995/07/28  17:38:30  brianp
  41.  * Initial revision
  42.  *
  43.  */
  44.  
  45.  
  46. /*
  47.  * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
  48.  * See README2 for more info.
  49.  */
  50.  
  51.  
  52. #include <stdlib.h>
  53. #include "gluP.h"
  54.  
  55. #define EPSILON 1e-06 /* epsilon for double precision compares */
  56.  
  57. typedef enum
  58. {
  59.     GLU_NURBS_CURVE, GLU_NURBS_SURFACE, GLU_NURBS_TRIM, GLU_NURBS_NO_TRIM,
  60.     GLU_NURBS_TRIM_DONE, GLU_NURBS_NONE
  61. } GLU_nurbs_enum;
  62.  
  63. typedef enum
  64. {
  65.     GLU_TRIM_NURBS, GLU_TRIM_PWL
  66. } GLU_trim_enum;
  67.  
  68. typedef struct
  69. {
  70.     GLint    sknot_count;
  71.     GLfloat    *sknot;
  72.     GLint    tknot_count;
  73.     GLfloat    *tknot;
  74.     GLint    s_stride;
  75.     GLint    t_stride;
  76.     GLfloat    *ctrlarray;
  77.     GLint    sorder;
  78.     GLint    torder;
  79.     GLint    dim;
  80.     GLenum    type;
  81. } surface_attribs;
  82.  
  83. typedef struct
  84. {
  85.     surface_attribs    geom;
  86.     surface_attribs    color;
  87.     surface_attribs    texture;
  88.     surface_attribs    normal;
  89. } nurbs_surface;
  90.  
  91. typedef struct
  92. {
  93.     GLint            knot_count;
  94.     GLfloat            *knot;
  95.     GLint            stride;
  96.     GLfloat            *ctrlarray;
  97.     GLint            order;
  98.     GLint            dim;
  99.     GLenum            type;
  100. } curve_attribs;
  101.  
  102. typedef struct
  103. {
  104.     GLint            pt_count;
  105.     GLfloat            *ctrlarray;
  106.     GLint            stride;
  107.     GLint            dim;
  108.     GLenum            type;
  109. } pwl_curve_attribs;
  110.  
  111. typedef struct
  112. {
  113.     curve_attribs    geom;
  114.     curve_attribs    color;
  115.     curve_attribs    texture;
  116.     curve_attribs    normal;
  117. } nurbs_curve;
  118.  
  119. typedef struct trim_list_str
  120. {
  121.     GLU_trim_enum            trim_type;
  122.     union
  123.     {
  124.         pwl_curve_attribs    pwl_curve;
  125.         curve_attribs        nurbs_curve;
  126.     }                        curve;
  127.     struct trim_list_str    *next;
  128. } trim_list;
  129.  
  130. typedef struct seg_trim_str
  131. {
  132.     GLfloat             *points;
  133.     GLint                pt_cnt,seg_array_len;
  134.     struct seg_trim_str    *next;
  135. } trim_segments;
  136.  
  137. typedef struct nurbs_trim_str
  138. {
  139.     trim_list                *trim_loop;
  140.     trim_segments            *segments;
  141.     struct nurbs_trim_str    *next;
  142. } nurbs_trim;
  143.  
  144. typedef struct
  145. {
  146.     GLfloat model[16],proj[16],viewport[4];
  147. } culling_and_sampling_str;
  148.  
  149. struct GLUnurbsObj {
  150.     GLboolean        culling;
  151.     GLenum            error;
  152.     void            (*error_callback)( GLenum err );
  153.     GLenum            display_mode;
  154.     GLU_nurbs_enum    nurbs_type;
  155.     GLboolean        auto_load_matrix;
  156.     culling_and_sampling_str
  157.                     sampling_matrices;
  158.     GLfloat            sampling_tolerance;
  159.     nurbs_surface    surface;
  160.     nurbs_curve        curve;
  161.     nurbs_trim        *trim;
  162. };
  163.  
  164. typedef struct
  165. {
  166.     GLfloat        *knot;
  167.     GLint        nknots;
  168.     GLfloat        *unified_knot;
  169.     GLint        unified_nknots;
  170.     GLint        order;
  171.     GLint        t_min,t_max;
  172.     GLint        delta_nknots;
  173.     GLboolean    open_at_begin,open_at_end;
  174.     GLfloat        *new_knot;
  175.     GLfloat        *alpha;
  176. } knot_str_type;
  177.  
  178. typedef struct
  179. {
  180.     GLfloat    *geom_ctrl;
  181.     GLint    geom_s_stride,geom_t_stride;
  182.     GLfloat    **geom_offsets;
  183.     GLint    geom_s_pt_cnt,geom_t_pt_cnt;
  184.     GLfloat    *color_ctrl;
  185.     GLint    color_s_stride,color_t_stride;
  186.     GLfloat    **color_offsets;
  187.     GLint    color_s_pt_cnt,color_t_pt_cnt;
  188.     GLfloat *normal_ctrl;
  189.     GLint    normal_s_stride,normal_t_stride;
  190.     GLfloat    **normal_offsets;
  191.     GLint    normal_s_pt_cnt,normal_t_pt_cnt;
  192.     GLfloat    *texture_ctrl;
  193.     GLint    texture_s_stride,texture_t_stride;
  194.     GLfloat    **texture_offsets;
  195.     GLint    texture_s_pt_cnt,texture_t_pt_cnt;
  196.     GLint    s_bezier_cnt,t_bezier_cnt;
  197. } new_ctrl_type;
  198.  
  199. void call_user_error( GLUnurbsObj *nobj, GLenum error );
  200.  
  201. GLenum test_knot(GLint nknots, GLfloat *knot, GLint order);
  202.  
  203. GLenum explode_knot(knot_str_type *the_knot);
  204.  
  205. GLenum calc_alphas(knot_str_type *the_knot);
  206.  
  207. GLenum calc_new_ctrl_pts(GLfloat *ctrl,GLint stride,knot_str_type *the_knot,
  208.     GLint dim,GLfloat **new_ctrl,GLint *ncontrol);
  209.  
  210. GLenum glu_do_sampling_2D(GLUnurbsObj *nobj, GLfloat *new_ctrl,GLint n_ctrl,
  211.     GLint order,GLint dim,GLint **factors);
  212.  
  213. GLenum glu_do_sampling_3D(GLUnurbsObj *nobj, new_ctrl_type *new_ctrl,
  214.     int **sfactors, GLint **tfactors);
  215.  
  216. GLboolean fine_culling_test_2D(GLUnurbsObj *nobj, GLfloat *ctrl, GLint n_ctrl,
  217.     GLint stride, GLint dim);
  218.  
  219. GLboolean fine_culling_test_3D(GLUnurbsObj *nobj, GLfloat *ctrl,
  220.     GLint s_n_ctrl, GLint t_n_ctrl, GLint s_stride, GLint t_stride, GLint dim);
  221.  
  222. void do_nurbs_curve( GLUnurbsObj *nobj);
  223.  
  224. void do_nurbs_surface( GLUnurbsObj *nobj);
  225.  
  226. GLenum patch_trimming(GLUnurbsObj *nobj,new_ctrl_type *new_ctrl,
  227.     GLint *sfactors, GLint *tfactors);
  228.  
  229. void collect_unified_knot(knot_str_type *dest, knot_str_type *src,
  230.     GLfloat maximal_min_knot, GLfloat minimal_max_knot);
  231.  
  232. GLenum select_knot_working_range(GLUnurbsObj *nobj,knot_str_type *geom_knot,
  233.     knot_str_type *color_knot, knot_str_type *normal_knot,
  234.     knot_str_type *texture_knot);
  235.  
  236. void free_unified_knots(knot_str_type *geom_knot, knot_str_type *color_knot,
  237.     knot_str_type *normal_knot, knot_str_type *texture_knot);
  238.  
  239.