Stefan's profileeXtreme's PlacePhotosBlogListsMore ![]() | Help |
|
April 26 BasicEffect: Lights / Part 1BasicEffect is not that basic, if you take another look at it! It has lots of properties and with addition of PerPixelLighting it's nice 'n' quick solution for rendering models. This article was written to show you how just a few lines of code can make your render stand out..Of course as title suggest, we're going to stick to lighting, at least in this article.. So basicEffect.enableDefaultLighting() gives you standard lighting rig which, honestly, in lot of cases work just fine:
But what if you wanted to render a model at night, or scene with one source of light, what then? Using DirectionalLight would be ideal if you ask me, so why not try it.. basicEffect.DirectionalLight0.Enabled = true;basicEffect.DirectionalLight0.Direction = new Vector3(0.2f, 0.0f, 0.5f);basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.2f, 0.4f, 0.2f);So after you've added these lines of code, which simply define diffuse color and light's source's direction..
As you can see it already looks much better, but for a final touch we're going to adjust specular power and color a bit.If you aren't sure what I'm talking about, Shawn's post might be good introduction to it basicEffect.SpecularColor = new Vector3(0.5f, 0.5f, 0.5f); basicEffect.SpecularPower = 8; For the specular color I'm using a light white color, and I've set a specular power to 8..Something not to shiny and plastic, but not too flat either.. Not too much of a difference, but that's mostly because we have used white color both as a light's color as well as specular color..You can play around with values and see different results! April 21 How to implement GameService?If you're working on a game that is made of several GameComponents, and you find out that "Skybox" component needs access of Matrix world, view and projection founded inside "Camera" component, then you're pretty much in trouble if you don't know how GameService works! Trying to make a instance of the Camera component (in this case) in Skybox, is simply impossible - because Camera component requires us to pass a game reference to it..Trying few other ways will fail as well.. That's where GameServices comes into play.A game service is nothing more than a simply interface, which you can use for passing fields, methods..Now there another problem occurs - wait we can't use fields in Interfaces right? Well that's not really a problem when you have the field you want into component itself.. Below is the example of using Player's (component) view Matrix inside Skybox (component): // Player Component public interface IPlayerShipService { Matrix View { get; set; } } public class Player : DrawableGameComponent, IPlayerShipService { private Matrix view; public Matrix View { get { return view; } set { view = value; } } public Player(Game game) : base(game) { game.Services.AddService(typeof(IPlayerShipService), this); } } // Skybox public partial class Skybox : DrawableGameComponent { Matrix view; Matrix proj; public override void Update(GameTime gameTime) { IPlayerShipService playerService = (IPlayerShipService)Game.Services.GetService(typeof(IPlayerShipService)); view = playerService.View; proj = playerService.Proj; } } So this is working example, as you can see later inside Skybox/Update(), we can simply assign view and proj to the Player's view and proj.The reason why I'm doing this inside Update() is so they will be updated. The reason why I'm inheriting interface IPlayerShipService from Player GameComponent is because we need to assign interface to that component.We finish that off by writing line of code in constructor..Later we simply use GetService in the Skybox Update() method to get all the things we need from the interface IPlayerShipService.. So that will wrap up this article - GameService and how they work! I hope you've enjoyed reading it and learned something from it, because this is really, I mean, really important if you're dealing with GameComponent.. If you have any question just drop a comment and I'll respond as soon as I can! Cheers April 13 Update(Skybox) && Information(Game)Hello, today I'm going to show you some features that has been added to the game, as well as give out more information about game and...well you'll see! First thing first, here's what this post is mainly all about - Skybox has been added! It has been painful and tendious task I must admit because this is first time I ever done it..But it was worth it! ![]() ![]() (Environment you see here isn't really for space game right? But that can be changed with a click of a mouse!) As you can see, the ship is still the same, even tho I said I'm going to change it as soon as possible..Well I thinked so "I'm 3D artist so it won't be a problem." But it's actually.I'm not going to do any 3D graphics for this game for simply reason - there's a big chance that next morning I'm not going to open the XNA, instead I will open Maya (3D modeling package I was working in).. FAQ - Well not that many many peoples have asked me this, but I guess that are the questions you might be interested to hear the answers for! What's it? Spaceship's Journey is a 3rd personal space shooter!It will be simply game with objectives such as destroy boss-ship and so on...After all this will be the first 3D game I ever made entirely by myself! Later on, it can be expanded with more features as I learn more and more! What's release date? No idea! Is this entry for DBP Challenge? Depends on what will the game looks like on the end, and will it be completed till deadline! Any demo, video? Yes, very soon! Next stage will be about collision and shooting, and I'll be sure to video tape that if not release demo of it! Tutorial perhaps? I wanted, if anything goes smoothly through end, to release full, in-depth tutorial on making this game from scratch..Of course if you're interested and if it would help you in any way! More about hearth of game - Engine! I was thinking something today and came up with idea, to make this game mod-driven..The idea is to make this game very easy to change completely.So from Space Shooter you'll get WWII battle game and vice versa. Right now if you take out HUD and change it, take out spaceship and change it, pick different skybox, you've got a completely different looking game and I will prove it in the next couple of days! I'll show the images in order (before/after). Cheers! April 11 Update - Interfaces, MenuAlright, here's another update - this time onto interfaces! I through I wouldn't be able to make such images in photoshop, but apparently I was wrong Game got nice(if you ask me) startup screen: ![]() As well as simple HUD: ![]() And of course pause mode so you can rest: ![]() Gameplay have not been changed, except from fixing few bugs here and there, and implementing smooth movement which really doesn't deserve some attention..Next step is make point system, and start working onto game itself - implementing shooting, enemies.. Cheers till next update! March 19 Update - 3rd Person CameraI just wanted to inform you that 3rd person camera has been added to Spaceship's Journey game! It still too rought and I need to come up with a way of smoothing it but it's working thanks to John Sedlak who has been helping me out! Screenshot (CMD Shows It!) ![]() By making 3rd person camera I have only added more to my "Objective list" but this is very important step in making any kind of game.. Feature I still need to implement: -Smooth movement -Camera rotation around model -Collision detection -Shooting -HUD -Menu Cheers! March 17 About my Spaceship's Journey gameTo be honest I haven't really thinked about storyline mostly because I knew things I need to implement no matter what storyline might be - 3rd person camera, movement, spaceship's rotations etc..So once I have those features working great I'll think more about storyline and leave programming a side for a while.. At the moment, when game start you'll see two spaceships. Your and enemy's (I'll also change the look of those spaceships in the future), trying to move and rotate around will also affect enemy (basic AI) so it'll be little hard to hit him...maybe too hard at this point, but I'll make it easier in the future! Screenshot of the gameplay ![]() Feature I still need to implement: -3rd person camera -Collision detection -Shooting -HUD -Menu It will still be a long way just to get to the stage called "something that looks like a game", but this is fun and I really enjoy working on it in my free time! From time to time, if something has been added to this game I'll be sure to write post about it! Cheers! Introduction To 3D Game Developing3D Space In the game development (just like in the real life) 3D world is an empty space.Every object in that space can be defined by X, Y and Z coordinate.X represent horizontal line, Y represent vertical line while Z represent depth. The only one type of element that can be drawn in 3D space is point.Unbelievable as it might sound, every model you see in your everyday game is represented by a n-points.By connecting n-points you can draw anything from lines, to spheres.. But before you're able to do that, we need to learn another thing called Vector. Vector "Vector is a concept characterized by a magnitude and a direction." - Wikipedia says.Now because I'm not going to act as professional game developer (which I'm not) I'm going to say it using my words: Put it simple vector is an arrow graphically. It's invisible in the game or anywhere else you might be using it.. There are two types of it : Scalar and Quantity. Scalar type represent vector defined by magnitude but without any direction being associated. Quantity type represent vector defined by magnitude and direction (Arrow's head point in the vector is its direction). Example Imagine you have given a point A in 3D space.You know its X, Y as well as Z coordinate position, and you're asked to represent that point by using Vector. X = 2; Y = 3; Z = 15 First write down the Vector3 (3 means 3 value are involved) skeleton -> A (x, y, z) Next simply replace the given coordinates with your skeleton code -> A (2, 3, 15) That's it, working with vectors can only make your life easier! After knowing vector you're able to position your model in 3D Space using XNA (and even move it around), but to be able to render them you're going to need to know what Matrix is and how can it ruin your life.. Matrix Forget about popular movie called "Matrix" it's not such fun in game developing world.. I'll explain it using my method, if you're up for some complicated theoricaly explanation just google for it! In XNA (and game development in general?) when you want to render your model in the game, you're going to need to define three things - Matrix World, Matrix View and Matrix Projection. -Matrix World If you want to rotate your model in any direction, translate it and do such major things you'll mostly create World Matrix for that purpose. Example: Matrix World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(spaceShip.modelRotationY); -Matrix View View Matrix is very simply - it just affect your camera.You mostly just need to setup CameraLookAt method there using camera position, camera's target and UP vector. Example: Matrix View = Matrix.CreateLookAt(spaceShip.cameraPosition, Vector3.Zero, Vector3.Up); -Matrix Projection Projection used to be quite challenging at first, but once you get feel of it, you can master it.It creates perspective by combining aspectRatio and FieldOfView. Example: Matrix Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); Now you might have learned something about Matrix, and next time you see them you'll at least know what each Matrix does.Of course you're going to need to understand them much better if you plan on making some complicated camera systems! Conclusion I hope you enjoyed reading this first article about 3D Space, there might be something wrong, etc but hopefully you learned something new.I'll soon introduce you to my hobby game I'm writing in free time and share some code out of it! Till then, Have Fun! March 16 Welcome!I'll kick this blog off giving you deep introduction into 3D.I hope this will be interesting for you and you'll learn a new things you didn't know before.Before I start writing anything, keep in mind that I'm by no means professional game developer, it's just hobby for me, so I'm just next XNA user! For the further reading, no C# knowledge is required, however if you want to learn to develop games on your own (using XNA) you're going to need to learn it. So let's begin! |
|
|