Using the DirectX SDK in Windows 8 with Visual C++ 2010

This post is a result of some insight and necessary steps to get the June 2010 DirectX SDK working on a Windows 8 system, with Visual C++ 2010 express. Given the fact that DirectX 11 comes bundled in with the Windows 8 SDK, my stubbornness to change the configuration is due to the fact that I wanted to follow Frank D. Luna’s latest book, mirroring the same development environment (Visual Studio 2010 and the DirectX SDK) in my Windows 8 machine. Without further ado, lets dive in to the details…

  • Windows 8 comes with DirectX bundled in – The Windows 8 SDK comes with the DirectX SDK bundled in, and in turn, Visual Studio 2012 comes with the Windows 8 SDK. This means, you can download VS 2012, and start writing DirectX code without any further configuration. Microsoft recommends (Specifically in this blog), that developers transition to coding DirectX application using the new Windows 8 SDK and VS2012. If you are planning to go down this route, just install VS 2012 Express for Desktop on your Window 8 machine, and try out these great tutorials.
  • Windows 8 Contains DirectX 11.1 – What you will not be able to get from the DirectX SDK are the new features available in DirectX 11.1. This does not pose much of a problem, as much of the DirectX code out there is based on the DirectX SDK, and DirectX 11.1 features have not been widely adopted yet. If you are interested in the new DirectX 11.1 features, head over to this page and check them out. But bear in mind that you need to develop using the Windows 8 SDK if you are planning to use it (The windows 8 SDK is available as a separate download if you want to develop in Windows 7 for example).

If you are like me and want to use Visual C++ 2010 and the June 2010 DirectX SDK in Windows 8, then the below steps outline what needs to be done (I am assuming you are using a Windows 8 machine):

  • Install Visual C++ 2010 Express Edition - Navigate to the download page for VC++ 2010 express and install the product on your Windows 8 machine. (On Windows 8, after installation, there were some problems where the product did not fire up, stating that I needed to install the service pack for all VS2010 products in my system. When downloading and installing the service pack, some errors were thrown as well. But after restarting the machine and firing up VC++ 2010 Express, it worked properly… am still investigating why all this fuss. This seems to happen if you have other VS2010 express edition products installed already).
  • Install the DirectX SDK on your machineGo to the DirectX SDK download page, download the SDK and install in your system. One thing to note when installing in Windows 8, you will get installation errors if there are existing 32-bit and 64-bit VC++ 2010 redistributables installed in your system (This is because the DirectX SDK uses an older version of them). Follow the steps outlined in this page, in order to get the DirectX SDK installed properly on your Windows 8 system.

If everything went well, you should be up and running in coding and building DirectX applications using VC++ 2010 (provided that you link the appropriate libraries and set the folder paths in the project settings) on your Windows 8 system.

Infragistics UltraWebGrid column format not being applied

Just a short post today, recalling an incident I came across recently, which I thought I should jot down here, and hopefully It’ll save someone else a headache.

If you have been working with the 3rd party UltraWebGrid control for asp.net offered by Infragistics, you would have worked with columns where you might have wanted to display numerical values formatted in a certain way (for example, you may want to show 12, 300, 450.0 instead of 12300450.0000). This is done by setting the format expression in the column.Format property inside the ‘InitializeLayout()’ UltraWebGrid method. This is exactly what I was doing but was puzzled to have rows of integers merged from two DataTable sources showing different formats, even though each Integer in the rows were applied the same column.Format expression in code. The first few integers would display in the correct format I apply, but sometimes the last few integers don’t have the formatting applied.

This was getting way too frustrating till I (out of curiosity, and nothing else to try) wrote the following line of code before the ‘column.Format’ expression:

string dType = column.DataType;

When I debugged the code, one set of integers from the original DataTable was of type ‘System.Decimal’, and displayed correctly, but the second set of merged integers from the second DataTable was of type ‘System.String’. When I set the following line of code inside the loop applying the formatting to the column.Format property, all the integers displayed in the correct format:

column.DataType = “System.Decimal”;

So bottom line? The UltraWebGrid control cannot format columns with decimal format expressions if even one value in the column is going to be of a type other than ‘System.Decimal’. If there are several columns which will display numerical data in a certain format that you need, it would be defensive coding to write the logic in UltraWebGrid_InitializeLayout() as follows:

foreach (<column in UltraWebGrid that is going to display numeric values>) {

column.DataType = “System.Decimal”;

column.Format = <your numeric format expression here>;

}

3D GAME MATH PRIMER 4: OPERATIONS ON VECTORS

In a 3D game environment, vectors are used to hold the values of points or vertices. Thus a vector would contain a coordinate [x, y, z] which represents the specific vertex in 3D space. Points are defined such by vectors because the start position of the vector is usually taken as [0, 0, 0] which is the origin of the coordinate space. Thus all the vertices in 3D models and game elements are represented by vectors, but it is important to remember that vectors are not 3D vertices. (There is another type of vector that is represented by 4 coordinates [x, y, z, w], which are homogenous coordinates. We will talk about this in a later post dedicated solely to this very important and interesting topic).

Another place where vectors are used are  surface normals. Every 3D surface has a surface normal, which is nothing but a vector pointing away from the surface and perpendicular to that surface. This vector (surface normal) determines how light sources in the environment light up the specific surface. This is just one aspect of the surface normal, as it is used in many other places in the game. Vectors are also used in shading (which we will talk about later), and dynamically processing visual elements in the game.

Simply put, vectors are one of the most used constructs in 3D games. This is why learning and understanding about vectors and their operations is very important. Without further ado, lets dive in to learn about vector operations and some basic linear algebra.

THE ZERO VECTOR

The zero vector is the additive identity in the set of vectors. The 3D zero vector would be denoted by [0, 0, 0]. This vector is a special vector because it is the only vector with no magnitude or direction. It would be easy to assume the zero vector as a point, but the reader should remember that a point represents a location. It is better to remember the zero vector as a vector with zero displacement.

VECTOR NEGATION

Vectors negation can be related to multiplication of scalar numbers by -1. The negated vector is known as the additive inverse of the original vector. A vector of any dimension is negated by all its individual components as shown below:

- [x, y] = [-x, -y]

-[x, y, z] = [-x, -y, -z]

Geometrically speaking, vector negation produces a vector same as the original, but with opposite direction.

MAGNITUDE OF A VECTOR

Vectors have a magnitude (length) which can be calculated simply by taking the root of the sum of squares of the individual dimensions. This is very simple if you remember the very basic skill of calculating the length of the hypotenuse in a right angled triangle using the Pythagorean theorem (for 2 dimensions).

For a 2D and 3D vector, the magnitudes are defined as below, respectively:

2D3D

VECTOR MULTIPLICATION AND DIVISION BY A SCALAR

Vectors can be multiplied by scalars, and this happens by multiplying the individual components of the vector by the scalar value. What we geometrically obtain by scalar multiplication is another vector that is parallel to the original vector, but which could differ by magnitude or direction, depending on the scalar value. Some examples are given below:

k[x, y, z] = [kx, ky, kz], -2[4, 0, 1] = [-8, 0, -2]

Vectors can be divided by scalars as well, and this would be equivalent to multiplying the vector with the reciprocal of the scalar value, which is shown as follows:

1/k[x, y, z] = [x/k, y/k, z/k]

Some important aspects to note:

  • We do not use the multiplication sign in scalar-vector multiplication, nor the division sign.
  • Multiplication and division take precedence over addition and subtraction.
  • Vector negation is a special case of scalar multiplication, where the scalar value is always -1.
  • The geometric interpretation of scalar – vector multiplication is the scaling of the vector by a magnitude of |k|, the scalar value.

VECTOR NORMALIZATION

In many situations, it is not the magnitude of the vector that is important, but the direction. In these cases it is convenient to work with unit vectors, which have the same direction of the original vectors, but their magnitude is 1. The process of taking a vector, and converting it into a vector of magnitude 1 while maintaining the direction, is known as vector normalization. The unit vector is known as the normal.

A vector is normalized by dividing the vector by its magnitude (scalar division, as the magnitude value is a scalar). The result is a vector which is the normal to the given original vector:

Vnorm = V/||V||, Where V is not zero.

The below image (courtesy of the book 3D math primer for graphics and games development, by F.Dunn and I.Parberry) show unit vectors in 2D space, which touch the surface of a circle of unit radius. In 3D space, unit vectors would touch the surface of a sphere of unit radius:

unitVectors

VECTOR ADDITION AND SUBTRACTION

Vectors can be added or subtracted only when their dimensions are equal. The individual components of the vectors are added or subtracted to obtain the resultant vector. Though vector addition is commutative, vector subtraction is not. Examples of vector addition and subtraction is given below:

[2, 5, -1] + [3, 1, 0] = [5, 6, -1]

[3, 0, -3] – [5, -2, 0] = [-2, 2, -3]

The geometrical concept of vector addition and subtraction is the basic triangle rule. Given the vector addition of two vectors A and B as A+B, we need to find the resultant vector which has the starting position of A, but the ending position of B. This can be applied to many vectors. Vector addition may seem a simple enough concept, but we will later see a similar mechanism to transform vectors from one coordinate space to another.

In the next post, we will continue the rest of the vector operations, and look at two very important operations: Vector dot product and the vector cross product.

3D GAME MATH PRIMER 3: WHAT ARE VECTORS ANYWAY?

Well what are vectors anyway? The topic of vectors crop up in geometry, physics, engineering disciplines, mechanics, etc. How they are used, as well as their definitions at times, vary from context to context. Below I have listed how vectors are defined in some contexts:

1. In geometry, Euclidian (or spatial) vectors are line segments that represent length and direction.
2. In physics, vectors are used to show magnitude (usually in some unit) and direction, representing aspects such as velocity, force etc.
3. In linear algebra, vectors are elements of vector spaces, but unlike the above attributes of vectors, may not always be made up of real numbers.

I liken vectors to cross-cutting concerns in regular software applications. One example of a cross cutting concern in software applications is logging. In any one of the layers in a layered software architecture, logging is an important function that is applied across the layers (or used as an aspect, in Aspect Oriented Programming lingo).

Vectors are a cross-cutting concern across geometry, linear algebra, mechanics, engineering, fluid dynamics, etc. Vectors are a necessary and critical element in each of these areas, but is pretty much the same thing when taken by itself, and can be treated as an aspect, if I may use the term again from AOP.

Lets backtrack for a moment: A geometrical point is something and nothing at the same time. It is purely a location in space, but has no width, height, length, or any type of dimensional size. Next, a line can be defined as the straight path between two points. But can this straight path have any thickness or size? Points and lines are abstract idealizations in geometry, we cannot create or draw them, but we can visualize them by giving them size, thickness etc, that will make sense to our eyes as points and lines. A vector is yet another abstraction, which represents the magnitude of something (denoted by the length of  a directional line segment), and the direction of the acting element to which the magnitude is applicable. A vector starts from a initial point, and ends at a terminal point, with the directed line segment connecting the two points representing the magnitude and direction.

What game programmers need to know is that vectors can be represented as lists of numbers (or arrays, to be more accurate). If the initial point of each vector is taken as the origin of a coordinate system, every vector can be represented by a list of numbers. In two dimension, vectors can exist only on a plane, and thus need a minimum of two numbers (or values) to be defined in a list. In 3D, vectors can exist in 3D space, and need a minimum of three numbers to be defined. But it can be more than three dimensions, and we will see about higher dimension vectors in a future post, which has further implications in 3D game programming.

One important consideration when talking about vectors, is the relationship they have to points. Points were explained to represent only position. Vectors do not have position, but have magnitude and directions (displacement). But points do not have precise or absolute locations, their locations are defined relative to some coordinate space. Now, what happens when you draw a line segment from the origin of this coordinate space to the point in question? What we get is the displacement of that point, from the origin. Thus, in a given coordinate system, if we have a vector starting from the origin and describing a displacement of [x, y], we end up in the location of the point represented by [x, y]. What we need to remember is that points and vectors are conceptually (think physics) different but mathematically (think geometry) equivalent.

To sum up, vectors are simply directional line segments that represent a certain direction, and a magnitude which is denoted by the length of the line. If the vector is initiated from the origin of a coordinate system, the vector is equivalent to a point in the coordinate space whose coordinates are the same as for the vectors terminal point (And vice-versa: The displacement of a point in a coordinate space from the origin, is given by the vector that begins from the origin and ends at the point).

In the next post, we will look at where vectors are used in 3D games development, and some of the basic vector operations that we need to know about.

PERIOD OF INACTIVITY IN PUBLISHING POSTS…

My sincere apologies to the readers and followers of GameCoderLogic, for the long period of inactivity in publishing posts. I have just recently moved to Singapore from Sri Lanka due to my change of workplace and job, and had to put blogging (and many other things) on hold till I transitioned from my previous job to the current one.

Now that I have had time to settle down (the writing of this post being proof of this fact, somewhat…), regular 3D Game Math primer posts will continue, starting from the upcoming weekend.