1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* cone.c - routines for making cones |
9 |
– |
* |
10 |
– |
* 2/12/86 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "standard.h" |
11 |
|
|
12 |
|
#include "object.h" |
45 |
|
register OBJREC *o; |
46 |
|
int getxf; |
47 |
|
{ |
51 |
– |
double fabs(), sqrt(); |
48 |
|
int sgn0, sgn1; |
49 |
|
register CONE *co; |
50 |
|
|
56 |
|
|
57 |
|
co->ca = o->oargs.farg; |
58 |
|
/* get radii */ |
59 |
< |
if (o->otype == OBJ_CYLINDER || o->otype == OBJ_TUBE) { |
59 |
> |
if (o->otype == OBJ_CYLINDER | o->otype == OBJ_TUBE) { |
60 |
|
if (o->oargs.nfargs != 7) |
61 |
|
goto argcerr; |
62 |
|
if (co->ca[6] < -FTINY) { |
66 |
|
co->ca[6] = -co->ca[6]; |
67 |
|
} else if (co->ca[6] <= FTINY) |
68 |
|
goto raderr; |
69 |
+ |
co->p0 = 0; co->p1 = 3; |
70 |
|
co->r0 = co->r1 = 6; |
71 |
|
} else { |
72 |
|
if (o->oargs.nfargs != 8) |
79 |
|
else sgn1 = 0; |
80 |
|
if (sgn0+sgn1 == 0) |
81 |
|
goto raderr; |
82 |
< |
if (sgn0 < 0 || sgn1 < 0) { |
82 |
> |
if (sgn0 < 0 | sgn1 < 0) { |
83 |
|
objerror(o, o->otype==OBJ_RING?USER:WARNING, |
84 |
|
"negative radii"); |
85 |
|
o->otype = o->otype == OBJ_CONE ? |
87 |
|
} |
88 |
|
co->ca[6] = co->ca[6]*sgn0; |
89 |
|
co->ca[7] = co->ca[7]*sgn1; |
90 |
< |
co->r0 = 6; |
94 |
< |
co->r1 = 7; |
95 |
< |
if (fabs(co->ca[7] - co->ca[6]) <= FTINY) { |
90 |
> |
if (co->ca[7] - co->ca[6] > FTINY) { |
91 |
|
if (o->otype == OBJ_RING) |
92 |
+ |
co->p0 = co->p1 = 0; |
93 |
+ |
else { |
94 |
+ |
co->p0 = 0; co->p1 = 3; |
95 |
+ |
} |
96 |
+ |
co->r0 = 6; co->r1 = 7; |
97 |
+ |
} else if (co->ca[6] - co->ca[7] > FTINY) { |
98 |
+ |
if (o->otype == OBJ_RING) |
99 |
+ |
co->p0 = co->p1 = 0; |
100 |
+ |
else { |
101 |
+ |
co->p0 = 3; co->p1 = 0; |
102 |
+ |
} |
103 |
+ |
co->r0 = 7; co->r1 = 6; |
104 |
+ |
} else { |
105 |
+ |
if (o->otype == OBJ_RING) |
106 |
|
goto raderr; |
107 |
|
o->otype = o->otype == OBJ_CONE ? |
108 |
|
OBJ_CYLINDER : OBJ_TUBE; |
109 |
|
o->oargs.nfargs = 7; |
110 |
< |
co->r1 = 6; |
110 |
> |
co->p0 = 0; co->p1 = 3; |
111 |
> |
co->r0 = co->r1 = 6; |
112 |
|
} |
113 |
|
} |
114 |
|
/* get axis orientation */ |
115 |
< |
co->p0 = 0; |
106 |
< |
if (o->otype == OBJ_RING) { |
107 |
< |
if (co->ca[6] > co->ca[7]) { /* make r0 smaller */ |
108 |
< |
co->r0 = 7; |
109 |
< |
co->r1 = 6; |
110 |
< |
} |
111 |
< |
co->p1 = 0; |
115 |
> |
if (o->otype == OBJ_RING) |
116 |
|
VCOPY(co->ad, o->oargs.farg+3); |
117 |
< |
} else { |
118 |
< |
co->p1 = 3; |
119 |
< |
co->ad[0] = co->ca[3] - co->ca[0]; |
120 |
< |
co->ad[1] = co->ca[4] - co->ca[1]; |
117 |
< |
co->ad[2] = co->ca[5] - co->ca[2]; |
117 |
> |
else { |
118 |
> |
co->ad[0] = CO_P1(co)[0] - CO_P0(co)[0]; |
119 |
> |
co->ad[1] = CO_P1(co)[1] - CO_P0(co)[1]; |
120 |
> |
co->ad[2] = CO_P1(co)[2] - CO_P0(co)[2]; |
121 |
|
} |
122 |
|
co->al = normalize(co->ad); |
123 |
|
if (co->al == 0.0) |
125 |
|
/* compute axis and side lengths */ |
126 |
|
if (o->otype == OBJ_RING) { |
127 |
|
co->al = 0.0; |
128 |
< |
co->sl = co->ca[co->r1] - co->ca[co->r0]; |
129 |
< |
} else if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) { |
128 |
> |
co->sl = CO_R1(co) - CO_R0(co); |
129 |
> |
} else if (o->otype == OBJ_CONE | o->otype == OBJ_CUP) { |
130 |
|
co->sl = co->ca[7] - co->ca[6]; |
131 |
|
co->sl = sqrt(co->sl*co->sl + co->al*co->al); |
132 |
< |
} else { /* OBJ_CYLINDER || OBJ_TUBE */ |
132 |
> |
} else { /* OBJ_CYLINDER or OBJ_TUBE */ |
133 |
|
co->sl = co->al; |
134 |
|
} |
135 |
|
co->tm = NULL; |
143 |
|
objerror(o, USER, "bad # arguments"); |
144 |
|
raderr: |
145 |
|
objerror(o, USER, "illegal radii"); |
146 |
+ |
return NULL; /* pro forma return */ |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
+ |
void |
151 |
|
freecone(o) /* free memory associated with cone */ |
152 |
|
OBJREC *o; |
153 |
|
{ |
154 |
|
register CONE *co = (CONE *)o->os; |
155 |
|
|
156 |
< |
if (o->os == NULL) |
156 |
> |
if (co == NULL) |
157 |
|
return; |
158 |
|
if (co->tm != NULL) |
159 |
< |
free((char *)co->tm); |
160 |
< |
free(o->os); |
159 |
> |
free((void *)co->tm); |
160 |
> |
free((void *)co); |
161 |
|
o->os = NULL; |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
+ |
void |
166 |
|
conexform(co) /* get cone transformation matrix */ |
167 |
|
register CONE *co; |
168 |
|
{ |
169 |
< |
double sqrt(), fabs(); |
164 |
< |
double m4[4][4]; |
169 |
> |
MAT4 m4; |
170 |
|
register double d; |
171 |
|
register int i; |
172 |
|
|
173 |
< |
co->tm = (double (*)[4])malloc(sizeof(m4)); |
173 |
> |
co->tm = (FLOAT (*)[4])malloc(sizeof(MAT4)); |
174 |
|
if (co->tm == NULL) |
175 |
|
error(SYSTEM, "out of memory in conexform"); |
176 |
|
|
179 |
|
if (co->r0 == co->r1) |
180 |
|
d = 0.0; |
181 |
|
else |
182 |
< |
d = co->ca[co->r0] / (co->ca[co->r1] - co->ca[co->r0]); |
182 |
> |
d = CO_R0(co) / (CO_R1(co) - CO_R0(co)); |
183 |
|
for (i = 0; i < 3; i++) |
184 |
< |
co->tm[3][i] = d*(co->ca[co->p1+i] - co->ca[co->p0+i]) |
185 |
< |
- co->ca[co->p0+i]; |
184 |
> |
co->tm[3][i] = d*(CO_P1(co)[i] - CO_P0(co)[i]) |
185 |
> |
- CO_P0(co)[i]; |
186 |
|
|
187 |
|
/* rotate to positive z-axis */ |
188 |
|
setident4(m4); |
206 |
|
multmat4(co->tm, co->tm, m4); |
207 |
|
|
208 |
|
/* scale z-axis */ |
209 |
< |
setident4(m4); |
210 |
< |
if (co->p0 != co->p1 && co->r0 != co->r1) { |
211 |
< |
d = fabs(co->ca[co->r1] - co->ca[co->r0]); |
212 |
< |
m4[2][2] = d/co->al; |
209 |
> |
if (co->p0 != co->p1 & co->r0 != co->r1) { |
210 |
> |
setident4(m4); |
211 |
> |
m4[2][2] = (CO_R1(co) - CO_R0(co)) / co->al; |
212 |
> |
multmat4(co->tm, co->tm, m4); |
213 |
|
} |
209 |
– |
multmat4(co->tm, co->tm, m4); |
214 |
|
} |