This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function NVec2(_x, _y) { | |
x = _x; | |
y = _y; | |
Add = function(_val) { | |
return new NVec2(x + _val.x, y + _val.y); | |
} | |
Sub = function(_val) { | |
return new NVec2(x - _val.x, y - _val.y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute vec3 in_Position; // (x,y,z) | |
//attribute vec3 in_Normal; // (x,y,z) unused in this shader. | |
attribute vec4 in_Colour; // (r,g,b,a) | |
attribute vec2 in_TextureCoord; // (u,v) | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
void main() { | |
vec4 object_space_pos = vec4(in_Position, 1.); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hex(str) { | |
var result = 0; | |
// special unicode values | |
static ZERO = ord("0"); | |
static NINE = ord("9"); | |
static A = ord("A"); | |
static F = ord("F"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function string_hex(value, padding) { | |
if (padding == undefined) padding = 0; | |
var s = sign(value); | |
var v = abs(value); | |
var output = ""; | |
while (v > 0) { | |
var c = v & 0xf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ds_collection_create() { | |
return [[undefined], 0, 0]; | |
} | |
function ds_collection_add(collection, value) { | |
collection[@ 2]++; | |
var arr = collection[@ 0]; | |
if (array_length(arr) <= collection[@ 1]) { | |
var new_arr = array_create(array_length(arr) * 2, undefined); | |
array_copy(new_arr, 0, arr, 0, array_length(arr)); |
OlderNewer