00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #include <string.h>
00043 #include <math.h>
00044 #include "mensagem.h"
00045 #include "memvirtu.h"
00046 #include "lowparam.h"
00047 #include "lowsolid.h"
00048 #include "eulerops.h"
00049 #include "mancommd.h"
00050 #include "shpshape.h"
00051 #include "disdispl.h"
00052
00053 void MSD_execNameMakeSphere(void)
00054 {
00055 char name[30];
00056 float r;
00057 int n;
00058
00059 while (3 != sscanf(restbuf, "%s %d %f", name, &n, &r))
00060 {
00061 printf("Objeto N_div Raio\n");
00062 if (!lineins("? "))
00063 {
00064 return;
00065 }
00066 }
00067 MSD_highNameMakeSphere(name, n, r);
00068 }
00069
00070 void MSD_highNameMakeSphere(char *name, int n, real r)
00071 {
00072 Id sn;
00073
00074 if (MSD_getSolidIdFromName(name) != -1)
00075 {
00076 fprintf(stderr, MEN_SolidoJaExiste, NAM_MakeSphere, name);
00077 return;
00078 }
00079 if ((sn = MSD_highMakeSphere(n, r)) != -1)
00080 {
00081 MSD_highName(sn, name, SOLID);
00082 }
00083 }
00084
00085 #ifdef __Extended_Version
00086 void MSD_execMakeSphere(void)
00087 {
00088 float r;
00089 int n;
00090
00091 while (2 != sscanf(restbuf, "%d %f", &n, &r))
00092 {
00093 printf("N_div Raio\n");
00094 if (!lineins("? "))
00095 {
00096 return;
00097 }
00098 }
00099 printf("Id = %d\n", MSD_highMakeSphere(n, r));
00100 }
00101
00102 #endif
00103
00104 Id MSD_highMakeSphere(int n, real r)
00105 {
00106 SPTYPE optr;
00107 Id sn;
00108
00109 sn = MSD_getMaxSolidId();
00110 if ((r != 0.0) && (n > 1))
00111 {
00112 if ((optr = MSD_lowMakeSphere(sn, r, n, 2 * n)) != SNIL)
00113 {
00114 MSD_lowDisplayMonitor('o', optr, GNIL);
00115 return(sn);
00116 }
00117 }
00118 fprintf(stderr, MEN_ParametrosIncorretos, NAM_MakeSphere);
00119 return(-1);
00120 }
00121
00122 SPTYPE MSD_lowMakeSphere(Id sn, real r, int nver, int nhor)
00123 {
00124 SPTYPE s;
00125 int flag = 1, GOld;
00126 static vector vect = { 0.0, 1.0, 0.0, 0.0 };
00127
00128 if ((nver < 2) || (nhor < 2))
00129 {
00130 return(SNIL);
00131 }
00132 GOld = Gdoinversion;
00133 Gdoinversion = FALSE;
00134 CommandCount++;
00135 if ((s = MSD_lowMVSF(sn, maxf++, maxv++, maxd++, 0.0, 0.0, r)) == SNIL)
00136 {
00137 flag = 0;
00138 }
00139 if (MSD_lowMakeArc(sn, maxf - 1, maxv - 1, 0.0, 0.0, r, 0.0, 0.0, 180.0, nver) == ERROR)
00140 {
00141 flag = 0;
00142 }
00143 if (MSD_lowMakeRotationalSweep(s, nhor, 2, 0, vect) == ERROR)
00144 {
00145 flag = 0;
00146 }
00147 if (flag == 1)
00148 {
00149 MSD_lowSetNormal(s, TRUE);
00150 MSD_lowSetEdgeAngle(s);
00151 MSD_lowSetInfo(s);
00152 }
00153 if (flag == 0)
00154 {
00155 MSD_lowHardRemove(s);
00156 }
00157 if (flag == 1)
00158 {
00159 MSD_lowAddEulerOp(s, HARDREM, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0);
00160 }
00161 Gdoinversion = GOld;
00162 return(flag == 0 ? SNIL : s);
00163 }
00164
00165
00166
00167
00168
00169
00170 char MSD_lowMakeArc(Id s, Id f, Id v, real cx, real cz, real rad, real \
00171 h, real phi1, real phi2, int n)
00172 {
00173 real x, z, angle, inc;
00174 Id prev;
00175 int i;
00176
00177 angle = phi1 * PI / 180.0;
00178 inc = (phi2 - phi1) * PI / (180.0 * n);
00179 maxv = MSD_getMaxVertexId(MSD_getSolid(s));
00180 for (prev = v, i = 0; i < n; ++i)
00181 {
00182 angle += inc;
00183 x = cx + sin(angle) * rad;
00184 z = cz + cos(angle) * rad;
00185 if (MSD_highMEV(s, f, prev, maxv, x, h, z) == ERROR)
00186 {
00187 return(ERROR);
00188 }
00189 prev = maxv++;
00190 }
00191 return(SUCCESS);
00192 }
00193
00194 SPTYPE MSD_lowMakeCircle(Id sn, real cx, real cz, real rad, real h, int n)
00195 {
00196 SPTYPE s;
00197 int flag = 1;
00198
00199 if ((s = MSD_lowMVSF(sn, maxf++, maxv++, maxd++, cx, h, cz + rad)) == SNIL)
00200 {
00201 flag = 0;
00202 }
00203 if (MSD_lowMakeArc(sn, maxf - 1, maxv - 1, cx, cz, rad, h, 0.0, (n - 1) * 360.0 / n, n - 1) == ERROR)
00204 {
00205 flag = 0;
00206 }
00207 if (MSD_highMEF(sn, maxv - n, maxv - 1, maxf - 1, maxf) == ERROR)
00208 {
00209 flag = 0;
00210 }
00211 maxf++;
00212 if (flag == 1)
00213 {
00214 MSD_lowSetNormal(s, TRUE);
00215 MSD_lowSetEdgeAngle(s);
00216 MSD_lowSetInfo(s);
00217 }
00218 if (flag == 0)
00219 {
00220 MSD_lowHardRemove(s);
00221 }
00222 return(flag == 0 ? SNIL : s);
00223 }