Skip to content

Instantly share code, notes, and snippets.

View DragoniteSpam's full-sized avatar
🐉
I like dragons

Michael DragoniteSpam

🐉
I like dragons
View GitHub Profile
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
#pragma include("lighting.f.xsh")
/// https://github.com/GameMakerDiscord/Xpanda
uniform float lightBuckets;
varying vec4 v_lightColour;
/// @param xx
/// @param yy
/// @param zz
/// @param view_mat
/// @param proj_mat
/*
Transforms a 3D world-space coordinate to a 2D window-space coordinate. Returns an array of the following format:
[xx, yy]
Returns [-1, -1] if the 3D point is not in view
/// @description convert_2d_to_3d(x, y, view_mat, proj_mat)
/// @param x
/// @param y
/// @param view_mat
/// @param proj_mat
/*
Transforms a 2D coordinate (in window space) to a 3D vector.
Returns an array of the following format:
[dx, dy, dz, ox, oy, oz]
where [dx, dy, dz] is the direction vector and [ox, oy, oz] is the origin of the ray.
@DragoniteSpam
DragoniteSpam / camera_roll.gml
Last active May 14, 2020 02:55
Calculate the roll of a 3D camera
// I haven't used this in anything yet, but TheSnidr on the GameMaker discord posted
// this in response to a question about camera roll. He's usually pretty good at 3D
// math so I'm going to assume it works. "roll" is the angle around the direction the
// camera is looking at. Use for the view matrix.
var c = dcos(roll);
var s = dsin(roll) / max(math_get_epsilon(), sqrt(sqr(xdir) + sqr(ydir)));
matrix_build_lookat(x, y, z, x + xdir, y + ydir, z + zdir, ydir * s, -xdir * s, c);
@DragoniteSpam
DragoniteSpam / triangle_normals.gml
Last active December 14, 2021 14:32
Calculate the vector perpendicular to a triangle (GML).
function triangle_normal(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
gml_pragma("forceinline");
var v1x = x2 - x1;
var v1y = y2 - y1;
var v1z = z2 - z1;
var v2x = x3 - x1;
var v2y = y3 - y1;
var v2z = z3 - z1;
var cx = v1y * v2z - v1z * v2y;
var cy = -v1x * v2z + v1z * v2x;