THREEDEE
This commit is contained in:
parent
757034f5b5
commit
bc06894859
7 changed files with 129 additions and 12 deletions
46
eastern flames/scripts/c_2dto3d/c_2dto3d.gml
Normal file
46
eastern flames/scripts/c_2dto3d/c_2dto3d.gml
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Script assets have changed for v2.3.0 see
|
||||
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
|
||||
/// @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.
|
||||
Works for both orthographic and perspective projections.
|
||||
Script created by TheSnidr
|
||||
(slightly modified by @dragonitespam)
|
||||
*/
|
||||
function c_2dto3d(_x,_y,V = ARTICULATOR.getView(), P = ARTICULATOR.getProj()){
|
||||
var mx = 2 * (_x / window_get_width() - .5) / P[0];
|
||||
var my = 2 * (_y / window_get_height() - .5) / P[5];
|
||||
var camX = - (V[12] * V[0] + V[13] * V[1] + V[14] * V[2]);
|
||||
var camY = - (V[12] * V[4] + V[13] * V[5] + V[14] * V[6]);
|
||||
var camZ = - (V[12] * V[8] + V[13] * V[9] + V[14] * V[10]);
|
||||
var theVar;
|
||||
if (P[15] == 0)
|
||||
{ //This is a perspective projection
|
||||
theVar = [V[2] + mx * V[0] + my * V[1],
|
||||
V[6] + mx * V[4] + my * V[5],
|
||||
V[10] + mx * V[8] + my * V[9],
|
||||
camX,
|
||||
camY,
|
||||
camZ];
|
||||
}
|
||||
else
|
||||
{ //This is an ortho projection
|
||||
theVar = [V[2],
|
||||
V[6],
|
||||
V[10],
|
||||
camX + mx * V[0] + my * V[1],
|
||||
camY + mx * V[4] + my * V[5],
|
||||
camZ + mx * V[8] + my * V[9]];
|
||||
}
|
||||
var s2w = theVar;
|
||||
var fx = s2w[0] * s2w[5] / -s2w[2] + s2w[3];
|
||||
var fy = s2w[1] * s2w[5] / -s2w[2] + s2w[4];
|
||||
return {x:fx,y:fy};
|
||||
}
|
12
eastern flames/scripts/c_2dto3d/c_2dto3d.yy
Normal file
12
eastern flames/scripts/c_2dto3d/c_2dto3d.yy
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"isDnD": false,
|
||||
"isCompatibility": false,
|
||||
"parent": {
|
||||
"name": "convenience",
|
||||
"path": "folders/Scripts/util/convenience.yy",
|
||||
},
|
||||
"resourceVersion": "1.0",
|
||||
"name": "c_2dto3d",
|
||||
"tags": [],
|
||||
"resourceType": "GMScript",
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue