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.

indicated amount.<br />

d3d_transform_add_translation(xt,yt,zt) Adds a translation over<br />

the indicated vector.<br />

d3d_transform_add_scaling(xs,ys,zs) Adds a scaling <strong>with</strong> the<br />

indicated amounts.<br />

d3d_transform_add_rotation_x(angle) Adds a rotation around the x-<br />

axis <strong>with</strong> the indicated amount.<br />

d3d_transform_add_rotation_y(angle) Adds a rotation around the y-<br />

axis <strong>with</strong> the indicated amount.<br />

d3d_transform_add_rotation_z(angle) Adds a rotation around the z-<br />

axis <strong>with</strong> the indicated amount.<br />

d3d_transform_add_rotation_axis(xa,ya,za,angle) Adds a rotation<br />

around the axis indicated by the vector <strong>with</strong> the indicated amount.<br />

Realize that rotation and scaling are <strong>with</strong> respect to the origin of the world, not <strong>with</strong> respect to<br />

the object that is to be drawn. If the object is not at the origin it will also move to a different<br />

place, which is not what we want. So to e.g. rotate an object over its own x-axis, we must first<br />

translate it to the origin, next rotate it, and finally translate it back to its position. This is what<br />

the functions to add transformations are for.<br />

The following examples might explain this better. Assume we have a sprite spr that we want<br />

to draw at position (100,100,10). We can use the following code to do this<br />

{<br />

d3d_transform_set_translation(100,100,10);<br />

draw_sprite(spr,0,0,0);<br />

d3d_transform_set_identity();<br />

}<br />

Note that because we use a translation we should now draw the sprite at position (0,0). (This<br />

assumes the current instance has a depth of 0! If you are not sure, first set the depth.) If we<br />

would use this in our first person shooter we would not see the sprite. The reason is that it is<br />

still parallel to the xy-plane. We want to rotate it over 90 degrees along the x-axis (or y-axis).<br />

So we need to add a rotation. Remember the order: we must first rotate the sprite and then<br />

translate it. So we can use the following code.

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

Saved successfully!

Ooh no, something went wrong!