Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for games/3do-view/3do-view.c between version 1.1 and 1.2

version 1.1, 2003/05/11 18:48:36 version 1.2, 2003/05/19 22:24:46
Line 1 
Line 1 
 /* $Platon: $ */  /* $Platon: games/3do-view/3do-view.c,v 1.1.1.1 2003/05/11 18:48:36 nepto Exp $ */
   
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
Line 21 
Line 21 
 #include <my-graph.h>  #include <my-graph.h>
 #include <mouse.h>  #include <mouse.h>
   
   #include "dir.h"
   
 #define PI    3.1415926536  #define PI    3.1415926536
 #define ALFA  PI/6  #define ALFA  PI/6
Line 30 
Line 31 
 #define OSY             2  #define OSY             2
 #define OSZ             4  #define OSZ             4
   
   enum modes
   {
           MODE_MAIN_MENU,
           MODE_AUTOMATIC_TURNING,
           MODE_MANUAL_TURNING,
           MODE_FILE_SELECTION,
           MODE_INFORMATION,
           MODE_EXIT_DIALOG,
           MODE_QUIT
   };
   
   enum file_selector_modes
   {
           MODE_SELECTED_NONE,
           MODE_SELECTED_DIRECTORY,
           MODE_SELECTED_FILE
   };
   
 int q,k,l,pocbod,stop=0;  int q,k,l,pocbod,stop=0;
 BYTE p;  BYTE p;
 double ALFAX,ALFAY,ALFAZ,POSUNX=0.04,POSUNY=0.075,POSUNZ=0.111,POSXOLD,POSYOLD,POSZOLD;  double ALFAX,ALFAY,ALFAZ,POSUNX=0.04,POSUNY=0.075,POSUNZ=0.111,POSXOLD,POSYOLD,POSZOLD;
Line 37  int bodxbase[100],bodybase[100],bodzbase
Line 56  int bodxbase[100],bodybase[100],bodzbase
         bodx[100],body[100],bodz[100];          bodx[100],body[100],bodz[100];
 int pocspoj[100],spoj[100][20];  int pocspoj[100],spoj[100][20];
   
   /* Function prototypes */
   void open_3do_file(const char *filename);
   void vykresli(int color);
   
 void intro(void) /* {{{ */  void intro(void) /* {{{ */
 {  {
         printf("\r\n3D OBJECTS (3DO) viewer\r\n");          printf("\r\n3D OBJECTS (3DO) viewer\r\n");
Line 78  void intface(void) /* {{{ */
Line 101  void intface(void) /* {{{ */
         rectangle(486,297,633,350);          rectangle(486,297,633,350);
         rectangle(486,387,633,440);          rectangle(486,387,633,440);
         setcolor(GREEN);          setcolor(GREEN);
         outtextxy(492,70,"AUTOMAT. OTACANIE");          outtextxy(559,70,"AUTOMAT. OTACANIE");
         outtextxy(492,160,"MANUALNE OTACANIE");          outtextxy(559,160,"MANUALNE OTACANIE");
         setcolor(LIGHTBLUE);          setcolor(LIGHTBLUE);
         outtextxy(545,250,"POMOC");          outtextxy(559,250,"OTVORENIE SUBORU");
         outtextxy(521,340,"INFORMACIE");          outtextxy(559,340,"INFORMACIE");
         setcolor(RED);          setcolor(RED);
         outtextxy(541,430,"KONIEC");          outtextxy(559,430,"KONIEC");
         setcolor(WHITE);          setcolor(WHITE);
         delay(50);          delay(50);
         q=1;          q = MODE_MAIN_MENU;
         showmouse();          showmouse();
 } /* }}} */  } /* }}} */
   
Line 97  void run(void) /* {{{ */
Line 120  void run(void) /* {{{ */
         hidemouse();          hidemouse();
         setfillstyle(0,0);          setfillstyle(0,0);
         bar(480,1,638,478);          bar(480,1,638,478);
         outtextxy(492,10,"AUTOMAT. OTACANIE");          outtextxy(559,16,"AUTOMAT. OTACANIE");
         rectangle(486,387,633,440);          rectangle(486,387,633,440);
         rectangle(486,297,633,350);          rectangle(486,297,633,350);
         rectangle(486,207,633,260);          rectangle(486,207,633,260);
Line 108  void run(void) /* {{{ */
Line 131  void run(void) /* {{{ */
         rectangle(486,140,526,170);          rectangle(486,140,526,170);
         rectangle(593,140,633,170);          rectangle(593,140,633,170);
         setcolor(GREEN);          setcolor(GREEN);
         outtextxy(547,51," X ");          outtextxy(559,55,"X");
         outtextxy(547,101," Y ");          outtextxy(559,105,"Y");
         outtextxy(547,151," Z ");          outtextxy(559,155,"Z");
         setcolor(RED);          setcolor(RED);
         outtextxy(502,51,"+");          outtextxy(506,55,"+");
         outtextxy(502,101,"+");          outtextxy(506,105,"+");
         outtextxy(502,151,"+");          outtextxy(506,155,"+");
         setcolor(LIGHTBLUE);          setcolor(LIGHTBLUE);
         outtextxy(609,51,"-");          outtextxy(612,55,"-");
         outtextxy(609,101,"-");          outtextxy(612,105,"-");
         outtextxy(609,151,"-");          outtextxy(612,155,"-");
         setcolor(WHITE);          setcolor(WHITE);
         outtextxy(513,250,"POKRACOVANIE");          outtextxy(559,250,"POKRACOVANIE");
         outtextxy(549,340,"STOP");          outtextxy(559,340,"STOP");
         outtextxy(517,430,"HLAVNE MENU");          outtextxy(559,430,"HLAVNE MENU");
         showmouse();          showmouse();
         delay(50);          delay(50);
         q=2;          q = MODE_AUTOMATIC_TURNING;
 } /* }}} */  } /* }}} */
   
 /********************** POKRACOVANIE OTACANIA *******************************/  /********************** POKRACOVANIE OTACANIA *******************************/
Line 167  void manual(void) /* {{{ */
Line 190  void manual(void) /* {{{ */
         rectangle(486,140,526,170);          rectangle(486,140,526,170);
         rectangle(593,140,633,170);          rectangle(593,140,633,170);
         rectangle(486,387,633,440);          rectangle(486,387,633,440);
         outtextxy(492,10,"MANUALNE OTACANIE");          outtextxy(559,16,"MANUALNE OTACANIE");
         setcolor(GREEN);          setcolor(GREEN);
         outtextxy(547,51," X ");          outtextxy(559,55,"X");
         outtextxy(547,101," Y ");          outtextxy(559,105,"Y");
         outtextxy(547,151," Z ");          outtextxy(559,155,"Z");
         setcolor(RED);          setcolor(RED);
         outtextxy(502,51,"+");          outtextxy(506,55,"+");
         outtextxy(502,101,"+");          outtextxy(506,105,"+");
         outtextxy(502,151,"+");          outtextxy(506,155,"+");
         setcolor(LIGHTBLUE);          setcolor(LIGHTBLUE);
         outtextxy(609,51,"-");          outtextxy(612,55,"-");
         outtextxy(609,101,"-");          outtextxy(612,105,"-");
         outtextxy(609,151,"-");          outtextxy(612,155,"-");
         setcolor(WHITE);          setcolor(WHITE);
         outtextxy(517,430,"HLAVNE MENU");          outtextxy(559,430,"HLAVNE MENU");
         showmouse();          showmouse();
         q=3;          q = MODE_MANUAL_TURNING;
   } /* }}} */
   
   /*************************** FILE SELECTOR **********************************/
   void file_selector(int mode, int item) /* {{{ */
   {
           register int i;
           static char **files = NULL;
           static char **directories = NULL;
           bar(10, 20, 500, 40);
           gl_printf(10, 30, "file_selector(%d, %d)      ", mode, item);
           if (mode == MODE_SELECTED_DIRECTORY
                           && directories != NULL && files != NULL) {
                   free_directories_or_files(directories);
                   free_directories_or_files(files);
                   directories = NULL;
                   files       = NULL;
           }
           if (files == NULL && directories == NULL) {
                   get_directories_and_files(NULL, &directories, &files);
                   hidemouse();
                   setfillstyle(0,0);
                   bar(480,1,638,478);
                   outtextxy(559,16,"OTVORENIE SUBORU");
                   rectangle(486,387,633,440);
                   outtextxy(559,430,"HLAVNE MENU");
                   rectangle(486,57,633,200);
                   rectangle(486,207,633,350);
                   settextjustify(LEFT_TEXT, CENTER_TEXT);
                   for (i = 0; directories != NULL && directories[i] != NULL; i++) {
                           outtextxy(490, 67 + i * 10, directories[i]);
                   }
                   for (i = 0; files != NULL && files[i] != NULL; i++) {
                           outtextxy(490, 217 + i * 10, files[i]);
                   }
                   settextjustify(CENTER_TEXT, CENTER_TEXT);
                   showmouse();
                   delay(150);
           }
           if (mode == MODE_SELECTED_FILE) {
                   vykresli(BLACK);
                   switch (item) {
                           case 0:  open_3do_file("data/rocket.3do");  break;
                           case 1:  open_3do_file("data/cube.3do");    break;
                           case 2:  open_3do_file("data/pyramid.3do"); break;
                           default: open_3do_file("data/stand.3do");   break;
                   }
                   vykresli(WHITE);
           }
           q = MODE_FILE_SELECTION;
 } /* }}} */  } /* }}} */
   
 /**************************** INFORMACIE ************************************/  /**************************** INFORMACIE ************************************/
Line 192  void info(void) /* {{{ */
Line 264  void info(void) /* {{{ */
         hidemouse();          hidemouse();
         setfillstyle(0,0);          setfillstyle(0,0);
         bar(480,1,638,478);          bar(480,1,638,478);
         outtextxy(512,10,"INFORMACIE");          outtextxy(559,16,"INFORMACIE");
         rectangle(486,387,633,440);          rectangle(486,387,633,440);
         outtextxy(517,430,"HLAVNE MENU");          outtextxy(559,430,"HLAVNE MENU");
         showmouse();          showmouse();
         delay(50);          delay(50);
         q=0;          q = MODE_INFORMATION;
 } /* }}} */  } /* }}} */
   
 /*************************** QUIT *******************************************/  /*************************** QUIT *******************************************/
Line 208  void quit(void) /* {{{ */
Line 280  void quit(void) /* {{{ */
         bar(480,1,638,478);          bar(480,1,638,478);
         rectangle(486,387,633,440);          rectangle(486,387,633,440);
         rectangle(486,297,633,350);          rectangle(486,297,633,350);
         outtextxy(496,10,"CHCETE SKONCIT ?");          outtextxy(559,16,"KONIEC PROGRAMU?");
         setcolor(RED);          setcolor(RED);
         outtextxy(545,340,"ANO");          outtextxy(559,340,"ANO");
         setcolor(LIGHTBLUE);          setcolor(LIGHTBLUE);
         outtextxy(545,430,"NIE");          outtextxy(559,430,"NIE");
         setcolor(WHITE);          setcolor(WHITE);
         showmouse();          showmouse();
         delay(100);          delay(100);
         q=32;          q = MODE_EXIT_DIALOG;
 } /* }}} */  } /* }}} */
   
 /******************** VYKRESLENIE OBJEKTU Z 3D DO 2D ************************/  /******************** VYKRESLENIE OBJEKTU Z 3D DO 2D ************************/
Line 305  BYTE isinbar(int x1,int y1,int x2,int y2
Line 377  BYTE isinbar(int x1,int y1,int x2,int y2
         return(0);          return(0);
 } /* }}} */  } /* }}} */
   
 /**************************** HLAVNY PROGRAM ********************************/  /**************************** OPEN 3DO FILE *********************************/
 int main(int argc,char *argv[]) /* {{{ */  void open_3do_file(const char *filename) /* {{{ */
 {  {
         char pomstr[100];  
         FILE *f;          FILE *f;
         clrscr();          if ((f=fopen(filename,"rt"))==NULL) {
         if (argc!=2)ERROR2();  
         if ((initmouse()!=2)&&(initmouse()!=3))ERROR1();  
         if ((f=fopen(argv[1],"rt"))==NULL) {  
                 my_graph_close();                  my_graph_close();
                 printf("File not found. [%s]\n",argv[1]);                  printf("File not found. [%s]\n",filename);
                 exit(1);                  exit(1);
         }          }
         fscanf(f,"%d",&pocbod);          fscanf(f,"%d",&pocbod);
Line 331  int main(int argc,char *argv[]) /* {{{ *
Line 399  int main(int argc,char *argv[]) /* {{{ *
                 }                  }
         }          }
         fclose(f);          fclose(f);
   } /* }}} */
   
   /**************************** HLAVNY PROGRAM ********************************/
   int main(int argc,char *argv[]) /* {{{ */
   {
           char pomstr[100];
           clrscr();
           if ((initmouse()!=2)&&(initmouse()!=3))ERROR1();
           if (argc > 1) {
                   if (strcmp(argv[1], "-h") && strcmp(argv[1], "--help"))
                           open_3do_file(argv[1]);
                   else
                           ERROR2();
           }
         if (my_graph_init(1) < 0) {          if (my_graph_init(1) < 0) {
                 return 1;                  return 1;
         }          }
           settextjustify(CENTER_TEXT, CENTER_TEXT);
           settextstyle(0,0,1);
         intface();          intface();
         ALFAY=0;          ALFAY=0;
         ALFAX=0;          ALFAX=0;
         ALFAZ=0;          ALFAZ=0;
         p=OSX+OSY+OSZ;          p=OSX+OSY+OSZ;
         showmouse();          showmouse();
         while (q!=33) {          while (q != MODE_QUIT) {
                 if ((isinbar(486,387,633,440)==1)&&(q==1))quit();                  bar(0, 0, 200, 30);
                 if ((isinbar(486,297,633,350)==1)&&(q==1))info();                  gl_printf(10, 10, "q = %d   ", q);
                 if ((isinbar(486,27,633,80)==1)&&(q==1))run();                  if (isinbar(486,387,633,440) == 1 && q == MODE_MAIN_MENU)
                 if ((isinbar(486,387,633,440)==1)&&(q==3)) {                          quit();
                   if (isinbar(486,297,633,350) == 1 && q == MODE_MAIN_MENU)
                           info();
                   if (isinbar(486,27,633,80) == 1 && q == MODE_MAIN_MENU)
                           run();
                   if (isinbar(486,387,633,440) == 1 && q == MODE_MANUAL_TURNING) {
                         intface();                          intface();
                         CONTINUE();                          CONTINUE();
                 }                  }
                 if ((isinbar(486,387,633,440)==1)&&(q!=1))intface();                  if (isinbar(486,387,633,440) == 1 && q != MODE_MAIN_MENU)
                 if ((isinbar(486,117,633,170)==1)&&(q==1))manual();                          intface();
                 if (q==2) {                  if (isinbar(486,207,633,260) == 1 && q == MODE_MAIN_MENU)
                           file_selector(MODE_SELECTED_NONE, 0);
                   if (isinbar(486,117,633,170) == 1 && q == MODE_MAIN_MENU)
                           manual();
                   if (q == MODE_FILE_SELECTION) {
                           int mode = MODE_SELECTED_NONE;
                           if (isinbar(486,57,633,200)) {
                                   mode = MODE_SELECTED_DIRECTORY;
                           } else if (isinbar(486,207,633,350)) {
                                   mode = MODE_SELECTED_FILE;
                           }
                           if (mode != MODE_SELECTED_NONE) {
                                   int yy;
                                   getmousepos(NULL, (WORD *) &yy);
                                   yy -= mode == MODE_SELECTED_FILE ? 212 : 62;
                                   yy /= 10;
                                   yy = min(13, yy);
                                   yy = max(0, yy);
                                   file_selector(mode, yy);
                           }
                   }
                   if (q == MODE_AUTOMATIC_TURNING) {
                         if (stop!=1) {                          if (stop!=1) {
                                 if (isinbar(486,40,526,70)==1) {                                  if (isinbar(486,40,526,70)==1) {
                                         if (POSUNX==0)p=p+OSX;                                          if (POSUNX==0)p=p+OSX;
Line 392  int main(int argc,char *argv[]) /* {{{ *
Line 502  int main(int argc,char *argv[]) /* {{{ *
                         }                          }
                         if (isinbar(486,207,633,260)==1)CONTINUE();                          if (isinbar(486,207,633,260)==1)CONTINUE();
                         if ((isinbar(486,297,633,350)==1)&&(stop!=1))STOP();                          if ((isinbar(486,297,633,350)==1)&&(stop!=1))STOP();
                         bar(481,171,638,206);  
                         setcolor(WHITE);                          setcolor(WHITE);
                         sprintf(pomstr,"X=%f",POSUNX);                          sprintf(pomstr,"%+04.0f",POSUNX*1000);
                         outtextxy(486,174,pomstr);                          bar(530,60,590,70);
                         sprintf(pomstr,"Y=%f",POSUNY);                          outtextxy(555,65,pomstr);
                         outtextxy(486,184,pomstr);                          sprintf(pomstr,"%+04.0f",POSUNY*1000);
                         sprintf(pomstr,"Z=%f",POSUNZ);                          bar(530,110,590,120);
                         outtextxy(486,194,pomstr);                          outtextxy(555,115,pomstr);
                           sprintf(pomstr,"%+04.0f",POSUNZ*1000);
                 }                          bar(530,160,590,170);
                 if (q==32)if (isinbar(486,297,633,350)==1)q=33;                          outtextxy(555,165,pomstr);
                 if (q==3) {                  }
                         if (isinbar(486,40,526,70)==1)POSUNX+=0.01;                  if (q == MODE_EXIT_DIALOG)
                         if (isinbar(593,40,633,70)==1)POSUNX-=0.01;                          if (isinbar(486,297,633,350) == 1)
                         if (isinbar(486,90,526,120)==1)POSUNY+=0.01;                                  q = MODE_QUIT;
                         if (isinbar(593,90,633,120)==1)POSUNY-=0.01;                  if (q == MODE_MANUAL_TURNING) {
                         if (isinbar(486,140,526,170)==1)POSUNZ+=0.01;                          if (isinbar(486,40,526,70)   == 1) POSUNX += 0.01;
                         if (isinbar(593,140,633,170)==1)POSUNZ-=0.01;                          if (isinbar(593,40,633,70)   == 1) POSUNX -= 0.01;
                           if (isinbar(486,90,526,120)  == 1) POSUNY += 0.01;
                           if (isinbar(593,90,633,120)  == 1) POSUNY -= 0.01;
                           if (isinbar(486,140,526,170) == 1) POSUNZ += 0.01;
                           if (isinbar(593,140,633,170) == 1) POSUNZ -= 0.01;
                 }                  }
                 my_graph_refresh();                  my_graph_refresh();
                 delay(50);                  delay(50);
                 if ((POSUNX>0.0005)||(POSUNY>0.0005)||(POSUNZ>0.0005)||(POSUNX<-0.0005)||(POSUNY<-0.0005)||(POSUNZ<-0.0005)) {                  if ((POSUNX>0.0005)||(POSUNY>0.0005)||(POSUNZ>0.0005)
                                   ||(POSUNX<-0.0005)||(POSUNY<-0.0005)||(POSUNZ<-0.0005)) {
                         vykresli(BLACK);                          vykresli(BLACK);
                         if (POSUNX!=0) {                          if (POSUNX!=0) {
                                 if (ALFAX>180)ALFAX=0;                                  if (ALFAX>=180)ALFAX=0;
                                 else ALFAX+=POSUNX;                                  else ALFAX+=POSUNX;
                         }                          }
   
                         if (POSUNY!=0) {                          if (POSUNY!=0) {
                                 if (ALFAY>180)ALFAY=0;                                  if (ALFAY>=180)ALFAY=0;
                                 else ALFAY+=POSUNY;                                  else ALFAY+=POSUNY;
                         }                          }
   
                         if (POSUNZ!=0) {                          if (POSUNZ!=0) {
                                 if (ALFAZ>180)ALFAZ=0;                                  if (ALFAZ>=180)ALFAZ=0;
                                 else ALFAZ+=POSUNZ;                                  else ALFAZ+=POSUNZ;
                         }                          }
   
                         posun();                          posun();
                         vykresli(WHITE);                          vykresli(WHITE);
                 }                  }
                 if (q==3) {                  if (q == MODE_MANUAL_TURNING) {
                         POSUNX=0;                          POSUNX=0;
                         POSUNY=0;                          POSUNY=0;
                         POSUNZ=0;                          POSUNZ=0;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top