From bc06894859a0954a547862af79026906d66e6169 Mon Sep 17 00:00:00 2001 From: Anumania <50345157+Anumania@users.noreply.github.com> Date: Tue, 16 Aug 2022 23:45:08 -0700 Subject: [PATCH] THREEDEE --- eastern flames/eastern flames.yyp | 1 + .../objects/ARTICULATOR/Create_0.gml | 21 ++++++++- .../objects/ARTICULATOR/Draw_72.gml | 12 ++++- eastern flames/objects/ARTICULATOR/Step_0.gml | 25 +++++++--- eastern flames/objects/o_unit/Draw_0.gml | 24 ++++++++-- eastern flames/scripts/c_2dto3d/c_2dto3d.gml | 46 +++++++++++++++++++ eastern flames/scripts/c_2dto3d/c_2dto3d.yy | 12 +++++ 7 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 eastern flames/scripts/c_2dto3d/c_2dto3d.gml create mode 100644 eastern flames/scripts/c_2dto3d/c_2dto3d.yy diff --git a/eastern flames/eastern flames.yyp b/eastern flames/eastern flames.yyp index e7ece53..97bac40 100644 --- a/eastern flames/eastern flames.yyp +++ b/eastern flames/eastern flames.yyp @@ -55,6 +55,7 @@ {"id":{"name":"keyboard_check_advanced","path":"scripts/keyboard_check_advanced/keyboard_check_advanced.yy",},"order":8,}, {"id":{"name":"collision_line_width","path":"scripts/collision_line_width/collision_line_width.yy",},"order":9,}, {"id":{"name":"draw_rectangle_width","path":"scripts/draw_rectangle_width/draw_rectangle_width.yy",},"order":7,}, + {"id":{"name":"c_2dto3d","path":"scripts/c_2dto3d/c_2dto3d.yy",},"order":20,}, {"id":{"name":"s_guy2","path":"sprites/s_guy2/s_guy2.yy",},"order":1,}, {"id":{"name":"s_momiji","path":"sprites/s_momiji/s_momiji.yy",},"order":0,}, {"id":{"name":"dir2hv","path":"scripts/dir2hv/dir2hv.yy",},"order":2,}, diff --git a/eastern flames/objects/ARTICULATOR/Create_0.gml b/eastern flames/objects/ARTICULATOR/Create_0.gml index 6353d5c..9342aee 100644 --- a/eastern flames/objects/ARTICULATOR/Create_0.gml +++ b/eastern flames/objects/ARTICULATOR/Create_0.gml @@ -11,4 +11,23 @@ c_addweapon(kris, wp[$"iron sword"], true); selectedunit = noone; hoveredunit = noone; global.gw = 640; -global.gh = 360; \ No newline at end of file +global.gh = 360; +global.camerax = 0; +global.cameray = 0; +//these are functions bc c_2dto3d uses them +function getProj(){ + return matrix_build_projection_perspective_fov(60,-16/9,1,4000) +} +function getView(){ + var _x = global.camerax; + var _y = global.cameray; + var half = (7.5*32)+40; + return matrix_build_lookat(_x,_y+100,100,_x,_y,0,0,0,-1); +} + +function setCam(){ + var cam = camera_get_active(); + camera_set_proj_mat(cam,getProj()); + camera_set_view_mat(cam,getView()) + camera_apply(cam); +} \ No newline at end of file diff --git a/eastern flames/objects/ARTICULATOR/Draw_72.gml b/eastern flames/objects/ARTICULATOR/Draw_72.gml index 8b429a9..2674f11 100644 --- a/eastern flames/objects/ARTICULATOR/Draw_72.gml +++ b/eastern flames/objects/ARTICULATOR/Draw_72.gml @@ -1,3 +1,8 @@ + +var cam = camera_get_active(); +global.projMat = camera_get_proj_mat(cam); +global.viewMat = camera_get_view_mat(cam); +setCam(); var i, j, k; for (i=0; i= 0 { if mousey < array_length(global.map[mousex]) && mousey >= 0 { @@ -15,8 +16,8 @@ if select && selectedunit == noone { } } } else if select { - if mouse_x > global.gw-100 { - var guyhits = floor(abs(mouse_y-global.gh-10)/32); + if mouse.x > global.gw-100 { + var guyhits = floor(abs(mouse.y-global.gh-10)/32); log(guyhits, array_length(selectedunit.inventory)); if guyhits < array_length(selectedunit.inventory) { //log("doing"); @@ -27,8 +28,8 @@ if select && selectedunit == noone { } } -var mousex = floor(mouse_x/global.tilesize.x); -var mousey = floor(mouse_y/global.tilesize.y); +var mousex = floor(mouse.x/global.tilesize.x); +var mousey = floor(mouse.y/global.tilesize.y); //log(mousex, mousey); hoveredunit = selectedunit; if mousex < array_length(global.map) && mousex >= 0 { @@ -40,4 +41,16 @@ if mousex < array_length(global.map) && mousex >= 0 { } } } +} +if(left){ + global.camerax--; +} +if(right){ + global.camerax++; +} +if(up){ + global.cameray--; +} +if(down){ + global.cameray++; } \ No newline at end of file diff --git a/eastern flames/objects/o_unit/Draw_0.gml b/eastern flames/objects/o_unit/Draw_0.gml index 3e4e439..4520b9d 100644 --- a/eastern flames/objects/o_unit/Draw_0.gml +++ b/eastern flames/objects/o_unit/Draw_0.gml @@ -1,12 +1,28 @@ +draw_set_color(c_gray); +draw_set_alpha(0.25); +draw_circle(x,y+5,10,false); +draw_set_alpha(1); +var worldMat = matrix_get(matrix_world); +//this is the location of where i want to draw from !!! +var worldMat2 = matrix_build(x,y,0,90,0,0,1,1,1); +matrix_set(matrix_world,worldMat2); if waiting image_blend = c_grey else image_blend = c_white; +var tempx = x; +var tempy = y; +x = 0; +y = 0; draw_self(); drawstate(); +x = tempx; +y = tempy; //log(data); draw_set_color(c_red); -draw_rectangle(x-ts.x/2, y-ts.y/2-1, - x-ts.x/2+(ts.x*(data.hp.val/data.hp.cap)), - y-ts.y/2+1, false +draw_rectangle(0-ts.x/2, 0-ts.y/2-1, + 0-ts.x/2+(ts.x*(data.hp.val/data.hp.cap)), + 0-ts.y/2+1, false ); draw_text(x, y-ts.y, data.hp.val); //draw_set_color(c_red); -//draw_circle(x, y, 5, false); \ No newline at end of file +//draw_circle(x, y, 5, false); + +matrix_set(matrix_world,worldMat); \ No newline at end of file diff --git a/eastern flames/scripts/c_2dto3d/c_2dto3d.gml b/eastern flames/scripts/c_2dto3d/c_2dto3d.gml new file mode 100644 index 0000000..93d2289 --- /dev/null +++ b/eastern flames/scripts/c_2dto3d/c_2dto3d.gml @@ -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}; +} \ No newline at end of file diff --git a/eastern flames/scripts/c_2dto3d/c_2dto3d.yy b/eastern flames/scripts/c_2dto3d/c_2dto3d.yy new file mode 100644 index 0000000..3b07896 --- /dev/null +++ b/eastern flames/scripts/c_2dto3d/c_2dto3d.yy @@ -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", +} \ No newline at end of file