Skip to content

Instantly share code, notes, and snippets.

@zhenzhenxiang
zhenzhenxiang / polynomial_fitting.cpp
Created November 12, 2020 08:18 — forked from ksjgh/polynomial_fitting.cpp
Polynomial fitting
// In this quiz you'll fit a polynomial to waypoints.
#include <iostream>
#include "Dense"
using namespace Eigen;
/////////////////////////////////////////////////////////////////////////////////////////////
// Fit a polynomial.
// Adapted from
// https://github.com/JuliaMath/Polynomials.jl/blob/master/src/Polynomials.jl#L676-L716
@qingfengxia
qingfengxia / enum_class_json_conversion.cpp
Last active April 23, 2023 18:11
example code to show c++ enum class to NLOHMANN json conversion
/*
NLOHMANN_JSON_SERIALIZE_ENUM expanded to inline functions, so this macro should be placed in header where enum class is declared
also this macro must be declared within enum type's namespace
```
// include loguru header here, declear enum NamedVerbosity
// this code injection happen in your project header file, no need to modify loguru.hpp
namespace loguru
{
// this macro must be called in the enum declaring namespace
@chutsu
chutsu / Eigen Spline Module 1D Example.md
Last active August 18, 2024 19:11
Eigen Spline Module 1D Example

Eigen has an unsupported spline module where you can fit a spline given some data. Once a spline is fitted you can use it as a function to obtain points inbetween. The following example fits 1D data but can be modified to fit N-dimensional data.

Usage

 git clone https://gist.github.com/chutsu/815c7c916c329eec85f34690a012f7cb spline_example
 g++ -I/usr/include/eigen3 spline_example.cpp -o spline_example

./spline_example

@sebbbi
sebbbi / FastUniformLoadWithWaveOps.txt
Last active October 23, 2025 09:04
Fast uniform load with wave ops (up to 64x speedup)
In shader programming, you often run into a problem where you want to iterate an array in memory over all pixels in a compute shader
group (tile). Tiled deferred lighting is the most common case. 8x8 tile loops over a light list culled for that tile.
Simplified HLSL code looks like this:
Buffer<float4> lightDatas;
Texture2D<uint2> lightStartCounts;
RWTexture2D<float4> output;
[numthreads(8, 8, 1)]
@gcatlin
gcatlin / glfw-metal-example.m
Last active October 13, 2025 01:15
Minimal C GLFW Metal example
//
// cc glfw-metal-example.m `pkg-config --cflags --libs glfw3` -framework AppKit -framework Metal -framework QuartzCore
//
#define GLFW_INCLUDE_NONE
#define GLFW_EXPOSE_NATIVE_COCOA
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
@gcatlin
gcatlin / sdl-metal-example.m
Last active February 24, 2025 15:11
Minimal C SDL2 Metal example
//
// cc sdl-metal-example.m `sdl2-config --cflags --libs` -framework Metal -framework QuartzCore && ./a.out
//
#include <SDL.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
int main (int argc, char *args[])
{
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
@isc30
isc30 / triangle.cpp
Last active January 28, 2025 12:11 — forked from vittorioromeo/hello_triangle.cpp
SDL2 + WebGL 2.0 = Triangle
#include <iostream>
#include <exception>
#include <functional>
#include <vector>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#ifndef __EMSCRIPTEN__
@qfgaohao
qfgaohao / pb_utils.cc
Last active April 6, 2023 11:05
Demonstrate how to save and read a protobuf message AddressBook to/from pb or pbtxt files.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <google/protobuf/text_format.h>
// for read_from_pbtxt_nocopy
#include <fcntl.h>
#pragma once
#include <Eigen/Dense>
#include <glm/matrix.hpp>
template<typename T, int m, int n>
inline glm::mat<m, n, float, glm::precision::highp> E2GLM(const Eigen::Matrix<T, m, n>& em)
{
glm::mat<m, n, float, glm::precision::highp> mat;
for (int i = 0; i < m; ++i)
{