|  | 
 
 Creating a 3D world is a lot like being a movie director. You have cameras, lights, actors, sets, special effects, a storyline, etc. And you, as the director, control where all of these things are and how the work together. If you think a light should be more bluish for a particular scene, you tell the light-person to use a blue-tinted filter. You want the camera to pan from left to right around an actor, you tell the camera that's what you're looking for. Well, you can do all of these things in B3D too! The only difference is that instead of just saying "pan from left to right slowly", you have to write the code that will do this. What we're going to do in this tutorial is show you how to light up a scene using the different light types, change the colors of the lights and watch how the different colored lights mix to make even more colors. Plus we're going to show how to move the camera around a scene, which is one of the coolest thing in a 3D game...in my opinion. 
 Ambient lighting is the term used to describe what the general lighting is like in the area, specifically the color. Here is a simple program that sets up our Ambient lighting to be red. 
 If you run that program you'll see a red Cylinder spinning in a bunch of different directions. It's red because it's reflecting the bright ambient light in the scene. Change the values after AmbientLight to see the different looks. The first number covers the reds, the second is for greens, and the third for blues. The values can be anywhere from 0 to 255, where 0 is darkest and 255 is lightest. Example: 0,0,0 would be black, and 255,255,255 would be white. 
 Directional lighting is simply having a light facing a certain direction. It's different than ambient lighting because it doesn't cover the entire scene. It only covers the stuff it's facing, or "directed" at. Here's an example: 
 This program will show two cylinders on opposite sides of the screen and a blue light will sweep across them. This is an example of directional lighting. 
 When creating a light of type "Point", you can imagine that you are literally creating a point of light. This light will radiate out at 360-degrees in whatever color you use. 
 Note that the top of the lower cylinder doesn't have any of the blue light shining on it. This is because I have moved the point of light to be under that cylinder, thus it's being blocked from shining there. If we were to move a camera behind those cylinders, we would see that the light isn't shining there either (you'll be able to seen how this works by moving the camera around in the last example presented in this tutorial). 
 The last light type you can use is a spotlight. Now we've all seen these in real life. They're basically big lights that are angled in such a way that as the light gets further from the source, it's radius expands. Think of when Gotham city signals for Batman and you'll get the idea ;) Like directional lights, spotlights can be positioned anywhere in the world, can have any color associated to them and the can move all around. The following demonstrates the use of a spot light: 
 When you run this, you'll see two spheres. One of them is close up and the other is farther out. A reddish spotlight will slowly move back and forth across them. The left-right movement of the spotlight is handled by the TurnEntity command, specifically using the Yaw element. But how do we know how far left to go before moving right again? We call the EntityYaw command to get the current Yaw position of the entity, our spotlight. If we were checking the up-down movement, we would call the EntityPitch command. And for the rolling position? You guessed it: EntityRoll. Also please note that the use of the AmbientLight command. This was done to show a sharper contrast for the spotlight. There are a couple of additional commands up there we should discuss. First, is the LightConeAngles command. There are three arguments sent to this command. The first is which light to use. The second is what the width of the inner light radius should be set to, and the last is the outer light radius. Since spotlights are shaped conically, they have an interior circle and an exterior circle. You can control the width of both of these. I played around with the angles until I got what I felt looked cool. You should mess with these values to see what other looks you can get. The second command is LightRange. Two arguments go to this command: entity and range. The entity is which light we want to set the range for, and the range is the distance the light can reach. This value is very approximate, and should be experimented with for best results. For example, I have set the light back 75 units but a value of 50 for the range will still hit the objects. I set the value to 75 for light range in the above example because I liked the effect better. Play around a bit with that value and see what happens. 
 Camera movement is a big deal when creating games for a number of reasons, but one of the coolest (in my opinion) is that it allows the player to see things from different perspectives. You can use cameras to see your character from the back, front, side, top, way high up, or right through your character's eyes. You can make it so if you cast a spell you now have a floating set of eyes that you can run quickly about a level to see what's around the corner before putting your character at risk. The following code is somewhat large, but it does some cool stuff. I added in two cones and started them spinning, so there'd be more to look at. I added two additional light sources, both stagnant spotlights. Finally, there is now the ability to move the camera forward, look up or down and turn left and right. So, although still a bland example compared to the power of B3D, this will give you an idea of movement through a B3D world. One last thing to note: This code would normally be broken up into smaller sub-routines, but for a quick demo on the use of these tools, I felt that would only lead to confusion. Here's the code: 
 There really isn't anything in this code that we haven't discussed already. It's just a culmination of the topics presented earlier in this and previous articles. Play around with the numbers up there and see what happens. Also, try and add a section for the camera to "roll" around. Here's the idea without giving you the code. You'll need to trap two keys for presses, set the roll speed, set the roll flag, and use TurnEntity to update the roll value. 
 I hope you're enjoying the B3D series. I will continue to work on getting these out the door as I learn more and more about this awesome tool! Until next time...cya! 
 For a printable copy of this article, please click HERE. 
 This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.   |