Changeset 4ece3bf in opengl-game


Ignore:
Timestamp:
Jan 21, 2020, 6:14:09 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
5a1ace0
Parents:
3e8cc8b
Message:

In VulkanGame, add the ability to delete asteroids and move them at a constant speed

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • game-gui-sdl.cpp

    r3e8cc8b r4ece3bf  
    127127         case SDL_AUDIODEVICEADDED:
    128128         case SDL_AUDIODEVICEREMOVED:
     129         case SDL_TEXTINPUT:
    129130         case SDL_TEXTEDITING: // TODO: Research this one later
    130131            event->type = UI_EVENT_UNKNOWN;
  • new-game.cpp

    r3e8cc8b r4ece3bf  
    731731      // temporary code to get around vsync issue in OSX Sierra
    732732      if (elapsedTime < (1.0f / TARGET_FPS)) {
    733         continue;
     733         continue;
    734734      }
    735735
  • shaders/asteroid.vert

    r3e8cc8b r4ece3bf  
    55   mat4 model;
    66   float hp;
     7   bool deleted;
    78};
    89
     
    4243  light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0));
    4344
    44   gl_Position = ubo.proj * vec4(position_eye, 1.0);
     45  if (sbo.objects[obj_index].deleted) {
     46     gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
     47  } else {
     48    gl_Position = ubo.proj * vec4(position_eye, 1.0);
     49  }
    4550}
  • vulkan-game.cpp

    r3e8cc8b r4ece3bf  
    9898   SDL_VERSION(&sdlVersion);
    9999
    100    cout << "SDL " << sdlVersion.major << "." << sdlVersion.minor << "." << sdlVersion.patch << endl;
     100   cout << "SDL "<<
     101      to_string(sdlVersion.major) << "." <<
     102      to_string(sdlVersion.minor) << "." <<
     103      to_string(sdlVersion.patch) << endl;
    101104
    102105   font = TTF_OpenFont("assets/fonts/lazy.ttf", 28);
     
    600603      scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    601604
    602    //vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f));
    603    vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f);
     605   // vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f));
     606   // vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f);
     607   // vec3 pos = vec3(1.0f, -1.2f, -1.0f);
     608   vec3 pos = vec3(0.0504826f, -1.2f, 1.0f);
    604609
    605610   asteroidObjects[0].model_base =
     
    608613      scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    609614   asteroidObjects[0].model_transform = mat4(1.0); // Might not be needed
     615
     616   so_Asteroid.hp = 10.0f;
     617   so_Asteroid.deleted = 0;
    610618}
    611619
     
    655663   bool quit = false;
    656664
     665   curTime = SDL_GetPerformanceCounter();
     666
    657667   while (!quit) {
     668
     669      prevTime = curTime;
     670      curTime = SDL_GetPerformanceCounter();
     671
     672      elapsedTime = (double)((curTime - prevTime) * 1000 / (double)SDL_GetPerformanceFrequency());
     673
    658674      gui->processEvents();
    659675
     
    693709
    694710                  createCommandBuffers();
     711               } else if (e.key.keycode == SDL_SCANCODE_Z) {
     712                  cout << "Deleting asteroid..." << endl;
     713                  so_Asteroid.deleted = so_Asteroid.deleted == 0 ? 1 : 0;
    695714               } else {
    696715                  cout << "Key event detected" << endl;
     
    717736      // Check which keys are held down
    718737
     738      float shipSpeed = 0.0005f;
     739      float asteroidSpeed = 0.002f;
     740
    719741      if (gui->keyPressed(SDL_SCANCODE_LEFT)) {
    720          transformObject(shipObjects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)));
     742         transformObject(shipObjects[0], translate(mat4(1.0f), vec3(-shipSpeed * elapsedTime, 0.0f, 0.0f)));
    721743      } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) {
    722          transformObject(shipObjects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)));
     744         transformObject(shipObjects[0], translate(mat4(1.0f), vec3(shipSpeed * elapsedTime, 0.0f, 0.0f)));
    723745      }
    724746
    725       // this code moves the asteroids
    726       transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)));
     747      if (gui->keyPressed(SDL_SCANCODE_DOWN)) {
     748         transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, asteroidSpeed * elapsedTime)));
     749      }
    727750
    728751      renderUI();
     
    750773
    751774   so_Asteroid.model = asteroidObjects[0].model_transform * asteroidObjects[0].model_base;
    752    so_Asteroid.hp = 10.0;
    753775
    754776   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats);
  • vulkan-game.hpp

    r3e8cc8b r4ece3bf  
    7070   alignas(16) mat4 model;
    7171   alignas(4) float hp;
     72   alignas(4) unsigned int deleted;
    7273};
    7374
     
    194195      UBO_VP_mats asteroid_VP_mats;
    195196      SBO_Asteroid so_Asteroid;
     197
     198      Uint64 curTime, prevTime;
     199      double elapsedTime;
    196200
    197201      bool initWindow(int width, int height, unsigned char guiFlags);
Note: See TracChangeset for help on using the changeset viewer.