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

Linux Cross Reference
Tina5/tina-tools/tinatool/draw/drawTv_zsurf.c

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_zsurf.c,v $
 36  * Date    :  $Date: 2003/10/01 16:02:47 $
 37  * Version :  $Revision: 1.2 $
 38  * CVS Id  :  $Id: drawTv_zsurf.c,v 1.2 2003/10/01 16:02:47 tony Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes : z-buffered surfaces;
 43  * simple surface types defined in tv.h
 44  *
 45  *********
 46 */
 47 
 48 #include "drawTv_zsurf.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/math/mathDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/geometry/geomDef.h>
 60 #include <tina/geometry/geomPro.h>
 61 #include <tinatool/draw/draw_TvDef.h>
 62 #include <tinatool/draw/draw_TvPro.h>
 63 
 64 void   *cylinder_make(Vec3 centre, Vec3 axis, double radius, double length)
 65 {
 66     Cylinder *c = ts_ralloc(Cylinder);
 67 
 68     c->centre = centre;
 69     vec3_basis(axis, vec3_ey(), &c->ex, &c->ey, &c->ez);
 70     c->radius = radius;
 71     c->length = length;
 72     return ((void *) c);
 73 }
 74 
 75 Vec3    cylinder_point(Cylinder * c, double u, double v)
 76 {
 77     Vec3    p = {Vec3_id};
 78 
 79     p = vec3_sum4(c->centre, vec3_times(u, c->ez),
 80                   vec3_times(c->radius * cos(v), c->ex),
 81                   vec3_times(c->radius * sin(v), c->ey));
 82     return (p);
 83 }
 84 
 85 /* ARGSUSED quieten lint */
 86 Vec3    cylinder_normal(Cylinder * c, double u, double v)
 87 {
 88     Vec3    n = {Vec3_id};
 89 
 90     n = vec3_sum(vec3_times(cos(v), c->ex), vec3_times(sin(v), c->ey));
 91     return (n);
 92 }
 93 
 94 void    tv_zbuff_cylinder(Tv * tv, Cylinder * c)
 95 {
 96     Vec3    cylinder_point(Cylinder * c, double u, double v);
 97     Vec3    cylinder_normal(Cylinder * c, double u, double v);
 98 
 99     tv_zbuff_surf3(tv, cylinder_point, cylinder_normal, (void *) c,
100                    0.0, 0.0, c->length, TWOPI, 4, 4, 10);
101 }
102 
103 Vec3    sphere(double u, double v)
104 {
105     double  s = sin(u);
106 
107     return (vec3(s * cos(v), s * sin(v), cos(u)));
108 }
109 
110 void   *quadric_make(Vec3 c, Mat3 s)
111 {
112     Quadric *q = ts_ralloc(Quadric);
113 
114     q->centre = c;
115     q->s = s;
116     q->g = mat3_transpose(mat3_inverse(s));
117     return ((void *) q);
118 }
119 
120 void    quadric_free(Quadric * q)
121 {
122     rfree((void *) q);
123 }
124 
125 Vec3    quadric_point(Quadric * q, double u, double v)
126 {
127     return (vec3_sum(q->centre, mat3_vprod(q->s, sphere(u, v))));
128 }
129 
130 Vec3    quadric_normal(Quadric * q, double u, double v)
131 {
132     return (vec3_unit(mat3_vprod(q->g, sphere(u, v))));
133 }
134 
135 void    tv_zbuff_quadric(Tv * tv, Quadric * q)
136 {
137     tv_zbuff_surf3(tv, quadric_point, quadric_normal, (void *) q,
138                    0.0, 0.0, PI, TWOPI, 4, 4, 10);
139 }
140 
141 void    tv_zbuff_sphere(Tv * tv, Vec3 c, double r)
142 {
143     void   *q = quadric_make(c, mat3_times(r * r, mat3_unit()));
144 
145     tv_zbuff_surf3(tv, quadric_point, quadric_normal, (void *) q,
146                    0.0, 0.0, PI, TWOPI, 4, 4, 10);
147     quadric_free(q);
148 }
149 void   *torus_make(Vec3 centre, Vec3 axis, double r1, double r2)
150 {
151     Torus  *t = ts_ralloc(Torus);
152 
153     t->centre = centre;
154     vec3_basis(axis, vec3_ey(), &t->ex, &t->ey, &t->ez);
155     t->r1 = r1;
156     t->r2 = r2;
157     return ((void *) t);
158 }
159 
160 Vec3    torus_point(Torus * t, double u, double v)
161 {
162     Vec3    p = {Vec3_id};
163     Vec3    er = {Vec3_id};
164 
165     er = vec3_sum(vec3_times(cos(u), t->ex), vec3_times(sin(u), t->ey));
166     p = vec3_sum4(t->centre, vec3_times(t->r1, er),
167                   vec3_times(t->r2 * cos(v), er),
168                   vec3_times(t->r2 * sin(v), t->ez));
169     return (p);
170 }
171 
172 Vec3    torus_normal(Torus * t, double u, double v)
173 {
174     Vec3    n = {Vec3_id};
175     Vec3    er = {Vec3_id};
176 
177     er = vec3_sum(vec3_times(cos(u), t->ex), vec3_times(sin(u), t->ey));
178     n = vec3_sum(vec3_times(cos(v), er), vec3_times(sin(v), t->ez));
179     return (n);
180 }
181 
182 void    tv_zbuff_torus(Tv * tv, Quadric * t)
183 {
184     tv_zbuff_surf3(tv, torus_point, torus_normal, (void *) t,
185                    0.0, 0.0, TWOPI, TWOPI, 4, 4, 10);
186 }
187 
188 void   *quad3_make(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4)
189 {
190     Quad3  *q = ts_ralloc(Quad3);
191 
192     q->p1 = p1;
193     q->p2 = p2;
194     q->p3 = p3;
195     q->p4 = p4;
196     q->n = vec3_unit(vec3_cross(vec3_diff(p2, p1),
197                                 vec3_diff(p4, p1)));
198     return ((void *) q);
199 }
200 
201 Vec3    quad3_point(Quad3 * q, double u, double v)
202 {
203     Vec3    x1 = {Vec3_id};
204     Vec3    x2 = {Vec3_id};
205 
206     x1 = vec3_sum(vec3_times(1.0 - u, q->p1), vec3_times(u, q->p2));
207     x2 = vec3_sum(vec3_times(1.0 - u, q->p4), vec3_times(u, q->p3));
208     return (vec3_sum(vec3_times(1.0 - v, x1), vec3_times(v, x2)));
209 }
210 
211 /* ARGSUSED quieten lint */
212 Vec3    quad3_normal(Quad3 * q, double u, double v)
213 {
214     return (q->n);
215 }
216 
217 void    tv_zbuff_quad3(Tv * tv, Quad3 * q)
218 {
219     tv_zbuff_surf3(tv, quad3_point, quad3_normal, (void *) q,
220                    0.0, 0.0, 1.0, 1.0, 1, 1, 10);
221 }
222 
223 void    tv_zbuff_tri3(Tv * tv, Vec3 p1, Vec3 p2, Vec3 p3)
224 {
225     Quad3  *q = quad3_make(p1, p2, p3, p3);
226 
227     tv_zbuff_quad3(tv, q);
228     rfree((void *) q);
229 }
230 

~ [ 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.