Content Archived

This content is no longer current.

Beginning Game Development: Part IV - DirectInput

Sign in to queue

The Discussion

  • User profile image
    acolyte

    I had to make up stuff as I went along to make this tutorial work. Iam glad the creator of this tutorial is not my professor or I'd be screwed.

  • User profile image
    Rob

    I actually am a professional programmer and I didn't find the jump at the beginning of this section that helpful.  I refactored the code no probs...  However, the creation of classes from previous material was a stretch.  When I encountered this jump, I just went to the end of this tutorial and started flipping the code.  What might be nice is a before and after of the code in each section if you are going to optimize and refactor.   All in all, still a pretty good tutorial though.

  • User profile image
    Johan

    Must agree with Carl, I wrote all code myself and when you start changing alot of stuff I can't follow along anymore. Else it was a good tutorial, but I am giving it up now.

  • User profile image
    Jeremy

    I have been playing around with directX a lil while now.. And honestly, this material has taught me more about the whole framework in general. And I didn't realize till now how trigonometry played such a big role in all of this.

    In response to Carl, personally, im quite the NOOB,  you just need to be willing to experiment with everything (change numbers, delete Classes, try to crash the system Expressionless if that helps.)

    For me, the Matrices were confusing but after a look through the sources provided things start to make sense. It's just mental debugging. Develop some logical sense... Run through the provided source codes in your head. It'll eventually make sense if you get a little confused.  Don't be a loser like Johan Tongue Out

    In closing, I agree with Rob .. All in all, GOod Tutorial. . Wink

  • User profile image
    Mike

    Dude... I wanna have your babies! I dont know what all these bad comments are about. These tutorials are amazing!! Just made my first little game moving a shuttlecraft around in space, thats right... im a loser, but i bloody love it!

  • User profile image
    Jerry aka 10pups

    Does anybody just sit down and type out an app or game and poof it works?

    I am just a beginner but I understand this.

    Summary

    Once again I find myself running out of space before being able to cover all of the items I wanted, but I hope there is enough stuff here to let you experiment on your own. We are going to continuously refine the game in each iteration rather than trying to get it perfect the first time; that is the sprit of Agile development.

  • User profile image
    Verry LongBottom

    it builds fine but when i try to debug it says line 273 in skybox textureloader is invaliddataexception

  • User profile image
    Jonas

    The tutorial it self is very good and i really appreciate it. The problem is when a lot of stuff is taked for granted, because in the 3 first parts everything was "do this and that because". Now suddenly we have new classes that merely is introduced at all. And the code is of course not that easy to interpret at novice level. But i decided to just copy the skybox and do the other work "manually". I guess you learn better if everything had been explained but still a good tutorial so far!

    Thanks

    Jonas

  • User profile image
    Jake

    I get an error in the public Device device; line it says:

    'Device' is an ambiguous reference between 'Microsoft.DirectX.Direct3D.Device' and 'Microsoft.DirectX.DirectInput.Device' (CS0104)

    Why is the 'Device' class in both these namespaces?

  • User profile image
    akaim

    I can't download the source file nor write it myself. Can someone help me (have the copy)?

  • User profile image
    Clint

    @akaim:  Download links are at the top of the page,  I just tried them and they work.

  • User profile image
    Clint

    This is Part 1 of an introductory series on game programming using the Microsoft .NET Framework and managed

  • User profile image
    Clint

    This is Part 2 of an introductory series on game programming using the Microsoft .NET Framework and managed

  • User profile image
    p

    on my first look at tut4, I also agreed with Carl. It looked very intimidating. But then i thought... what the heck. give it a go. Took me a while, but i managed to get it to work (customising my code from the first three tuts to be the same as tut4).

    My advice to you: take ur time and read the code cleanup section slowly and thouroughly. Its not that cryptic as it looks. Dont give up. and try to understand what the code does. not just copy and paste Smiley

  • User profile image
    Edward

    I agree with Carl, but the tutorial is quite useful anyways.

    I am new to DirectX as most of you and also programming in general. I am trying to follow the series with November2008DirectXSDK which does not support managed environment as before as I discovered. However, it is still possible to follow the tutorial, untill now I had trouble only with timer and I wished to share how I was able to get over it. The code is working just the same as the downloaded one - as some say it is impossible to follow the tutorial in this 4th part without dowloading the code.

    Hope it helps:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    //ForStopwatch class add:

    using System.Diagnostics;

    namespace BattleTank2008

    {

       class Timer

       {

           /*"Stopwatch.Frequency" is managed equivalent of  unmanaged "QueryPerformanceFrequency"

            *"Stopwatch.GetTimestamp ( )" is managed equivalent of unmanaged "QueryPerformanceCounter"

            *I hope I was able to apply them correctly

            *deltaTime=1000000000d/Stopwatch.Frequency*FrameworkTimer.ElapsedTicks;

            *time=1000000000d/Stopwatch.GetTimestamp ( )*FrameworkTimer.ElapsedTicks;

           */

           #region Fields

           private static bool isTimerStopped;

           private static double ticksPerSecond;

           private static double stopTime;

           private static double lastElapsedTime;

           private static double baseTime;

           #endregion

           static Stopwatch FrameworkTimer = new Stopwatch();

           private Timer() { }//No creation

           static Timer()

           {

               isTimerStopped = true;

               ticksPerSecond = 0;

               stopTime = 0;

               lastElapsedTime = 0;

               baseTime = 0;

               ticksPerSecond = Stopwatch.Frequency;

           }

           //Returns true if timer stopped

           public static bool IsStopped { get { return isTimerStopped; } }

           //Advance the timer a tenth of a second

           public static void Advance()

           {

               if (Stopwatch.Frequency <= 0) return;

               stopTime += ticksPerSecond / 10;

           }

           //Get the absolute system time

           public static double GetAbsoluteTime()

           {

               if (Stopwatch.Frequency <= 0) return -1.0;

               //Get either the current time or stop time

               double time = 0;

               if (stopTime != 0) time = stopTime;

               else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

               return time / ticksPerSecond;

           }

           //Get the time that elapsed between GetElapsedTime() calls

           public static double GetElapsedTime()

           {

               if (Stopwatch.Frequency <= 0) return -1.0;//Nothing to do

               //Get either the current time or stop time

               double time = 0;

               if (stopTime != 0) time = stopTime;

               else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

               double elapsedTime = (time - lastElapsedTime) / ticksPerSecond;

               lastElapsedTime = time;

               return elapsedTime;

           }

           //Get the current time

           public static double GetTime()

           {

               if (Stopwatch.Frequency <= 0) return -1.0;

               //Get either the current time or stop time

               double time = 0;

               if (stopTime != 0) time = stopTime;

               else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

               return (time - baseTime) / ticksPerSecond;

           }

           //Reset the timer

           public static void Reset()

           {

               if (Stopwatch.Frequency <= 0) return;//Nothing to do

               //Get either the current time or stop time

               double time = 0;

               if (stopTime != 0) time = stopTime;

               else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

               baseTime = time;

               lastElapsedTime = time;

               stopTime = 0;

               isTimerStopped = false;

           }

           //Start the timer

           public static void Start()

           {

               if (Stopwatch.Frequency <= 0) return;

               //Get either the current time or stop time

               double time = 0;

               if (stopTime != 0) time = stopTime;

               else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

               if (isTimerStopped) baseTime += time - stopTime;

               stopTime = 0;

               lastElapsedTime = time;

               isTimerStopped = false;

           }

           //Stop or pause the timer

           public static void Stop()

           {

               if (Stopwatch.Frequency <= 0) return;

               if (!isTimerStopped)

               {

                   //Get either the current time or stop time

                   double time = 0;

                   if (stopTime != 0) time = stopTime;

                   else time = 1000000000d / Stopwatch.GetTimestamp() * FrameworkTimer.ElapsedTicks;

                   stopTime = time;

                   lastElapsedTime = time;

                   isTimerStopped = true;

               }

           }

       }

    }

  • User profile image
    Mike

    Carl

    I would have to agree with you.   Part I, II, and III were good.  Good explanations, good explaining what the code does and where it goes and more, But when I hit part four I was thrown way off.

    In the download sample there's classes we never made and in the tutorial it never went over any off it.  Also it give code snippets but don't explain where it goes.

    The tutorial just went down hill fast.  I am not new to developing web or desktop apps but I am new to game development and direct X.  So I would like a more clearer explanation of how this all works and ties in together.

  • User profile image
    Dave

    This is actually pretty sweet how it takes those 6 simple images and blends them all together. Pain in the butt with these ambiguous names spaces in the DirectX libraries but I figured it out. Saaaawweeeet!  On to part 5!   The tutorial is pretty good actually but you definately need some experience with debugging to find the problems. I'm still using the August 2007 SDK with visual studio 2003 and everything seems to work. It's still really complicated to grasp how the actual functions work with all the coordinates that have to be manually added. Might be a good idea to memorize what each of these variables are. Also, what is the point to using an underscore (_)  at the beginning of all these objects?

           _frontFaceVertex(0).X = -100.0F

           _frontFaceVertex(0).Y = 100.0F

           _frontFaceVertex(0).Z = 100.0F

           _frontFaceVertex(0).Tu = 0.0F

           _frontFaceVertex(0).Tv = 0.0F

           _frontFaceVertex(0).Nx = 0.0F

           _frontFaceVertex(0).Ny = 0.0F

           _frontFaceVertex(0).Nz = -1.0F

  • User profile image
    A N

    Drawing the actual skybox uses the techniques we have discussed in the previous articles and I am not going to cover them in detail. The basic steps are as follows.

    1- Define a PositionNormalTextured vertex array to hold the data for the four corners of each cube face and texture information.

    2- Load the texture for each cube face from a file.

    3- Setup the Vertex buffer for each face.

    4- On each Render loop readjust the skybox.

    On each Render loop disable Z-buffering.

    On each Render loop use the Camera object passed in to determine the direction the camera is facing and draw the appropriate face.

    On each Render loop turn Z-buffering back on.

    1 to 3 were NOT mentioned earlier. can you explain these portions?

  • User profile image
    A N

    Well everyone, you've all waiting patiently 3(or maybe 4) years and after less than a month of work i've found the solution!

    Inside your loading sub use

    texture1 = TextureLoader.FromFile(mydevice, "img1.jpg")'Only load once!

    In your loop use

    device.SetTexture(0, texture1) 'Set the rendering texture for the following vertex object

    device.DrawUserPrimitives(PrimitiveType.TriangleFan, 4, CreateSquare())'

    if you've been following so far in the tutorial you know what "CreateSquare()" is for.

    Don't forget though:

    Tu is 0 to 1 for the x coordinate on the texture

    Tv is 0 to 1 for the y coordinate on the texture

    Enjoy

  • User profile image
    Clint

    @ge-force download the source code at the top of the page.  this article was designed to complement the source code, not be a step by step tutorial.

  • User profile image
    ge-force

    Where do you put the device.RenderState.ZBufferWriteEnable = false;

    // draw the skybox here

    device.RenderState.ZBufferWriteEnable = true;?

  • User profile image
    Clint

    @Aleksey, rereading this, this does teach and explain a lot of stuff.  This was one of our first series we did and it is a very complex subject matter.  I'd love to hear how we can improve if you'd like to contact us.

  • User profile image
    Aleksey

    This 4th section totally discouraged me from reading further on. Tutorials are ment to teach you how to do something and samples are to show you whats done. I do not feel that this 4th section is teaching anyone what is done. You just throw stuff out there and tell us to figure stuff on our own. Why would we bother reading this tutorial then. Might as well read comments in directx samples.

Add Your 2 Cents