GM: d3d draw cylinder

From GMpedia.org Wiki

Jump to: navigation, search
The correct title of this article is d3d_draw_cylinder(x1,y1,z1,x2,y2,z2,texid,hrepeat,vrepeat,closed,steps). It appears incorrectly here because of technical restrictions.
The correct title of this article is d3d_draw_cylinder. It appears incorrectly here because of technical restrictions.


Arguments

x1, y1, z1, x2, y2, z2 = Real valued co-ordinates that define the position and size of the block.

tepid = the id of the texture to draw the block with.

repeat = How many times the texture should be repeated horizontally.

repeat = How many times the texture should be repeated vertically.

closed = True / False - Should the cylinder have caps at the end.

steps = Integer defining how many faces the cylinder should have around the outsid

Limitations

Registered

Note: Please remove limitations and port them in the "Remarks" section at the end of the article.

This function will draw a vertical cylinder (like a tin of beans), with or without a texture, using the current drawing colour. For the coordinates, think of the cylinder inside a box like this:

If you think like that, then you can apply the same techniques as used in d3d_draw_block. All the parameter details for drawing a block are applicable to drawing a cylinder. If you don't want the cylinder to be standing up vertically like a tin, then you must transform it.

To not use a texture for this primitive, put -1 in place of texid, else provide the id of a texture. Even if you don't use a texture, you must fill in the hrepeat and vrepeat parameters. If you are not using a texture, it does not matter what value you enter, I usually put a 0. If however you are using a texture, set vrepeat to how many times the texture should be repeated along the horizontal edges of faces, and hrepeat to how many times the texture should be repeated along the vertical edges of faces. Repeating a texture that tiles well can be used to cover large areas without losing definition.

[edit] Example

d3d_draw_cylinder(0,16,16,16,16,0,spr_texture,5,5,true,16)

The additional parameters in the cylinder are closed and steps. Steps is the number of rotational steps used to draw the round part of the cylinder. Because (most) 3d rendering software can not handle curved surfaces, we simply approximate a curved surface by drawing many flat surfaces. For example if you put steps as 5, the top view of your cylinder would look like this:

Closed is an option for whether to have caps at the end of your cylinder. You may find you often don't want to close the cylinder. It is one way of making a "barrel" that has the correct texture on the top, bottom and side. You could draw a cylinder with no caps, and then draw 2 floors at either end, with circular textures for the ends of the barrel.

// first draw a cylinder to represent the body of the barrel
d3d_draw_cylinder(x-8, y-8, z, x+8, y+8, z+32, tex_barrel_side, 1, 1, 0, 24)
// then draw a floor at the bottom
d3d_draw_floor(x-8, y-8, z, x+8, y+8, z, tex_barrel_end, 1, 1)
// finally draw a floor at the top
d3d_draw_floor(x-8, y-8, z+32, x+8, y+8, z+32, tex_barrel_end, 1, 1)
This article was originally found at the Game Maker Knowledge Base, contributed by monkey dude.
See the talk page for details
Personal tools