gamemaker 3d 1 draw call with multiple cubes
It goes without saying that nigh every game developer probably started out wanting to make games in 3D. Later all, practically all of the AAA games that we played growing up were in 3D, so it comes every bit no surprise that we want to create our own 3D wonderworks.
What you may or may not realize is that the humble Game Maker comes with the ability to depict 3D graphics. This makes the job of putting 3D games together a lot simpler. However, i thing I would like to emphasize early is that 3D is merely another tool – nothing more, nothing less. Giving a game 3D graphics will non magically get in improve. In fact, it tin can complicate a blueprint that would otherwise work perfectly well in 2nd. Conversely, using 3D in GM can also simplify certain graphical aspects of your game. It's upwards to you lot to make up one's mind whether it's worth all the actress attempt, and to be enlightened of the limitations of Game Maker's 3D functions.
Bear in listen that GM'south 3D functions are fairly simplistic. GM is a 2d game engine with some 3D graphics functions slapped in for good measure out. You lot'll as well need to exist quite familiar with GML scripting, since 3D is beyond the scope of the elevate 'northward' drib beginner's interface.
Furthermore, before yous go all excited, accept note – Game Maker does NOT do the following:
- Shaders. Forget almost it.
- 3D movement and positioning calculations. Call up that even though it'southward rendering in 3D, GM still operates on a 2 dimensional plane under the hood. If you want to build an FPS where you tin fire projectiles up and down equally well as horizontally, you'll have to be prepared to script your own code to have things position and motility properly in 3D. GM doesn't do it for you out of the box. You'll exist fine for two.5D games though.
- Accurate 3D polygonal standoff detection. GM doesn't do this for y'all, nor does it give y'all straight admission to mesh data or the matrix functions you'd need to implement it yourself. At that place are ways to practice collision detection, just non on a per-polygon footing. This makes 3D level blueprint particularly choosy.
- Intelligent rendering. About 3D game engines have fancy lawmaking running nether the hood to ensure that they only draw what they need to, instead of lobbing every polygon in the scene at the graphics carte and slowing things down to slideshow speeds. GM doesn't do this. Depending on the complexity of your rendered scene, you may take to implement your own system to prevent unwanted objects from being drawn.
- Fancy 3D modelling and animation. While scripts exist for y'all to import 3D models, and even build animations, GM (say it with me) does not back up this out of the box.
I should note that if you search the Net hard enough, you can find scripts and stand-solitary engines that you can plug into a GM game to give it the above functionality. These vary in quality and ease of employ, and autumn outside the scope of this tutorial.
Okay, plenty disclaimers and doomsaying. Let's see what this thing tin can do. This tutorial will guide y'all through setting up a basic 3D scene, and show you what commands are available and how they're used.
The camera
The camera is your window into the 3D globe, so it makes sense that we cover it first. Without the photographic camera, GM won't know from which viewpoint you want your 3D earth to be rendered, and give you a bizarre upside-down default view. As such, it helps to accept a core camera object from which you can control the 3D viewpoint. Your implementation may differ, only I by and large similar to put all of the 3D initialization stuff into the camera object besides, since it keeps information technology in one logical and convenient identify.
The outset thing we need to do to get our 3D game up and running is to initialize 3D manner. We'll practice this in our camera object. Here'southward a sample of the lawmaking that goes into the Create consequence of my camera object:
//Start 3D fashion d3d_start(); //Enable lighting d3d_set_lighting(truthful); //Enable backface culling. This stops the renderer from drawing polygons that //face away from the camera, speeding the return upwards. d3d_set_culling(truthful); //Define and enable a global directional light. We won't go into the details //right at present, simply I will cover this in a after tutorial. d3d_light_define_direction(1,i,0.5,0,c_white); d3d_light_enable(1,true);
And that does it for your initialization. The next exciting bit will be in your Draw event:
d3d_set_projection(x,y,0,x+twenty,y,0,0,0,1);
This do-all part specifies where your camera will be placed, and where it volition exist pointing. And that's information technology. Using the data you requite that office, GM will render the scene. Quick and easy. For now, the above lawmaking will point the camera to the correct of wherever it'due south placed. Patently, you can replace the constants here with any variable you like, allowing yous to change the viewpoint all the same you crave. I recommend playing with these variables past yourself once y'all've got this tutorial code upward and running, to become a better thought of what they practise.
One last thing. In 3D mode, it is incredibly important that you lot take annotation of the club in which things are drawn, especially the photographic camera. The camera must always be drawn beginning. No exceptions. So how do y'all command this? Simple – the "depth" variable that comes part of every GM object you lot create. If you've played with it in 2D mode, you'll know that objects with higher depths are processed and drawn first. Equally such, it's good to set your photographic camera object's depth to a really loftier number to ensure that it goes commencement (I tend to use 10000000 or so). If your 3D scene draws itself from a elevation-down perspective instead of from the camera, that's a certain sign that the draw order is out.
Drawing 3D primitives
Now that we take a camera to render stuff from, we need something to point it at. Normally this would involve a whole lot of 3D modeling. Fortunately, GM comes with a set of functions that allows you to render a choice of 3D primitives using nothing but a unmarried line of code. Let's have a look.
To showtime off with, we'll describe a expert old cube. Create an object called "Cube", and place the post-obit in its Describe event.
draw_set_color(c_white); d3d_draw_block(x-16,y-16,-16,x+xvi,y+16,sixteen,-one,ane,one);
Firstly, we need to ascertain the colour that our archaic is drawn in. We practise this using the good one-time draw_set_color() function that we use in 2D. It's important to set the colour starting time, because otherwise our polygons volition be fatigued in black by default – non the finest colour for 3D objects to be.
The second line contains the command to draw a cube. The first six arguments permit you to define the dimensions of the cube, using 2 sets of x,y,and z variables that you want your cube to be draw between. Using these, yous can control the proportions of your cube. The last three arguments are used for texture mapping. Since we don't have a texture at the moment, we'll set the texture to -1, and the terminal two variables to 1. Don't worry – when nosotros somewhen delve into texture mapping, I'll let you know how they work.
At that place are other primitives that you lot can draw in a very similar style. Once you lot take this tutorial lawmaking upwards and running, try playing with the post-obit functions: d3d_draw_floor(), d3d_draw_wall(), d3d_draw_cone(), d3d_draw_cylinder(), and d3d_draw_ellipsoid(). You tin find out more most them in the GM assist file.
Rendering!
Adjacent, put your Photographic camera and Wall objects in a room. Prepare the room groundwork to a colour that won't interfere with the visibility of your cube. So place your camera, and place your cube object to the right of information technology (since we've fix the camera to point to the right of where it's placed).
And then run the game! You should run into a greyness square rendered in front end of the photographic camera! That'south one face of your cube! Try altering the positioning arguments of the d3d_set_projection() function to get different views of the cube.
That's it for this month! Until adjacent consequence, try playing around with using unlike primitives, and experiment with positioning and orienting the camera. Next issue, nosotros'll await at rotating and transforming 3D objects, and find out a piddling fleck more about lighting. Until then!
robinsonbhars1951.blogspot.com
Source: http://devmag.org.za/2009/04/05/3d-graphics-in-game-maker-part-1/
0 Response to "gamemaker 3d 1 draw call with multiple cubes"
Yorum Gönder