Skip to content

Instantly share code, notes, and snippets.

#include "shortcut.h"
#include <QKeyEvent>
#include <QCoreApplication>
#include <QDebug>
Shortcut::Shortcut(QObject *parent)
: QObject(parent)
, m_keySequence()
, m_keypressAlreadySend(false)
{
@anunyin
anunyin / gist:7180565
Created October 27, 2013 11:16
Unity Rotation API
void Entity::SetRotation(const glm::quat& rotation)
{
m_Rotation = rotation;
// The const values are the world forward & world up respectively (in this case, a left-handed coordinate system).
m_Forward = glm::rotate(m_Rotation, glm::vec3(0.0f, 0.0f, 1.0f));
m_Up = glm::rotate(m_Rotation, glm::vec3(0.0f, 1.0f, 0.0f);
}
void Entity::SetEuler(const glm::vec3& rotation)
{
m_Rotation = glm::quat(rotation);
// Overwrite the rotation value entirely w/ a new one.
SetRotation(quaternion rot);
SetRotationEuler(vec3 rot);
SetRotationAxis(float angle, vec3 axis);
// Apply an additional rotation to the currently existing one.
Rotate(quaternion rot);
RotateEuler(vec3 rot);
RotateAxis(float angle, vec3 axis);
vec3 object1(15.2f, 0.0f, -12.0f);
vec3 object2(0.0f, 0.0f, 0.0f);
// Set the forward vector to align with the vector between these two positions.
// Effectively having the second object "look at" the first.
object2.SetForward(object1 - object2);
@anunyin
anunyin / gist:6604014
Last active January 22, 2019 15:53
SDL 2: Changing Resolution at Runtime
// windowHandle is a pointer to an SDL_Window object, acquired and stored from your original call to SDL_CreateWindow
SDL_DestroyWindow(windowHandle);
// You'll probably want to keep the window title and window position unchanged
// by caching those values before you destroy the previous window.
windowHandle = SDL_CreateWindow("Window Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, newWidth, newHeight, SDL_WINDOW_OPENGL);
// windowContext is an SDL_GLContext object, acquired and stored from your initial SDL_GL_CreateContext call.
SDL_GL_MakeCurrent(windowHandle, windowContext);
// Again, keeping in mind that resolution and window size are separate things --
// windowHandle is a pointer to an SDL_Window object, acquired and stored from your original call to SDL_CreateWindow
SDL_DestroyWindow(windowHandle);
// You'll probably want to keep the window title and window position unchanged
// by caching those values before you destroy the previous window.
windowHandle = SDL_CreateWindow("Window Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, newWidth, newHeight, SDL_WINDOW_OPENGL);
// windowContext is an SDL_GLContext object, acquired and stored from your initial SDL_GL_CreateContext call.
SDL_GL_MakeCurrent(windowHandle, windowContext);
// Still needs to be called to update the rendered area.
glViewport(newWidth, newHeight);
@anunyin
anunyin / gist:6603453
Created September 18, 2013 01:56
SDL2: Changing Resolution during Runtime
SDL_DestroyWindow(windowHandle);
windowHandle = SDL_CreateWindow("Window Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, newWidth, newHeight, SDL_WINDOW_OPENGL);
SDL_GL_MakeCurrent(windowHandle, windowContext);
@anunyin
anunyin / gist:5145718
Created March 12, 2013 18:44
ShaderlessOpenGL
#include <SDL.h>
#include <Windows.h>
#include <gl/glew.h>
#include <gl/GL.h>
#include <stdexcept>
#undef main
struct Vector3 {
float x, y, z;
Vector3(float _x, float _y, float _z) {
@anunyin
anunyin / gist:5145715
Created March 12, 2013 18:44
ShaderlessOpenGL
#include <SDL.h>
#include <Windows.h>
#include <gl/glew.h>
#include <gl/GL.h>
#include <stdexcept>
#undef main
struct Vector3 {
float x, y, z;
Vector3(float _x, float _y, float _z) {
#include <SDL.h>
#include <Windows.h>
#include <gl/glew.h>
#include <gl/GL.h>
#include <stdexcept>
#undef main
struct Vector3 {
float x, y, z;
Vector3(float _x, float _y, float _z) {