08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Default you look along the negative z-axis toward the middle of the room. Often in 3D games<br />

you want to change how you look at the world. For example, in a first person shooter you<br />

probably want to have the camera look from a position a bit above the xy-plane along the xy-<br />

plane. In graphics terms you are setting the correct projection. To change the way you look<br />

the following two functions exist.<br />

d3d_set_projection(xfrom,yfrom,zfrom,xto,yto,zto,xup,yup,zu<br />

p) Defines how to look in the world. You specify the point to look from, the<br />

point to look to and the up vector.<br />

This function requires some explanation. To set the projection you first need the position you<br />

look from. This is indicated by the parameters (xfrom,yfrom,zfrom). Next you must<br />

specify the direction you look in. This is done by giving a second point to look towards. This is<br />

the point (xto,yto,zto). Finally, you can still rotate the camera around the line from the<br />

viewpoint to the looking point. To specify this we must give an up vector, that is, the direction<br />

that is upwards in the camera. This is given by the last three parameters (xup,yup,zup).<br />

Let me given an example. To look along the xy-plane as in a first person shooter you can use<br />

{<br />

}<br />

d3d_set_projection(100,100,10,200,100,10,0,0,1);<br />

So you look from point (100,100) and 10 above the plane in the direction of (200,100). The<br />

up vector points is the z-direction as required. To make this slightly more complicated,<br />

assume you have an instance in your room that specifies the position of the camera. It will<br />

have a current (x,y) position and a direction (and maybe even a speed). You can now specify<br />

this as your camera by using the following code:<br />

{<br />

<strong>with</strong> (obj_camera)<br />

d3d_set_projection(x,y,10,<br />

sin(direction*pi/180),10,<br />

}<br />

x+cos(direction*pi/180),y-<br />

0,0,1);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!