K
K
Kokos Belyi2020-12-16 22:50:18
C++ / C#
Kokos Belyi, 2020-12-16 22:50:18

How to make a simple c++ menu?

Hello :) someone fumbles help to make a similar menu in C ++
5fda646b29afe060130922.png

, the menu should be in the console for the program whose code is below, I do not expect a full answer, but I will be glad to help, thanks in advance)

#include <iostream>
#include <conio.h>
#include "winbgim.h"
#include <math.h>
#include <cstdlib>
#define ESC 27
#define LEFT 75
#define RIGHT 77
#define TOP 72
#define BOT 80
#define ROTX 100
#define ROTY 115
#define ROTZ 97
#define RSZP 120
#define RSZM 122

using namespace std;

struct Dot3d 
{
  int x, y, z;
};
Dot3d Hammer[20]; //Òî÷êè
int Rebro = 10; 

  int AngleX=0;
  int AngleY=0;
  int AngleZ=0;
  


  int Krok=5;
    
  int Mx, My;

  

int Rebra[24][2]
{{1,2},{2,3},{3,4},{4,1}, /////Âåðõíÿ ÷àñòü ìîëîòà
         {5,6},{6,7},{7,8},{8,5},  ////Íèæíÿ ÷àñòü ìîëîòà
          {1,5},{2,6},{4,8},{3,7},
          {9,10},{11,12},{13,14},{15,16},
          {10,14},{10,12},{16,12},{14,16},
          {9,11},{11,13},{13,15},{15,11},}; ////Ñîåäèíåíèå ÷àñòèí ³ ðó÷êà

void InitHammer(int, int, int, int);
void PaintHammer(Dot3d *);
void OffsetHammerHorizontal(int);
void OffsetHammerVertical(int);
void OffsetHammerResize(int);
void rotationX(int);
void rotationZ(int);
void rotationY(int);
void ResizePlus(int);
void ResizeMinus(int);
void Manipulate();



int main()    //Ãîëîâíå Ìåíþ
{
  int variant;
  system ("color 6"); 
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251); 
  cout << "3D ìîäåëü ìîëîòêà\n" << endl;
  cout << "Âèáåð³òü áàæàíó ä³þ\n" << endl;
    cout << "1. ij¿ íàä ô³ãóðîþ\n" 
     << "2. ßê êåðóâàòè?\n"
     << "3. Àâòîð\n";
  cout << ">";
 
  {
  

    cin >> variant;
    {
      switch (variant)
      {
       
        case 1:
          cout << "ij¿ íàä ô³ãóðîþ" << endl;
          Manipulate();
        break;
        
        case 2:
          cout << "ßê êåðóâàòè:\n"
                 <<"Ñòð³ëêà âïðàâî - ïåðåì³ùåííÿ âïðàâî\n"
              	<< "Ñòð³ëêà âë³âî - ïåðåì³ùåííÿ âë³âî \n"
             		<<	"Ñòð³ëêà ââåðõ - ïåðåì³ùåííÿ ââåðõ\n"
             			<< "Ñòð³ëêà âíèç - ïåðåì³ùåííÿ  âíèç\n"
             				<< "a - Îáåðòàííÿ ïî îñ³ Z\n"
             					<< "s - Îáåðòàííÿ ïî îñ³ Y\n"
                        << "d - Îáåðòàííÿ ïî îñ³ X\n"
             							<< "z - Çìåíøåííÿ ìàñøòàáó\n" 
             								<< "x - Çá³ëüøåííÿ ìàñøòàáó\n"<< endl;			
        break;
        
        case 3:
          cout << "21" << endl;
        break;
        
      }
    }
  }
}

  
void Manipulate()
{
    initwindow(1200, 1000);
    Mx = getmaxx()/2;;
    My = getmaxy()/2;;
    
    InitHammer(Mx,My,0,Rebro);
    PaintHammer(Hammer);
  
  
  int v;
  while (getch()!= ESC)
  {
    {
      v=getch();
      
      if (v== RIGHT)
      {
        OffsetHammerHorizontal(Krok);
      };
  
      if (v== LEFT)
      {
        OffsetHammerHorizontal(-Krok);
      };
      
      if (v== BOT)
      {
        OffsetHammerVertical(Krok);
      };
      
      if (v== TOP)
      {
        OffsetHammerVertical(-Krok);
      };
      
      if (v== ROTX)
      {
        rotationX(5) ;
      }
      
      if (v== ROTY)
      {
        rotationY(5) ;
      }
      
      if (v== ROTZ)
      {
        rotationZ(5) ;
      };
      
      if (v== RSZM)
      {
        ResizeMinus(5) ;
      }
      
      if (v== RSZP)
      {
        ResizePlus(5) ;
      }
      std::cout<<v<<endl;	
   }
    cleardevice();
    PaintHammer(Hammer);
  }
             
    getch();

}	


void InitHammer(int x0, int y0, int z0, int m)// Ââåäåííÿ êîîðäèíàò âñ³õ òî÷îê
 {
 	///////X	                                      ///////Y                                             /////////Z

Hammer[0].x=x0;									 Hammer[0].y=y0;									Hammer[0].z=z0;
Hammer[1].x=Hammer[0].x-5*m;				     Hammer[1].y=Hammer[0].y+25*m;						Hammer[1].z=Hammer[0].z-7*m;
Hammer[2].x=Hammer[0].x+5*m; 					 Hammer[2].y=Hammer[0].y+25*m;						Hammer[2].z=Hammer[0].z-7*m;
Hammer[3].x=Hammer[0].x+5*m;              		 Hammer[3].y=Hammer[0].y+25*m;						Hammer[3].z=Hammer[0].z+7*m;
Hammer[4].x=Hammer[0].x-5*m; 				     Hammer[4].y=Hammer[0].y+25*m;						Hammer[4].z=Hammer[0].z+7*m;
Hammer[5].x=Hammer[0].x-5*m;                     Hammer[5].y=Hammer[0].y+2*m; 						Hammer[5].z=Hammer[0].z-7*m;
Hammer[6].x=Hammer[0].x+5*m;					 Hammer[6].y=Hammer[0].y+20*m;						Hammer[6].z=Hammer[0].z-7*m;
Hammer[7].x=Hammer[0].x+2*m;			         Hammer[7].y=Hammer[0].y+20*m;						Hammer[7].z=Hammer[0].z+12*m;
Hammer[8].x=Hammer[0].x-2*m;			         Hammer[8].y=Hammer[0].y+20*m;						Hammer[8].z=Hammer[0].z+12*m;
Hammer[9].x=Hammer[0].x+2*m;					 Hammer[9].y=Hammer[0].y+20*m;						Hammer[9].z=Hammer[0].z-2*m;

Hammer[10].x=Hammer[0].x+2*m;					 Hammer[10].y=Hammer[0].y;	           			    Hammer[10].z=Hammer[0].z-2*m;
Hammer[11].x=Hammer[0].x-2*m; 					 Hammer[11].y=Hammer[0].y+20*m;						Hammer[11].z=Hammer[0].z-2*m;
Hammer[12].x=Hammer[0].x-2*m; 				 	 Hammer[12].y=Hammer[0].y;							Hammer[12].z=Hammer[0].z-2*m;
Hammer[13].x=Hammer[0].x+2*m;                  	 Hammer[13].y=Hammer[0].y+20*m;						Hammer[13].z=Hammer[0].z+2*m;

Hammer[14].x=Hammer[0].x+2*m; 					 Hammer[14].y=Hammer[0].y;     						Hammer[14].z=Hammer[0].z+2*m; 
Hammer[15].x=Hammer[0].x-2*m;                    Hammer[15].y=Hammer[0].y+20*m;						Hammer[15].z=Hammer[0].z+2*m;
Hammer[16].x=Hammer[0].x-2*m;                    Hammer[16].y=Hammer[0].y;							Hammer[16].z=Hammer[0].z+2*m;

  
}

void PaintHammer(Dot3d *c)
{
  int yt1, yt2, xt1, xt2, zt1, zt2;
  
  double anX=(AngleX%360/180.0)*3.14;
  double anY=(AngleY%360/180.0)*3.14;
  double anZ=(AngleZ%360/180.0)*3.14;

  for(int i=0; i<=20; i++)
  {
  
    //*******
    //x'=x;
    //y':=y*cos(L)+z*sin(L) ;
    //z':=-y*sin(L)+z*cos(L) ;	
    xt1=(c[Rebra[i][0]].x);
    yt1=(c[Rebra[i][0]].y)*cos(anX)+c[Rebra[i][0]].z*sin(anX);
    zt1=-(c[Rebra[i][0]].y)*sin(anX)+c[Rebra[i][0]].z*cos(anX);
    
    
    xt2=(c[Rebra[i][1]].x);
    yt2=(c[Rebra[i][1]].y)*cos(anX)+c[Rebra[i][1]].z*sin(anX);
    zt2=-(c[Rebra[i][1]].y)*sin(anX)+c[Rebra[i][1]].z*cos(anX);
    
    //*******
    //x'=x*cos(L)+z*sin(L);
    //y'=y;
    //z'=-x*sin(L)+z*cos(L);
    xt1=xt1*cos(anY)+zt1*sin(anY);
    yt1=yt1;
    zt1=-xt1*sin(anY)+zt1*cos(anY);
    
    xt2=xt2*cos(anY)+zt2*sin(anY);
    yt2=yt2;
    zt2=-xt2*sin(anY)+zt2*cos(anY);
    
    //******
    //x'=x*cos(L)-y*sin(L);
    //y'=-x*sin(L)+y*cos(L);
    //z'=z;		
    xt1=xt1*cos(anZ)+yt1*sin(anZ);
    yt1=-xt1*sin(anZ)+yt1*cos(anZ);
    zt1=zt1;
    
    xt2=xt2*cos(anZ)+yt2*sin(anZ);
    yt2=-xt2*sin(anZ)+yt2*cos(anZ);
    zt2=zt2;
    setcolor(10);

    
    line(xt1+Mx, yt1+My, xt2+Mx, yt2+My);
  }
    
}



//Ïåðåì³ùåííÿ ìîäåë³;

void OffsetHammerHorizontal(int ofs)
  {
    Mx=Mx+ofs;
  }


void OffsetHammerVertical(int ofs)
  {
    My=My+ofs;
  }
  


//Îáåðòàííÿ ìîäåë³;
void rotationX(int a)
{	
  AngleX=AngleX+a;
  
    InitHammer(Hammer[0].x, Hammer[0].y, Hammer[0].y, Rebro);
}


void rotationY(int a)
{	
  AngleY=AngleY+a;
    InitHammer(Hammer[0].x, Hammer[0].y, Hammer[0].y, Rebro);
}

void rotationZ(int a)
{	
  AngleZ=AngleZ+a;
    InitHammer(Hammer[0].x, Hammer[0].y, Hammer[0].y, Rebro);
}

//Ìàøòàáóâàííÿ ìîäåë³;
void ResizePlus(int r)
{
  Rebro=Rebro+r;
  InitHammer(Hammer[0].x, Hammer[0].y, Hammer[0].y, Rebro);
}

void ResizeMinus(int r)
{
  Rebro=abs(Rebro-r);
  InitHammer(Hammer[0].x, Hammer[0].y, Hammer[0].y, Rebro);
  
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-12-16
@primatsKompom

If the code above is yours, then I don’t understand what the problem is to make the menu.
It's just five lines of output, waiting for input, and a switch. You can wrap it all up in a loop. Well, or you did not describe the condition enough

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question