GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2015-08-05 14:47:54

iFredQC
Member
Registered: 2015-06-05
Posts: 6

d3d_set_projection_view

This script will setup the 3D projection to perfectly mimic GM's view system. It is mostly useful for people doing a 3D game that has 2D game mechanics.

This script does not require d3d_start() to work.

A useful feature of the script is that if you set zfar to a negative number, it will set zfar to the distance from the camera to the Z == 0 plane, multiplied by -zfar. So if the camera is 1000 units away from Z == 0 and zfar is set to -1, zfar will be set to 1000 * -(-1) or 1000.

Arguments:
view_id = Which view index to take the settings from
fov = Field of View of the camera
znear = znear of the camera
zfar = zfar of the camera (If zfar is smaller than 0, zfar is set to the calculated camera distance to the Z == 0 plane times -(zfar argument))

Expand///d3d_set_projection_view(view_id,fov,znear,zfar)
var vcx = view_xview[argument0] + view_wview[argument0] * 0.5;
var vcy = view_yview[argument0] + view_hview[argument0] * 0.5;
var h = view_hview[argument0] / (2 * dtan(argument1 * 0.5));
var zn = argument2;
var zf = argument3;
if(zf < 0) {
    zf = h * -zf;
}
d3d_set_projection_ext(vcx, vcy, h, vcx, vcy, 0, dcos(view_angle[argument0] - 90), dsin(view_angle[argument0] - 90), 0, argument1, view_wview[argument0] / view_hview[argument0], zn, zf);

I can't think of any optimization that could be done.

Edit: Removed someone from credits mention at his request.

Last edited by iFredQC (2015-08-06 02:47:27)

Offline

Board footer

Powered by FluxBB