home *** CD-ROM | disk | FTP | other *** search
Wrap
#define True 1 #define False 0 #include <fcntl.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <unistd.h> #include <math.h> /* Declaracion de funciones globales */ void ChoseFont(char *); void PutsFont(char); void SetScale(void); void ScaleTexture(char); void SetTexture(void); void SetRotate(void); void PutsRotate(void); void PutsDescription(void); void PutsTranslate(void); void SetTranslate(void); void SetFrames(void); void PutsTranslateLineal(void); void SetAmbiente(void); void PutsStartUnion(void); void PutsEndObject(void); void PutsDefCamera(void); /* Debido a la gran cantidad de variables existentes intercambiables */ /* entre las distintas funciones y dada la simpleza del programa se */ /* han declarado todas las variables globales. */ char Buffer[255], ObjectName[255], IncludeFile[255], Select, Texture; double x, y, angle, LongIdeal, Separacion, TotalAngle, StartAngle; double Scale, CamPos, Zoom, Radio, RadioF, w, LongPag, CamIdeal = -100.0; char rotado, letra, Operacion; int pointer, cont, Long1, Long2, Lineas, ContLineas; FILE *Temp, *out; char font1, font2, Color[255], FileName[255]; char TextoI[255] = "", TextoS[255] = ""; double CamOffset, ZoomOffset; int Frames, ContFrames; double StartAngle, AngleOffset, Rx, Ry, Rz, RxOffset, RyOffset, RzOffset; char Fx[255], Fy[255], Fz[255], Aspect[10]; double Tx, Ty, Tz, TxOffset, TyOffset, TzOffset; unsigned sFx, sFy, sFz, sColor, sTextoS; double ScaleF = 1.2; char fontF = '1', Ambiente, TextName[255]; char IncludeName[255], Color2[255], Texture2, Select2; double CamOffsetX, CamOffsetY, CamX, CamY; double Rix, Riy, Riz, RiOffsetX, RiOffsetY, RiOffsetZ; int ContText, NumText, YetMulti = False, YetFont = False; double Z, EndZ; char RayT, ext[4]; int main(void) { int Menu(void); void PonerAmbiente(void); void DosLineas(void); void DosLineasY(void); void LineaCircular(void); void LineasTexto(void); int ErrorLevel; /* Abrimos un fichero donde contener los datos (circulo.pov) */ puts(""); highvideo(); cprintf("Rotate Fonts & Objects for POV & Poly Ray ver. 1.1"); lowvideo(); puts(""); /* Presentamos el Menu */ ErrorLevel = Menu(); if (ErrorLevel != 0) return ErrorLevel; /* Ponemos una camara y dos luces */ if (Ambiente == '4') strcpy(ext, "inc"); else { if (RayT == '1') strcpy(ext, "pov"); else strcpy(ext, "pi"); } if (Frames == 1 || (RayT == '2') ) { printf ("\nIntroduce el nombre del fichero de salida [circulo.%s] : ", ext); gets(Buffer); if (Buffer[0]) strcpy(FileName, Buffer); else sprintf(FileName, "circulo.%s", ext); _fmode = O_TEXT; if ((out = fopen(FileName, "w+")) == NULL) { printf("Error no puedo abrir el fichero de salida.\n"); return 1; } /* Comienzan los calculos */ switch (Operacion) { case '1': case '2': { PutsDescription(); PutsTranslate(); PonerAmbiente(); DosLineas(); } break; case 'Y': { PutsDescription(); PutsTranslate(); PonerAmbiente(); DosLineasY(); } break; case 'E': case 'C': { PutsDescription(); PutsTranslate(); PonerAmbiente(); LineaCircular(); } break; case 'L': { PutsDescription(); LineasTexto(); } break; } fclose(out); /* Mensajillo de exito */ printf("\nFichero generado ---> %s", FileName); } else { if ( Frames > 1) { printf("\n"); for (ContFrames = 1; ContFrames <= Frames; ContFrames++) { sprintf(FileName, "frame%d.pov", ContFrames); _fmode = O_TEXT; if ((out = fopen(FileName, "w+")) == NULL) { printf("Error no puedo abrir el fichero de salida.\n"); return 1; } /* Comienzan los calculos */ switch (Operacion) { case '1': case '2': { PutsDescription(); PutsTranslate(); PonerAmbiente(); DosLineas(); } break; case 'Y': { PutsDescription(); PutsTranslate(); PonerAmbiente(); DosLineasY(); } break; case 'E': case 'C': { PutsDescription(); PutsTranslate(); PonerAmbiente(); LineaCircular(); } break; case 'L': { PutsDescription(); LineasTexto(); } break; } printf("Generado fichero --> %s", FileName); gotoxy(1, wherey()); if (RayT == '1') { CamX += CamOffsetX; /* Simples acercamientos de camará */ CamY += CamOffsetY; CamPos += CamOffset; Zoom += ZoomOffset; Rx += RxOffset; /* Rotaciones de un objeto */ Ry += RyOffset; Rz += RzOffset; Rix += RiOffsetX; /* Rotaciones de un objeto */ Riy += RiOffsetY; Riz += RiOffsetZ; } fclose(out); } } /* Fin del if */ } /* fin del else */ printf("\n\n"); if (Operacion == 'L') /* Borramos los temporales */ { fclose(Temp); unlink("Temp.$$$"); } return 0; } int Menu(void) { int font_x; unsigned ObjectSize; /* Opciones del modo de operacion */ printf("\n (1) Un circulo vertical\n (2) Dos semicirculos verticales\n (Y) Dos semicirculos horizontales\n (C) Una linea en circulo\n (E) Una linea en espiral\n (L) Fonts lineales"); printf("\n\nEligue orientacion: (1/2/Y/C/E/L) [C]: "); Operacion = toupper(getc(stdin)); if (Operacion == '\n') Operacion = 'C'; else getc(stdin); printf("\n (1) Pov-Ray ver 2.x\n (2) PolyRay ver 1.7"); printf("\n\nEligue raytracer: (1/2) [2]: "); RayT = getc(stdin); if (RayT == '\n') RayT = '2'; else getc(stdin); /* Opciones especificas de cada modo de operacion */ switch (Operacion) { case '1': case 'Y': case '2': { /* Peticion de datos importantes */ printf ("Introduce el texto a circular por arriba [Hello] : "); gets(Buffer); if (Buffer[0]) strcpy(TextoS, Buffer); else strcpy(TextoS, "Hello"); ChoseFont(&font1); if (Operacion == '2' || Operacion == 'Y') { printf ("Introduce el texto a circular por abajo [World] : "); gets(Buffer); if (Buffer[0]) strcpy(TextoI, Buffer); else strcpy(TextoI, "World"); ChoseFont(&font2); } SetScale(); printf("Introduce el radio [20] : "); gets(Buffer); if (Buffer[0]) Radio = atof(Buffer); else Radio = 20; SetFrames(); SetTexture(); SetRotate(); SetTranslate(); } break; case 'E': case 'C': { /* Peticion de datos importantes */ printf ("Introduce el texto a circular [Hello World] : "); gets(Buffer); if (Buffer[0]) strcpy(TextoS, Buffer); else strcpy(TextoS, "Hello World"); ChoseFont(&font1); if (Operacion == 'E') { printf("Introduce el radio Inicial [20] : "); gets(Buffer); if (Buffer[0]) Radio = atof(Buffer); else Radio = 20; printf("Introduce el radio Final [30] : "); gets(Buffer); if (Buffer[0]) RadioF = atof(Buffer); else RadioF = 30; printf("Introduce la Z Inicial [-5] : "); gets(Buffer); if (Buffer[0]) Z = atof(Buffer); else Z = -5; printf("Introduce la Z Final [10] : "); gets(Buffer); if (Buffer[0]) EndZ = atof(Buffer); else EndZ = 10; } else { printf("Introduce el radio [20] : "); gets(Buffer); if (Buffer[0]) Radio = atof(Buffer); else Radio = 20; } SetScale(); printf ("Introduce el angulo total de recorrido [315] : "); gets(Buffer); if (Buffer[0]) TotalAngle = atof(Buffer); else TotalAngle = 315; printf ("Introduce el angulo de comienzo [225] : "); gets(Buffer); if (Buffer[0]) StartAngle = atof(Buffer); else StartAngle = 225; SetFrames(); SetTexture(); SetRotate(); SetTranslate(); } break; case 'L': { /* Habilitamos un fichero temporal para guardar */ /* las distintas lineas de texto. */ _fmode = O_BINARY; if ((Temp = fopen("temp.$$$", "w+")) == NULL) { printf("Error no puedo abrir el fichero temporal.\n"); return 2; } /* Peticion de datos importantes */ printf ("Cuantas lineas de texto quieres introducir [1] : "); gets(Buffer); if (Buffer[0]) Lineas = atoi(Buffer); else Lineas = 1; SetFrames(); for (ContLineas = 1; ContLineas <= Lineas; ContLineas ++) { printf ("\nIntroduce la linea de texto%d [Linea %d] : ", ContLineas, ContLineas); gets(Buffer); if (Buffer[0]) strcpy(TextoS, Buffer); else sprintf(TextoS, "Linea %d", ContLineas); ChoseFont(&font1); if (font1 == '2') /* Estratagema */ font2 = '2'; SetScale(); printf("Pixels de separacion entre letras [2]: "); gets(Buffer); if (Buffer[0]) Separacion = atof(Buffer); else Separacion = 2; if (font1 == '1') font_x = 5; else font_x = 8; SetTexture(); SetRotate(); SetTranslate(); /* Swappeada al Temporal en binario */ ObjectSize = strlen(ObjectName)+1; fwrite(&ObjectSize, sizeof(unsigned), 1, Temp); fwrite(ObjectName, ObjectSize, 1, Temp); fwrite(&Rx, sizeof(Rx), 1, Temp); fwrite(&Ry, sizeof(Ry), 1, Temp); fwrite(&Rz, sizeof(Rz), 1, Temp); fwrite(&Tx, sizeof(Tx), 1, Temp); fwrite(&Ty, sizeof(Ty), 1, Temp); fwrite(&Tz, sizeof(Tz), 1, Temp); fwrite(&Rix, sizeof(double), 1, Temp); fwrite(&Riy, sizeof(double), 1, Temp); fwrite(&Riz, sizeof(double), 1, Temp); fwrite(&RxOffset, sizeof(RxOffset), 1, Temp); fwrite(&RyOffset, sizeof(RyOffset), 1, Temp); fwrite(&RzOffset, sizeof(RzOffset), 1, Temp); fwrite(&TxOffset, sizeof(TxOffset), 1, Temp); fwrite(&TyOffset, sizeof(TyOffset), 1, Temp); fwrite(&TzOffset, sizeof(TzOffset), 1, Temp); fwrite(&RiOffsetX, sizeof(double), 1, Temp); fwrite(&RiOffsetY, sizeof(double), 1, Temp); fwrite(&RiOffsetZ, sizeof(double), 1, Temp); sFx = strlen(Fx)+1; sFy = strlen(Fy)+1; sFz = strlen(Fz)+1; fwrite(&sFx, sizeof(sFx), 1, Temp); fwrite(&sFy, sizeof(sFy), 1, Temp); fwrite(&sFz, sizeof(sFz), 1, Temp); fwrite(Fx, sFx, 1, Temp); fwrite(Fy, sFy, 1, Temp); fwrite(Fz, sFz, 1, Temp); LongPag = (font_x + Separacion) * Scale * strlen(TextoS); fwrite(&Texture, sizeof(char), 1, Temp); fwrite(&Select, sizeof(char), 1, Temp); sColor = strlen(Color)+1; fwrite(&sColor, sizeof(unsigned), 1, Temp); fwrite(Color, sColor, 1, Temp); fwrite(&font1, sizeof(char), 1, Temp); sTextoS = strlen(TextoS)+1; fwrite(&sTextoS, sizeof(unsigned), 1, Temp); fwrite(TextoS, sTextoS, 1, Temp); fwrite(&Scale, sizeof(Scale), 1, Temp); fwrite(&LongPag, sizeof(LongPag), 1, Temp); } } break; } /* Opciones generales */ SetAmbiente(); if (Ambiente != '4') { printf ("Posicion horizontal de la camara [0]: "); gets(Buffer); if (Buffer[0]) CamX = atof(Buffer); else CamX = 0; printf ("Posicion vertical la camara [0]: "); gets(Buffer); if (Buffer[0]) CamY = atof(Buffer); else CamY = 0; printf ("Lejanía de la camara [%d]: ", (int) CamIdeal); gets(Buffer); if (Buffer[0]) CamPos = atof(Buffer); else CamPos = CamIdeal; printf ("Factor de zoom: [1] : "); gets(Buffer); if (Buffer[0]) Zoom = atof(Buffer); else Zoom = 1; if (Frames > 1) { printf ("Desplazamiento horizontal de la camara [0]: "); gets(Buffer); if (Buffer[0]) CamOffsetX = atof(Buffer); else CamOffsetX = 0; printf ("Desplazamiento vertical de la camara [0]: "); gets(Buffer); if (Buffer[0]) CamOffsetY = atof(Buffer); else CamOffsetY = 0; printf ("Acercamiento de la camara [0]: ", CamOffset); gets(Buffer); if (Buffer[0]) CamOffset = atof(Buffer); else CamOffset = 0; printf ("Incremento del factor de zoom [0] : "); gets(Buffer); if (Buffer[0]) ZoomOffset = atof(Buffer); else ZoomOffset = 0; } if (Frames > 1) strcpy(Aspect, "1.6"); else strcpy(Aspect, "4/3"); printf ("Aspect Ratio (320 x 200 = 1.6, 640 x 480 = 4 / 3) [%s]: ", Aspect); gets(Buffer); if (Buffer[0]) strcpy(Aspect, Buffer); } Long1 = strlen(TextoS); Long2 = strlen(TextoI); return 0; } void PonerAmbiente(void) { /* Ponemos los distintos includes */ if (Ambiente != '4') { if (RayT == '1') { fprintf(out, "#include \"colors.inc\"\n"); fprintf(out, "#include \"textures.inc\"\n"); fprintf(out, "#include \"stones.inc\"\n"); } else { fprintf(out, "include \"dat\\colors.inc\"\n"); fprintf(out, "include \"dat\\texture.inc\"\n"); if (Frames > 1) { fprintf(out, "start_frame 0\n"); fprintf(out, "end_frame %d\n\n", Frames-1); } } if ( font1 == '1' || font2 == '1') if (RayT == '1') fprintf(out, "#include \"chars.inc\"\n\n"); if ( font1 == '2' || font2 == '2') if (RayT == '1') fprintf(out, "#include \"fntrnd.inc\"\n\n"); if ( font1 == '3' || font2 == '3' || RayT == '2' || YetFont == True) if (RayT == '1') fprintf(out, "#include \"%s\"\n\n", IncludeFile); else fprintf(out, "include \"%s\"\n\n", IncludeFile); if (Texture == '2' || YetMulti == True) if (RayT == '1') fprintf(out, "#include \"%s\"\n\n", TextName); else fprintf(out, "include \"%s\"\n\n", TextName); switch (Ambiente) { case '1': { if (RayT == '1') fprintf(out, "#include \"%s\"\n\n", IncludeName); else fprintf(out, "include \"%s\"\n\n", IncludeName); PutsDefCamera(); } break; case '2': { if (RayT == '1') { fprintf(out, "#declare PosCamX = %f\n", CamX); fprintf(out, "#declare PosCamY = %f\n", CamY); fprintf(out, "#declare PosCamZ = %f\n", CamPos); fprintf(out, "#declare Zoom = %f\n\n", Zoom); fprintf(out, "#include \"%s\"\n\n", IncludeName); } else { fprintf(out, "define PosCamX %f+(frame*%f) \n", CamX, CamOffsetX); fprintf(out, "define PosCamY %f+(frame*%f) \n", CamY, CamOffsetY); fprintf(out, "define PosCamZ %f+(frame*%f) \n", CamPos, CamOffset); fprintf(out, "define Zoom %f+(frame*%f) \n\n", Zoom, ZoomOffset); fprintf(out, "include \"%s\"\n\n", IncludeName); } } break; case '3': { if (RayT == '1') { fprintf(out, "#declare PosCamX = %f\n", CamX); fprintf(out, "#declare PosCamY = %f\n", CamY); fprintf(out, "#declare PosCamZ = %f\n", CamPos); fprintf(out, "#declare Zoom = %f\n\n", Zoom); } else { fprintf(out, "define PosCamX %f+(frame*%f) \n", CamX, CamOffsetX); fprintf(out, "define PosCamY %f+(frame*%f) \n", CamY, CamOffsetY); fprintf(out, "define PosCamZ %f+(frame*%f) \n", CamPos, CamOffset); fprintf(out, "define Zoom %f+(frame*%f) \n\n", Zoom, ZoomOffset); } PutsDefCamera(); } break; } /* Fin del Switch */ } /* End del If */ } void DosLineas(void) { /* Texto 1 */ ContText=0; pointer=0; PutsStartUnion(); fprintf(out, " // Texto superior: %s\n\n", TextoS); for (cont = 0; cont < Long1; cont ++ ) { if ( TextoS[pointer] != ' ' ) { letra = TextoS[pointer]; fprintf(out, " object {\n"); PutsFont(font1); if (Operacion == '2') angle = cont*(M_PI/Long1); else angle = cont*((2*M_PI)/Long1); x = Radio * cos(M_PI - angle); y = Radio * sin(angle); if (RayT == '2') { fprintf(out, " rotate <Rix, Riy, Riz>\n"); fprintf(out, " translate <%f, %f, -1.1>\n", x, y); } else { fprintf(out, " rotate <%f, %f, %f>\n", Rix, Riy, Riz); fprintf(out, " translate <%f, %f, -1.1>\n", x, y); } ScaleTexture('1'); fprintf(out, " }\n\n"); if (cont < (Long1-1)) PutsEndObject(); } pointer++; ContText++; } ScaleTexture('2'); PutsRotate(); fprintf(out, " }// Fin de la union del texto superior.\n"); /* Texto 2*/ ContText=0; if (Operacion == '2') { pointer=Long2 - 1; PutsStartUnion(); fprintf(out, " // Texto inferior: %s\n\n", TextoI); for (cont = 0; cont < Long2; cont ++ ) { if ( TextoI[pointer] != ' ' ) { letra = TextoI[pointer]; fprintf(out, " object {\n"); PutsFont(font2); angle = cont*(M_PI/Long2); x = Radio * cos(-angle); y = Radio * sin(-angle); if (RayT == '2') { fprintf(out, " rotate <Rix, Riy, Riz>\n"); fprintf(out, " translate <%f, %f, -1.1>\n", x, y); } else { fprintf(out, " rotate <%f, %f, %f>\n", Rix, Riy, Riz); fprintf(out, " translate <%f, %f, -1.1>\n", x, y); } if (Select2 == '1' && RayT == '1') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); if (Texture2 == '1') fprintf(out, " texture { %s }\n", Color2); else fprintf(out, " pigment { %s }\n", Color2); } else { if (Select2 == '1' && RayT == '2') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); fprintf(out, " %s\n", Color2); } } fprintf(out, " }\n\n"); if (cont < (Long2-1)) PutsEndObject(); } pointer--; ContText++; } if (Select2 == '1' && RayT == '1') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); if (Texture2 == '1') fprintf(out, " texture { %s }\n", Color2); else fprintf(out, " pigment { %s }\n", Color2); } else { if (Select2 == '1' && RayT == '2') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); fprintf(out, " %s\n", Color2); } } PutsRotate(); fprintf(out, "} // Fin de la union del texto inferior.\n"); } /* Fin del if Lineas */ } void DosLineasY(void) { /* Texto 1 */ ContText=0; pointer=Long1 - 1; PutsStartUnion(); fprintf(out, " // Texto superior: %s\n\n", TextoS); for (cont = 0; cont < Long1; cont ++ ) { if ( TextoS[pointer] != ' ' ) { letra = TextoS[pointer]; fprintf(out, " object {\n"); PutsFont(font1); angle = cont*(M_PI/Long1); x = Radio * cos(- angle); y = Radio * sin(- angle); if ( RayT == '1') { fprintf(out, " rotate <%f, ", Rix); fprintf(out, "%f, %f>\n", (double) - 90 + (angle*180/M_PI) + Riy, Riz); fprintf(out, " translate <%f, 0, %f>\n", x, y); } else { fprintf(out, " rotate <Rix, "); fprintf(out, "Riy + %f, Riz>\n", (double) - 90 + (angle*180/M_PI)); fprintf(out, " translate <%f, 0, %f>\n", x, y); } ScaleTexture('1'); fprintf(out, " }\n\n"); if (cont < (Long1-1)) PutsEndObject(); } pointer--; ContText++; } ScaleTexture('2'); PutsRotate(); fprintf(out, " } // Fin de la union del texto superior.\n"); /* Texto 2*/ ContText=0; pointer=Long2 - 1; PutsStartUnion(); fprintf(out, " // Texto inferior: %s\n\n", TextoI); for (cont = 0; cont < Long2; cont ++ ) { if ( TextoI[pointer] != ' ' ) { letra = TextoI[pointer]; fprintf(out, " object {\n"); PutsFont(font2); angle = cont*(M_PI/Long2); x = Radio * cos(M_PI - angle); y = Radio * sin(angle); if ( RayT == '1') { fprintf(out, " rotate <%f, ", Rix); fprintf(out, "%f, %f>\n", (double) 90 + (angle*180/M_PI) + Riy, Riz); fprintf(out, " translate <%f, 0, %f>\n", x, y); } else { fprintf(out, " rotate <Rix, "); fprintf(out, "Riy+%f, Riz>\n", (double) 90 + (angle*180/M_PI)); fprintf(out, " translate <%f, 0, %f>\n", x, y); } if (Select2 == '1' && RayT == '1') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); if (Texture2 == '1') fprintf(out, " texture { %s }\n", Color2); else fprintf(out, " pigment { %s }\n", Color2); } else { if (Select2 == '1' && RayT == '2') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); fprintf(out, " %s\n", Color2); } } fprintf(out, " }\n\n"); if (cont < (Long2-1)) PutsEndObject(); } pointer--; ContText++; } if (Select2 == '2' && RayT == '1') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); if (Texture2 == '1') fprintf(out, " texture { %s }\n", Color2); else fprintf(out, " pigment { %s }\n", Color2); } else { if (Select2 == '2' && RayT == '2') { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); fprintf(out, " %s\n", Color2); } } PutsRotate(); fprintf(out, "} // Fin de la union del texto inferior.\n"); } void LineaCircular(void) { double IncRadio; double z = -1.1; double IncZ; if (Operacion == 'E') { IncRadio = (RadioF-Radio)/Long1; IncZ = (EndZ -Z)/Long1; } ContText=0; pointer=0; PutsStartUnion(); fprintf(out, " // Texto : %s\n\n", TextoS); for (cont = 0; cont < Long1; cont ++ ) { if ( TextoS[pointer] != ' ' ) { letra = TextoS[pointer]; fprintf(out, " object {\n"); PutsFont(font1); angle = cont*( TotalAngle * (M_PI / 180) / Long1); w = StartAngle * (M_PI / 180); x = Radio * cos( w - angle ); y = Radio * sin( w - angle ); if (RayT == '1') { fprintf(out, " rotate <%f, %f,", Rix, Riy); fprintf(out, "%f", (double) (135 - (angle*180/M_PI) ) + Riz ); fprintf(out, ">\n"); } else { fprintf(out, " rotate <Rix, Riy, "); fprintf(out, "Riz + %f", (double) (135 - (angle*180/M_PI)) ); fprintf(out, ">\n"); } fprintf(out, " translate <%f, %f, %f>\n", x, y, z); ScaleTexture('1'); fprintf(out, " }\n\n"); if (cont < (Long1-1)) PutsEndObject(); if (Operacion == 'E') { Radio+=IncRadio; z+=IncZ; } } pointer++; ContText++; } ScaleTexture('2'); PutsRotate(); fprintf(out, "} // Fin de la union del texto.\n"); } void LineasTexto(void) { long FilePos, New; double a, b, c; unsigned ObjectSize; PutsTranslateLineal(); /* Ponemos todas las definiciones de formulas */ PonerAmbiente(); rewind(Temp); /* "Revovinamos" el fichero temporal */ y = CamPos / (1 + Lineas) ; /* Offset de y */ for (ContLineas = 1; ContLineas <= Lineas; ContLineas ++) { fread(&ObjectSize, sizeof(unsigned), 1, Temp); fread(ObjectName, ObjectSize, 1, Temp); FilePos = ftell(Temp); fread(&Rx, sizeof(Rx), 1, Temp); fread(&Ry, sizeof(Ry), 1, Temp); fread(&Rz, sizeof(Rz), 1, Temp); fread(&Tx, sizeof(Tx), 1, Temp); fread(&Ty, sizeof(Ty), 1, Temp); fread(&Tz, sizeof(Tz), 1, Temp); fread(&Rix, sizeof(double), 1, Temp); fread(&Riy, sizeof(double), 1, Temp); fread(&Riz, sizeof(double), 1, Temp); fread(&RxOffset, sizeof(RxOffset), 1, Temp); fread(&RyOffset, sizeof(RyOffset), 1, Temp); fread(&RzOffset, sizeof(RzOffset), 1, Temp); fread(&TxOffset, sizeof(TxOffset), 1, Temp); fread(&TyOffset, sizeof(TyOffset), 1, Temp); fread(&TzOffset, sizeof(TzOffset), 1, Temp); fread(&RiOffsetX, sizeof(double), 1, Temp); fread(&RiOffsetY, sizeof(double), 1, Temp); fread(&RiOffsetZ, sizeof(double), 1, Temp); New = ftell(Temp); fseek(Temp, FilePos, SEEK_SET); a = Rx + RxOffset; b = Ry + RyOffset; c = Rz + RzOffset; fwrite(&a, sizeof(Rx), 1, Temp); fwrite(&b, sizeof(Ry), 1, Temp); fwrite(&c, sizeof(Rz), 1, Temp); a = Tx + TxOffset; b = Ty + TyOffset; c = Tz + TzOffset; fwrite(&a, sizeof(Tx), 1, Temp); fwrite(&b, sizeof(Ty), 1, Temp); fwrite(&c, sizeof(Tz), 1, Temp); a = Rix + RiOffsetX; b = Riy + RiOffsetY; c = Riy + RiOffsetZ; fwrite(&a, sizeof(double), 1, Temp); fwrite(&b, sizeof(double), 1, Temp); fwrite(&c, sizeof(double), 1, Temp); fseek(Temp, New, SEEK_SET); fread(&sFx, sizeof(unsigned), 1, Temp); fread(&sFy, sizeof(unsigned), 1, Temp); fread(&sFz, sizeof(unsigned), 1, Temp); strcpy(Fx, ""); strcpy(Fy, ""); strcpy(Fz, ""); fread(Fx, sFx, 1, Temp); fread(Fy, sFy, 1, Temp); fread(Fz, sFz, 1, Temp); fread(&Texture, sizeof(char), 1, Temp); fread(&Select, sizeof(char), 1, Temp); strcpy(Color, ""); fread(&sColor, sizeof(unsigned), 1, Temp); fread(Color, sColor, 1, Temp); fread(&font1, sizeof(char), 1, Temp); strcpy(TextoS, ""); fread(&sTextoS, sizeof(unsigned), 1, Temp); fread(&TextoS, sTextoS, 1, Temp); fread(&Scale, sizeof(Scale), 1, Temp); fread(&LongPag, sizeof(LongPag), 1, Temp); ContText=0; Long1 = strlen(TextoS); pointer=0; /* Apuntamos al primer carcater */ PutsStartUnion(); fprintf(out, " // Texto : %s\n\n", TextoS); for (cont = 0; cont < Long1; cont ++ ) { if ( TextoS[pointer] != ' ' ) { letra = TextoS[pointer]; fprintf(out, " object {\n"); PutsFont(font1); x = LongPag * Scale; if (RayT == '1') fprintf(out, " rotate <%f, %f, %f>\n", Rix, Riy, Riz); else fprintf(out, " rotate <Rix%d, Riy%d, Riz%d>\n", ContLineas, ContLineas, ContLineas); fprintf(out, " translate <%f, %f, -1.1>\n", (- x / 2.0) + cont * ( (LongPag / Long1) * Scale), (-CamPos / 2.0) + (y * ContLineas) ); ScaleTexture('1'); fprintf(out, " }\n\n"); if (cont < (Long1-1)) PutsEndObject(); } pointer++; ContText++; } ScaleTexture('2'); PutsRotate(); fprintf(out, "} // Fin de la union del texto.\n"); } } void ChoseFont(char *font) { char dOn[255]; if (RayT == '1') { printf("\n (1) Chars (mayusculas)\n (2) Font Round\n (3) Objeto definido por el usuario\n\nEligue tipo de letra (1/2/3) [%c]: ", fontF); (*font) = getc(stdin); if ((*font) == '\n') *font = fontF; else { getc(stdin); fontF = *font; } if ((*font) == '3') { printf("Introduce el nombre del fichero incluido [shapes.inc]: "); gets(Buffer); if (Buffer[0]) strcpy(IncludeFile, Buffer); else strcpy(IncludeFile, "shapes.inc"); printf("Introduce el nombre del objeto [Paraboloid_X]: "); gets(Buffer); if (Buffer[0]) strcpy(ObjectName, Buffer); else strcpy(ObjectName, "Paraboloid_X"); } } else { printf("\n (1) True type extraida con el GetFont.bat\n (2) Objeto definido por el usuario\n\nEligue tipo de letra (1/2) [%c]: ", fontF); (*font) = getc(stdin); if ((*font) == '\n') *font = fontF; else { getc(stdin); fontF = *font; } if ((*font) == '2') { printf("Introduce el nombre del fichero incluido [shapes.inc]: "); gets(Buffer); if (Buffer[0]) strcpy(IncludeFile, Buffer); else strcpy(IncludeFile, "shapes.inc"); printf("Introduce el nombre del objeto [sphere <0,0,0>, 6]: "); gets(Buffer); if (Buffer[0]) strcpy(ObjectName, Buffer); else strcpy(ObjectName, "sphere <0,0,0>, 6"); } else { if (!YetFont) { printf("Introduce el nombre del fichero incluido [arial.inc]: "); gets(Buffer); if (Buffer[0]) strcpy(IncludeFile, Buffer); else strcpy(IncludeFile, "arial.inc"); YetFont = True; } } } } void PutsFont(char font) { if (RayT == '1') { switch (font) { case '1': { letra = toupper(letra); switch (letra) { case '$': fprintf(out, " char_Dol\n"); break; case '(': fprintf(out, " char_LPar\n"); break; case ')': fprintf(out, " char_RPar\n"); break; case '[': fprintf(out, " char_LSqu\n"); break; case ']': fprintf(out, " char_RSqu\n"); break; case '+': fprintf(out, " char_Plus\n"); break; case '-': fprintf(out, " char_Dash\n"); break; case '%': fprintf(out, " char_Perc\n"); break; case '^': fprintf(out, " char_Hat\n"); break; case '&': fprintf(out, " char_Amps\n"); break; case '*': fprintf(out, " char_Astr\n"); break; case '!': fprintf(out, " char_ExclPt\n"); break; case '#': fprintf(out, " char_Num\n"); break; case '@': fprintf(out, " char_AtSign\n"); break; default: fprintf(out, " char_%c\n", letra); break; } } break; case '2': fprintf(out, " Font_Round_%c\n", letra); break; case '3': fprintf(out, " %s\n", ObjectName); break; } } else { if (font == '1') fprintf(out, " char_%c\n", letra); else fprintf(out, " %s\n", ObjectName); } } void ScaleTexture(char Site) { if (Select == Site) { fprintf(out, " scale <%f, %f, %f>\n", Scale, Scale, Scale); if (RayT == '1') { if (Texture == '1') fprintf(out, " texture { %s }\n", Color); else if (Texture == '0') fprintf(out, " pigment { %s }\n", Color); else fprintf(out, " texture { Texture%d }\n", ContText % NumText); } else { if (Texture != '2') fprintf(out, " %s\n", Color); else fprintf(out, " Texture%d \n", ContText % NumText); } } } void SetTexture(void) { char Tmp[255]; if (RayT == '1') { printf ("\n (0) Color\n (1) Textura\n (2) Multitextura\n\nSuperficie en los objetos [0] : "); Texture = getc(stdin); if (Texture == '\n') Texture = '0'; else getc(stdin); if (Texture == '1') strcpy(Tmp, "Jade"); else strcpy(Tmp, "Red"); if (!(Texture == '2')) { printf ("Ahora el nombre del color o la textura de las letras [%s] : ", Tmp); gets(Buffer); if (Buffer[0]) strcpy(Color, Buffer); else strcpy(Color, Tmp); } else { if (!YetMulti) { if (RayT == '1') strcpy(Tmp, "multpov.inc"); else strcpy(Tmp, "multpoly.inc"); printf ("Introduce el nombre del fichero de texturas [%s]: ", Tmp); gets(Buffer); if (Buffer[0]) strcpy(TextName, Buffer); else strcpy(TextName, Tmp); printf ("Cuantas texturas hay en el fichero %s [12]: ", TextName); gets(Buffer); if (Buffer[0]) NumText = atoi(Buffer); else NumText = 12; YetMulti = True; } } } else { printf ("\n (1) Color o Textura\n (2) Multitextura\n\nSuperficie en los objetos [1] : "); Texture = getc(stdin); if (Texture == '\n') Texture = '1'; else getc(stdin); if (Texture == '1') { printf ("Ahora el nombre del color o la textura de las letras [matte_red] : ", Tmp); gets(Buffer); if (Buffer[0]) strcpy(Color, Buffer); else strcpy(Color, "matte_red"); } else { if (!YetMulti) { if (RayT == '1') strcpy(Tmp, "multpov.inc"); else strcpy(Tmp, "multpoly.inc"); printf ("Introduce el nombre del fichero de texturas [%s]: ", Tmp); gets(Buffer); if (Buffer[0]) strcpy(TextName, Buffer); else strcpy(TextName, Tmp); printf ("Cuantas texturas hay en el fichero %s [12]: ", TextName); gets(Buffer); if (Buffer[0]) NumText = atoi(Buffer); else NumText = 12; YetMulti = True; } } } printf ("\n (1) Individuales \n (2) Agrupadas\n\n Como quieres los objetos [1] : "); Select = getc(stdin); if (Select == '\n') Select = '1'; else getc(stdin); if (Operacion == '2' || Operacion == 'Y') { if (RayT == '2') { printf ("\n (1) Color o Textura\n (2) Multitextura\n\nSuperficie en los objetos [1] : "); Texture2 = getc(stdin); if (Texture2 == '\n') Texture2 = '1'; else getc(stdin); if (Texture2 == '1') { printf ("Ahora el nombre del color o la textura de las letras [matte_red] : ", Tmp); gets(Buffer); if (Buffer[0]) strcpy(Color2, Buffer); else strcpy(Color2, "matte_red"); } } else { printf ("\n (0) Color\n (1) Textura \n\nSuperficie en los objetos inferiores [%c] : ", Texture); Texture2 = getc(stdin); if (Texture2 == '\n') Texture2 = Texture; else getc(stdin); printf ("Ahora el nombre del color o la textura de las letras [%s] : ", Color); gets(Buffer); if (Buffer[0]) strcpy(Color2, Buffer); else strcpy(Color2, Color); } printf ("\n (1) Individuales \n (2) Agrupadas\n\n Como quieres los objetos [%c] : ", Select); Select2 = getc(stdin); if (Select2 == '\n') Select2 = Select; else getc(stdin); } } void SetRotate(void) { printf("\nAhora vamos a hacer un Rotate\n\n"); printf ("Introduce el angulo de comienzo en x [0]: "); gets(Buffer); if (Buffer[0]) Rx = atof(Buffer); else Rx = 0; printf ("Introduce el angulo de comienzo en y [0]: "); gets(Buffer); if (Buffer[0]) Ry = atof(Buffer); else Ry = 0; printf ("Introduce el angulo de comienzo en z [0]: "); gets(Buffer); if (Buffer[0]) Rz = atof(Buffer); else Rz = 0; if (Frames > 1) { printf ("Introduce el incremento del angulo en x [0]: "); gets(Buffer); if (Buffer[0]) RxOffset = atof(Buffer); else RxOffset = 0; printf ("Introduce el incremento del angulo en y [0]: "); gets(Buffer); if (Buffer[0]) RyOffset = atof(Buffer); else RyOffset = 0; printf ("Introduce el incremento del angulo en z [0]: "); gets(Buffer); if (Buffer[0]) RzOffset = atof(Buffer); else RzOffset = 0; } printf("\nAhora vamos a hacer un Rotate Interno\n\n"); printf ("Introduce el angulo de comienzo en x [0]: "); gets(Buffer); if (Buffer[0]) Rix = atof(Buffer); else Rix = 0; printf ("Introduce el angulo de comienzo en y [0]: "); gets(Buffer); if (Buffer[0]) Riy = atof(Buffer); else Riy = 0; printf ("Introduce el angulo de comienzo en z [0]: "); gets(Buffer); if (Buffer[0]) Riz = atof(Buffer); else Riz = 0; if (Frames > 1) { printf ("Introduce el incremento del angulo en x [0]: "); gets(Buffer); if (Buffer[0]) RiOffsetX = atof(Buffer); else RiOffsetX = 0; printf ("Introduce el incremento del angulo en y [0]: "); gets(Buffer); if (Buffer[0]) RiOffsetY = atof(Buffer); else RiOffsetY = 0; printf ("Introduce el incremento del angulo en z [0]: "); gets(Buffer); if (Buffer[0]) RiOffsetZ = atof(Buffer); else RiOffsetZ = 0; } } void PutsRotate(void) { if (RayT == '1') fprintf(out, " rotate <%f, %f, %f>\n", Rx, Ry, Rz); else { if (Operacion == 'L') fprintf(out, " rotate <Rx%d, Ry%d, Rz%d>\n", ContLineas, ContLineas, ContLineas); else fprintf(out, " rotate <Rx, Ry, Rz>\n"); } if (Frames > 1 ) { if (Operacion == 'L') fprintf(out, " translate <Fx%d, Fy%d, Fz%d>\n", ContLineas, ContLineas, ContLineas); else fprintf(out, " translate <Fx, Fy, Fz>\n"); } } void PutsDescription(void) { unsigned ObjectSize; /* Escribimos la descripcion en la cabecera del fichero destino. */ if (RayT == '2') fprintf(out, "define PI 3.141592645\n\n"); fprintf(out, "// Opciones de generacion del fichero %s\n", FileName); switch (Operacion) { case '1': case 'Y': case '2': { fprintf(out, "// Radio de la circunferencia: "); fprintf(out, "%f\n", Radio); fprintf(out, "// Texto superior: "); fprintf(out, "%s\n", TextoS); fprintf(out, "// Texto inferior: "); fprintf(out, "%s\n", TextoI); fprintf(out, "// Escala del font: "); fprintf(out, "%f\n", Scale); if ( font1 == '1' ) fprintf(out, "// Tipo de letra superior: Chars.\n"); else if (font1 == '2') fprintf(out, "// Tipo de letra superior : Font Round.\n"); else fprintf(out, "// Grafico superior definido por el usuario : %s.\n", ObjectName); if ( font2 == '1' ) fprintf(out, "// Tipo de letra inferior: Chars.\n"); else if (font2 == '2') fprintf(out, "// Tipo de letra inferior : Font Round.\n"); else fprintf(out, "// Grafico inferior definido por el usuario : %s.\n", ObjectName); if ( Texture == '1') fprintf(out, "// Textura del objeto: %s\n", Color); else fprintf(out, "// Color del objeto: %s\n", Color); } break; case 'E': case 'C': { if (Operacion == 'E') { fprintf(out, "// Radio Inicial de la circunferencia: "); fprintf(out, "%f\n", Radio); fprintf(out, "// Radio Final de la circunferencia: "); fprintf(out, "%f\n", RadioF); } else { fprintf(out, "// Radio de la circunferencia: "); fprintf(out, "%f\n", Radio); } fprintf(out, "// Texto: "); fprintf(out, "%s\n", TextoS); fprintf(out, "// Escala del font: "); fprintf(out, "%f\n", Scale); if ( font1 == '1' ) fprintf(out, "// Tipo de letra: Chars.\n"); else if (font1 == '2') fprintf(out, "// Tipo de letra: Font Round.\n"); else fprintf(out, "// Grafico definido por el usuario : %s.\n", ObjectName); if ( Texture == '1') fprintf(out, "// Textura del objeto: %s\n", Color); else fprintf(out, "// Color del objeto: %s\n", Color); fprintf(out, "// Angulo Total : "); fprintf(out, "%f\n", TotalAngle); fprintf(out, "// Angulo de cominenzo : "); fprintf(out, "%f\n", StartAngle); } break; case 'L': { rewind(Temp); /* "Revovinamos" el fichero temporal */ for (ContLineas = 1; ContLineas <= Lineas; ContLineas ++) { fread(&ObjectSize, sizeof(unsigned), 1, Temp); fread(ObjectName, ObjectSize, 1, Temp); fread(&Rx, sizeof(Rx), 1, Temp); fread(&Ry, sizeof(Ry), 1, Temp); fread(&Rz, sizeof(Rz), 1, Temp); fread(&Tx, sizeof(Tx), 1, Temp); fread(&Ty, sizeof(Ty), 1, Temp); fread(&Tz, sizeof(Tz), 1, Temp); fread(&Rix, sizeof(double), 1, Temp); fread(&Riy, sizeof(double), 1, Temp); fread(&Riz, sizeof(double), 1, Temp); fread(&RxOffset, sizeof(RxOffset), 1, Temp); fread(&RyOffset, sizeof(RyOffset), 1, Temp); fread(&RzOffset, sizeof(RzOffset), 1, Temp); fread(&TxOffset, sizeof(TxOffset), 1, Temp); fread(&TyOffset, sizeof(TyOffset), 1, Temp); fread(&TzOffset, sizeof(TzOffset), 1, Temp); fread(&RiOffsetX, sizeof(double), 1, Temp); fread(&RiOffsetY, sizeof(double), 1, Temp); fread(&RiOffsetZ, sizeof(double), 1, Temp); fread(&sFx, sizeof(unsigned), 1, Temp); fread(&sFy, sizeof(unsigned), 1, Temp); fread(&sFz, sizeof(unsigned), 1, Temp); strcpy(Fx, ""); strcpy(Fy, ""); strcpy(Fz, ""); fread(Fx, sFx, 1, Temp); fread(Fy, sFy, 1, Temp); fread(Fz, sFz, 1, Temp); fread(&Texture, sizeof(char), 1, Temp); fread(&Select, sizeof(char), 1, Temp); strcpy(Color, ""); fread(&sColor, sizeof(unsigned), 1, Temp); fread(Color, sColor, 1, Temp); fread(&font1, sizeof(char), 1, Temp); strcpy(TextoS, ""); fread(&sTextoS, sizeof(unsigned), 1, Temp); fread(TextoS, sTextoS, 1, Temp); fread(&Scale, sizeof(Scale), 1, Temp); fread(&LongPag, sizeof(LongPag), 1, Temp); fprintf(out, "// Linea %d: ", ContLineas); fprintf(out, "%s\n", TextoS); fprintf(out, "// Escala del font: "); fprintf(out, "%f\n", Scale); if ( font1 == '1' ) fprintf(out, "// Tipo de letra: Chars.\n"); else if (font1 == '2') fprintf(out, "// Tipo de letra: Font Round.\n"); else fprintf(out, "// Grafico definido por el usuario : %s.\n", ObjectName); if ( Texture == '1') fprintf(out, "// Textura del objeto: %s\n", Color); else fprintf(out, "// Color del objeto: %s\n", Color); fprintf(out, "// Separacion de la letras: "); fprintf(out, "%f\n", Separacion); fprintf(out, "// Longitud de linea: "); fprintf(out, "%f\n", LongPag); } /* Fin del For */ } break; } /* Fin del Case */ fprintf(out, "// Rotacion del objeto en X: "); fprintf(out, "%f\n", Rx); fprintf(out, "// Rotacion del objeto en Y: "); fprintf(out, "%f\n", Ry); fprintf(out, "// Rotacion del objeto en Z: "); fprintf(out, "%f\n", Rz); fprintf(out, "// Rotacion Interna del objeto en X: "); fprintf(out, "%f\n", Rix); fprintf(out, "// Rotacion Interna del objeto en Y: "); fprintf(out, "%f\n", Riy); fprintf(out, "// Rotacion Interna del objeto en Z: "); fprintf(out, "%f\n", Riz); fprintf(out, "// Posicion a priori del objeto en X: "); fprintf(out, "%f\n", Tx); fprintf(out, "// Posicion a priori del objeto en Y: "); fprintf(out, "%f\n", Ty); fprintf(out, "// Posicion a priori del objeto en Z: "); fprintf(out, "%f\n", Tz); fprintf(out, "// Lejania de la camara: "); fprintf(out, "%f\n", CamPos); fprintf(out, "// Factor de zoom: "); fprintf(out, "%f\n\n", Zoom); } void PutsTranslate(void) { if (Operacion == 'L' && Frames > 1 && RayT == '1') { fprintf(out, "#declare Tx%d = %f\n", ContLineas, Tx); fprintf(out, "#declare Ty%d = %f\n", ContLineas, Ty); fprintf(out, "#declare Tz%d = %f\n", ContLineas, Tz); fprintf(out, "#declare Fx%d = %s\n", ContLineas, Fx); fprintf(out, "#declare Fy%d = %s\n", ContLineas, Fy); fprintf(out, "#declare Fz%d = %s\n", ContLineas, Fz); } else { if (RayT == '1' && Frames > 1) { Tx += TxOffset; Ty += TyOffset; Tz += TzOffset; fprintf(out, "#declare Tx = %f\n", Tx); fprintf(out, "#declare Ty = %f\n", Ty); fprintf(out, "#declare Tz = %f\n", Tz); fprintf(out, "#declare Fx = %s\n", Fx); fprintf(out, "#declare Fy = %s\n", Fy); fprintf(out, "#declare Fz = %s\n", Fz); } fprintf(out, "\n"); } if (Operacion == 'L' && RayT == '2') { fprintf(out, "define Tx%d %f+(frame*%f)\n", ContLineas, Tx, TxOffset); fprintf(out, "define Ty%d %f+(frame*%f)\n", ContLineas, Ty, TyOffset); fprintf(out, "define Tz%d %f+(frame*%f)\n", ContLineas, Tz, TzOffset); fprintf(out, "define Rx%d %f+(frame*%f)\n", ContLineas, Rx, RxOffset); fprintf(out, "define Ry%d %f+(frame*%f)\n", ContLineas, Ry, RyOffset); fprintf(out, "define Rz%d %f+(frame*%f)\n", ContLineas, Rz, RzOffset); fprintf(out, "define Rix%d %f+(frame*%f)\n", ContLineas, Rix, RiOffsetX); fprintf(out, "define Riy%d %f+(frame*%f)\n", ContLineas, Riy, RiOffsetY); fprintf(out, "define Riz%d %f+(frame*%f)\n", ContLineas, Riz, RiOffsetZ); if (Frames > 1) { fprintf(out, "define Fx%d %s\n", ContLineas, Fx); fprintf(out, "define Fy%d %s\n", ContLineas, Fy); fprintf(out, "define Fz%d %s\n", ContLineas, Fz); } } else { if (RayT == '2') { fprintf(out, "define Tx %f+(frame*%f)\n", Tx, TxOffset); fprintf(out, "define Ty %f+(frame*%f)\n", Ty, TyOffset); fprintf(out, "define Tz %f+(frame*%f)\n", Tz, TzOffset); fprintf(out, "define Rx %f+(frame*%f)\n", Rx, RxOffset); fprintf(out, "define Ry %f+(frame*%f)\n", Ry, RyOffset); fprintf(out, "define Rz %f+(frame*%f)\n", Rz, RzOffset); fprintf(out, "define Rix %f+(frame*%f)\n", Rix, RiOffsetX); fprintf(out, "define Riy %f+(frame*%f)\n", Riy, RiOffsetY); fprintf(out, "define Riz %f+(frame*%f)\n", Riz, RiOffsetZ); if (Frames > 1) { fprintf(out, "define Fx %s\n", Fx); fprintf(out, "define Fy %s\n", Fy); fprintf(out, "define Fz %s\n", Fz); } } fprintf(out, "\n"); } } void SetTranslate(void) { printf("\nAhora vamos a hacer un Translate\n\n"); printf ("Introduce el offset de comienzo en x [0]: "); gets(Buffer); if (Buffer[0]) Tx = atof(Buffer); else Tx = 0; printf ("Introduce el offset de comienzo en y [0]: "); gets(Buffer); if (Buffer[0]) Ty = atof(Buffer); else Ty = 0; printf ("Introduce el offset de comienzo en z [0]: "); gets(Buffer); if (Buffer[0]) Tz = atof(Buffer); else Tz = 0; if (Frames > 1) { printf ("Introduce el incremento de la x [0]: "); gets(Buffer); if (Buffer[0]) TxOffset = atof(Buffer); else TxOffset = 0; printf ("Introduce el incremento de la y [0]: "); gets(Buffer); if (Buffer[0]) TyOffset = atof(Buffer); else TyOffset = 0; printf ("Introduce el incremento de la z [0]: "); gets(Buffer); if (Buffer[0]) TzOffset = atof(Buffer); else TzOffset = 0; if (!(Operacion == 'L')) { printf ("Introduce la formula de la x [Tx]: "); gets(Buffer); if (Buffer[0]) strcpy(Fx, Buffer); else strcpy(Fx, "Tx"); printf ("Introduce la formula de la y [Ty]: "); gets(Buffer); if (Buffer[0]) strcpy(Fy, Buffer); else strcpy(Fy, "Ty"); printf ("Introduce la formula de la z [Tz]: "); gets(Buffer); if (Buffer[0]) strcpy(Fz, Buffer); else strcpy(Fz, "Tz"); } else { printf ("Introduce la formula de la x [Tx%d]: ", ContLineas); gets(Buffer); if (Buffer[0]) strcpy(Fx, Buffer); else sprintf(Fx, "Tx%d", ContLineas); printf ("Introduce la formula de la y [Ty%d]: ", ContLineas); gets(Buffer); if (Buffer[0]) strcpy(Fy, Buffer); else sprintf(Fy, "Ty%d", ContLineas); printf ("Introduce la formula de la z [Tz%d]: ", ContLineas); gets(Buffer); if (Buffer[0]) strcpy(Fz, Buffer); else sprintf(Fz, "Tz%d", ContLineas); } } } void SetFrames(void) { printf ("Número de frames (eligue 1 si no quieres animaciones) [1]: "); gets(Buffer); if (Buffer[0]) Frames = atoi(Buffer); else Frames = 1; } void PutsTranslateLineal(void) { unsigned ObjectSize; rewind(Temp); for (ContLineas = 1; ContLineas <= Lineas; ContLineas ++) { fread(&ObjectSize, sizeof(unsigned), 1, Temp); fread(ObjectName, ObjectSize, 1, Temp); fread(&Rx, sizeof(Rx), 1, Temp); fread(&Ry, sizeof(Ry), 1, Temp); fread(&Rz, sizeof(Rz), 1, Temp); fread(&Tx, sizeof(Tx), 1, Temp); fread(&Ty, sizeof(Ty), 1, Temp); fread(&Tz, sizeof(Tz), 1, Temp); fread(&Rix, sizeof(double), 1, Temp); fread(&Riy, sizeof(double), 1, Temp); fread(&Riz, sizeof(double), 1, Temp); fread(&RxOffset, sizeof(RxOffset), 1, Temp); fread(&RyOffset, sizeof(RyOffset), 1, Temp); fread(&RzOffset, sizeof(RzOffset), 1, Temp); fread(&TxOffset, sizeof(TxOffset), 1, Temp); fread(&TyOffset, sizeof(TyOffset), 1, Temp); fread(&TzOffset, sizeof(TzOffset), 1, Temp); fread(&RiOffsetX, sizeof(double), 1, Temp); fread(&RiOffsetY, sizeof(double), 1, Temp); fread(&RiOffsetZ, sizeof(double), 1, Temp); fread(&sFx, sizeof(unsigned), 1, Temp); fread(&sFy, sizeof(unsigned), 1, Temp); fread(&sFz, sizeof(unsigned), 1, Temp); strcpy(Fx, ""); strcpy(Fy, ""); strcpy(Fz, ""); fread(Fx, sFx, 1, Temp); fread(Fy, sFy, 1, Temp); fread(Fz, sFz, 1, Temp); fread(&Texture, sizeof(char), 1, Temp); fread(&Select, sizeof(char), 1, Temp); strcpy(Color, ""); fread(&sColor, sizeof(unsigned), 1, Temp); fread(Color, sColor, 1, Temp); fread(&font1, sizeof(char), 1, Temp); strcpy(TextoS, ""); fread(&sTextoS, sizeof(unsigned), 1, Temp); fread(TextoS, sTextoS, 1, Temp); fread(&Scale, sizeof(Scale), 1, Temp); fread(&LongPag, sizeof(LongPag), 1, Temp); PutsTranslate(); } } void SetScale(void) { printf ("Introduce tamaño de la letra o el objeto [%f] : ", ScaleF); gets(Buffer); if (Buffer[0]) { Scale = atof(Buffer); ScaleF = Scale; } else Scale = ScaleF; } void SetAmbiente(void) { char AmbName[255]; printf("Quieres incluir un fichero con una camara o mas objetos.\n"); printf("\n (1) Incluir el fichero."); printf("\n (2) Incluir el fichero y anular los objetos internos."); printf("\n (3) No incluir ningun fichero."); printf("\n (4) No incluir ningun fichero y anular objetos internos (inc).\n"); printf("\nTu eligues [3]: "); Ambiente = getc(stdin); if (Ambiente == '\n') Ambiente = '3'; else getc(stdin); if (RayT == '1') strcpy(AmbName, "Ambpov.inc"); else strcpy(AmbName, "Ambpoly.inc"); if (Ambiente == '1' || Ambiente == '2') { printf("Nombre del fichero a incluir [%s]: ", AmbName); gets(Buffer); if (Buffer[0]) strcpy(IncludeName, Buffer); else strcpy(IncludeName, AmbName); } } void PutsStartUnion(void) { if (RayT == '2') fprintf(out, "object {"); else fprintf(out, "union {"); } void PutsEndObject(void) { if (RayT == '2') fprintf(out, " +\n"); } void PutsDefCamera(void) { if (RayT == '1') { fprintf(out, "// Posicion de la camara\n"); fprintf(out, "camera {\n"); fprintf(out, " location <%f, %f, %f>\n", CamX, CamY, CamPos); fprintf(out, " direction <0.0, 0.0, %f>\n", Zoom); fprintf(out, " up <0.0, 1.0, 0.0>\n"); fprintf(out, " right <%s, 0.0, 0.0>\n", Aspect); fprintf(out, " look_at <0, 0.0, 0.0 >\n"); fprintf(out, "}\n\n"); fprintf(out, "// Aqui van las fuentes de luz.\n"); fprintf(out, "object {\n"); fprintf(out, " light_source { <3.0, 15.0, -20.0>\n"); fprintf(out, " colour White\n"); fprintf(out, " }\n"); fprintf(out, "}\n\n"); fprintf(out, "object {\n"); fprintf(out, " light_source { <15.0, 10.0, -25.0>\n"); fprintf(out, " colour White\n"); fprintf(out, " }\n"); fprintf(out, "}\n\n"); } else { fprintf (out, "viewpoint {\n"); fprintf(out, " from <PosCamX, PosCamY, PosCamZ>\n"); fprintf(out, " at <0,0,0>\n"); fprintf(out, " up <0,1,0>\n"); fprintf(out, " angle 45\n"); fprintf(out, " resolution 160, 120\n"); fprintf(out, " aspect %s\n", Aspect); fprintf(out, "}\n\n"); fprintf(out, "light <1, 1, 1>, <0,0,-50>\n\n"); } }