Blitz3D Newbies: Getting Started with Blitz3D
by Krylar

Introduction:

I'm a veteran Blitz2D programmer, so I assumed that I would be able to jump into B3D with no problems whatsoever. I was almost right! B3D requires a different way of thinking, but once you get that new way down it's just as easy as its predecessor. In fact, you could bring your 2D game into Blitz3D, change your "Graphics" command to say "Graphics3D", and then it would run fine. It would likely be slower since the 2D engine is optimized for 2D and the 3D for 3D, but it should still run--I did this with Rocktoids and it ran fine.

Now, just because the language is just as easy that doesn't mean that making games in B3D will be as easy...unless you just do 2D stuff, of course. Making a 3D game requires a lot more work in the grahics department. One example: where you typically make flat images for 2D games, you have to make full images (known as meshes) for 3D games.

But once you get used to it you'll likely find that it's not tons more complicated and it's actually a lot of fun. At lease for me it is! Besides, in the next couple of articles I'm going to show you how to create some cheezy meshes and textures using inexpensive (or free tools).

Now let's just touch on how to create an extremely simple program in B3D. This will give you an idea of what your B3D programs will look like.

A Simple Program in B3D

The following program simply displays a cylinder on the screen and rotates it.


Now, if you've already been following BlitzCoder's 2D articles/tutorials, you'll see a number of those commands as familiar already. If not, you may consider running through the 2D tutorials first.

Let's pick apart that code and really explain what's happening. I'm not going to cover all of commands because they are thoroughly covered in the Blitz2D tutorials. I'm only going to touch on the ones specific to B3D. Here ya go:


The Graphics3D command tells B3D that you're ready to start up the graphics system. You can use any valid resolution as arguments, but your program may fail if your video card and/or drivers don't support the requested resolution.


In B3D, a camera is going to be necessary to use the 3D elements of the world. The best way to grasp the camera entity is to imagine that your eye is a camera. As you look around you see things in 3D. Now imaging that you've drawn this amazing scene that you players to enjoy, but you don't put a camera (eyes) for them to see with...what will they see? Nothing.

Why is it that in 2D you don't need this camera thing? Actually, you do, you just don't have to position it. Because 2D is a flat surface that extends from the top of the screen to the bottom, the camera is always in the same spot. Yet, if you've ever played a 3D game you know that you can spin around an see what's behind you, or look up, or even hit a button and see your character from a different angle. This is because in 3D you can change the camera's location and position. It's really cool stuff :)


Now that we have our camera created, we need to tell B3D where we want to place it. Using the CameraViewport command, I simply made the camera be the full screen. So, it's a lot like our standard 2D camera. The first two numbers, 0,0, are the upper left position to start the camera's portal on the screen. Then I use the GraphicsWidth() and GraphicsHeight() commands (which will return our resolution minus 1...remember computers start counting at 0, not 1!) to say how wide I want the camera to be. Change that command to:


...and rerun the program. You'll see your viewport is quite a bit smaller! Play around with those numbers a bit to see what you can do.


In order to show something on the screen, I decided to create a cylinder. I could have decided on a Cube or Sphere instead, but I kinda like the cylinder. The "6" that is sent to CreateCylinder instructs B3D on how many "segments" to use to create the cylinder. A segement is a trangle. If you put a bunch of triangles together, you can create any shape. It's hard to believe, but try it and you'll see it's true. The more segments you use, the smoother your image will be. But be warned that this will also mean the slower your program will run...and it may even crash. Now, while a single cylinder with a 100 segments isn't a big deal, a 1,000 cylinders with a 100 segments can be.

To get a better understanding of this, add the Wireframe command to your code above the While (as shown):


This will show the actual lines that draw your images (please note that some video cards and/or drivers may not work properly with this command!). Now, change the number passed to CreateCylinder to various things and see what happens.


This is a fun one! TurnEntity is going to be one of the more useful commands at your disposal. Why? Simple, you want to have a moving, living, 3D world, and the only way to do that is to have objects turn and move and such. The TurnEntity command allows 3 types of turning: pitch, yaw, and roll. Any of you who are familiar with airplanes have likely heard these terms, but here's a description of each just in case.

Pitch
Imagine you are behind a fighter jet and you ask the pilot to do a loop. When he pulls the nose of the plane up, he is adjusting the pitch of the plane. So, pointing the nose down or pulling it up is controlling the pitch.

Yaw
If you're like me, you probably thought that "yaw" was the word southern folks used to refer to a group of people, but that's "Ya'll" ;) Putting yourself behind that plane again, imagine the pilot leaves his wings in position, but begins moving the nose of his plane left and right. This is controlling the yaw.

Roll
This one's easy. Image the pilot spinning the plane from wing to wing. Simply "rolling" the plane over and you'll get what roll is about.

To see each of these in action so they become more clear, you'll need to change the TurnEntity line. First let's see what Pitch is all about. Change to the following and run the program again:


Now, change it again and rerun to see Yaw:


And finally, change it and rerun to see Roll:


Pretty cool stuff, eh?


This command is an integral part of B3D because it's in charge of updating all of the objects (known as "entities") in your world. So if you had a jet, water, mountains, and a sky, this command would ensure that they are all updated to give the player the illusion of flight. Of course if you don't move anything, it'll be a still screen, but when you do start moving, UpdateWorld will make it all graphically move on the screen. You don't really need this command to make our example program work, but it's a good idea to keep in the habit of having it in your code.


One of the things you'll hear alot in the 3D world is "rendering". This term simply means that stuff will be drawn. So if you have that jet, water, mountains, and sky on the screen, B3D will need to "draw" those images each frame. To do this, the RenderWorld command must be used.

Conclusion

There are a ton more things we can do with B3D, but I just wanted you to get your feet wet and to start playing around...like I'm doing! ;) The next article, "B3D Primitives" will take us a step further into our journey of the B3D world.

Until next time...cya!

-Krylar


For a printable copy of this article, please click HERE.


This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.