Thursday, December 8, 2011

Nominate a Great TA for the SCS TA Excellence Award

With the last assignment marked and your projects coming in, I guess this pretty much wraps up our time together this term! It was awesome working with you and I hope I was able to be helpful to you all.

I wanted to draw your attention to the School of Computer Science's TA Excellence Award.  I started this with the admin staff a couple of years ago when I was the TA Mentor, and its success depends very much on you guys making meaningful nominations.  In the past, we've had lots of amazing comments from both students and profs so I hope this can continue this year, even though I've moved back into regular TA'ing and someone else has taken over the mentor role!

So, if you had a TA you really liked this term, or have a great one next term, please do consider nominating him or her.  (That includes me, if you happen to think I'm deserving!)

Nominate a great TA here

Best of luck on your exams, and hope you have an awesome second term! :D

Assignment 4 Marked

Everything should be in WebCT now.  Make sure to get back to me about any issues as soon as you can, since my baby is due December 24th and things only get more and more crazy until then. ;)  Thanks for your patience in getting this done!

Tuesday, November 29, 2011

Midterm 2 Marking Comments

The midterms are marked and the grades are in WebCT. Here are some comments on the way I marked them.

I must admit I had to go through these more quickly, so if you are unsure of why you lost marks somewhere because I didn't write much, let me know.  If you think your answer deserves more marks or that I missed something in determining the correctness of your answer, send an email that demonstrates this. If indeed I think you deserve more marks, I’ll ask you to bring in your midterm paper.

Be sure to check my addition!

Note: The prof said that as long as you didn’t go over the number of questions allowed for each section I could count all the marks for those questions, even if it takes you over 90. I am hoping this was clear for you during the exam, especially because this wasn't the case for the first one.

Number 1

In 1.1, I want to see specifics, especially what function is applied and what you do with the result of that function (add to the height of vertices). Being too general gets you 2/5. If you didn’t mention what the output of the wave function is doing you lost one mark.

In 1.2, the full formula is:
height = amplitude * sin (wavelength * distanceFromSource + angularFrequency*time + shift)
I am taking off 0.5 each for missing wavelength, angular frequency and shift and 1 for missing the others (amplitude, distance from source, and time). Same amount for missing or incorrect explanations. The height/sin part of the equation is worth 1 mark. If you added any terms that shouldn’t be there, I took off 0.5.

In 1.3, the idea is to find which source a particular wave is closer to – that will be the distance used to compute the vertex height. If you correctly did something that added the heights from the two waves together, we are giving marks (12/15).

Number 2

In 2.2, if you only talked about normals needing a proper transformation when transformations like shear are applied, you got 3/7. I needed to know what happens and why it matters in more detail (normals won’t be perpendicular, lighting will be wrong, etc).

Number 4

Forgetting to discuss 2-3 operations for the shaders will lose you 2 points each for 4.1 and 4.2.

Forgetting to state output for 4.1 and 4.2 loses you 1 mark.

Number 5


In 5.1, half marks are given for a reasonable discussion that shows a misunderstanding of the lighting components.

In 5.3, if you say that vertex shaders can be used to do bump mapping but don’t say how (as in, where are you going to get info on how to modify normals, such as from a texture), I took off 1 mark.

Number 6

In 6.1, getting the wrong R vector results in two marks lost (especially if I can’t see how you computed it).

In 6.3, if you forget the surface material value you lose 1 mark, and if you forget the source light you lose 1 mark. If you don’t normalize V and R you lose 1 mark.

Thursday, November 24, 2011

Ask Your Questions Today

Just a quick note to say that tomorrow, unfortunately, I will be in Toronto last-minute for a family illness and likely won't be able to answer your questions regarding the assignment.  So be sure to ask as much as you can today! Also, if enough of you could check WebCT through the day tomorrow, you may be able to help each other in the discussion forums.

Sorry about this!

Assignment 4 Clarification

I have confirmed a couple of things about the assignment that many of you were wondering about.  First of all, before starting task two, you should set the scaling of the earth object to be (1,1,1) again.  Answer all the questions up until 4.2 using this value.  Then change it to (0.1, 1, 0.1).  The question about what issue you observe and how to fix it is directly related to the midterm question on world inverse/tranpose matrix.  An answer of "don't scale it that way" is not correct, because of course you might actually want to scale it that way.  Think about what happens with the normals when you scale the sphere and whether they remain perpendicular to the surface.

Wednesday, November 23, 2011

Upcoming Grading Plans

Assignment 4

My first task is to actually do the assignment so that I can better answer some of your questions before it's due.  This will also make it easier to mark the midterm (and of course the assignment itself).  I am still waiting for confirmation about some of the issues you brought up regarding the assignment questions, and when I know more I will post here.

I will be grading the assignment after the midterms, so you probably won't see your mark back for these until the first full week of December or so.

Midterm

The plan is to have the grades up on WebCT by the end of the day Tuesday November 29, which should be in time to decide to drop the course if needed.  Depending on exactly when I finish, you might get the papers back in class Tuesday, or Thursday at the latest.

Wednesday, November 16, 2011

The Best Midterm Tip I Can Give...

...is to work on Assignment 4.  Trying to understand all the pieces and at least starting to code them will be invaluable.

Also be sure to have a good understanding of all the questions given as samples on the course webpage.

Remember, if you have any questions about any of these things, please ask sooner rather than later so I'll have time to give you a decent answer!

Sunday, November 13, 2011

Clarification from Tutorial

During our informal tutorial, I pointed out that a position (VPOS) was indeed available to be passed in to a pixel shader.  However, it is not the vertex's position as I may have said or implied, but rather the pixel's position on the screen.  If you wanted to know where that pixel would have been in the 3D world, you would indeed need to "cheat" by passing the information in some other way (possibly using texture coordinates, as the prof was suggesting).

Thursday, November 10, 2011

Give Your TA Feedback

A few TA's in SCS (myself included) are participating in voluntary feedback through the TA Mentorship program.  The idea is to collect your thoughts on how we're doing both so we can improve and so we can have a record of our performance.

You can leave feedback on the participating TA's with this convenient online form.  I'd love to get your feedback about me. :)

Wednesday, November 9, 2011

Informal Tutorial Update 2

Room has been booked! Our informal tutorial will take place here:

HP 4325
12:00pm - 1:00pm
Thursday, November 10, 2011

Tuesday, November 8, 2011

Informal Tutorial Update 1

Hey all, I'm working on getting a room booked for our informal tutorial.  So far Thursday this week is the best day for most people, but our SCS seminar room is taken, so I'm trying for a nice room in the Math department.  If I can't find anything, I might try for something on the following Monday.  Watch this space and I'll update with a new post as soon as I know more.

Thursday, November 3, 2011

Informal Tutorial: Help Pick a Time

Fill in this poll if you are interested in an informal tutorial to help you prepare for the second midterm:

http://www.doodle.com/pvy7tn9zn225fnmp

Please only fill in the days you know you will be able to attend.

Assignment 3 Marked

The third assignment is now marked and on WebCT.  Overall, most of those who attempted it did well.  A few general comments:
  • There were a few assignments that looked suspiciously similar.  It might have been a coincidence (and it might have carried over from the previous assignment, and I just didn't notice it then).  But just in case it is not, please be more careful in the future.  Your best bet is to make a note of who you worked with on an assignment when you submit if you did indeed work together.
     
  • There are still some basic code-related issues (so I made sure there were some marks for that).  For instance, I want to continue to get you to use good practices like making your class members protected or private, not using the 'this' pointer to access your members unnecessarily, and avoiding magic numbers.
     
  • Please remember to clear all your warnings before submitting!
     
  • And check whether you check your project file for this stuff before submitting.  You don't want to make your TA do more work than she has to before she even starts grading. ;)  I'll take marks off in the future if I have to modify it for you.

Two-Kings DirectX Tutorials

A student mentioned using this site for their texture tutorial, and since it looks useful I figured I'd share:

http://www.two-kings.de/

If you have any great DirectX resource websites, comment here or send them to me so I can share with everyone else as well.

Thursday, October 27, 2011

Diffuse, Ambient, and Specular Lighting

I have another applet I wrote a while back that might be useful to you. It demonstrates the various kinds of lighting and can really help you understand what's happening behind the equations.  

In class you learned about diffuse, ambient, and specular lighting.  Diffuse lighting comes from a direct light source like the sun, while ambient lighting is just what's hanging around in the environment.  Highlights on a surface from the direct light source appear as specular highlights and depend on where your eye is positioned relative to the surface.

In my applet, you can adjust the intensities of the red, green, and blue light coming from the ambient and direct light sources.  You can also adjust the surface reflectance, which determines how much of a certain colour of light will be reflected back from the surface (and eventually reach your eye, making the material look like a certain colour).  If the surface does not reflect any blue, then changing the blue intensity on the lights won't affect anything (the only exception being for the specular highlight, since those are made before the light would be absorbed/reflected in the surface anyway).

You can move the sun (direct light source) and the eye (viewpoint/camera centre), and you can tilt the surface to see how the angle between its normal and the other directions changes the outcome.

I recommend trying to isolate each type of light first to see how they look.  Turn the specular highlight off at first as well.  Then try to compare what you see with the equations involved in defining the light sources.

As always, if you have any questions, comment here or email me!

Go to the applet now...

Wednesday, October 26, 2011

Midterm Comments

Here are some general comments about the more problematic questions. I sometimes referred to these comments on your midterm paper.

These notes assume that you have access to the prof’s answer key. If you answered more questions than those that would give you 100 possible points, I stopped after 100 possible points as per the instructions on the midterm booklet. (In the future, if there are certain questions you don’t want marked, write “do not mark” on them and I will skip them.)
  1. In Number 8, some said that flickering could be caused by objects that occupy the same space, and that you could fix this by always choosing just one of the objects to render. If both objects were being rendered because they are the same distance away, then you wouldn’t have the flickering. If they were alternating being rendered then choosing just one object wouldn’t fix the problem unless you had a way to always choose the same one (but how would you ensure that?). Suggesting that you change the z-value of one of the objects is a bit more reasonable, but I’m not convinced it’s a great solution since you might have to go in and change your model and because inaccuracies could still be an issue. The answer that was being looked for was that the flickering is caused by inaccuracies of the z-buffer, so to fix it you want to increase the buffer’s resolution.
     
  2. In Number 1, if you draw a diagram that shows the overall idea but not the defining parameters (or if you label angles and such but don’t say what they are for), you will get 1 mark. If the defining parameters are more related to what I showed in my lecture, that’s fine, but I want to know more detail. Also, a few people were getting concepts mixed up between the geometry of the viewing plane (pinhole camera model for instance) versus the actual viewing frustum. We want to know about the frustum here, but I tried to give some marks for the perspective projection diagrams as well so long as you didn’t mix things up too much.
     
  3.  In Number 10, a good description of what the center and position points are comes from the Toymaker website (that place just keeps popping up in my Google searches!). It’s not clear to me whether the description in the answer key is also correct (can’t tell in the API, don’t now from experience), but it’s certainly possible and it does appear in the notes. (It seems to not make sense to have to update the position any time you want to change the center of rotation, leading me to believe that these are unrelated to each other, but I’ll go by what’s in the notes.)

    Center: “pointer to a 3D vector specifying the position in the sprite around which it can be rotated or NULL for top left”

    Position (aka translation): “pointer to a 3D vector defining the screen position of the sprite. Note: in Direct3D 0,0 is the top left of the screen”
     
  4. In Number 1, if you talk about implications related to the perspective transform itself rather than the frustum, I accepted that, so long as that made sense in the context of your previous answers.
     
  5. In Number 7 if you talked about giving the system incorrect drawing instructions (e.g. triangle set vs. triangle fan), I accepted that.
     
  6. There seemed to be a fair number of issues with Number 4. First of all, when given actual points in the question, you should make sure to use them in the answer. In other words, be mathematically specific. Also, there seems to be some misunderstandings in how to actually compare the normal to the view point to see if they can “see” each other. The trick is to use the fact that the sign of the dot product of the two entities can tell you something about the angle between them, and thus whether they are pointing away from each other or not.
     
  7. In Number 3, remember that if you are putting your point first (to the left of the transformation matrices) that it would be a row vector, not a column vector, in order to get the correct matrix multiplication happening.
     
  8. The biggest problems in Number 4 were either not giving enough detail (how do you actually compute certain things, etc) or just plain old having the method wrong. Be sure to review the answer for this one carefully, and keep in mind for the future that a question worth 25 marks is going to warrant some specific detail (in this case, including the mathematics behind it).

Midterm Marking Scheme

I've marked the midterms and posted the grades on WebCT. Hopefully you will receive your papers back in class tomorrow (Oct 27).

Here is how I broke down the marks for most questions (some of the 5 mark questions aren’t listed because they are more straightforward).

If you think your answer deserves more marks or that I missed something in determining the correctness of your answer, send an email that demonstrates this.  If indeed I think you deserve more marks, I’ll ask you to bring in your midterm paper.

Be sure to check my addition!

Number 1
·         2 for the projection role
·         2.5 for the defining parameters (0.5 each)
·         2.5 for the diagram
·         1 for what defining parameters form
·         2 for implication on visualizing game objects

Number 2
·         4 for explaining what homogeneous coordinates are
o   3 if correct but not quite enough detail
·         4 for explaining the motivation for them
·         2 for giving example of where they are used
o   1 if you give a correct example but offer an incorrect reason

Number 3
·         For general matrices, 1.5 each for the two translation matrices and 2 for the rotation
·         5 marks for the second part: 1 mark for each of four matrices (including the point) and 1 one mark for the correct order

Number 4
·         15 for describing the steps properly
o   4 for defining two vectors using the triangle points
o   3 for finding the normal via the cross product of these two vectors
o   4 for defining a vector from the triangle to the viewpoint
o   4 for computing the cosine of the angle between normal and vector to the viewpoint (only the sign matters)
·         5 for drawing an accurate picture
o   2.5 if the overall idea is there but it does not generalize well and/or does not show U, V, W, P, or other parts of the computation in the first part
o   2 if the diagram is good but based on wrong method
·         5 for correctly computing whether T is visible from P

Number 5
·         5 for saying why the transformation computes Z-values
o   1 if you mention removing shapes outside view frustum (this will happen before the projection transformation)
·         10 for correct computation
o   7 if correct but not enough math shown to show full understanding
o   9 if there’s a small error
o   7 if you don’t properly multiply the homogeneous coordinate of the point with the value in position (4,3) in the matrix to end up getting zero in the result
Number 6
·         5 for computing orientation
·         7 for computing avatar position
o   5 if you don’t show enough math
o   4 if you don’t normalize the orientation vector and multiply that by 50 units
·         8 for  avatar’s position and orientation
o   7 if you did not do the math and/or there are small errors
o   4 if the method is wrong
Number 8
·         2.5/5 for saying the objects occupy the same space and to pick just one (without saying how)
·         3.5/5 for saying the objects occupy the same space and to change their z-value

Number 9
·         3/5 for saying the object is outside the “render distance”

Number 10
·         3 for explaining the purpose
·         2 for the example
o   1.5 if example is good but based on incorrect understanding of part 1

Friday, October 21, 2011

Assignment 2 Marked

Tried really hard to get it marked by yesterday so you'd have more time to take into account any useful feedback for Assignment 3, but I just couldn't make it happen.  It's done now, and just like last time, you will find a PDF attached with the marking scheme and my comments to you.

I will be marking the midterm next, so I won't get to the third assignment for a while.

Wednesday, October 19, 2011

DirectX Matrices Related to Viewing

I promised a while back to write a post that related the theory in the lecture that I did a while back on viewing/cameras/projection in DirectX, but alas I haven't had the chance until now. Though it's perhaps a bit late, hopefully this can serve as another point of view for understanding things, or act as a reference.

The Toymaker website I mentioned in an earlier post has a good page on the various matrices you need in Direct3D to go from your model to the screen.  Let's have a look at the descriptions there and see how it relates to the terminology and concepts from my lecture.

Note: DirectX assumes a horizontal/row vector that is multiplied on the left hand side of the transformation matrices.  This means that the transformations are applied from left to right.  In linear algebra class and in my notes, a vertical/column vector is multiplied on the right hand side so that transformations are actually applied right to left.  I'm not going to switch things around from my lecture here, so keep this discrepancy in mind when looking at the Toymaker site in more detail.

Toymaker lists the following three matrices used to transform your game content from 3D model space to 2D screen space:
  1. World Matrix - Transforms 3D data from Model Space into World Space. You need to set this before rendering every entity in your world.
  2. View Matrix - Transforms from World Space into View Space. You need to set this each time your camera changes position
  3. Projection Matrix - Transforms from View Space into Screen Space. You normally set this just once during initialization.
The projection matrix mentioned here is like MoMp from my slides (i.e. the combination of the orthographic projection, which included the windowing transform, and the projection transform that squished the view frustum into a rectangular prism).

The view matrix here is the same as the view matrix Mv in my slides, which essentially did a coordinate transform so the model points in world coordinates would instead become relative to the camera's coordinate system.

The world matrix isn't something I talked about explicitly in the slides.  If you look at the orthographic viewing volume or the view frustum, you can imagine that the model points inside are going to be in the coordinate system of the world or camera (depending which stage you are looking at).  Of course, if our models are defined according to their own coordinate systems, then their points would first have to be transformed to be relative to the world coordinate system.

Toymaker goes on to show the nice helper functions that DirectX has to help you set up these three matrices.  You don't even have to know how these matrices look.

For the view matrix, you can use the same entities we defined in the slides to define where the camera is.  Then DirectX will construct the viewing matrix for you.  As described on Toymaker:
D3DXMatrixLookAtLH(D3DXMATRIX *out, CONST D3DXVECTOR3 *eye, CONST D3DXVECTOR3 *at, CONST D3DXVECTOR3 *up );
  • out - this is where we pass in the address of the matrix we want filling
  • eye - the world position of the eye point
  • at - the position in the world we are looking at
  • up - defines which way is up. This is needed because if you are positioned somewhere in the world looking in a certain direction you could be upright or standing on your head and in each case the position and direction would still be the same. So to determine which way up we are we need to provide it here
So the 'eye' here is the eye position/camera center e in the slides, 'at' here is the gaze direction g in the slides, and 'up' here is the view-up vector t in the slides.

Notice that the projection matrix is defined on Toymaker a bit differently than we define it (in addition to the fact that the DirectX projection matrix takes you from the world to the screen in one fell swoop).  While we talked about the view frustum as a set of planes, they use the field of view, aspect, and near and far planes instead.  Either way is fine because there is enough information to move from one representation to the other - for instance, the field of view can be determined at the angle between the lines from the origin to the edges of the frustum's side planes.

That should basically cover it.  You can take a look at the Toymaker page on cameras as well to see some methods they use to define the view matrix.  I encourage you to try to relate what you see there to what's in the slides to get a good feel for how well you understand the concepts.

Tuesday, October 11, 2011

Comments on Assignment 1

Overall, the first assignment was quite well done.  There were a few reoccurring issues that I figured I'd point out here so that everyone can avoid these (mostly minor) problems in the future:
  • Be sure to remove all warnings before submitting your assignment.  I did not take marks off for this, but it's very good practice to fix your warnings.  Even though most may be harmless, they can make you not notice more serious warnings.  I have seen even professional developers get into trouble when they let their warnings slide in large projects.
     
  • Try to organize your code in a nice, object-oriented way.  Don't just add code to the main game class that was provided without thinking about whether that makes sense.  Instead, decide what concepts should be their own objects and how these objects should interact.  This will be especially important for your project since you'll inevitably have more code than on the shorter assignments.
     
  • A lot of you used int to define things like the colour of your block.  Though this does work, I want to encourage you all to use enumerations in cases like these.  There is some good discussion as to why to favour this approach on this Stack Overflow discussion.  Again, from my own experience, I can say that using enum has proven to be rather useful.
      
  • Avoid using magic numbers.  A fair number of you used literal numbers to both define the size of your game grid and to loop through its elements.  In one case, these numbers didn't even agree.  You can use a #DEFINE for your numbers, or even better, use const variables.  If you group all your defines together in your header file, you also have a one-stop shop for adjusting values in your game.
      
  • Be careful with your user interface.  Why leave the window the size used for the demo when you are only using a fraction of it for your game? Even worse is if you don't show the bounds of the actual playing area.  How is the player to know where their blocks can go when there's an invisible wall? In each assignment think about how to help your user better know what's going on.  This and feedback are important elements of game design.
I think that's it for now.  If there was something specific I commented about on your assignment that you'd like to know more about, just send me an email.

VS2010 Project for Assignment 2

In the announcements section of WebCT I uploaded a Visual Studio 2010 project for those who need it.  There are a couple of changes I made to the Project Properties that should be useful to you in the future (if you make these changes directly, you should be able to do the conversion yourself from now on):
  • Go to C/C++ > General and paste the following into Additional Include Directories:
    $(DXSDK_DIR)Include;%(AdditionalIncludeDirectories)
  • Go to Linker > General and paste the following into Additional Library Directories:
    $(DXSDK_DIR)Lib\x86;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)
  • Go to Linker > Input and under Additional Dependencies, remove the d3dxerr9.lib file (we don't appear to actually need it)
Before submitting your assignment, be sure to remove all warnings (I didn't do that with the sample project).

Friday, October 7, 2011

Assignment 1 Graded

You'll find a PDF attached to your assignment submission in WebCT.  I tried to put as many useful general comments as I could find time to write.  (I probably won't be able to spend as much time doing that on future assignments, unfortunately!)

Overall the assignment was well done.  I'll try to post some general comments here early next week, along with the promised relationship between my viewing lecture and relevant DirectX functions.

Have a great Thanksgiving weekend!

Wednesday, October 5, 2011

Assignment 1 and Midterm 1

I'm currently working through the first assignment submissions and hope to have it all graded on WebCT in the next couple of days.  I'm writing out a bunch of notes/suggestions that are not necessarily related to the actual marks for the assignment, so if you see a bunch of text, don't panic!

I also just found out your first midterm is coming up Tuesday next week.  I had been hoping to do an informal tutorial before the midterm to help you prepare, but the test is a little too soon.  So instead what I might do is organize one after the midterms are marked so we can at least go over the topics that caused the most trouble.  We can also do one before the second midterm.

A quick tip for the midterm: whenever you see inconsistencies in things like how transformation matrices are written (is the vector on the left hand side or the right?) or what kind of coordinate system is being used (left handed or right handed?), don't worry about which one you use on the test - just make sure it's clear to me. You can write a little note at the start of a question if it helps.

Thursday, September 29, 2011

The Missing Details of the Coordinate Transform

As promised, here is an explanation of the coordinate transform part of the lecture I gave on viewing...

As you may recall, we used the following example to visualize what we were trying to do:


Point p could be written in terms of either the xy-coordinate system or the uv-coordinate system.

Let's say we have point p in terms of uv.  We would write that as (up,vp), as in the u and v coordinates of point p.  We want a matrix that can give us that point in terms of xy: (xp,yp).  An easy way to do this is find the linear combination of the basis vectors u and v, but with those vectors written with their coordinates relative to xy.

To make life even easier, we can imagine temporarily translating u and v so that the point e lines up with the xy-coordinate system's origin o:


Then we can easily write u and v with xy coordinates: u=(xu,yu) and v=(xv,yv).  That's what gives us the first matrix we multiplied (up,vp) by in the coordinate transform:


This matrix multiplication results in the same linear combination of u and v we had before, except now we are multiplying p with the xy coordinates of these basis vectors rather than their usual uv values.

The result will almost be the point p in xy coordinates... we just have to compensate for the fact that we moved u and v to overlap with x and y.  Since we know we translated the basis vectors by the distance from o to e, we can move our resulting point to its proper home by translating it back.  That distance in xy-coordinates is xe and ye.



This will hopefully make sense to you all now (it finally makes sense to me! heh), but please feel free to ask further questions in the comments or via email if I can clarify any little bit of it.


Note: While I'm sure the slides will be posted on the course webpage/WebCT, you can download them here now if you'd like.  Remember that there are explanations in the notes section.

Tuesday, September 27, 2011

2D Transformations

Before moving on to 3D transformations, you should make sure you have a good handle on the same transformations in 2D.  Earlier this year I had made an applet that lets you play around with the basic transformation matrices - it might be useful to you when reviewing how it all works.

In this applet, an arrow is transformed according to the matrices along the bottom.  You can imagine the points in the arrow being in a matrix to the far right, as would be the case when working these things out on paper.  The right-most matrix is applied first, then the next one to its left, and so on.

You can rearrange the matrices to understand exactly how order matters.  You can also play around with the raw transformation values and see how the matrices are updated.

Press play to see the animation, and stop to reset it and allow you to make further changes.

Go to the applet now...

Sunday, September 25, 2011

Issue With gameIO::keyboardPressed Function

A student discovered that he was unable to get the arrow keys working using the skeleton io_demo code provided for Assignment 1, despite the fact that other keys seemed to work fine.

As it turns out, the main issue is with the data type chosen for the argument key: char.  This is a signed data type, but the DIK_* values used to identify the keys chosen are in the range of 0-255.  So when an arrow key value like DIK_RIGHTARROW - which is over 200 - is interpreted as a signed value, it ends up being negative (due to the most significant bit being 1).  This means that when we index mKeyboardState we are actually referencing memory that is before the start of the array.  If that memory happens to contain just the right thing (which is easy to do - all it needs is to have its most significant bit being 1), our function will return true even if the right arrow is not being pressed.

The solution is simple: just change the argument type to be an unsigned char or cast the argument to be unsigned before using it to index the array.

Toymaker: Computer Games Programming

I found the Toymaker site when researching how the DirectInput interface worked.  It looks like there is a lot of useful stuff not only for DirectX game programming, but also XNA.  Should be worth bookmarking for learning more about various topics as we go through the course and possibly for some of your future courses / projects.

Purpose of this blog

Hello everyone! I decided to start this blog so that we would have a one-stop place for addressing common issues that come up in assignments and course material.  I will try to share useful resources that I've found and write out solutions to issues I think many students may face.  I will also likely post a list of common issues with completed assignments and refer to that list when I return your work.

Please feel free to comment here or email me directly with questions.