~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tv/tv_zbuff_surf.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 z-buffered surfaces;
  3 simple surface types defined in tv.h
  4 **/
  5 #include <math.h>
  6 #include <values.h>
  7 #include <tina/sys.h>
  8 #include <tina/sysfuncs.h>
  9 #include <tina/math.h>
 10 #include <tina/mathfuncs.h>
 11 #include <tina/vision.h>
 12 #include <tina/visionfuncs.h>
 13 #include <tina/tv.h>
 14 #include <tina/tvfuncs.h>
 15 
 16 void   *cylinder_make(Vec3 centre, Vec3 axis, double radius, double length)
 17 {
 18     Cylinder *c = ts_ralloc(Cylinder);
 19 
 20     c->centre = centre;
 21     vec3_basis(axis, vec3_ey(), &c->ex, &c->ey, &c->ez);
 22     c->radius = radius;
 23     c->length = length;
 24     return ((void *) c);
 25 }
 26 
 27 Vec3    cylinder_point(Cylinder * c, double u, double v)
 28 {
 29     Vec3    p = {Vec3_id};
 30 
 31     p = vec3_sum4(c->centre, vec3_times(u, c->ez),
 32                   vec3_times(c->radius * cos(v), c->ex),
 33                   vec3_times(c->radius * sin(v), c->ey));
 34     return (p);
 35 }
 36 
 37 /* ARGSUSED quieten lint */
 38 Vec3    cylinder_normal(Cylinder * c, double u, double v)
 39 {
 40     Vec3    n = {Vec3_id};
 41 
 42     n = vec3_sum(vec3_times(cos(v), c->ex), vec3_times(sin(v), c->ey));
 43     return (n);
 44 }
 45 
 46 void    tv_zbuff_cylinder(Tv * tv, Cylinder * c)
 47 {
 48     Vec3    cylinder_point(Cylinder * c, double u, double v);
 49     Vec3    cylinder_normal(Cylinder * c, double u, double v);
 50 
 51     tv_zbuff_surf3(tv, cylinder_point, cylinder_normal, (void *) c,
 52                    0.0, 0.0, c->length, TWOPI, 4, 4, 10);
 53 }
 54 
 55 Vec3    sphere(double u, double v)
 56 {
 57     double  s = sin(u);
 58 
 59     return (vec3(s * cos(v), s * sin(v), cos(u)));
 60 }
 61 
 62 void   *quadric_make(Vec3 c, Mat3 s)
 63 {
 64     Quadric *q = ts_ralloc(Quadric);
 65 
 66     q->centre = c;
 67     q->s = s;
 68     q->g = mat3_transpose(mat3_inverse(s));
 69     return ((void *) q);
 70 }
 71 
 72 void    quadric_free(Quadric * q)
 73 {
 74     rfree((void *) q);
 75 }
 76 
 77 Vec3    quadric_point(Quadric * q, double u, double v)
 78 {
 79     return (vec3_sum(q->centre, mat3_vprod(q->s, sphere(u, v))));
 80 }
 81 
 82 Vec3    quadric_normal(Quadric * q, double u, double v)
 83 {
 84     return (vec3_unit(mat3_vprod(q->g, sphere(u, v))));
 85 }
 86 
 87 void    tv_zbuff_quadric(Tv * tv, Quadric * q)
 88 {
 89     tv_zbuff_surf3(tv, quadric_point, quadric_normal, (void *) q,
 90                    0.0, 0.0, PI, TWOPI, 4, 4, 10);
 91 }
 92 
 93 void    tv_zbuff_sphere(Tv * tv, Vec3 c, double r)
 94 {
 95     void   *q = quadric_make(c, mat3_times(r * r, mat3_unit()));
 96 
 97     tv_zbuff_surf3(tv, quadric_point, quadric_normal, (void *) q,
 98                    0.0, 0.0, PI, TWOPI, 4, 4, 10);
 99     quadric_free(q);
100 }
101 void   *torus_make(Vec3 centre, Vec3 axis, double r1, double r2)
102 {
103     Torus  *t = ts_ralloc(Torus);
104 
105     t->centre = centre;
106     vec3_basis(axis, vec3_ey(), &t->ex, &t->ey, &t->ez);
107     t->r1 = r1;
108     t->r2 = r2;
109     return ((void *) t);
110 }
111 
112 Vec3    torus_point(Torus * t, double u, double v)
113 {
114     Vec3    p = {Vec3_id};
115     Vec3    er = {Vec3_id};
116 
117     er = vec3_sum(vec3_times(cos(u), t->ex), vec3_times(sin(u), t->ey));
118     p = vec3_sum4(t->centre, vec3_times(t->r1, er),
119                   vec3_times(t->r2 * cos(v), er),
120                   vec3_times(t->r2 * sin(v), t->ez));
121     return (p);
122 }
123 
124 Vec3    torus_normal(Torus * t, double u, double v)
125 {
126     Vec3    n = {Vec3_id};
127     Vec3    er = {Vec3_id};
128 
129     er = vec3_sum(vec3_times(cos(u), t->ex), vec3_times(sin(u), t->ey));
130     n = vec3_sum(vec3_times(cos(v), er), vec3_times(sin(v), t->ez));
131     return (n);
132 }
133 
134 void    tv_zbuff_torus(Tv * tv, Quadric * t)
135 {
136     tv_zbuff_surf3(tv, torus_point, torus_normal, (void *) t,
137                    0.0, 0.0, TWOPI, TWOPI, 4, 4, 10);
138 }
139 
140 void   *quad3_make(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4)
141 {
142     Quad3  *q = ts_ralloc(Quad3);
143 
144     q->p1 = p1;
145     q->p2 = p2;
146     q->p3 = p3;
147     q->p4 = p4;
148     q->n = vec3_unit(vec3_cross(vec3_diff(p2, p1),
149                                 vec3_diff(p4, p1)));
150     return ((void *) q);
151 }
152 
153 Vec3    quad3_point(Quad3 * q, double u, double v)
154 {
155     Vec3    x1 = {Vec3_id};
156     Vec3    x2 = {Vec3_id};
157 
158     x1 = vec3_sum(vec3_times(1.0 - u, q->p1), vec3_times(u, q->p2));
159     x2 = vec3_sum(vec3_times(1.0 - u, q->p4), vec3_times(u, q->p3));
160     return (vec3_sum(vec3_times(1.0 - v, x1), vec3_times(v, x2)));
161 }
162 
163 /* ARGSUSED quieten lint */
164 Vec3    quad3_normal(Quad3 * q, double u, double v)
165 {
166     return (q->n);
167 }
168 
169 void    tv_zbuff_quad3(Tv * tv, Quad3 * q)
170 {
171     tv_zbuff_surf3(tv, quad3_point, quad3_normal, (void *) q,
172                    0.0, 0.0, 1.0, 1.0, 1, 1, 10);
173 }
174 
175 void    tv_zbuff_tri3(Tv * tv, Vec3 p1, Vec3 p2, Vec3 p3)
176 {
177     Quad3  *q = quad3_make(p1, p2, p3, p3);
178 
179     tv_zbuff_quad3(tv, q);
180     rfree((void *) q);
181 }
182 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.