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.