home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / menu / menu.cpp next >
Encoding:
C/C++ Source or Header  |  2000-11-20  |  6.3 KB  |  358 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "..\gamelib\gamelib.h"
  3. #include "menu.h"
  4.  
  5. menugroup_desc cd_menugroup;
  6. menuitem_desc cd_menuitem;
  7. menucamera_desc cd_menucamera;
  8.  
  9. BOOL APIENTRY DllMain(HINSTANCE hModule, 
  10.                       DWORD  ul_reason_for_call, 
  11.                       LPVOID lpReserved)
  12. {    
  13.     switch( ul_reason_for_call ) 
  14.     {
  15.     case DLL_PROCESS_ATTACH:
  16.     case DLL_THREAD_ATTACH:
  17.     case DLL_THREAD_DETACH:
  18.     case DLL_PROCESS_DETACH:
  19.         break;
  20.     }
  21.     return TRUE;
  22. }
  23.  
  24. __declspec( dllexport )
  25. int num_classes()
  26. {
  27.     return 3;
  28. }
  29.  
  30. __declspec( dllexport )
  31. class_desc *get_class_desc(int i)
  32. {
  33.     switch(i)
  34.     {
  35.     case 0:
  36.         return &cd_menugroup;
  37.     case 1:
  38.         return &cd_menuitem;
  39.     case 2:
  40.         return &cd_menucamera;
  41.     default: return 0;
  42.     }
  43. }
  44.  
  45. __declspec( dllexport )
  46. int fly_message(int msg,int param,void *data)
  47. {
  48.     switch(msg)
  49.     {
  50.     case FLYM_DRAWSCENE:
  51.         flyengine->set_camera(flyengine->cam);
  52.         flyengine->draw_bsp();
  53.         directx->set_listener(
  54.             &flyengine->cam->pos.x,0,
  55.             &flyengine->cam->Y.x,&flyengine->cam->Z.x);
  56.         break;
  57.     }
  58.     return 1;
  59. }
  60.  
  61. void menugroup::draw()
  62. {
  63.     int i;
  64.     for( i=0;i<nitem;i++ )
  65.         if (item[i])
  66.         {
  67.             if (i==selitem)
  68.                 item[i]->color.w=1.0f;
  69.             else item[i]->color.w=0.4f;
  70.             glPushMatrix();
  71.             glTranslatef(pos.x,pos.y,pos.z+height/2-height*i/(nitem-1));
  72.             glMultMatrixf((float *)&mat);
  73.             item[i]->draw();
  74.             glPopMatrix();
  75.         }
  76. }
  77.  
  78. bsp_object *menugroup::clone()
  79. {
  80.     menugroup *tmp=new menugroup;
  81.     *tmp=*this;
  82.     tmp->source=this;
  83.     return tmp;
  84. }
  85.  
  86. int menugroup::get_custom_param_desc(int i,param_desc *pd)
  87. {
  88.     if (pd!=0)
  89.     switch(i)
  90.     {
  91.     case 0:
  92.         pd->type='i';
  93.         pd->data=&nitem;
  94.         strcpy(pd->name,"nitem");
  95.         break;
  96.     case 1:
  97.         pd->type=TYPE_MENUITEM;
  98.         pd->data=&item[0];
  99.         strcpy(pd->name,"item1");
  100.         break;
  101.     case 2:
  102.         pd->type=TYPE_MENUITEM;
  103.         pd->data=&item[1];
  104.         strcpy(pd->name,"item2");
  105.         break;
  106.     case 3:
  107.         pd->type=TYPE_MENUITEM;
  108.         pd->data=&item[2];
  109.         strcpy(pd->name,"item3");
  110.         break;
  111.     case 4:
  112.         pd->type=TYPE_MENUITEM;
  113.         pd->data=&item[3];
  114.         strcpy(pd->name,"item4");
  115.         break;
  116.     case 5:
  117.         pd->type=TYPE_MENUITEM;
  118.         pd->data=&item[4];
  119.         strcpy(pd->name,"item5");
  120.         break;
  121.     case 6:
  122.         pd->type=TYPE_MENUITEM;
  123.         pd->data=&item[5];
  124.         strcpy(pd->name,"item6");
  125.         break;
  126.     case 7:
  127.         pd->type=TYPE_MENUITEM;
  128.         pd->data=&item[6];
  129.         strcpy(pd->name,"item7");
  130.         break;
  131.     case 8:
  132.         pd->type=TYPE_MENUITEM;
  133.         pd->data=&item[7];
  134.         strcpy(pd->name,"item8");
  135.         break;
  136.     case 9:
  137.         pd->type='f';
  138.         pd->data=&height;
  139.         strcpy(pd->name,"height");
  140.         break;
  141.     }
  142.     return 10;
  143. }
  144.  
  145. void menuitem::draw()
  146. {
  147.     static vector x,y,c,v;
  148.  
  149.     glDepthMask(GL_FALSE);
  150.     glBlendFunc(GL_ONE, GL_ONE);
  151.     glDisable(GL_FOG);
  152.  
  153.     tc->use(texture);
  154.  
  155.     glColor3f(color.w,color.w,color.w);
  156.     
  157.     x=flyengine->cam->X*width;
  158.     y=flyengine->cam->Y*height;
  159.  
  160.     glBegin(GL_QUADS);
  161.  
  162.     v.x=pos.x+x.x-y.x;
  163.     v.y=pos.y+x.y-y.y;
  164.     v.z=pos.z+x.z-y.z;
  165.     glTexCoord2f(1,1);
  166.     glVertex3fv((float *)&v);
  167.  
  168.     v.x=pos.x+x.x+y.x;
  169.     v.y=pos.y+x.y+y.y;
  170.     v.z=pos.z+x.z+y.z;
  171.     glTexCoord2f(1,0);
  172.     glVertex3fv((float *)&v);
  173.  
  174.     v.x=pos.x-x.x+y.x;
  175.     v.y=pos.y-x.y+y.y;
  176.     v.z=pos.z-x.z+y.z;
  177.     glTexCoord2f(0,0);
  178.     glVertex3fv((float *)&v);
  179.  
  180.     v.x=pos.x-x.x-y.x;
  181.     v.y=pos.y-x.y-y.y;
  182.     v.z=pos.z-x.z-y.z;
  183.     glTexCoord2f(0,1);
  184.     glVertex3fv((float *)&v);
  185.  
  186.     glEnd();
  187.  
  188.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  189.     if (flyengine->fog) glEnable(GL_FOG);
  190.     glDepthMask(GL_TRUE);
  191. }
  192.  
  193. bsp_object *menuitem::clone()
  194. {
  195.     menuitem *tmp=new menuitem;
  196.     *tmp=*this;
  197.     tmp->source=this;
  198.     return tmp;
  199. }
  200.  
  201. int menuitem::get_custom_param_desc(int i,param_desc *pd)
  202. {
  203.     if (pd!=0)
  204.     switch(i)
  205.     {
  206.     case 0:
  207.         pd->type='f';
  208.         pd->data=&width;
  209.         strcpy(pd->name,"width");
  210.         break;
  211.     case 1:
  212.         pd->type='f';
  213.         pd->data=&height;
  214.         strcpy(pd->name,"height");
  215.         break;
  216.     case 2:
  217.         pd->type='p';
  218.         pd->data=&texture;
  219.         strcpy(pd->name,"texture");
  220.         break;
  221.     case 3:
  222.         pd->type='c';
  223.         pd->data=&color;
  224.         strcpy(pd->name,"color");
  225.         break;
  226.     case 4:
  227.         pd->type='f';
  228.         pd->data=&color.w;
  229.         strcpy(pd->name,"transp");
  230.         break;
  231.     case 5:
  232.         pd->type='s';
  233.         pd->data=command;
  234.         strcpy(pd->name,"command");
  235.         break;
  236.     }
  237.     return 6;
  238. }
  239.  
  240. int menucamera::step(int dt)
  241. {
  242.     if (target)
  243.     {
  244.     menugroup *m=(menugroup *)target;
  245.  
  246.     if (l)
  247.         {
  248.         l->pos=m->pos;
  249.         l->color=m->item[m->selitem]->color;
  250.         l->pos.z+=m->height/2-m->height*m->selitem/(m->nitem-1);
  251.         l->step(dt);
  252.         }
  253.  
  254.     vector dir;
  255.     dir=pos-target->pos;
  256.     dir.normalize();
  257.     float dot=vec_dot(dir,Z);
  258.     float ang=(float)acos(dot)*180.0f/M_Pi;
  259.     if (ang<1.0f)
  260.         align_z(dir);
  261.     else
  262.         {
  263.         if (ang>179.0f)
  264.             rotate(dt*rotvel,Y);
  265.         else
  266.             {
  267.             if (ang>dt*rotvel)
  268.                 ang=dt*rotvel;
  269.             if (ang>0)
  270.                 {
  271.                 dir.negate();
  272.                 rotate(dir,Z,ang);
  273.                 }
  274.             }
  275.         }
  276.  
  277.     if (directx->diks[0xc8]&0x80) // up
  278.         if ((keystatus&0x100)==0 && m->selitem>0)
  279.         {
  280.         m->selitem--;
  281.         keystatus|=0x100;
  282.         if (sndchangesel)
  283.             sndchangesel->add_sound_clone(&m->pos,0);
  284.         }
  285.         else ;
  286.     else if (keystatus&0x100)
  287.             keystatus&=0x011;
  288.  
  289.     if (directx->diks[0xd0]&0x80) // down
  290.         if ((keystatus&0x010)==0 && m->selitem<m->nitem-1)
  291.         {
  292.         m->selitem++;
  293.         keystatus|=0x010;
  294.         if (sndchangesel)
  295.             sndchangesel->add_sound_clone(&m->pos,0);
  296.         }
  297.         else ;
  298.     else if (keystatus&0x010)
  299.             keystatus&=0x101;
  300.  
  301.     if (directx->diks[0x1c]&0x80) // enter
  302.         if ((keystatus&0x001)==0 && m->selitem<m->nitem)
  303.         {
  304.         strcpy(flyengine->console_command,m->item[m->selitem]->command);
  305.         keystatus|=0x001;
  306.         if (sndselect)
  307.             sndselect->add_sound_clone(&m->pos,0);
  308.         }
  309.         else ;
  310.     else if (keystatus&0x001)
  311.             keystatus&=0x110;
  312.     }
  313.         
  314.     return 1;
  315. }
  316.  
  317. bsp_object *menucamera::clone()
  318. {
  319.     menucamera *tmp=new menucamera;
  320.     *tmp=*this;
  321.     tmp->source=this;
  322.     return tmp;
  323. }
  324.  
  325. int menucamera::get_custom_param_desc(int i,param_desc *pd)
  326. {
  327.     if (pd!=0)
  328.     switch(i)
  329.     {
  330.     case 0:
  331.         pd->type='d';
  332.         pd->data=⌖
  333.         strcpy(pd->name,"target");
  334.         break;
  335.     case 1:
  336.         pd->type='f';
  337.         pd->data=&rotvel;
  338.         strcpy(pd->name,"rotvel");
  339.         break;
  340.     case 2:
  341.         pd->type=TYPE_LIGHT;
  342.         pd->data=&l;
  343.         strcpy(pd->name,"light");
  344.         break;
  345.     case 3:
  346.         pd->type=TYPE_SOUND;
  347.         pd->data=&sndselect;
  348.         strcpy(pd->name,"sndselect");
  349.         break;
  350.     case 4:
  351.         pd->type=TYPE_SOUND;
  352.         pd->data=&sndchangesel;
  353.         strcpy(pd->name,"sndchangesel");
  354.         break;
  355.     }
  356.     return 5;
  357. }
  358.