source: opengl-game/utils.hpp@ 9d21aac

feature/imgui-sdl
Last change on this file since 9d21aac was db2d995, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

Make the printVec and printMat functions a bit easier to use and add a printVec for vec2

  • Property mode set to 100644
File size: 979 bytes
Line 
1#ifndef __UTILS_H__
2#define __UTILS_H__
3
4#include <string>
5
6#include <glm/mat4x4.hpp>
7#include <glm/gtc/type_ptr.hpp>
8
9using namespace std;
10using namespace glm;
11
12void seedRandomNums();
13float getRandomNum(float low, float high);
14
15void printVec(string label, const vec2& v);
16void printVec(string label, const vec3& v);
17void printVec(string label, const vec4& v);
18void printMat(string label, const mat4& m);
19
20// Code for offset_of function from https://gist.github.com/graphitemaster/494f21190bb2c63c5516
21
22template <typename T1, typename T2>
23struct offset_of_impl {
24 static T2 object;
25 static constexpr size_t offset(T1 T2::*member) {
26 return size_t(&(offset_of_impl<T1, T2>::object.*member)) -
27 size_t(&offset_of_impl<T1, T2>::object);
28 }
29};
30template <typename T1, typename T2>
31T2 offset_of_impl<T1, T2>::object;
32
33template <typename T1, typename T2>
34inline constexpr size_t offset_of(T1 T2::*member) {
35 return offset_of_impl<T1, T2>::offset(member);
36}
37
38#endif
Note: See TracBrowser for help on using the repository browser.