sunnuntai 31. maaliskuuta 2013

Back To The Drawing Desk

It has been a little quiet time in the project. I had to go back to the drawing desk to research more about game programming. I found out, that my method to build game engine piece by piece was a sligthly poor approach.

I had to get more knowledge about the game engine programming, so I went and bought a book called "Game Engine Architectures" 1st edition by Jason Gregory. It took few weeks to read the book, hence it has about 800 pages, but I think it was totally worth of. I found about, that modern game engine is veerryyyy complex piece of engineering work. Especially if you really want to take care of protability, performance and scalability issues.

It is not just one executable which runs game content, but the game engine consists many support applications, what you need to do in order to create a good game engine system. Game engine has to have game content creation applications, game content database and the engine which drives built game content. The complexity is so vast, that it is really hard to explain in just one blog page. I can only suggest, to everyone interested in the industry, to get one good book about game engine architectures to get an idea about the topic.

I also took a level of abstraction and started to design the engine architecture by UML modeling. I think it really helps to clarify the idea about document flow in the system and what kind of components you need for your system.

Speaking of game content creation


I also started practicing 3d modeling with 3ds max by doing tutorial in the book "Game Character Modeling and Animation with 3ds Max" by Yancey Clinton. At some point I have to create content for my game, so it is better to learn necessary skills at the beginning.

Here are some pictures about the progress:

1. Half of the model body

2. Same with surface added and shading on. Background planes are also
visible in this picture.
 
3. Whole body. Same than previous, but
mirror attribute added.
 


4. Creating the face.
 
4. More accurate face.
 
5. Face with surface modifier added.


So I think I don't continue development at code level for awhile. Not until I get the tutorial at least done. When I have completed the model and made some animations to it, I think I try to run model and animations with DirectX. But progress to that point should take about one month or so.

perjantai 8. helmikuuta 2013

Controlling Meshes with UI

One object done. Now I can control my meshes via UI. I made an indicator, which consists of "hard coded" primitive geometric types. I build for each mesh it's own unique indicator, whenever a mesh is created. When the mesh is selected I can control it's position and orientation.


Here I have three meshes which I have transformed to some nice position and orientation. One chair is selected, which transformation I can control with UI. Nice!

I also improved quite a lot of my camera movement in the world. Now I have implemented regular WASD controls, what every first person shooter has. I also learned quite a lot of linear algebra during this feature.

I really recommend good mathematics book if you're into the industry. I use finnish 3D-graphics book by Antti Puhakka, which is really good. It covers most of must know topics about linear algebra if you're new to 3D calculation. It has also nice solutions for most general 2D and 3D geometric problems. I.e. line/plane intersection. It also introduces to spatial data structures.

I am waiting to get Game Engine Architectures book. I've heard that it has got some good reviews, so I decided to get one. I really need some information about game engine architectures, because if I just create "some" engine by implementing feature by feature, I might get some really awful engine which is slow as hell and hard to maintain or manage.

sunnuntai 3. helmikuuta 2013

For DirectX beginners - Accessing The Vertex Buffer in DirectX 9

Okay, I thought to write post how to access to contents of vertex buffer in Directx 9. This is for DX 9 beginners who doesn't know how to manage and acces the content of vertex buffer. I don't go any vertex buffer details here, because you can find them from quite many other blogs and sites in the internet. In quite many tutorials and samples, they are represting only how to create the content of the vertex buffer. In this example, I show that you can also use the contents of vertex buffer for your own purposes.

Vertex buffer

So what is vertex buffer? In short, vertex buffer holds the data, what you use when you're rendering any kind of 3d object with direct x. You can find more deeply information from Microsoft's library: MSDN - Vertex Buffer

How to access it's content


The way to acces created vertex buffer contents is done same way as you insert the content to the vertex buffer.

This is quite common way to insert the data to the vertex buffer. Seen in most tutorials and directx books:

vertexBuffer->Lock( 0, 0,(void**)&pData, 0);
//Copy vertex data to Vertex Buffer
memcpy(pData, &vertices, bytes );
vertexBuffer->Unlock();

Where "vertexBuffer" is IDirect3DVertexBuffer9 variable, "pData" is void pointer and "vertices" is array of structs. Let's say that the struct holds float x,y,z variable and dword color data. Name of the struct is "CUSTOM_VERTEX". With this way memcpy funtion insertes the data to the vertex buffer.

With quite same mannor you can access to the data of allready intialized vertex buffer.

CUSTOM_VERTEX* p;
vertexBuffer->Lock( 0, 0, (void**)&pData, D3DLOCK_READONLY );
p = static_cast< CUSTOM_VERTEX* >(pData);

Here we again take the address of memory buffer (vertex buffer data) to pData void pointer. Because void pointer can point to any kind of data type, we can cast it to the data type what refers to the same data type we used when we created the contents of vertex buffer. Now you can use "p" variable as an ordinary array of elements.

Two zeros in the beginning of "Lock" function tells that we are using whole buffer. You can also use only part of the buffer by setting the offset and size of the vertex data. Those integer values represents the size in bytes.

In example:

vertexBuffer->Lock( sizeof( CUSTOM_VERTEX, sizeof( CUSTOM_VERTEX), (void**)&pData, D3DLOCK_READONLY );

This would lock the second vertice in the vertex buffer. Remember that "sizeof" returns amount of bytes in integer.

Remember to ensure, that when iterating over the pointer, you don't go over the reserved memory area. You can easily determine amount of the data types in the vertex buffer by using Directx 9 D3DVERTEXBUFFER_DESC stuct. Vertex buffer has function "GetDesc" which takes the struct address as  parameter. From the struct you can get size of the vertex buffer in bytes. When you know size, you can calculate amount of data types in the buffer.

In example:

D3DVERTEXBUFFER_DESC desc;
vertexBuffer->GetDesc( &desc );
int vertices = desc.Size / sizeof( CUSTOM_VERTEX );

And to iterate over elements:

float x;
float y;
float z;

for (int i = 0; i < vertices; i++ )
{
   //Do something with variables
   x = p[i].x;
   y = p[i].y;
   z = p[i].z;
}

Hope this helps somebody who is wondering how to use contents of the vertex buffer for your own purposes.

keskiviikko 16. tammikuuta 2013

Loading multiple OBJs completed!

Again I have made some nice progress.

I have managed to:

  • load multiple meshes and material data for the mesh
  • OBJ loader loads also multiple material data and application tracks correct texture the mesh
  • I can insert dynamically * amount of meshes to the world
  • I can test if ray (user mouse click on the screen) has intersected a mesh
Currently I'm doing:

  • Lines which indicates that a mesh has been selected

Next I'm going to do:

  • When a mesh is selected, user can alter transformation of the mesh




























Here I have a picture where I have inserted two own meshes to the world. This starts to look quite cool. It is not so far away that I can start to create some content to the game.

It was a bit of pain to manage resource de-allocation. I constantly got invalid pointer, when I tried to release DX data. Altough I have now managed to get rid of those errors. It was funny to notice, that when I used memcpy to copy meshes, I also copied it's destructor address and that way de-allocation was total failure at every time.

torstai 27. joulukuuta 2012

Nice progress

I have done so much work for my game in the past three weeks and now I can really see it! I have learned so much about DirectX 9 API and I start to feel quite comfortable with it. I have also learned nice bunch of linear algebra, which I can see now why it's so important part of game programming,

My accomplishes at December:

  • OBJ-loader. Done! (Thanks to GameDev.net forum for a bug fix!)
  • Dynamic Mesh creation. Done!
  • Controlling meshes so that user can change position and rotation of the mesh. Done!
  • Better camera controlling, than in previous post. Done!
  • I have a plane where I can insert a line dynamically with cursor -> Casting a ray and checking collision with ray and plane. Done and done!


Here I have a picture where I have inserted lines dynamically by clicking the plane with cursor. Green lines are single line primitives and red,green,blue cross is origin of the world.

I have now line-plane intersection test and now I have to change it so that I can check collision with ray and a mesh.

keskiviikko 24. lokakuuta 2012

So far so good...

Time for my second post and give you some info what I allready has made. It's been awhile since last post but be patient, I will update this blog from time to time.

Ok, so in this post I'll give heads up what I have allready done and what is my next step.

Done


I have set up basic environment where I can render a 3d object, get user input and with user input to move and rotate camera in the 3d world. So far I have a static single 3d object in the world what I can view as I please. The 3d object is a cat from the DirectX Mesh sample. Also my algorithm to load a 3d model from a file is copied from that source. You can find the sample from DirectX SDK kit.

I think what I really should do, is to keep track of hours what I have spent for my project. Currently I have no idea how much of time I have used so far.

Here is the picture of my application. As you can see I have named this application as "Level Editor" which I will explain in the next post. The post includes also what "administrative" tools I will create for my game and also a little bit of overall view of the project. I also try to get a picture of my KanBan board to the post, so stay tuned!


I will name this picture as "Hello Kitty" picture, like the famous "Hello world!" application, which we all have done in some stage of our life.

To do

So the next task is to create more dynamical way to load 3d models to the Level editor tool. I think the algorithm should load the models from some source and user then could choose in the application what model the user wants to use. I think it will demand more coding than so far and I also have to think a little bit future as well, that I am not doing something stupid which I will most certainly rewrite.

It will be another task, that user can place the model in the world.

tiistai 9. lokakuuta 2012

The Start

I have studied programming in university of applied sciences for three years and I'm really into for the industry. For this project I have reserved good amount of time. Something about three or four years would be sufficient to actually accomplish something. I am seeking for doing master on software development, so I have plenty of time to work on this project.

I hope that if some other software engineering students tend to find themselves from my blog, we could perhaps create a team. But that's another story and another cup of coffee.

The Project:

I try to keep my posts short and simple and to inform you as much as I can about my project and how it developes. If somebody have questions about programming or anything related to my projects, please post and share your thoughts.

First I think I should present my technical aspects on this project:

  • language is C++
  • IDE at the moment is VS 2010
  • I use KanBan board (ToDo, InProcess, Done) to visualize my current project features
  • Autodesk 3dsMax for 3D models

APIs and other properties:
  • DirectX 9 for graphics API
  • Win32 App for platform where I run my game
  • 3D graphics
  • No networking at the beginning
In next post I will tell you what I have allready done. I have developed my project about three weeks and I have accomplished a bit. But that's another post.