Skip to content

Instantly share code, notes, and snippets.

View XProger's full-sized avatar

Timur Gagiev XProger

View GitHub Profile
Nintendo
- GameBoy - Dot Matrix Game
- 64 - Project Reality
- DS - Nitro
- 2DS/3DS - Citra
- GameCube - Dolphin
- Wii - Revolution
- Wii U - Cafe
- Switch - NX
@XProger
XProger / pvr.h
Last active January 20, 2019 22:34
PVR file loader for OGL
#define PVR_RGBA8 0x61626772
#define PVR_PVRTC4 0x00000002
#define PVR_ETC1 0x00000006
#define PVR_BC1 0x00000007
#define PVR_ALPHA 0x00000061
#define GL_COMPRESSED_RGB_S3TC_DXT1 0x83F0
#define GL_ETC1_RGB8_OES 0x8D64
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1 0x8C00
@XProger
XProger / support_map.cpp
Created September 17, 2018 13:32
support mapping for basic primitives
void supportPoint(const Body &body, const vec3 &dir, vec3 &v) {
v = vec3::ZERO;
}
void supportSegment(const Body &body, const vec3 &dir, vec3 &v) {
v.x = v.z = 0.0f;
v.y = sign(dir.y) * body.height;
}
void supportRect(const Body &body, const vec3 &dir, vec3 &v) {
@XProger
XProger / cloth_gl.cpp
Last active November 6, 2017 02:25
cloth simulation
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <gl/GL.h>
// simulation
#define SIZE_X 129
#define SIZE_Y 129
#define RIGID_FACTOR 0.5f
#define DAMPING_FACTOR 0.998f
@XProger
XProger / circle_vs_segment.cpp
Created September 20, 2017 00:13
circle vs line segment intersection check
bool Circle::intersect(const Segment2D &segment, vec2 &n, float &t) const {
vec2 ap = center - segment.a;
vec2 ab = segment.b - segment.a;
float dab = ab.dot(ab);
if (dab == 0.0f) return false;
t = clamp(ap.dot(ab) / dab, 0.0f, 1.0f);
n = center - (segment.a + ab * t);
t = n.length2();
@XProger
XProger / quat_quat2.cpp
Created August 22, 2017 20:26
quaternions and dual-quaternions
// quat
const quat quat::IDENTITY(0.0f, 0.0f, 0.0f, 1.0f);
const quat quat::ZERO(0.0f, 0.0f, 0.0f, 0.0f);
quat::quat() {}
quat::quat(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
quat::quat(const vec3 &axis, float angle) {
angle *= 0.5f;
float s = sinf(angle);
@XProger
XProger / aabb_ray.cpp
Last active February 9, 2017 16:25
AABB vs Ray intersection test
bool AABB::intersect(const vec3 &rayPos, const vec3 &rayDir, float &t) const {
float t1 = INF, t0 = -t1;
for (int i = 0; i < 3; i++)
if (rayDir[i] != 0) {
float lo = (min[i] - rayPos[i]) / rayDir[i];
float hi = (max[i] - rayPos[i]) / rayDir[i];
t0 = _max(t0, _min(lo, hi));
t1 = _min(t1, _max(lo, hi));
} else
if (rayPos[i] < min[i] || rayPos[i] > max[i])
@XProger
XProger / quinqunx_3x3_blur.glsl
Last active February 2, 2017 00:30
Get average color for 3x3 kernel by 4 fetch using bilinear filter
vec4 dx = vec4(0.25, 0.96, -0.25, -0.96) * uTexelSize.xyxy + vTexCoord.xyxy;
vec4 dy = vec4(0.25, 0.96, -0.25, -0.96) * uTexelSize.yxyx + vTexCoord.yxyx;
vec4 average = (texture2D(sTex, dx.zy) + texture2D(sTex, dx.xw) +
texture2D(sTex, dy.yx) + texture2D(sTex, dy.wz)) * 0.25;
@XProger
XProger / frustum_sphere.glsl
Created August 23, 2016 09:06
frustum culling for sphere
// Computes signed distance between a point and a plane
// vPlane: Contains plane coefficients (a,b,c,d) where: ax + by + cz = d
// vPoint: Point to be tested against the plane.
float DistanceToPlane( vec4 vPlane, vec3 vPoint )
{
return dot(vec4(vPoint, 1.0), vPlane);
}
// Frustum cullling on a sphere. Returns > 0 if visible, <= 0 otherwise
float CullSphere( vec4 vPlanes[6], vec3 vCenter, float fRadius )
@XProger
XProger / fast_orho_basis.c
Last active March 13, 2018 04:53
method to get orthonormal basis without normalization by Jeppe Revall Frisvad (jrf@imm.dtu.dk)
void getBasis(const vec3 &n, vec3 &t, vec3 &b) {
if (n.z < -0.9999999f) {
t = vec3( 0.0f, -1.0f, 0.0f);
b = vec3(-1.0f, 0.0f, 0.0f);
return;
}
const float x = 1.0f / (1.0f + n.z);
const float y = -n.x*n.y*x;
t = vec3(1.0f - n.x*n.x*x, y, -n.x);
b = vec3(b, 1.0f - n.y*n.y*x, -n.y);