Vulkan-Hpp
math.cpp
Go to the documentation of this file.
1 // Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 
16 // ignore warning 4127: conditional expression is constant
17 #if defined( _MSC_VER )
18 # pragma warning( disable : 4127 )
19 #elif defined( __GNUC__ )
20 // don't know how to switch off that warning here
21 #else
22 // unknow compiler... just ignore the warnings for yourselves ;)
23 #endif
24 
25 #include "math.hpp"
26 
27 namespace vk
28 {
29  namespace su
30  {
31  glm::mat4x4 createModelViewProjectionClipMatrix( vk::Extent2D const & extent )
32  {
33  float fov = glm::radians( 45.0f );
34  if ( extent.width > extent.height )
35  {
36  fov *= static_cast<float>( extent.height ) / static_cast<float>( extent.width );
37  }
38 
39  glm::mat4x4 model = glm::mat4x4( 1.0f );
40  glm::mat4x4 view = glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
41  glm::mat4x4 projection = glm::perspective( fov, 1.0f, 0.1f, 100.0f );
42  // clang-format off
43  glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
44  0.0f, -1.0f, 0.0f, 0.0f,
45  0.0f, 0.0f, 0.5f, 0.0f,
46  0.0f, 0.0f, 0.5f, 1.0f ); // vulkan clip space has inverted y and half z !
47  // clang-format on
48  return clip * projection * view * model;
49  }
50  } // namespace su
51 } // namespace vk
glm::mat4x4 createModelViewProjectionClipMatrix(vk::Extent2D const &extent)
Definition: math.cpp:31
Definition: vulkan.cppm:23