Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.77 KB | None | 0 0
  1. //DISCLAIMER. THIS USES THE GAME ENGINES 4-1 AS A FOUNDATION. WHILE IT HAS BEEN HEAVILY MODIFIED, MOST CODE HAS BEEN INSPIRED BY TUTORIALS BUT HAS BEEN CHANGED
  2. //Declares header files
  3. #include "SystemStarter.h"
  4. #include "Skybox.h"
  5. #include "Terrain.h"
  6. #include "Billboards.h"
  7.  
  8. //declares keyboard handler for use in main
  9. class MyKeyboardHandler : public KeyboardHandler {
  10. public:
  11.     MyKeyboardHandler() {
  12.         for (int idx = 0; idx < 256; idx++) {
  13.             Keys[idx] = false;
  14.         }
  15.     }
  16.  
  17.     void KeyPressed(char c) {
  18.         Keys[c] = true;
  19.  
  20.     }
  21.  
  22.     void KeyReleased(char c) {
  23.         Keys[c] = false;
  24.     }
  25.  
  26.     bool IsKeyDown(char c) {
  27.         return Keys[c];
  28.     }
  29.  
  30. private:
  31.     bool Keys[256];
  32. };
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //Windows main function
  39. int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLineArgs, int nInitialWinShowState)
  40. {
  41.     //FPS decleration
  42.     wchar_t fps[64];
  43.  
  44.     ZeroMemory(fps, 64);
  45.  
  46.    
  47.     int increase = 1.0f;
  48.     //Keyboard handler
  49.     MyKeyboardHandler keyb;
  50.  
  51.     //System starter
  52.     SystemStarter sysStart;
  53.     //Model handler
  54.     Model model;
  55.     //Skybox handler
  56.     Skybox sky;
  57.     //Billboard handler
  58.     Billboards bill;
  59.     //Terrain handler
  60.     Terrain ter;
  61.     //Starts window with 1000x80 resolution
  62.     if (!sysStart.Initialiser(1000, 800)) {
  63.         MessageBox(NULL, L"Unable to initialise DirectX", L"TGE", MB_OK);
  64.  
  65.         return -1;
  66.     }
  67.  
  68.    
  69.  
  70.     //Sets the handler
  71.     sysStart.SetKeyboardHandler(&keyb);
  72.  
  73.     //Sets the camera position
  74.     sysStart.SetCameraPosi(Vector(0.0f, 5.0f, -10.0f));
  75.     //Declares all used models
  76.     Model *ModelShack = sysStart.AddModel();
  77.     Model *ModelHuman = sysStart.AddModel();
  78.     Model *ModelSign = sysStart.AddModel();
  79.     Model *ModelMug = sysStart.AddModel();
  80.     Model *ModelTable = sysStart.AddModel();
  81.     Model *ModelCabinet = sysStart.AddModel();
  82.     Model *ModelHouses = sysStart.AddModel();
  83.     Model *ModelAxes = sysStart.AddModel();
  84.     Model *ModelShield = sysStart.AddModel();
  85.     Model *ModelChalice = sysStart.AddModel();
  86.  
  87.     //Loads the shack model
  88.     if (!ModelShack->LoadModel(".\\klo_uv.x", sysStart.GetDevice())) {
  89.         MessageBox(NULL, L"Unable to load earth.x", L"TGE", MB_OK);
  90.  
  91.         return false;
  92.     }
  93.  
  94.     ModelShack->SetPosition(mVector(10.0f, -2.0f, 12.0f));
  95.     ModelShack->SetScale(mVector(0.03f, 0.03f, 0.03f));
  96.     ModelShack->SetRotation(mVector(-1.57f, 3.14f, 0.0f));
  97.     // Next human model
  98.     if (!ModelHuman->LoadModel(".\\Male1.x", sysStart.GetDevice())) {
  99.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  100.  
  101.         return false;
  102.     }
  103.    
  104.     ModelHuman->SetPosition(mVector(0.0f, -2.0f, 10.0f));
  105.     ModelHuman->SetScale(mVector(0.3f, 0.3f, 0.3f));
  106.    
  107.     // Next sign model
  108.     if (!ModelSign->LoadModel(".\\Placa01.obj", sysStart.GetDevice())) {
  109.         MessageBox(NULL, L"Unable to load Placa.obj", L"TGE", MB_OK);
  110.  
  111.         return false;
  112.     }
  113.  
  114.     ModelSign->SetPosition(mVector(5.0f, -3.0f, 10.0f));
  115.     ModelSign->SetScale(mVector(0.1f, 0.1f, 0.1f));
  116.  
  117.     // Next mug model
  118.     if (!ModelMug->LoadModel(".\\wooden mug1.x", sysStart.GetDevice())) {
  119.         MessageBox(NULL, L"Unable to load wooden mug1.x", L"TGE", MB_OK);
  120.  
  121.         return false;
  122.     }
  123.  
  124.     ModelMug->SetPosition(mVector(-5.0f, -0.7f, 6.0f));
  125.     ModelMug->SetScale(mVector(0.01f, 0.01f, 0.01f));
  126.  
  127.     // Next table model
  128.     if (!ModelTable->LoadModel(".\\Table.x", sysStart.GetDevice())) {
  129.         MessageBox(NULL, L"Unable to load Barrel.x", L"TGE", MB_OK);
  130.  
  131.         return false;
  132.     }
  133.  
  134.     ModelTable->SetPosition(mVector(-5.0f, -2.0f, 6.0f));
  135.     ModelTable->SetRotation(mVector(-1.57f, 0.0f, 0.0f));
  136.  
  137.  
  138.     // Next cabinet model
  139.     if (!ModelCabinet->LoadModel(".\\cabinet.x", sysStart.GetDevice())) {
  140.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  141.  
  142.         return false;
  143.     }
  144.  
  145.     ModelCabinet->SetPosition(mVector(-7.0f, -2.0f, 5.0f));
  146.     ModelCabinet->SetRotation(mVector(-1.57f, 0.0f, 0.0f));
  147.  
  148.  
  149.     // Next houses model
  150.     if (!ModelHouses->LoadModel(".\\medstreet.obj", sysStart.GetDevice())) {
  151.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  152.  
  153.         return false;
  154.     }
  155.  
  156.     ModelHouses->SetPosition(mVector(0.0f, -2.0f, 20.0f));
  157.     ModelHouses->SetScale(mVector(2.1f, 2.1f, 2.1f));
  158.  
  159.     // Next axes model
  160.     if (!ModelAxes->LoadModel(".\\FREE AXE.obj", sysStart.GetDevice())) {
  161.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  162.  
  163.         return false;
  164.     }
  165.  
  166.     ModelAxes->SetPosition(mVector(0.5f, -0.5f, 10.0f));
  167.     ModelAxes->SetScale(mVector(0.1f, 0.1f, 0.1f));
  168.  
  169.     // Next shield model
  170.     if (!ModelShield->LoadModel(".\\SA_LD_Wooden_Shield.obj", sysStart.GetDevice())) {
  171.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  172.  
  173.         return false;
  174.     }
  175.  
  176.     ModelShield->SetScale(mVector(0.5f, 0.5f, 0.5f));
  177.  
  178.     // Next chalice model
  179.     if (!ModelChalice->LoadModel(".\\SA_LD_Chalice.obj", sysStart.GetDevice())) {
  180.         MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
  181.  
  182.         return false;
  183.     }
  184.  
  185.     ModelChalice->SetPosition(mVector(-8.0f, 2.0f, 5.0f));
  186.     ModelChalice->SetScale(mVector(0.1f, 0.1f, 0.1f));
  187.  
  188.     sysStart.CreateConstantBuffer(sysStart.m_hMainWnd);
  189.  
  190.     sysStart.CreateCullingRasterizersOnDepthTestStates(sysStart.m_hMainWnd);
  191.  
  192.     sysStart.SetRasterizerState(sysStart.m_hMainWnd);
  193.  
  194.     sysStart.CreateMeshes(sysStart.m_hMainWnd);
  195.  
  196.     //Creates skybox with chosen textures
  197.     if (sysStart.CreateCubemapSkybox(L".\\hills_up.jpg",
  198.         L".\\hills_dn.jpg",
  199.         L".\\hills_lf.jpg",
  200.         L".\\hills_rt.jpg",
  201.         L".\\hills_ft.jpg",
  202.         L".\\hills_bk.jpg", 512)) {
  203.         //return 1;
  204.     }
  205.  
  206.     //Declares billboards. PROBLEM WITH THIS AS THEY MAY ALL Be loading in exact same position
  207.     Billboards *treeBill = sysStart.AddBillboard();
  208.     Billboards *treeBill2 = sysStart.AddBillboard();
  209.     Billboards *treeBill3 = sysStart.AddBillboard();
  210.     Billboards *treeBill4 = sysStart.AddBillboard();
  211.     Billboards *treeBill5 = sysStart.AddBillboard();
  212.  
  213.     //Main loop
  214.     DWORD current = GetTickCount();
  215.     int count = 0;
  216.     int move = 0;//Declares movement values for animation
  217.    
  218.     while (sysStart.Run()) {
  219.         //Checks to see if program is trying to be exited
  220.         if (keyb.IsKeyDown(VK_ESCAPE)) {
  221.             //Exit loop when it is
  222.             break;
  223.         }
  224.  
  225.        
  226.  
  227.         sysStart.StartFrame(100, 100, 250);//Starts the frame
  228.  
  229.         sysStart.DrawAll();//Draws all
  230.        
  231.  
  232.         sysStart.EnableCamera();//Enables the camera
  233.  
  234.         //updates positions of animated models
  235.         ModelHuman->SetPosition(mVector(0.0f, 0.0f, 0.0f - (move/999.99)));
  236.         ModelShield->SetPosition(mVector(0.62f, 2.0f, 0.0f - (move/999.99)));
  237.         ModelMug->SetRotation(mVector(0.0f, 0.0f - (move / 999.99), 0.0f));
  238.         ModelChalice->SetRotation(mVector(0.0f, 0.0f - (move / 999.99), 0.0f));
  239.         ModelAxes->SetRotation(mVector(0.0f - (move / 999.99), 0.0f , 0.0f));
  240.         sysStart.EndFrame();
  241.  
  242.         count++;
  243.         move++;//Counts 1 to movement value every frame
  244.         DWORD now = GetTickCount();
  245.         //Sets FPS counter
  246.         if (now - current > 1000) {
  247.             wsprintf(fps, L"FPS = %d", count);
  248.  
  249.             sysStart.SetWindowTitle(fps);//Displays fps in title of window
  250.  
  251.  
  252.             count = 0;
  253.  
  254.             current = now;
  255.         }
  256.  
  257.        
  258.     }
  259.  
  260.  
  261.     return 0;
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement