Skip to content

Instantly share code, notes, and snippets.

@ongamex
ongamex / file2array.py
Created April 29, 2022 22:15
Converts a binary file to char[] in C++
import sys
import argparse
def bytesToCHeader(fileBytes: bytes, inputFileName: str, variableName: str) -> str:
fileText = "#pragma once\n";
fileText += "\n";
fileText += "//----------------------------------------------\n";
fileText += "// This is an auto-generated file.\n";
fileText += "// It contains the binary representation of " + inputFileName + " as a C-Array.\n";
fileText += "//----------------------------------------------\n";
// <?php PHP for syntax, but the language is actually MEL
proc exportSceneToFBX()
{
string $sceneFilename = `file -q -sn`;
string $buffer[];
tokenize $sceneFilename "." $buffer;
string $outFilename = $buffer[0];
void ACar::update(const GameUpdateSets& updateSets)
{
if(updateSets.isGamePaused())
return;
m_traitCamera.update(this, updateSets);
m_traitCamera.rotateWorkingDirectionTowardsFlat((-getTransformMtx().data[0].xyz().normalized0() + 2.5f*vec3f::getAxis(1)).normalized(), updateSets.dt);
//m_traitCamera.rotateWorkingDirectionTowardsFlat((-getTransformMtx().data[0].xyz().normalized0() + 0.5f*vec3f::getAxis(1)).normalized(), updateSets.dt);
struct Tyre
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>constref</Title>
<Shortcut>constref</Shortcut>
</Header>
<Snippet>
<Code Language="CPP">
<![CDATA[const $selected$&]]>
@ongamex
ongamex / stb.c
Created May 25, 2018 22:22 — forked from urraka/stb.c
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STBI_ONLY_PNG
#define STBI_ONLY_JPEG
#define STBI_ONLY_BMP
#define STBI_ONLY_GIF
#include "stb_image.h"
#include "stb_image_write.h"
@ongamex
ongamex / d_ggx.glsl
Created February 2, 2018 21:32 — forked from meshula/d_ggx.glsl
D_GGX in mediump/half float
float D_GGX(float linearRoughness, float NoH, const vec3 h) {
// Walter et al. 2007, "Microfacet Models for Refraction through Rough Surfaces"
// In mediump, there are two problems computing 1.0 - NoH^2
// 1) 1.0 - NoH^2 suffers floating point cancellation when NoH^2 is close to 1 (highlights)
// 2) NoH doesn't have enough precision around 1.0
// Both problem can be fixed by computing 1-NoH^2 in highp and providing NoH in highp as well
// However, we can do better using Lagrange's identity:
// ||a x b||^2 = ||a||^2 ||b||^2 - (a . b)^2
@ongamex
ongamex / imgui_node_graph_test.cpp
Created November 4, 2017 22:02 — forked from ocornut/imgui_node_graph_test.cpp
Node graph editor basic demo for ImGui
// Creating a node graph editor for ImGui
// Quick demo, not production code! This is more of a demo of how to use ImGui to create custom stuff.
// Better version by @daniel_collin here https://gist.github.com/emoon/b8ff4b4ce4f1b43e79f2
// See https://github.com/ocornut/imgui/issues/306
// v0.02
// Animated gif: https://cloud.githubusercontent.com/assets/8225057/9472357/c0263c04-4b4c-11e5-9fdf-2cd4f33f6582.gif
// NB: You can use math functions/operators on ImVec2 if you #define IMGUI_DEFINE_MATH_OPERATORS and #include "imgui_internal.h"
// Here we only declare simple +/- operators so others don't leak into the demo code.
static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
bool MyImGui::DragFloats(const char* label, float* floats, int numFloats, bool* pJustReleased, float v_speed, float v_min, float v_max, const char* display_format, float power)
{
ImGuiWindow* window = ImGui::GetCurrentWindow();
if(window->SkipItems)
return false;
if(pJustReleased) {
*pJustReleased = false;
}
@ongamex
ongamex / ImguiMayaStyle.cpp
Created December 29, 2016 12:05
ImGui style that look like Maya
ImGuiStyle& style = ImGui::GetStyle();
style.ChildWindowRounding = 3.f;
style.GrabRounding = 0.f;
style.WindowRounding = 0.f;
style.ScrollbarRounding = 3.f;
style.FrameRounding = 3.f;
style.WindowTitleAlign = ImVec2(0.5f,0.5f);
style.Colors[ImGuiCol_Text] = ImVec4(0.73f, 0.73f, 0.73f, 1.00f);
// variadic.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <memory>
#include <iostream>
#include <functional>