d3d_set_projection_ext(xfrom, yfrom, zfrom, xto, yto, zto, xup, yup, zup, angle, aspect, znear, zfar)
Argument | Description |
---|---|
xfrom | The x coordinate of the position to look from. |
yfrom | The y coordinate of the position to look from. |
zfrom | The z coordinate of the position to look from. |
xto | The x coordinate of the position to look to. |
yto | The x coordinate of the position to look to. |
zto | The x coordinate of the position to look to. |
xup | The x coordinate of the "up" vector. |
yup | The y coordinate of the "up" vector. |
zup | The z coordinate of the "up" vector. |
angle | The field of view angle. |
aspect | Aspect ratio between horizontal and vertical size of the view. |
znear | The near clipping plane. |
zfar | The far clipping plane. |
Returns: N/A
This function sets up the initial projection matrix as well as the view matrix for a 3D game, where (basically) the view matrix controls where the camera is and the projection matrix controls how the world is
projected onto a 2D screen. If you just wish to move the view (camera) around, you should be using the function d3d_set_projection.
To set the view into the world you first need the position you look from , which is indicated by the parameters (xfrom, yfrom, zfrom). Next you must specify the direction you look in and this is done by giving a second
point to look towards with the arguments (xto, yto, zto). Finally, you can still rotate the camera around the line from the viewpoint to the looking point, and to specify this we must give an "up" vector, that is,
the direction that is upwards in the camera and this is given by the three arguments (xup, yup, zup).
Once you specify the camera position, point to look at, and up vector, you can still change how wide the lens of the camera is (called the field of view) by setting the (angle) argument to a chosen value, with a
reasonable value being somewhere between 40 and 45 degrees. Next you can specify the aspect ratio between the horizontal and vertical projection. Now, normally you want to use the same as the aspect ratio of the
room or view, e.g. 640/480, but in special circumstances you may wish to change this. Finally you can indicate the clipping planes. Objects that are closer than znear to the camera are not drawn, and similarly, objects that
are further than zfar will not be drawn. It can be important to set these parameters to reasonable values because they also influence the precision of the z-comparisons and if you make the range too large then the
precision gets worse. The default values are 1 and 32000, and znear must be larger than 0.
with (obj_camera)
{
var xx, yy, r;
xx = x + cos(direction * pi / 180);
yy = y - sin(direction * pi / 180);
r = view_wview[0] / view_hview[0];
d3d_set_projection_ext(x, y, 10, xx, yy, 10, 0, 0, 1, 60, r, 1, 16000);
}
The above code creates a typical first person shooter projection, rotated using the current camera object direction, and with a custom field of view of 60 degrees and a low far clipping distance.