back one level

DirectX projects





Hi there!

These are my d3d projects coded in asm using masm32. All sources are written by myself. The knowledge used here was collected from MSDN, Gamedev.net and from helpfull fellow-coders.

I created these projects just for fun, they are totally FREE. Please have a look on them, use them as you like!
Sources for MASM32

Last version:d3d080911.zip
Earlier version:d3d071012.zip
Contents

  1. Empty project
  2. Simple rectangle
  3. Textured rectangle
  4. Rotation
  5. Lights
  6. Sprites
  7. Camera and sprites
Future improvements

In 3D area:
In 2D area:
1. Empty project
back to contents
Example1 In this project the d3d initialization is done. It has all the basic functions that are extended and improved in the next projects. Initialization is done in the initAll proc, rendering in the RenderScene updating the frames in the UpdateScene procedures.
 
2. Simple rectangle
back to contents
Example2 The second project draws a rectangle by creating 2 connected triangles. The vertices of the triangles are transformed (they have a rhw property) and have a diffuse color.
 
3. Textured rectangle
back to contents
Example3 This demo creates a texture and fills it by copying an image onto it. The texture is applied to the rectangle from the previous project.
 
4. Rotation
back to contents
Example4 Here I made a few more steps. First I create a cube in the initGeometry proc. Every side of the cube has its own diffuse color and the same texture mapped onto it. For the rotation transformation the vertices hsa to be untransformed and 3 transformation matrices have to de defined and calculated. The wordMatrix places an object into the world by specifying rotation, scale and positon (translation). The viewMatrix tells the system which point we are looking at (lookAt vector) from which point (cameraPosition vector). Finally, the projectionMatrix adjusts the perspective and the clipping distances on the Z axis. Rotation is done by using triangular calculations that can lead the anomaly known as the gimbal lock. I've created a library to hold structures, functions and macros used for 3D maths and transformations. My intension is to create the functions in 2 version: one for FPU and one for SSE. I also want to create a timing procedure that measures every function to decide which version is faster.
 
5. Lights
back to contents
Example5 In this project 3 different lights are added: ambient, directional and point light. Ambient lighting is just a value that is added to every face lighting level. Directional light is like sunlight, it has a direction. This light has a middle gray color in the demo. Point lights have a range and attenuation. There are 3 such lights in the demo each light has a base color: red, green and blue. The lights are indicated by lines between the light position and the center of the cube.
 
6. Sprites
back to contents
Example6 D3D can be used for 2D graphics as well. All we hav eto do is to create a quad (a rectangle like in example 2) and map a texture on it. We can draw on that texture or simply swap several textures to change the drawn images. I created a small lib for my sprite implementation. This demo creates a hand shaped sprite to substitute the windows mouse cursor. It also creates 2.000 small sprites that rotating and moving within the window bouncing on all 4 sides of the window.
 
7. Camera and sprites
back to contents
Example7 This project has 2 major features. The first is the more important one, the usage of quaternions are introduced in the rotation transformation. Quaternion based rotation eliminates the gimbal lock. This method is used when the camera is moved in the 3D world by rotating it around the cube's center. This is done by moving the mouse whily by holding the left mouse button pressed. The transformation is done in the SetCamera procedure. The second feature is combining a 3D object and a 2D sprite. The vertices that construct the 3D cube are untransformed, have normals to allow proper lighting calculations. The 2D triangles are transformed, have no normals thus they need the d3d lighting to be turned off. There are some other rendering options that have to be switched when rendering 3D or 2D faces. This can be followed in the RenderScene procedure.