Content Archived

This content is no longer current.

Beginning Game Development: Part III - DirectX II

Sign in to queue

The Discussion

  • User profile image
    John

    I am having the same problem as waco it says that a get or set accessor is expected can some one explain

  • User profile image
    Ryan

    Any idea how we're supposed to read these coordinates?

    crossHairs(0).Position = New Vector3(1.0F, -1.0F, zval)

    what does the .of stand for? How are these numbers read?

    What does the "f' stand for in front of each number? Are these left hand cartesian coordinates?

    Drop me a line at tramel_e4196@sbcglobal.net if you know the answers. I've been struggling with this for weeks now.

    crossHairs[6].Position = new Vector3 ( -1f, -1f, zval );

  • User profile image
    Daniel

    'F' indicates that the value is of type float.

  • User profile image
    djhayman

    Ryan:

    The "f" on the end of a number tells the compiler that it is a floating-point number, not an integer.

    The ".0f" is just saying "1.0 as a float".

    Likewise, you could say "1.5f" which means "1.5 as a float".

  • User profile image
    WydOne

    At this point you also need a:

    using Microsoft.DirectX;

    at the beginning of your GameEngine.cs file in order to have the Vertex3 and Matrix classes.

  • User profile image
    Peter Keating

    To fix the exception mentioned by many people you must move this line:

    _device.VertexFormat = CustomVertex.PositionColored.Format;

    above these lines:

    _device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayTop());

    _device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayBottom());

    Hope this helps Smiley

  • User profile image
    Jon

    I was getting the runtime error

    An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in Microsoft.DirectX.Direct3D.dll

    So I moved the line

    device.VertexFormat=CustomVertecPositionColored.Format

    directly after the device.BeginScene() and before device.DrawUserPrimitives

    this sorted it out for me

  • User profile image
    jtrosp

    I am new to writing code and this has been a challenging experience so far.  In each part, I have had to use both the tutorial and the help comments to work the bugs out of my code.  Thanks All!

    Due to my experience I will not be able to help others with the code.  However, to other newbes you might want to cut and past the tutorial to a word document (and Print).  If you notice some of the longer lines of code on the right side get cut off.  If you cut and past you will be able to read them.

    I hope this helps.

  • User profile image
    prem

    Everything works fine until I add the following line of code:

    device.DrawUserPrimitives ( PrimitiveType.LineStrip, 6,

      CreateCrossHairVertexArrayTop ( ) );

    device.DrawUserPrimitives ( PrimitiveType.LineStrip, 6,

      CreateCrossHairVertexArrayBottom ( ) );

  • User profile image
    janaka

    I have the same problem as prem; the error messages I get is :

    The name 'CreateCrossHairVertexArrayTop' does not exist in the current context

    The name 'CreateCrossHairVertexArrayBottom' does not exist in the current context

    Those lines of code appear right after:

    device.BeginScene();

    thanks

  • User profile image
    akaim

    To fix the exception mentioned by many people you must move this line:

    _device.VertexFormat = CustomVertex.PositionColored.Format;

    above these lines:

    _device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayTop());

    _device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayBottom());

    Hope this helps Smiley

    =================================

    it doesn#t help at all :/

  • User profile image
    Link_Dead

    ok to fix the "InvalidCallException" in the OnPaint code block, make SURE these statements are in this EXACT order...

    protected override void OnPaint(PaintEventArgs e)

           {

               deltaTime = FrameworkTimer.GetElapsedTime();

               this.Text = string.Format("Framerate: {0}", FrameRate.CalculateFrameRate());

               this.Invalidate();

               FrameworkTimer.Start();

               device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

               device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 5f), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

               device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 100.0f);

               device.RenderState.Lighting = false;

               device.RenderState.CullMode = Cull.None;

               device.BeginScene();

               device.VertexFormat = CustomVertex.PositionColored.Format;

               device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayTop());

               device.DrawUserPrimitives(PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayBottom());

               device.EndScene();

               device.Present();

               this.Size = new Size(800, 600);

           }

    c/p (copy/paste) if you want, mine were in the wrong order giving me an error. If this does NOT help, email the person, he DOES read his email Wink

  • 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
    biswarup ghosh

    all prob.s related to error in the foll:

    device.DrawUserPrimitives ( PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayTop ( ) );

    device.DrawUserPrimitives ( PrimitiveType.LineStrip, 6, CreateCrossHairVertexArrayBottom ( ) );

    gets resolved ONCE YOU DOWNLOAD THE SRC-CODE GIVEN ON THIS PAGE.

    on analysing, u'll find out that PROBLEM LIES IN THE POSITION OF THE FOLL:

    device.EndScene ( );

    device.Present ( );

    THESE 2 LINES HAVE TO BE PLACED AFTER THE

    device.DrawUserPrimitives(..) LINES OF CODE.

    ITS MENTIONED TO INCLUDE EndScene IMMEDIATELY BEFORE THE PresentScene

    BUT NO-WHERE IS IT STATED THAT EndScene IS TO BE HAD AFTER DrawUserPrimitives.

    HAVING SAID THAT, ITS REALLY A TUTORIAL IN WHICH MOST OF THE THINGS HAVE BEEN STATED EXCEPTIONALLY WELL AND CLEARLY.

    AND FURTHERMORE, THE SRC-CODE IS ALWYS ACCOMPANYING THE TUTORIAL SO THAT IF ANYTHING GOES WRONG, THEN SRC-CODE MAY COME TO RESCUE!!!

    AND AFTER ALL, THE AUTHOR TOO'S A HUMAN-BEING. A TRIVIAL LITTLE SOMETHING LEFT OUT CAN BE EASILY MANAGED ONCE U FOLLOW THE SOURCE-CODE.

    I'D GIVE THUMBS UP TO ALL THE AUTHOR'S EFFORTS.

    Smiley

  • User profile image
    Edward

    Thank you to all who contributed in this tutorial. It still is helping people out there.

  • User profile image
    Sharad

    Yes...indeed - extremely helpful and a superb explanation of how DirectX works Smiley Many many thanks!!

  • User profile image
    Brian

    if you get a mmds loader lock problem thing, go to  the debug menu item in your ide, click on Exceptions, go to the managed Debugging assistant and Uncheck the Loader Lock flag

  • User profile image
    Dave

    Well, I pretty much worked all the bugs out within 10-20 minutes and I can even see the rotating cube but this is a real challanging tutorial because of all the co-ordinates being used to draw the shapes. Very brain busting. Is there an easy way to plot out how you are going to create a shape or object and mark out the co-ordinates. For the triangle, the first point is the top part of the triangle, the second is the right side, and the third is the left. Had to play with the numbers just to figure that out.

  • User profile image
    TPL

    haloo, I m newbies to this. I would like to know that how if I wanna draw a shape and I wanna show it from the start to end of scene.

    Before that, i was tried put the code to draw the shape before the function for drawCube. The result I got is shape follow the drawCube function change.

  • User profile image
    MDSquared

    To everyone having a problem with an un-handled exception, some of the statements are ordered incorrectly in the tutorial. Your OnPaint method should look something like this (if you are using C#. Sorry VB guys and girls):

    deltatime = FrameworkTimer.GetElapsedTime();

    this.Text = string.Format("The framerate is {0}",

    FrameRate.CalculateFrameRate());

    FrameworkTimer.Start();

    //device.Clear(ClearFlags.Target, Color.Navy, 1.0f, 0);

    device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

    device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 5f),

    new Vector3(0, 0, 0),

    new Vector3(0, 1, 0));

    device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI /4, this.Width / this.Height, 1.0f, 100.0f);

    // turn off the light source

    device.RenderState.Lighting = false;

    // Turn off backface culling

    device.RenderState.CullMode = Cull.None;

    // Tell DirectX we are about to draw something

    device.BeginScene();

    // Tell DirectX that we are done drawing

    // Flip the back buffer to the front

    device.VertexFormat = CustomVertex.PositionColored.Format;

    device.DrawUserPrimitives(PrimitiveType.LineStrip, 6,

    CreateCrossHairVertexArrayTop()); device.DrawUserPrimitives(PrimitiveType.LineStrip, 6,

    CreateCrossHairVertexArrayBottom());

    device.EndScene();

    device.Present();

    this.Invalidate();

  • User profile image
    MDsquared

    It would be AWESOME if these tutorials were made available is a pdf format so that I can use them offline. These are the best tutorials I have encountered, minus a few clarity complaints. Thank you!

Add Your 2 Cents