Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- //Declares header files
- #include "SystemStarter.h"
- #include "Skybox.h"
- #include "Terrain.h"
- #include "Billboards.h"
- //declares keyboard handler for use in main
- class MyKeyboardHandler : public KeyboardHandler {
- public:
- MyKeyboardHandler() {
- for (int idx = 0; idx < 256; idx++) {
- Keys[idx] = false;
- }
- }
- void KeyPressed(char c) {
- Keys[c] = true;
- }
- void KeyReleased(char c) {
- Keys[c] = false;
- }
- bool IsKeyDown(char c) {
- return Keys[c];
- }
- private:
- bool Keys[256];
- };
- //Windows main function
- int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLineArgs, int nInitialWinShowState)
- {
- //FPS decleration
- wchar_t fps[64];
- ZeroMemory(fps, 64);
- int increase = 1.0f;
- //Keyboard handler
- MyKeyboardHandler keyb;
- //System starter
- SystemStarter sysStart;
- //Model handler
- Model model;
- //Skybox handler
- Skybox sky;
- //Billboard handler
- Billboards bill;
- //Terrain handler
- Terrain ter;
- //Starts window with 1000x80 resolution
- if (!sysStart.Initialiser(1000, 800)) {
- MessageBox(NULL, L"Unable to initialise DirectX", L"TGE", MB_OK);
- return -1;
- }
- //Sets the handler
- sysStart.SetKeyboardHandler(&keyb);
- //Sets the camera position
- sysStart.SetCameraPosi(Vector(0.0f, 5.0f, -10.0f));
- //Declares all used models
- Model *ModelShack = sysStart.AddModel();
- Model *ModelHuman = sysStart.AddModel();
- Model *ModelSign = sysStart.AddModel();
- Model *ModelMug = sysStart.AddModel();
- Model *ModelTable = sysStart.AddModel();
- Model *ModelCabinet = sysStart.AddModel();
- Model *ModelHouses = sysStart.AddModel();
- Model *ModelAxes = sysStart.AddModel();
- Model *ModelShield = sysStart.AddModel();
- Model *ModelChalice = sysStart.AddModel();
- //Loads the shack model
- if (!ModelShack->LoadModel(".\\klo_uv.x", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load earth.x", L"TGE", MB_OK);
- return false;
- }
- ModelShack->SetPosition(mVector(10.0f, -2.0f, 12.0f));
- ModelShack->SetScale(mVector(0.03f, 0.03f, 0.03f));
- ModelShack->SetRotation(mVector(-1.57f, 3.14f, 0.0f));
- // Next human model
- if (!ModelHuman->LoadModel(".\\Male1.x", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelHuman->SetPosition(mVector(0.0f, -2.0f, 10.0f));
- ModelHuman->SetScale(mVector(0.3f, 0.3f, 0.3f));
- // Next sign model
- if (!ModelSign->LoadModel(".\\Placa01.obj", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load Placa.obj", L"TGE", MB_OK);
- return false;
- }
- ModelSign->SetPosition(mVector(5.0f, -3.0f, 10.0f));
- ModelSign->SetScale(mVector(0.1f, 0.1f, 0.1f));
- // Next mug model
- if (!ModelMug->LoadModel(".\\wooden mug1.x", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load wooden mug1.x", L"TGE", MB_OK);
- return false;
- }
- ModelMug->SetPosition(mVector(-5.0f, -0.7f, 6.0f));
- ModelMug->SetScale(mVector(0.01f, 0.01f, 0.01f));
- // Next table model
- if (!ModelTable->LoadModel(".\\Table.x", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load Barrel.x", L"TGE", MB_OK);
- return false;
- }
- ModelTable->SetPosition(mVector(-5.0f, -2.0f, 6.0f));
- ModelTable->SetRotation(mVector(-1.57f, 0.0f, 0.0f));
- // Next cabinet model
- if (!ModelCabinet->LoadModel(".\\cabinet.x", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelCabinet->SetPosition(mVector(-7.0f, -2.0f, 5.0f));
- ModelCabinet->SetRotation(mVector(-1.57f, 0.0f, 0.0f));
- // Next houses model
- if (!ModelHouses->LoadModel(".\\medstreet.obj", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelHouses->SetPosition(mVector(0.0f, -2.0f, 20.0f));
- ModelHouses->SetScale(mVector(2.1f, 2.1f, 2.1f));
- // Next axes model
- if (!ModelAxes->LoadModel(".\\FREE AXE.obj", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelAxes->SetPosition(mVector(0.5f, -0.5f, 10.0f));
- ModelAxes->SetScale(mVector(0.1f, 0.1f, 0.1f));
- // Next shield model
- if (!ModelShield->LoadModel(".\\SA_LD_Wooden_Shield.obj", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelShield->SetScale(mVector(0.5f, 0.5f, 0.5f));
- // Next chalice model
- if (!ModelChalice->LoadModel(".\\SA_LD_Chalice.obj", sysStart.GetDevice())) {
- MessageBox(NULL, L"Unable to load dwarf.x", L"TGE", MB_OK);
- return false;
- }
- ModelChalice->SetPosition(mVector(-8.0f, 2.0f, 5.0f));
- ModelChalice->SetScale(mVector(0.1f, 0.1f, 0.1f));
- sysStart.CreateConstantBuffer(sysStart.m_hMainWnd);
- sysStart.CreateCullingRasterizersOnDepthTestStates(sysStart.m_hMainWnd);
- sysStart.SetRasterizerState(sysStart.m_hMainWnd);
- sysStart.CreateMeshes(sysStart.m_hMainWnd);
- //Creates skybox with chosen textures
- if (sysStart.CreateCubemapSkybox(L".\\hills_up.jpg",
- L".\\hills_dn.jpg",
- L".\\hills_lf.jpg",
- L".\\hills_rt.jpg",
- L".\\hills_ft.jpg",
- L".\\hills_bk.jpg", 512)) {
- //return 1;
- }
- //Declares billboards. PROBLEM WITH THIS AS THEY MAY ALL Be loading in exact same position
- Billboards *treeBill = sysStart.AddBillboard();
- Billboards *treeBill2 = sysStart.AddBillboard();
- Billboards *treeBill3 = sysStart.AddBillboard();
- Billboards *treeBill4 = sysStart.AddBillboard();
- Billboards *treeBill5 = sysStart.AddBillboard();
- //Main loop
- DWORD current = GetTickCount();
- int count = 0;
- int move = 0;//Declares movement values for animation
- while (sysStart.Run()) {
- //Checks to see if program is trying to be exited
- if (keyb.IsKeyDown(VK_ESCAPE)) {
- //Exit loop when it is
- break;
- }
- sysStart.StartFrame(100, 100, 250);//Starts the frame
- sysStart.DrawAll();//Draws all
- sysStart.EnableCamera();//Enables the camera
- //updates positions of animated models
- ModelHuman->SetPosition(mVector(0.0f, 0.0f, 0.0f - (move/999.99)));
- ModelShield->SetPosition(mVector(0.62f, 2.0f, 0.0f - (move/999.99)));
- ModelMug->SetRotation(mVector(0.0f, 0.0f - (move / 999.99), 0.0f));
- ModelChalice->SetRotation(mVector(0.0f, 0.0f - (move / 999.99), 0.0f));
- ModelAxes->SetRotation(mVector(0.0f - (move / 999.99), 0.0f , 0.0f));
- sysStart.EndFrame();
- count++;
- move++;//Counts 1 to movement value every frame
- DWORD now = GetTickCount();
- //Sets FPS counter
- if (now - current > 1000) {
- wsprintf(fps, L"FPS = %d", count);
- sysStart.SetWindowTitle(fps);//Displays fps in title of window
- count = 0;
- current = now;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement