mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-01-23 19:38:05 +01:00
d3d camera, upvector, view/world conversion
This commit is contained in:
parent
8109c22ffa
commit
6633cc5d0c
12 changed files with 320 additions and 193 deletions
|
@ -237,6 +237,7 @@
|
|||
{"name":"s_node_tunnel_out","order":22,"path":"sprites/s_node_tunnel_out/s_node_tunnel_out.yy",},
|
||||
{"name":"__background_set_element","order":3,"path":"scripts/__background_set_element/__background_set_element.yy",},
|
||||
{"name":"s_node_3d_obj","order":3,"path":"sprites/s_node_3d_obj/s_node_3d_obj.yy",},
|
||||
{"name":"d3d_camera","order":13,"path":"scripts/d3d_camera/d3d_camera.yy",},
|
||||
{"name":"ds_list_queue","order":6,"path":"scripts/ds_list_queue/ds_list_queue.yy",},
|
||||
{"name":"s_node_scale","order":6,"path":"sprites/s_node_scale/s_node_scale.yy",},
|
||||
{"name":"sh_color_picker_value","order":1,"path":"shaders/sh_color_picker_value/sh_color_picker_value.yy",},
|
||||
|
@ -472,6 +473,7 @@
|
|||
{"name":"sh_fd_calculate_pressure_jacobi_glsl","order":8,"path":"shaders/sh_fd_calculate_pressure_jacobi_glsl/sh_fd_calculate_pressure_jacobi_glsl.yy",},
|
||||
{"name":"node_color_from_rgb","order":7,"path":"scripts/node_color_from_rgb/node_color_from_rgb.yy",},
|
||||
{"name":"node_struct_get","order":1,"path":"scripts/node_struct_get/node_struct_get.yy",},
|
||||
{"name":"d3d_plane","order":14,"path":"scripts/d3d_plane/d3d_plane.yy",},
|
||||
{"name":"curveBox","order":8,"path":"scripts/curveBox/curveBox.yy",},
|
||||
{"name":"s_node_iterator_length","order":24,"path":"sprites/s_node_iterator_length/s_node_iterator_length.yy",},
|
||||
{"name":"preview_overlay_vector","order":2,"path":"scripts/preview_overlay_vector/preview_overlay_vector.yy",},
|
||||
|
@ -1257,7 +1259,7 @@
|
|||
{"name":"s_node_array_reverse","order":8,"path":"sprites/s_node_array_reverse/s_node_array_reverse.yy",},
|
||||
{"name":"o_process_handler","order":3,"path":"objects/o_process_handler/o_process_handler.yy",},
|
||||
{"name":"sh_ani_noise","order":8,"path":"shaders/sh_ani_noise/sh_ani_noise.yy",},
|
||||
{"name":"d3d_camera","order":3,"path":"scripts/d3d_camera/d3d_camera.yy",},
|
||||
{"name":"d3d_camera_object","order":3,"path":"scripts/d3d_camera_object/d3d_camera_object.yy",},
|
||||
{"name":"sh_level","order":14,"path":"shaders/sh_level/sh_level.yy",},
|
||||
{"name":"sh_grid_tri","order":3,"path":"shaders/sh_grid_tri/sh_grid_tri.yy",},
|
||||
{"name":"s_node_text","order":1,"path":"sprites/s_node_text/s_node_text.yy",},
|
||||
|
|
|
@ -752,6 +752,7 @@
|
|||
{"id":{"name":"s_node_tunnel_out","path":"sprites/s_node_tunnel_out/s_node_tunnel_out.yy",},},
|
||||
{"id":{"name":"__background_set_element","path":"scripts/__background_set_element/__background_set_element.yy",},},
|
||||
{"id":{"name":"s_node_3d_obj","path":"sprites/s_node_3d_obj/s_node_3d_obj.yy",},},
|
||||
{"id":{"name":"d3d_camera","path":"scripts/d3d_camera/d3d_camera.yy",},},
|
||||
{"id":{"name":"ds_list_queue","path":"scripts/ds_list_queue/ds_list_queue.yy",},},
|
||||
{"id":{"name":"s_node_scale","path":"sprites/s_node_scale/s_node_scale.yy",},},
|
||||
{"id":{"name":"sh_color_picker_value","path":"shaders/sh_color_picker_value/sh_color_picker_value.yy",},},
|
||||
|
@ -1025,6 +1026,7 @@
|
|||
{"id":{"name":"node_struct_get","path":"scripts/node_struct_get/node_struct_get.yy",},},
|
||||
{"id":{"name":"node_3d_mesh_cube","path":"scripts/node_3d_mesh_cube/node_3d_mesh_cube.yy",},},
|
||||
{"id":{"name":"node_transform","path":"scripts/node_transform/node_transform.yy",},},
|
||||
{"id":{"name":"d3d_plane","path":"scripts/d3d_plane/d3d_plane.yy",},},
|
||||
{"id":{"name":"curveBox","path":"scripts/curveBox/curveBox.yy",},},
|
||||
{"id":{"name":"s_node_iterator_length","path":"sprites/s_node_iterator_length/s_node_iterator_length.yy",},},
|
||||
{"id":{"name":"preview_overlay_vector","path":"scripts/preview_overlay_vector/preview_overlay_vector.yy",},},
|
||||
|
@ -1925,7 +1927,7 @@
|
|||
{"id":{"name":"sh_ani_noise","path":"shaders/sh_ani_noise/sh_ani_noise.yy",},},
|
||||
{"id":{"name":"rectangle_collision","path":"scripts/rectangle_collision/rectangle_collision.yy",},},
|
||||
{"id":{"name":"s_contest_banner","path":"sprites/s_contest_banner/s_contest_banner.yy",},},
|
||||
{"id":{"name":"d3d_camera","path":"scripts/d3d_camera/d3d_camera.yy",},},
|
||||
{"id":{"name":"d3d_camera_object","path":"scripts/d3d_camera_object/d3d_camera_object.yy",},},
|
||||
{"id":{"name":"sh_level","path":"shaders/sh_level/sh_level.yy",},},
|
||||
{"id":{"name":"sh_grid_tri","path":"shaders/sh_grid_tri/sh_grid_tri.yy",},},
|
||||
{"id":{"name":"s_node_text","path":"sprites/s_node_text/s_node_text.yy",},},
|
||||
|
|
|
@ -35,6 +35,8 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
drag_c2x = 0;
|
||||
drag_c2y = 0;
|
||||
|
||||
drag_original = 0;
|
||||
|
||||
axis_hover = noone;
|
||||
|
||||
tools = [
|
||||
|
@ -49,11 +51,12 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
var _rot = inputs[| 1].getValue(,,, true);
|
||||
var _sca = inputs[| 2].getValue(,,, true);
|
||||
|
||||
var _camPos = params.cameraPosition;
|
||||
var _camTar = params.cameraFocus;
|
||||
var _camDis = params.camera_Dist;
|
||||
var _camAx = params.camera_Ax;
|
||||
var _camAy = params.camera_Ay;
|
||||
var _camera = params.camera;
|
||||
var _camPos = _camera.position;
|
||||
var _camTar = _camera.focus;
|
||||
var _camDis = _camera.focus_dist;
|
||||
var _camAx = _camera.focus_angle_x;
|
||||
var _camAy = _camera.focus_angle_y;
|
||||
|
||||
var _qrot = new BBMOD_Quaternion().FromEuler(_rot[0], -_rot[1], -_rot[2]);
|
||||
var _qview = new BBMOD_Quaternion().FromEuler(_camAy, -_camAx, 0);
|
||||
|
@ -65,7 +68,7 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
var sq = 8;
|
||||
|
||||
var _vpos = new __vec3( _pos[0], _pos[1], _pos[2] );
|
||||
var _posView = params.applyCamera(_vpos);
|
||||
var _posView = _camera.worldPointToViewPoint(_vpos);
|
||||
|
||||
var cx = _posView.x;
|
||||
var cy = _posView.y;
|
||||
|
@ -92,6 +95,26 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
new BBMOD_Vec3(-hs - sq, -hs + sq, 0),
|
||||
new BBMOD_Vec3(-hs + sq, -hs + sq, 0), ];
|
||||
|
||||
for( var i = 0; i < 3; i++ ) {
|
||||
ga[i] = _qview.Rotate(_qrot.Rotate(ga[i]));
|
||||
|
||||
th = 2 + (axis_hover == i || drag_axis == i);
|
||||
if(drag_axis != noone && drag_axis != i)
|
||||
continue;
|
||||
|
||||
draw_set_color(COLORS.axis[i]);
|
||||
if(point_distance(cx, cy, cx + ga[i].X, cy + ga[i].Y) < 5)
|
||||
draw_line_round(cx, cy, cx + ga[i].X, cy + ga[i].Y, th);
|
||||
else
|
||||
draw_line_round_arrow(cx, cy, cx + ga[i].X, cy + ga[i].Y, th, 2);
|
||||
|
||||
var _d = distance_to_line(_mx, _my, cx, cy, cx + ga[i].X, cy + ga[i].Y);
|
||||
if(_d < _hoverDist) {
|
||||
_hover = i;
|
||||
_hoverDist = _d;
|
||||
}
|
||||
}
|
||||
|
||||
for( var i = 3; i < 6; i++ ) {
|
||||
for( var j = 0; j < 4; j++ )
|
||||
ga[i][j] = _qview.Rotate(_qrot.Rotate(ga[i][j]));
|
||||
|
@ -103,6 +126,14 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
var p2x = cx + ga[i][2].X, p2y = cy + ga[i][2].Y;
|
||||
var p3x = cx + ga[i][3].X, p3y = cy + ga[i][3].Y;
|
||||
|
||||
var _pax = (p0x + p1x + p2x + p3x) / 4;
|
||||
var _pay = (p0y + p1y + p2y + p3y) / 4;
|
||||
|
||||
if((abs(p0x - _pax) + abs(p1x - _pax) + abs(p2x - _pax) + abs(p3x - _pax)) / 4 < 1)
|
||||
continue;
|
||||
if((abs(p0y - _pay) + abs(p1y - _pay) + abs(p2y - _pay) + abs(p3y - _pay)) / 4 < 1)
|
||||
continue;
|
||||
|
||||
draw_set_color(COLORS.axis[(i - 3 - 1 + 3) % 3]);
|
||||
if(axis_hover == i || drag_axis == i) {
|
||||
draw_primitive_begin(pr_trianglestrip);
|
||||
|
@ -123,27 +154,8 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
_hover = i;
|
||||
}
|
||||
|
||||
for( var i = 0; i < 3; i++ ) {
|
||||
ga[i] = _qview.Rotate(_qrot.Rotate(ga[i]));
|
||||
|
||||
th = 2 + (axis_hover == i || drag_axis == i);
|
||||
if(drag_axis != noone && drag_axis != i)
|
||||
continue;
|
||||
|
||||
draw_set_color(COLORS.axis[i]);
|
||||
if(point_distance(cx, cy, cx + ga[i].X, cy + ga[i].Y) < 5)
|
||||
draw_line_round(cx, cy, cx + ga[i].X, cy + ga[i].Y, th);
|
||||
else
|
||||
draw_line_round_arrow(cx, cy, cx + ga[i].X, cy + ga[i].Y, th, 2);
|
||||
|
||||
var _d = distance_to_line(_mx, _my, cx, cy, cx + ga[i].X, cy + ga[i].Y);
|
||||
if(_d < _hoverDist) {
|
||||
_hover = i;
|
||||
_hoverDist = _d;
|
||||
}
|
||||
}
|
||||
|
||||
axis_hover = _hover;
|
||||
print(_camera.viewPointToWorldRay(_mx, _my))
|
||||
|
||||
if(drag_axis != noone) {
|
||||
if(!MOUSE_WRAPPING) {
|
||||
|
@ -160,21 +172,29 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
mAdj = dot_product(_mmx, _mmy, _max, _may);
|
||||
|
||||
if(drag_prev != undefined) {
|
||||
_pos[drag_axis] += (mAdj - drag_prev) * params.camera_Dist / 20000;
|
||||
_pos[drag_axis] += (mAdj - drag_prev) * _camDis / 20000;
|
||||
|
||||
if(inputs[| 0].setValue(_pos))
|
||||
UNDO_HOLDING = true;
|
||||
}
|
||||
} else {
|
||||
var _max1 = drag_c1x, _may1 = drag_c1y;
|
||||
var _max2 = drag_c2x, _may2 = drag_c2y;
|
||||
var ray = _camera.viewPointToWorldRay(_mx, _my);
|
||||
var nor;
|
||||
|
||||
mAdj = [ dot_product(_mmx, _mmy, _max1, _may1),
|
||||
dot_product(_mmx, _mmy, _max2, _may2) ];
|
||||
switch(drag_axis) {
|
||||
case 3 : nor = new __vec3(0, 0, 1); break;
|
||||
case 4 : nor = new __vec3(1, 0, 0); break;
|
||||
case 5 : nor = new __vec3(0, 1, 0); break;
|
||||
}
|
||||
|
||||
var pln = new __plane(drag_original, nor);
|
||||
mAdj = d3d_intersect_ray_plane(ray, pln);
|
||||
|
||||
if(drag_prev != undefined) {
|
||||
_pos[(drag_axis - 3)] += (mAdj[0] - drag_prev[0]) * params.camera_Dist / 20000;
|
||||
_pos[(drag_axis - 3 + 1) % 3] += (mAdj[1] - drag_prev[1]) * params.camera_Dist / 20000;
|
||||
var _diff = mAdj.subtract(drag_prev);
|
||||
_pos[0] += _diff.x;
|
||||
_pos[1] += _diff.y;
|
||||
_pos[2] += _diff.z;
|
||||
|
||||
if(inputs[| 0].setValue(_pos))
|
||||
UNDO_HOLDING = true;
|
||||
|
@ -188,6 +208,25 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
drag_px = _mx;
|
||||
drag_py = _my;
|
||||
}
|
||||
|
||||
if(_hover != noone && mouse_press(mb_left, active)) {
|
||||
drag_axis = _hover;
|
||||
drag_prev = undefined;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_px = _mx;
|
||||
drag_py = _my;
|
||||
|
||||
drag_c0x = cx;
|
||||
drag_c0y = cy;
|
||||
|
||||
drag_original = new __vec3(_pos);
|
||||
|
||||
if(drag_axis < 3) {
|
||||
drag_c1x = ga[drag_axis].X;
|
||||
drag_c1y = ga[drag_axis].Y;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} else if(isUsingTool(1)) { #region rotate
|
||||
|
||||
|
@ -201,28 +240,6 @@ function Node_3DObject(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
|
|||
drag_axis = noone;
|
||||
UNDO_HOLDING = false;
|
||||
}
|
||||
|
||||
if(_hover != noone && mouse_press(mb_left, active)) {
|
||||
drag_axis = _hover;
|
||||
drag_prev = undefined;
|
||||
drag_mx = _mx;
|
||||
drag_my = _my;
|
||||
drag_px = _mx;
|
||||
drag_py = _my;
|
||||
|
||||
drag_c0x = cx;
|
||||
drag_c0y = cy;
|
||||
|
||||
if(drag_axis < 3) {
|
||||
drag_c1x = ga[drag_axis].X;
|
||||
drag_c1y = ga[drag_axis].Y;
|
||||
} else {
|
||||
drag_c1x = ga[(drag_axis - 3)].X;
|
||||
drag_c1y = ga[(drag_axis - 3)].Y;
|
||||
drag_c2x = ga[(drag_axis - 3 + 1) % 3].X;
|
||||
drag_c2y = ga[(drag_axis - 3 + 1) % 3].Y;
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static setTransform = function() {
|
||||
|
|
|
@ -1,49 +1,101 @@
|
|||
function __3dCamera() : __3dObject() constructor {
|
||||
ivw = 0.2; //innerViewWidth
|
||||
ivh = 0.2; //innerViewHeight
|
||||
ovw = 0.5; //outerViewWidth
|
||||
ovh = 0.5; //outerViewHeight
|
||||
len = 0.5; //cameraLength
|
||||
function __3dCamera() constructor {
|
||||
position = new __vec3();
|
||||
focus = new __vec3();
|
||||
up = new __vec3(0, 0, -1);
|
||||
|
||||
vertex = [
|
||||
[ len, -ivw, ivh ], [ len, ivw, ivh ],
|
||||
[ len, ivw, ivh ], [ len, ivw, -ivh ],
|
||||
[ len, ivw, -ivh ], [ len, -ivw, -ivh ],
|
||||
[ len, -ivw, -ivh ], [ len, -ivw, ivh ],
|
||||
|
||||
[ -len, -ovw, ovh ], [ -len, ovw, ovh ],
|
||||
[ -len, ovw, ovh ], [ -len, ovw, -ovh ],
|
||||
[ -len, ovw, -ovh ], [ -len, -ovw, -ovh ],
|
||||
[ -len, -ovw, -ovh ], [ -len, -ovw, ovh ],
|
||||
|
||||
[ len, -ivw, ivh ], [ -len, -ovw, ovh ],
|
||||
[ len, ivw, ivh ], [ -len, ovw, ovh ],
|
||||
[ len, ivw, -ivh ], [ -len, ovw, -ovh ],
|
||||
[ len, -ivw, -ivh ], [ -len, -ovw, -ovh ],
|
||||
focus_angle_x = 0;
|
||||
focus_angle_y = 0;
|
||||
focus_dist = 1;
|
||||
|
||||
fov = 60;
|
||||
view_near = 1;
|
||||
view_far = 32000;
|
||||
|
||||
view_w = 1;
|
||||
view_h = 1;
|
||||
view_aspect = 1;
|
||||
|
||||
viewMat = new __mat4();
|
||||
projMat = new __mat4();
|
||||
|
||||
static getUp = function() {
|
||||
var upVector = new __vec3(0, 0, 0);
|
||||
|
||||
var hRad = degtorad(focus_angle_x);
|
||||
var vRad = degtorad(focus_angle_y);
|
||||
|
||||
[ -len, -ovw * 0.5, ovh + 0.2 ], [ -len, ovw * 0.5, ovh + 0.2 ],
|
||||
[ -len, 0, ovh + 0.6 ], [ -len, ovw * 0.5, ovh + 0.2 ],
|
||||
[ -len, -ovw * 0.5, ovh + 0.2 ], [ -len, 0, ovh + 0.6 ],
|
||||
];
|
||||
upVector.x = -sin(hRad) * sin(vRad);
|
||||
upVector.y = cos(hRad) * -sin(vRad);
|
||||
upVector.z = cos(vRad);
|
||||
|
||||
return upVector._normalize();
|
||||
}
|
||||
|
||||
VF = global.VF_POS_COL;
|
||||
render_type = pr_linelist;
|
||||
VB = build();
|
||||
static applyCamera = function(cam) {
|
||||
camera_set_proj_mat(cam, projMat.raw);
|
||||
camera_set_view_mat(cam, viewMat.raw);
|
||||
|
||||
camera_apply(cam);
|
||||
}
|
||||
|
||||
position.set(-5, -5, 5);
|
||||
rotation.set(0, 30, 135);
|
||||
scale.set(1, room_width / room_height, 1);
|
||||
}
|
||||
|
||||
function calculate_3d_position(camFx, camFy, camFz, camAx, camAy, camDist) {
|
||||
var pos = new __vec3();
|
||||
static setMatrix = function() {
|
||||
projMat.setRaw(matrix_build_projection_perspective_fov(fov, view_aspect, view_near, view_far));
|
||||
viewMat.setRaw(matrix_build_lookat(position.x, position.y, position.z, focus.x, focus.y, focus.z, up.x, up.y, up.z));
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static setFocusAngle = function(ax, ay, dist) {
|
||||
focus_angle_x = ax;
|
||||
focus_angle_y = ay;
|
||||
focus_dist = dist;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static setViewFov = function(fov, near = view_near, far = view_far) {
|
||||
self.fov = fov;
|
||||
self.view_near = near;
|
||||
self.view_far = far;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static setViewSize = function(w, h) {
|
||||
view_w = w;
|
||||
view_h = h;
|
||||
view_aspect = w / h;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static worldPointToViewPoint = function(vec3) {
|
||||
var _vec4 = new __vec4().set(vec3, 1);
|
||||
var _view = viewMat.transpose().multiplyVector(_vec4);
|
||||
var _proj = projMat.transpose().multiplyVector(_view);
|
||||
|
||||
_proj._divide(_proj.w);
|
||||
_proj.x = view_w / 2 + _proj.x * view_w / 2;
|
||||
_proj.y = view_h / 2 + _proj.y * view_h / 2;
|
||||
|
||||
return _proj;
|
||||
}
|
||||
|
||||
static viewPointToWorldRay = function(_x, _y) {
|
||||
var rayOrigin = position;
|
||||
|
||||
var normalizedX = (2 * _x / view_w) - 1;
|
||||
var normalizedY = 1 - (2 * _y / view_h);
|
||||
|
||||
var tanFOV = tan(degtorad(fov) * 0.5);
|
||||
var _up = getUp();
|
||||
var forward = focus.subtract(position)._normalize();
|
||||
var right = forward.cross(_up)._normalize();
|
||||
|
||||
var rayDirection = forward.add(right.multiply(normalizedX * tanFOV * view_aspect))
|
||||
.add(_up.multiply(normalizedY * tanFOV))
|
||||
._normalize();
|
||||
|
||||
var radAx = degtorad(camAx);
|
||||
var radAy = degtorad(camAy);
|
||||
|
||||
pos.x = camFx + (cos(radAy) * sin(radAx)) * camDist;
|
||||
pos.y = camFy + (cos(radAy) * cos(radAx)) * camDist;
|
||||
pos.z = camFz + (sin(radAy)) * camDist;
|
||||
|
||||
return pos;
|
||||
return new __ray(rayOrigin, rayDirection);
|
||||
}
|
||||
}
|
49
scripts/d3d_camera_object/d3d_camera_object.gml
Normal file
49
scripts/d3d_camera_object/d3d_camera_object.gml
Normal file
|
@ -0,0 +1,49 @@
|
|||
function __3dCamera_object() : __3dObject() constructor {
|
||||
ivw = 0.2; //innerViewWidth
|
||||
ivh = 0.2; //innerViewHeight
|
||||
ovw = 0.5; //outerViewWidth
|
||||
ovh = 0.5; //outerViewHeight
|
||||
len = 0.5; //cameraLength
|
||||
|
||||
vertex = [
|
||||
[ len, -ivw, ivh ], [ len, ivw, ivh ],
|
||||
[ len, ivw, ivh ], [ len, ivw, -ivh ],
|
||||
[ len, ivw, -ivh ], [ len, -ivw, -ivh ],
|
||||
[ len, -ivw, -ivh ], [ len, -ivw, ivh ],
|
||||
|
||||
[ -len, -ovw, ovh ], [ -len, ovw, ovh ],
|
||||
[ -len, ovw, ovh ], [ -len, ovw, -ovh ],
|
||||
[ -len, ovw, -ovh ], [ -len, -ovw, -ovh ],
|
||||
[ -len, -ovw, -ovh ], [ -len, -ovw, ovh ],
|
||||
|
||||
[ len, -ivw, ivh ], [ -len, -ovw, ovh ],
|
||||
[ len, ivw, ivh ], [ -len, ovw, ovh ],
|
||||
[ len, ivw, -ivh ], [ -len, ovw, -ovh ],
|
||||
[ len, -ivw, -ivh ], [ -len, -ovw, -ovh ],
|
||||
|
||||
[ -len, -ovw * 0.5, ovh + 0.2 ], [ -len, ovw * 0.5, ovh + 0.2 ],
|
||||
[ -len, 0, ovh + 0.6 ], [ -len, ovw * 0.5, ovh + 0.2 ],
|
||||
[ -len, -ovw * 0.5, ovh + 0.2 ], [ -len, 0, ovh + 0.6 ],
|
||||
];
|
||||
|
||||
VF = global.VF_POS_COL;
|
||||
render_type = pr_linelist;
|
||||
VB = build();
|
||||
|
||||
position.set(-5, -5, 5);
|
||||
rotation.set(0, 30, 135);
|
||||
scale.set(1, room_width / room_height, 1);
|
||||
}
|
||||
|
||||
function calculate_3d_position(camFx, camFy, camFz, camAx, camAy, camDist) {
|
||||
var pos = new __vec3();
|
||||
|
||||
var radAx = degtorad(camAx);
|
||||
var radAy = degtorad(camAy);
|
||||
|
||||
pos.x = camFx + (cos(radAy) * sin(radAx)) * camDist;
|
||||
pos.y = camFy + (cos(radAy) * cos(radAx)) * camDist;
|
||||
pos.z = camFz + (sin(radAy)) * camDist;
|
||||
|
||||
return pos;
|
||||
}
|
11
scripts/d3d_camera_object/d3d_camera_object.yy
Normal file
11
scripts/d3d_camera_object/d3d_camera_object.yy
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"resourceType": "GMScript",
|
||||
"resourceVersion": "1.0",
|
||||
"name": "d3d_camera_object",
|
||||
"isCompatibility": false,
|
||||
"isDnD": false,
|
||||
"parent": {
|
||||
"name": "3d",
|
||||
"path": "folders/functions/3d.yy",
|
||||
},
|
||||
}
|
|
@ -109,30 +109,6 @@ function __3dObject() constructor {
|
|||
}
|
||||
}
|
||||
|
||||
function __3dObjectParameters(camPos, camFoc) constructor {
|
||||
self.cameraPosition = camPos;
|
||||
self.cameraFocus = camFoc;
|
||||
|
||||
camera_Ax = 0;
|
||||
camera_Ay = 0;
|
||||
camera_Dist = 0;
|
||||
|
||||
camera_w = 1;
|
||||
camera_h = 1;
|
||||
|
||||
camera_viewMat = new __mat4();
|
||||
camera_projMat = new __mat4();
|
||||
|
||||
static applyCamera = function(vec3) {
|
||||
var _cam = vec3;
|
||||
var _vec4 = new __vec4().set(_cam, 1);
|
||||
|
||||
var _view = camera_viewMat.transpose().multiplyVector(_vec4);
|
||||
var _proj = camera_projMat.transpose().multiplyVector(_view);
|
||||
_proj._divide(_proj.w);
|
||||
_proj.x = camera_w / 2 + _proj.x * camera_w / 2;
|
||||
_proj.y = camera_h / 2 + _proj.y * camera_h / 2;
|
||||
|
||||
return _proj;
|
||||
}
|
||||
function __3dObjectParameters(camera) constructor {
|
||||
self.camera = camera;
|
||||
}
|
30
scripts/d3d_plane/d3d_plane.gml
Normal file
30
scripts/d3d_plane/d3d_plane.gml
Normal file
|
@ -0,0 +1,30 @@
|
|||
function __ray(origin, direction) constructor {
|
||||
self.origin = origin;
|
||||
self.direction = direction.normalize();
|
||||
|
||||
static sampleDistance = function(t) {
|
||||
gml_pragma("forceinline");
|
||||
return origin.add(direction.multiply(t));
|
||||
}
|
||||
}
|
||||
|
||||
function __plane(origin, normal) constructor {
|
||||
self.origin = origin;
|
||||
self.normal = normal.normalize();
|
||||
}
|
||||
|
||||
#region functions
|
||||
function d3d_intersect_ray_plane(ray, plane) {
|
||||
print($"Intersect {ray}\n\tto {plane}");
|
||||
|
||||
var det = plane.normal.dot(ray.direction);
|
||||
if(det == 0) return new __vec3();
|
||||
|
||||
var rayToPlane = plane.origin.subtract(ray.origin);
|
||||
var t = rayToPlane.dot(plane.normal) / det;
|
||||
|
||||
if(t < 0) return new __vec3();
|
||||
|
||||
return ray.sampleDistance(t);
|
||||
}
|
||||
#endregion
|
11
scripts/d3d_plane/d3d_plane.yy
Normal file
11
scripts/d3d_plane/d3d_plane.yy
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"resourceType": "GMScript",
|
||||
"resourceVersion": "1.0",
|
||||
"name": "d3d_plane",
|
||||
"isCompatibility": false,
|
||||
"isDnD": false,
|
||||
"parent": {
|
||||
"name": "3d",
|
||||
"path": "folders/functions/3d.yy",
|
||||
},
|
||||
}
|
|
@ -3,11 +3,6 @@
|
|||
#macro __vec3_up new __vec3(0.0, 0.0, 1.0)
|
||||
|
||||
function __vec3(_x = 0, _y = 0, _z = 0) constructor {
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
|
||||
// Static methods
|
||||
static set = function(_x = 0, _y = _x, _z = _x) {
|
||||
if(is_struct(_x) && is_instanceof(_x, __vec3)) {
|
||||
x = _x.x;
|
||||
|
@ -16,11 +11,18 @@ function __vec3(_x = 0, _y = 0, _z = 0) constructor {
|
|||
return;
|
||||
}
|
||||
|
||||
if(is_array(_x)) {
|
||||
x = _x[0];
|
||||
y = _x[1];
|
||||
z = _x[2];
|
||||
return;
|
||||
}
|
||||
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
return self;
|
||||
}
|
||||
} set(_x, _y, _z);
|
||||
|
||||
static setIndex = function(index, value) {
|
||||
gml_pragma("forceinline");
|
||||
|
@ -116,6 +118,11 @@ function __vec3(_x = 0, _y = 0, _z = 0) constructor {
|
|||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
static normalize = function() {
|
||||
gml_pragma("forceinline");
|
||||
return clone()._normalize();
|
||||
}
|
||||
|
||||
static _normalize = function() {
|
||||
gml_pragma("forceinline");
|
||||
var _length = length();
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
function __vec4(_x = 0, _y = 0, _z = 0, _w = 0) constructor {
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
w = _w;
|
||||
|
||||
// Static methods
|
||||
static set = function(_x = 0, _y = _x, _z = _x, _w = _x) {
|
||||
if (is_struct(_x)) {
|
||||
if(is_instanceof(_x, __vec4)) {
|
||||
|
@ -21,13 +15,20 @@ function __vec4(_x = 0, _y = 0, _z = 0, _w = 0) constructor {
|
|||
return self;
|
||||
}
|
||||
|
||||
if(is_array(_x)) {
|
||||
x = _x[0];
|
||||
y = _x[1];
|
||||
z = _x[2];
|
||||
return;
|
||||
}
|
||||
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
w = _w;
|
||||
|
||||
return self;
|
||||
}
|
||||
return self;
|
||||
} set(_x, _y, _z, _w);
|
||||
|
||||
static setIndex = function(index, value) {
|
||||
gml_pragma("forceinline");
|
||||
|
|
|
@ -85,16 +85,12 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
d3_surface = noone;
|
||||
d3_outline_surface = noone;
|
||||
|
||||
d3_view_camera = new __3dCamera();
|
||||
d3_camW = 1;
|
||||
d3_camH = 1;
|
||||
|
||||
d3_view_camera.setFocusAngle(135, 45, 16);
|
||||
d3_camLerp = false;
|
||||
d3_camPos = new __vec3();
|
||||
d3_camTar = new __vec3();
|
||||
|
||||
d3_camAx = 135;
|
||||
d3_camAy = 45;
|
||||
d3_camDist = 16;
|
||||
|
||||
d3_camTarget = new __vec3();
|
||||
|
||||
|
@ -104,11 +100,9 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
|
||||
d3_zoom_speed = 0.2;
|
||||
d3_pan_speed = 2;
|
||||
|
||||
d3_camera = new __3dCamera();
|
||||
d3_preview_params = new __3dObjectParameters(d3_camPos, d3_camTar);
|
||||
|
||||
d3_light_ambient = $303030;
|
||||
d3_preview_params = new __3dObjectParameters(d3_view_camera);
|
||||
d3_light_ambient = $303030;
|
||||
#endregion
|
||||
|
||||
tb_framerate = new textBox(TEXTBOX_INPUT.number, function(val) { preview_rate = real(val); });
|
||||
|
@ -632,63 +626,40 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
_prev_node.previewing = 1;
|
||||
|
||||
#region draw
|
||||
d3_view_camera.setViewSize(w, h);
|
||||
d3_surface = surface_verify(d3_surface, w, h);
|
||||
d3_outline_surface = surface_verify(d3_outline_surface, w, h);
|
||||
|
||||
d3_camW = w;
|
||||
d3_camH = h;
|
||||
|
||||
var cam = camera_get_active();
|
||||
var _pos, targ;
|
||||
|
||||
if(keyboard_check(vk_tab)) {
|
||||
_pos = d3_camera.position;
|
||||
var _camDir = d3_camera.rotation.toDirection();
|
||||
_camDir._multiply(_pos.z / _camDir.z);
|
||||
targ = _pos.subtract(_camDir);
|
||||
d3_camLerp = true;
|
||||
} else {
|
||||
_pos = calculate_3d_position(d3_camTarget.x, d3_camTarget.y, d3_camTarget.z, d3_camAx, d3_camAy, d3_camDist);
|
||||
targ = d3_camTarget;
|
||||
}
|
||||
targ = d3_camTarget;
|
||||
_pos = calculate_3d_position(targ.x, targ.y, targ.z, d3_view_camera.focus_angle_x, d3_view_camera.focus_angle_y, d3_view_camera.focus_dist);
|
||||
|
||||
if(d3_camLerp) {
|
||||
d3_camPos._lerp(_pos, 0.2);
|
||||
d3_camTar._lerp(targ, 0.2);
|
||||
d3_view_camera.position._lerp(_pos, 0.2);
|
||||
d3_view_camera.focus._lerp(targ, 0.2);
|
||||
|
||||
if(d3_camPos.equal(_pos) && d3_camTar.equal(targ))
|
||||
if(d3_view_camera.position.equal(_pos) && d3_view_camera.focus.equal(targ))
|
||||
d3_camLerp = false;
|
||||
} else {
|
||||
d3_camPos.set(_pos);
|
||||
d3_camTar.set(targ);
|
||||
d3_view_camera.position.set(_pos);
|
||||
d3_view_camera.focus.set(targ);
|
||||
}
|
||||
|
||||
d3_preview_params.cameraPosition = d3_camPos;
|
||||
d3_preview_params.cameraFocus = d3_camTar;
|
||||
d3_preview_params.camera_Ax = d3_camAx;
|
||||
d3_preview_params.camera_Ay = d3_camAy;
|
||||
d3_preview_params.camera_Dist = d3_camDist;
|
||||
|
||||
d3_preview_params.camera_w = d3_camW;
|
||||
d3_preview_params.camera_h = d3_camH;
|
||||
|
||||
d3_preview_params.camera_projMat.setRaw(matrix_build_projection_perspective_fov(60, w / h, 1, 32000));
|
||||
d3_preview_params.camera_viewMat.setRaw(matrix_build_lookat(d3_camPos.x, d3_camPos.y, d3_camPos.z, d3_camTar.x, d3_camTar.y, d3_camTar.z, 0, 0, -1));
|
||||
d3_view_camera.setMatrix();
|
||||
|
||||
surface_set_target(d3_surface);
|
||||
draw_clear(COLORS.panel_3d_bg);
|
||||
|
||||
camera_set_proj_mat(cam, d3_preview_params.camera_projMat.raw);
|
||||
camera_set_view_mat(cam, d3_preview_params.camera_viewMat.raw);
|
||||
|
||||
camera_apply(cam);
|
||||
d3_view_camera.applyCamera(cam);
|
||||
|
||||
gpu_set_ztestenable(true);
|
||||
gpu_set_zwriteenable(false);
|
||||
shader_set(sh_d3d_grid_view);
|
||||
var _dist = round(d3_camTar.distance(d3_camPos));
|
||||
var _tx = round(d3_camTar.x);
|
||||
var _ty = round(d3_camTar.y);
|
||||
var _dist = round(d3_view_camera.focus.distance(d3_view_camera.position));
|
||||
var _tx = round(d3_view_camera.focus.x);
|
||||
var _ty = round(d3_view_camera.focus.y);
|
||||
|
||||
var _scale = _dist;
|
||||
while(_scale > 32) _scale /= 2;
|
||||
|
@ -718,9 +689,7 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
surface_set_target(d3_outline_surface);
|
||||
draw_clear(c_black);
|
||||
|
||||
camera_set_proj_mat(cam, d3_preview_params.camera_projMat.raw);
|
||||
camera_set_view_mat(cam, d3_preview_params.camera_viewMat.raw);
|
||||
camera_apply(cam);
|
||||
d3_view_camera.applyCamera(cam);
|
||||
|
||||
gpu_set_ztestenable(false);
|
||||
inspect_node.submitSel(d3_preview_params);
|
||||
|
@ -737,8 +706,8 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
|
||||
#region camera
|
||||
if(pHOVER) {
|
||||
if(mouse_wheel_up()) d3_camDist = max( 1, d3_camDist * (1 - d3_zoom_speed));
|
||||
if(mouse_wheel_down()) d3_camDist = min(1000, d3_camDist * (1 + d3_zoom_speed));
|
||||
if(mouse_wheel_up()) d3_view_camera.focus_dist = max( 1, d3_view_camera.focus_dist * (1 - d3_zoom_speed));
|
||||
if(mouse_wheel_down()) d3_view_camera.focus_dist = min(1000, d3_view_camera.focus_dist * (1 + d3_zoom_speed));
|
||||
}
|
||||
|
||||
if(d3_camPanning) {
|
||||
|
@ -746,8 +715,8 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
var dx = mx - d3_camPan_mx;
|
||||
var dy = my - d3_camPan_my;
|
||||
|
||||
d3_camAx += dx * 0.2 * d3_pan_speed;
|
||||
d3_camAy += dy * 0.1 * d3_pan_speed;
|
||||
d3_view_camera.focus_angle_x += dx * 0.2 * d3_pan_speed;
|
||||
d3_view_camera.focus_angle_y += dy * 0.1 * d3_pan_speed;
|
||||
}
|
||||
|
||||
d3_camPan_mx = mx;
|
||||
|
|
Loading…
Reference in a new issue