Skip to content

Instantly share code, notes, and snippets.

View gszauer's full-sized avatar
💻
Living life 16.6 ms at a time

Gabor Szauer gszauer

💻
Living life 16.6 ms at a time
View GitHub Profile
@gszauer
gszauer / PolyRasterV0.cpp
Created September 13, 2021 00:11
PolygonRasterizer
#include "PolyRasterV0.h"
#include <cmath>
#include <iostream>
namespace Rasterizer {
void raster_polygon_assert(bool b) {
if (!b) {
*((u8*)0) = 42;
}
}
@gszauer
gszauer / Font.cpp
Last active July 26, 2023 06:21
Minimal ttf parser and rasterizer
#define _CRT_SECURE_NO_WARNINGS
#include "Font.h"
#include <tuple>
using std::vector;
using std::tuple;
using std::get;
void DrawPixel(i32 x, i32 y, u8 r, u8 g, u8 b);
@gszauer
gszauer / Line.cpp
Last active May 20, 2021 04:43
LineBlog
#include "Line.h"
#include <cmath>
#include <iostream>
inline int max(int a, int b) {
if (a > b) {
return a;
}
return b;
}
@gszauer
gszauer / gameplay::Animation.md
Last active August 20, 2020 21:17
gameplay3d::Animation breakdown

Core classes

class Animation

Defines a generic property animation. To run an animation you must play an AnimationClip. Every Animation has the default clip which will run from begin-end time. You can create additional clips to run only parts of an animation and control various runtime characteristics, such as repeat count, etc.

TODO: Fill ouy with own words

@gszauer
gszauer / CurveExplorer
Created July 28, 2020 07:04
Explore Unity Curves
using System.Collections;
using UnityEngine;
using UnityEditor;
public class CurveExplorer : MonoBehaviour
{
public AnimationCurve curve;
[MenuItem("CONTEXT/CurveExplorer/Copy Data")]
static void CopyCurveInfo(MenuCommand command)
--no-sandbox --disable-gpu-watchdog --gpu-startup-dialog --no-sandbox --disable-gpu-watchdog --gpu-startup-dialog
@gszauer
gszauer / handle.cpp
Created December 20, 2019 08:09
Win32-Wait-For-VSYNCH
typedef LONG NTSTATUS;
typedef UINT D3DKMT_HANDLE;
typedef UINT D3DDDI_VIDEO_PRESENT_SOURCE_ID;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
typedef struct _D3DKMT_WAITFORVERTICALBLANKEVENT {
D3DKMT_HANDLE hAdapter; // in: adapter handle
D3DKMT_HANDLE hDevice; // in: device handle [Optional]
@gszauer
gszauer / orbit.cpp
Last active October 8, 2019 22:45
OrbitCamera
// https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
float getRoll(const quat& q) {
// roll (x-axis rotation)
float sinr_cosp = 2.0f * (q.w * q.x + q.y * q.z);
float cosr_cosp = 1.0f - 2.0f * (q.x * q.x + q.y * q.y);
return atan2(sinr_cosp, cosr_cosp);
}
float getPitch(const quat& q) {
// pitch (y-axis rotation)
@gszauer
gszauer / look.cpp
Created May 30, 2019 01:46
OpenGL Look At
mat4 lookAt(const vec3& position, const vec3& target, const vec3& up) {
// Remember, forward is negative z
vec3 f = normalized(target - position) * -1.0f;
vec3 r = cross(up, f);
if (r == vec3(0, 0, 0)) {
std::cout << "WARNING: mat4 lookAt has invalid right vector\n";
return mat4(); // Error
}
normalize(r);
vec3 u = normalized(cross(f, r));
@gszauer
gszauer / DualQuatWithScaling.glsl
Created March 31, 2019 19:57
Dual Quaternion With Scaling
// Dual quaternion vertex shader with arbitrary scaling support
// Shown here: https://twitter.com/gszauer/status/1108618057637724160
/* Data that ends up getting passed to this shader:
void CombineDualQuaternions(
glm::quat &real_r, glm::quat &dual_r, // output
glm::quat &real_a, glm::quat &dual_a, // input left
glm::quat &real_b, glm::quat &dual_b) { // input right
glm::quat real = real_a * real_b;