Tags
Programming III – Do it again and do it right
09 Friday Jan 2015
Posted School related
in09 Friday Jan 2015
Posted School related
inTags
02 Friday Jan 2015
Posted School related
inTags
A quick update from me this, week. I caught a virus and have been lying sick all week so no progress from me unfortunately but I’ve been to the doctor and hopefully I’ll be better in the following days but I’ve been thinking about how to set up and refine the state system and then code in a simple main menu with interactable buttons for the mouse.
26 Friday Dec 2014
Posted School related
inTags
I’ve been looking through your code for the menu state. You can see how this is created with the knowledge from previous courses. Really good to see that you have set up a simple collision system in a 2D space in order to simplify the creation process.
class Hitbox2D {
public:
Hitbox2D() {
m_x = 0;
m_y = 0;
m_w = 0;
m_h = 0;
}
Hitbox2D(float x, float y, float w, float h) {
m_x = x;
m_y = y;
m_w = w;
m_h = h;
};
And then later on tracking the mouse’s position in order to check if the mouse’s position is within the menu button’s collision area (to trigger perhaps a higlated state in the menu). This reading of the code was really usefull to me since I am to set up a quick menu and of course a menu state our game as well. And since we all (well most of us) are using the helium project as base it is really easy to understand what’s going on.
This was a really short review but everything looks good for now, keep up the good work.
//Simon Johansson
For this week’s progress it has been really slow, the whole group is scattered so I’ve been completing my individual task for programming III, I completed the last methods for binary source tree; traversing and pre order printing, it was a matter of thinking and placing the print code at the right spot. The base code I hade already coded in my print after sorting.
And that was it this week, Happy Holidays!
20 Saturday Dec 2014
Posted School related
inTags
This week has mainly gone to figuring out how to import 3d models into a DirectX powered application, following an advice from my teacher I chose to use the third party program Assimp, which as it name so humorously describes, imports assets.
However to get the program to import correctly into a DirectX powered program we need to use another tool to aid the importation. Cmake is a program which will as far as I’ve learned translate the conversion process into the language and coding environment of the coder’s choosing. But this is basically how far I’ve managed to get while trying to import assets. While converting the Assimp code the first time I encountered some errors so I thought that I might as well talk about the error so less people get stuck like I did.
The tutorial is extremely lacking in information so you might do yourself a favor to download Assimp and Cmake as usual but also the DirectX SDK. The SDK is mandatory in order to get the conversion to DirectX. I also learned that if your pc is running windows 8 you already have the SDK installed compared to Windows 7 where you will have to download it from Microsoft’s download site.
Other than that I’ve completed my individual assignments but I’ve only leak checked the assignment where we are to create a webserver. The tool I used visual leak detector. To enable it you first of all have to install the program from the developer’s site (it’s free) then you open up the program you desire to test and right click the solution inside of visual studios and enter properties. While there enter the general c++ section and point the additional directories to where the dll’s lie (the include file) and then go to the linker section where you found the general c++ section. Go to the linker tab and link additional libraries (located in the lib folder).
And that’s what I had to say for this week.
13 Saturday Dec 2014
Posted School related
inTags
This week we have been creating a skybox in our 3D-project. Tho create a skybox there are two things you must keep in mind; that you always is in the skybox (important for culling) and that a skybox isn’t an object in the traditional meaning.
Let’s compare the skybox to our box. A box has several sides built up from vertices, in this aspect the box and skybox is almost identical, only thing that separates them are that the skybox does not have a bottom side, well there are a bottom side but it should never be seen so how you handle it’s textures does not have great importance.
But we want our skybox not to be seen as a barrier that is obvious to the player’s eye, right? Well we are creating the skybox from the texture seen beneath. But the texture itself has white boxes in the corners. These boxes are there because it is nearly impossible to make a round object flat and not have distance errors and scale errors. By adding the white boxes we can keep the scale and distances but it also complicates the creation of the skybox, well mainly the texturizing of it.
The texture used.
To calculate the position of the boxes we can either make an estimation of where they start and end in our normalized vectors. For this example you can go with the real texture starting ¼ in to the texture file. But if you really want an accurate projection of the texture you can check on the pixel where the sky texture starts and then add it into vectors and then use them as referral points for the other sides of the skybox.
One thing I have not written about is that the skybox does not need to have a normal vector or a world position since we do not want the “sun” to reflect on the surface and we want the skybox to act omnipresent.
And here’s how the box looks in its current state.
06 Saturday Dec 2014
Posted School related
inTags
Hello, this week we have been going through how to properly render something in dirextX, there are several things to be considered. In my recent post I talked about creating a box and how we calculate it. But in order to make our box act as if it were in the real world there are a few things we must code, a light source is one major aspect in order to get an object to feel more real.
In directX there are a few methods of doing this, for this example we’ve chosen a Point type, it is a positional light that emits light in all directions, evenly. But there are two more lighting types that we unfortunately don’t use in this program. There is the spot lighting that is a positional lighting just as point but this type emits light in a specified direction. The last major type is the directional lighting type, it emits light in a specific direction but it does not have a position, this type however doesn’t have a position. This may sound odd but the source of the light is indefinitely far away. It’s perfect for simulating a sun.
You can see on the left side of the box the textures are black. It’s an effect of the light not being reflected on the surface.
Not showing on the picture is a prototype for gui (graphical user interface). It is the latest addition to the project, I have not really dug down into the code but I believe that the gui is located in in the camera space, so that it always will follow the camera.
Well that’s it for me. Next week is Culling J
30 Sunday Nov 2014
Posted School related
inTags
A bit late to post but better late than ever, this week has been all about 3D-graphics, we have gotten a small introduction on how to initialize DirectX in a program. But we have also gained knowledge on how the computer sees graphical structures. When we see a box the computer actually sees it as triangles, well…if you go even deeper the computer sees the triangles as vertices (dots) in a 3D-space, between these dots it connects with lines in order to form the triangle.
I’ll show some code to explain a bit further:
vertices[] =
{
// triangle 1
{ -1.0f, 1.0f, 0.0f, 0x99FF99 },
{ 1.0f, 1.0f, 0.0f, 0x000000ff },
{ 1.0f, -1.0f, 0.0f, 0x99FF99 },
}
If you imagine a coordinate system with X,Y and Z-axis and let’s for the simplicity of it make 1 as its maximum value. At the center of the screen you will find origo (0,0,0). From there we will try to create a triangle. Now before we start we must also remember in what order we want the vertices to be calculated, this is important because it will determine on how the surface/texture is displayed. DirectX counts the vertices clockwise so in order to have the surface being displayed from the right angle we must also count clockwise (unless we define it to count counter-clockwise). So back to the triangle, starting from origo we place our first vertice at the top left corner with no depth (-1,1,0) and then we want it to connect to the next vertice at the top right corner with zero depth (1,1,0) and the last one to be connected is at the bottom right corner with no depth (1,-1,0). When the third vertice is calculated the third and the first will be connected as well in order to form a triangle; like this:
How it actually looks though is like this, do notice that I’ve enabled colors in my surface (the hexadecimal values in the code). The colors are enabled by writing your own shader. Bu any way, here’s how the triangle really looks like:
And by using triangle you can create more complex structures like the lectures final shapes; a cube (sorry for the weird angle):
And that concludes my coding blog post of the week 🙂