~sircmpwn/xrgears

ref: c4afd33e13398688fc03f60ef3d0a498bf40bfdd xrgears/vitamin-k/VikCamera.hpp -rw-r--r-- 1.2 KiB
c4afd33e — Lubosz Sarnecki add new abstract classes for interfaces between vks and vkc. 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * XRGears
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_FORCE_LEFT_HANDED

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <gli/gli.hpp>

#include "../vks/vksCamera.hpp"

#include "VikBuffer.hpp"

class VikCamera {
 public:
  vks::Buffer uniformBuffer;

  struct UBOCamera {
    glm::mat4 projection[2];
    glm::mat4 view[2];
    glm::mat4 skyView[2];
    glm::vec3 position;
  } uboCamera;

  ~VikCamera() {
    uniformBuffer.destroy();
  }

  virtual void update(Camera camera) {
    uboCamera.projection[0] = camera.matrices.perspective;
    uboCamera.view[0] = camera.matrices.view;
    uboCamera.skyView[0] = glm::mat4(glm::mat3(camera.matrices.view));
    uboCamera.position = camera.position * -1.0f;
    memcpy(uniformBuffer.mapped, &uboCamera, sizeof(uboCamera));
  }

  void prepareUniformBuffers(vks::Device *vulkanDevice) {
    VikBuffer::create(vulkanDevice, &uniformBuffer, sizeof(uboCamera));
  }
};