August 13, 2009

The new face of a conspiracy

Posted in Computer Graphics tagged , , , , , , , , , , , , , , , , , , at 6:48 pm by sagito

Hi everyone! It was a long time since I posted something new here, because my network keeps going down… But this time, I’m bringing you news about the Conspiracy engine. Missed him? Me too… πŸ˜› Well, it has a brand new face since many new features have been added that make him stand much higher then before.

To start, a small problem with the vertices was corrected. Somehow the vertex data was getting scrambled all the way through the CMOL (Conspiracy Mesh Optimization Pipeline), and I ended up removing some of the optimization routines that could be handled in another way by DirectX himself. And by doing so, the GenerateAdjacency problem was also solved! This way, the meshes are more perfect and faster than ever! πŸ˜€

Also, I’ve implemented a XML parser system from scratch. With that, I created implicit support for something else: Scene graphs! And this is a very important part of the engine, as some objects might now be loaded directly through a simple configuration file. This is great for scenarios, lights, etc., but also for the future creation of a visual editor for the engine!

With so many new features, something logical occurred! A game is being developed on top of it and I can guarantee that it is already in a very advanced state! Stand by for more news! πŸ˜‰

July 31, 2009

Constraints

Posted in Computer Graphics tagged , , , , , , , , , , , at 11:11 pm by sagito

Hi everyone! After some absence due to the lost of someone who was very close to me, I’m back to posting… This time to talk about a constraining system that I will attempt to implement within the Conspiracy Engine.

I have been having some problems with some DirectX functions, namely GenerateAdjacency and OptimizeInplace. These functions just crash unexplainably in some memory address that is not in my addressing space. Also, neither the DirectX debugger nor the PIX (tried it in despair), not even the Visual Studio 2008 debugger could do anything to show me the problem… So, I analyzed the assembly code, to find out that something inside the mesh is not properly set. However, I don’t have the means to find out what, so I just commented out the functions and moved on until I have the patience to deal with Microsoft’s brilliant lack of information.

So, I decided to implement a constraining system. Now, what the hell is that? Basically a system of something that constraints something to some other something. πŸ˜› Ideally, this will, for example, stick a camera to a travelling object! Imagine a car in a racing game. We want the camera to be able to follow the car along the track as it moves, otherwise the camera would just be left in the beginning of the track.

It is important to say that… I never, ever, whatsoever, tried anything even near such a thing… My basic idea so far is really making an object stick with other… You could say that this can be achieved using hierarchy. Yes it could! However, I think some more flexibility is desirable… For example, if I want to attach a gun to my vehicle, I would probably like to place it in the door or in the roof… I need something that allows me to control its position and the constraining system will hopefully give me that kind of offset.

I know that there is a huge number of possible constraints to be implemented. However, I will stick to this one at the moment, but I will create a solid enough structure that can be expanded to some other constraint types further on… For now on, I will be keeping you posted! πŸ˜‰

July 26, 2009

Octree in DirectX

Posted in Computer Graphics tagged , , , , , , , , , , , , , at 11:27 am by sagito

Hello everyone! Back to some news from the Conspiracy… πŸ˜‰ This time I’m implementing a feature that is quite new for me. An octree! Ok… Wait… What’s an octree? Well, an octree is basically a technique for dividing the drawing space. You start with a huge cube which surrounds the entire scene. If there is something inside it, then you subdivide that cube in eight smaller and identical cubes. Then, for each of these cubes, we must check if there is something inside them, if there is we subdivide them again, and so on…

Ok, now… Why is this so useful? Lets consider rendering… It is not necessary to render everything that we don’t see (because its behind us for example). This seems quite logic to me. But, the DirectX backface culling and occlusion system should be capable of doing this, right? Yes and no! In a matter of fact it really does not render the objects that we can’t see… However, it sends them to the graphics pipeline, executes a draw and only checks if they are visible afterwards. Only at this moment it decides if it really sent to the screen or not. With an octree, we are actually able to avoid such a thing, because we just don’t sent the objects which belong to an octant that we cannot see to the pipeline, avoiding some unwanted overhead.

Another example is the picking! Why try to perform picking on something that we cannot select? It is a heavy operation and we want to be able to ignore such operations if they are unnecessary!

However, there is a small problem, at least, with my implementation. I can reach 6 iterations of depth in an admissible time… Seems that these are few iterations, and maybe they really are… But if we think it through, each subdivision creates 8 space divisions. So, for 6 iterations, that stands for 8^6 = 262144 divisions (maximum). After doing the maths, this seems quite acceptable now… πŸ˜›

So, standby for new updates, as they are coming fast! πŸ˜€

July 23, 2009

Physics of Conspiracy

Posted in Computer Graphics tagged , , , , , , , at 10:58 pm by sagito

Hi again! This time I dwelling through some unknown ground and finding some real big monster-problems as I go. I’m trying to create a physics engine for the Conspiracy Engine! Well, as some of you might now, the ideia behind a physics engine is to predict where will something be in a future moment! (Yes, we, the computer people can predict the future!).

For example, if I have a ball and I drop it from a tall building, I want to be able to predict where will the ball be after 1 second, after 2 seconds, 3 seconds and so on, so I can be able to draw it on the screen. And I also want to do this in a minimally realistic way, so that the ball doesn’t start to fall and comes back up or something. So, many laws must be considered here and all of those come from general physics. These are not my big problems, because fortunately, many scientists around the world have already documented those.

The biggest problems are integration and programming. The first one can be solved in three possible ways. Give up, which is never considered in my life; using the Euler method; using the Runge-Kutta 4 Solver. As I have read through some documentation, Euler has some huge mistakes and can easily lead to big problems in a short interval of time. Runge-Kutta needs some more calculations, but guarantees pleasant results! As Gaffer On Games says: “If you use Euler, then you are a bloody idiot!” πŸ˜€

The second problem is how to integrate this in an existing engine. This can be done either as a separate DLL (which I think its best) or within the engine itself. The last approach is probably the reason for many suicidal or depressive mental states. So, I’m thinking about creating a separate engine that is able to represent the physics laws and somehow connect both in order to create a nice realistic environment.

And meanwhile, I will keep you posted… πŸ˜‰

July 12, 2009

C++ Reflection

Posted in Computer Graphics tagged , , , , , , , , , , , at 10:48 pm by sagito

Today I faced a different problem while trying to build an external interface for the Conspiracy Engine… As it was built on C++, which is a compiled (not interpreted) language, the compiler does not have the concept of reflection. In the first place, what is reflection? Reflection is a technique that makes a language able to know, observe and modify its own structure and behaviour. For example, if I have a class A that wants to know which methods and variables are in class B, I just ask the compiler to tell me. This happens, for example in C#, where we can ask the compiler for class methods, variables, and even execute the methods if we want.

Problem is: There is no direct support for this in C++… However, I need that, because my intention is to build an external editor that can interact directly with the engine like the CryEditor, for example. So, I’m trying to find a solution! There are several ways of attempting such a thing. The first one is to read through the debug information… This is not viable because different compilers use different approaches for debug and the program would have to be always built with debug information (which is huge).

Second solution would be to create a compiler that supported reflection for C++… I have already create one (not for the C++ language!) and I guarantee that it is not something neither pretty to see nor easy to implement. Third solution: Create a specialized pre-processor that could build over the class descriptions… This solution could be viable… However, parsing the C++ language is not trivial and would require a two-pass-process which would introduce a huge overhead.

So, there is no solution for this problem? What if the engine had a specialized class that would store the data for reflection? Every class that derived from this base would register their variables and methods in a global storage that could be accessed from any other class. This is not the real reflection that we are to, but it seems like a nice approach. And it contemplates the cases in which a variable (or class) is sealed, i.e., not accessible through reflection. In that case, the class simply does not register its variables or methods! This approach seems to be the best one so far and I have already implemented it on Conspiracy.

So far it is working fine! πŸ˜€ I should give you some news very soon about the new editor for Conspiracy! πŸ˜‰

July 8, 2009

Sky is not the limit!

Posted in Computer Graphics tagged , , , , , , , , , , , at 9:40 pm by sagito

After a short break due to WordPress maintenaince, I’m back to post about the new stuff that I implemented in the Conspiracy Engine! It now features skybox support, collision detection and a very complete particle engine!

Implementing a skybox was pretty easy. For those of you that do not know what a skybox is… Well, it is pretty much that, a box that represents the sky. So, what about that, why can’t it be just a cube with some texture mapped like every other object? Because unlike other objects, the skybox must move with the viewer… I.e., the user cannot get out of the box as the skybox itself must move with the camera. Just like a person can’t reach the horizon! So, how can one implement a skybox? Pretty easy, you get the view matrix (through IDirect3DDevice9::GetTransform(D3DTS_VIEW, &view);), reset the last row to 0.0 except for the last value and set the new view matrix. After that, the world matrix must be set as an identity too in order to remove any unwanted transformation. Then we can render the skybox! After rendering, we put back the old view and world matrix.

For collision detection, DirectX already provides some very useful functions that automatically calculate the bounding box and sphere for a given object! After that, I just took some optimization measures and converted the bounding box to an axis-aligned oriented bounding box (see http://www.toymaker.info/Games/html/collisions.html for more info). Then, the objects are tested for collision… If a collision happened, it is propagated through a chain of responsability to some entity that handles the event or discard if no one does…

Finally, the particle system was based on a tutorial from CodeSampler (http://www.codesampler.com/dx9src/dx9src_7.htm). The system described in this tutorial is awsome and very complete! Also, the code is very well structured and commented, so it was pretty easy to implement this too.

To end this (already long) post, here is an image of the engine with the skybox and the textured cube:

skybox

July 7, 2009

Textures!

Posted in Uncategorized tagged , , , , , , , , , , , , at 12:06 am by sagito

After a long, long day of work, I’m proud to announce that the Conspiracy Engine now feature textures (finally)! Well, textures do not use to be such a pain, why did it took so long this time? The answer is quite simple… When exporting the object data, 3D Studio Max exports the (X,Y,Z) vertex data and the (U, V, W) texture coordinate data. However, I was surprised to see that I had 8 vertices in my object and 12 sets of texture coordinates… Well, this made sense, because a vertex shared between edges may hava different texture coordinates along each face!

The problem is that 3DS does not keep any kind of relation between one vertex and its texture coordinates. So, we must first ask the face which vertices and which texture coordinates it uses and only then attempt to relate both these kinds of vertices. I could have done this the easy way by just ignoring repetitions of vertices and letting DirectX handle the optimizations. Of course that I chose not to…

So, I had to create two auxiliar data structures to aid me: An Hash Table (with customizable rehashing) and a Pair. With the Hash Table I was now able to set keys for each vertex individually, thereby removing repeated indices and vertices with ease! The Pair was just a helper utility that I used to handle some data more easily. However, I think that these structures will prove worthy in the future, as they did now! πŸ˜€

Well, here is the actual result from all this work:

textured

Tomorrow I will be working with collisions, although that should be a pretty simple matter to handle… πŸ˜‰ As promised, I will be keeping you posted!

July 5, 2009

New Stuff!

Posted in Computer Graphics tagged , , , , , , , , , , , , , , , , , at 10:58 pm by sagito

I’m bringing you some news from the Conspiracy Engine! Since yesterday, I have been able to implement three new important things in the engine. The first is a TAL (Top Abstraction Layer) that manages the engine almost totally. This was implemented through several Adapters and a Facade pattern. It is working nicely now, and most of the code that was in the main.cpp could be hidden under this layer now, simplifying the whole thing. I will try to create a configuration (scene-graph like) file that will be loaded by this class and automagically presented. The whole engine is already prepared for that, it is just a matter of putting things together.

I have also implemented geometrical transformations. Due to the overall organization and architecture of the engine, this was much quicker than I expected and took only about fifteen minutes to complete.

Finally, I have managed to get the Picking-related stuff working. Picking is always a big headache because it envolves a lot of maths (matrix inversion between three vectorial spaces, conversions, etc), and also because it is a HUGE design problem! Why? Well, as some of you should know, Picking is the possibility of selecting an object in a 3D world through the click of the mouse. However, the mouse “lives” in 2D space while the scene is usually 3D. So, the mouse coordinates are caught up in the Input layer and must be propagated to the Object Rendering layer in order to check if some object was intersected by the ray generated by the mouse click. As you can imagine, crossing several layers many times and returning to the interface is a quite tough design job…

However, my approach tried to obtain not only quality in the design (without violating any abstraction encapsulation) and also performance. As I already need to go through every object while drawing, I figured that I could use the drawing cycles to perform picking. As every function returned void at the time, they now return the set of picked objects! This way, I shared as less code as possible (in a Aspect-Oriented Programming way) and still managed to obtain the most of the engine performance!

Now I shall work in the textures. There is not much work left, so that when I finish some last things, the game should be born! πŸ˜€ Promise that will keep you posted… πŸ˜‰

Conspiracy Engine First Render!

Posted in Computer Graphics tagged , , , , , , , , , , , , , , at 12:23 am by sagito

And finally, here it is! The Conspiracy Engine first rendered screenshot! Well, it consists of a single teapot lit by diffuse and ambient lighting using Gouraud shading, some text on the screen, one camera (so far), and two lights (one ambient and a point light). It is not something amazing, but this is only the first nice render screen of this engine! And what is most impressive is that this is not a standard DirectX teapot, but a 3DS Max exported teapot, which was loaded using my 3DS Exporter and Importer, presented below. I changed the code a bit to support materials and textures and also to optimize it a bit… Please note that the normals are still not being saved directly, so the lighting can look a bit awkward…

Here is the screenshot of my new engine:

Conspiracy First ShotConspiracy First Shot

Feel free to comment! πŸ˜€

July 3, 2009

3D Model Loading

Posted in Computer Graphics tagged , , , , , , , , , , at 12:07 am by sagito

Hi all! πŸ˜€

After a small time without posting anything, due to an exam which happenned today, I’m now proud to say that the Conspiracy Engine is already capable of loading Β three-dimensional objects from the CMF format defined below. It still does not try to load neither textures nor materials, but the geometry is already being properly loaded!

In the past, I have tried to create a mesh from a format other than .X and I failed because I just couldn’t get access do an ID3DXMesh* vertex buffer correctly. Either the data was scrumbled and corrupted or the mesh would just not grant me access to the buffer. This time, I tried to adopt a different system and I created the mesh with different pool and memory flags. Apparently, this did solve the problem! πŸ˜› However, I’m still looking forward to see if that really stands when I try to put some animations within!

I will be posting some screenshots very soon! The Conspiracy engine is now getting really solid and robust. I could even say, that even in such an early development stage it already is more robust than all of my Enoch engines all together!

So, what is it needing now? From my perspective, mainly two things… A scene file loader, which takes a file and builds a scene from it, and a graphical editor. This graphical editor should be a tool that would let me import new things into the game world, position stuff, create AI routines, etc… Something like all real engines have! And I’m looking forward for the challenge of developping such a thing.

Will be posting news pretty soon, stand by… πŸ˜‰

Next page