January 20th, 2010 by ofer
Posted in Coding
When you draw sprites you are thinking in 2D. I was using DirectX’s ID3DXSprite interface to draw sprites. I had to scale up a sprite to cover the whole screen. The sprite can be in different resolutions. If the sprite is quarter the size of the screen, then it needs to scale up by 2.
When I scaled my sprite by 2 everything worked, but when I scaled it by 4 it was not visible. What was the problem?
The sprite draw call gets a 3D position as a parameter, so I passed the x and y I needed and have put 0.5 for the z. I don’t remember why I did that.
It turned out that when I scaled the sprite by 4, it scaled the z component of the position to the value of 2. It meant that the sprite, which is actually a quad, was outside of the viewing frustum.
In the case of the sprites rendering, the viewing frustum is a box of the dimensions [0..Width]X[0..Height]X[0..1]. Anything with a z value greater than 1 will not be visible.
These kind of bugs might be difficult to figure for a beginner, and even for someone who is not a beginner it can waste time. Luckily, once you wrap the DirectX ID3DSprite with some abstraction and after you encounter this bug once, you can protect yourself from the same bug in the future.
No Comments »
January 15th, 2010 by ofer
Posted in Labyrinthica, The RPG Game
A full rebuild of Labyrinthica takes quite a while and some of my code goes way back. This has led me to the decision of trying to revisit my code of Labyrinthica, with a focus on my next project(TRG) as what will be the product. I plan on blogging on how this will go.
A few things I have learned from my new workplace(Microsoft), is how to profile builds. For instance, the use of precompiled headers, and turnning on the build timing option in VS express 2008.
Here is an article talking about this.
No Comments »
January 12th, 2010 by ofer
Posted in Other blogs
I was starting to work at a new workplace last week. They have set me up a temporary desktop computer.
It was placed on a “table corner”, where two perpendicular tables connect. The set up was inconvenient. The monitor was placed far into the corner, and the mouse and keyboard cord barely reach the table’s edge.
Since the monitor was far, it was making my eyes tired. I don’t know exactly what I was thinking, but I rationalized why I should not try to pull the monitor closer.
At first I thought that because the mouse and keyboard cords can’t be pulled, there will be a problem with the monitor cord as well. Then I was told that I will get a new monitor today, so I said after I will get the new monitor this problem will be fixed.
I then talked about it with my boss, and while talking to him I figured how silly it sound that I just didn’t check or try to pull the monitor closer. I tried to gently pull the monitor and found out there was a lot of loose cable.
We some time rationalize things or find excuses to not try things because of a future event we are looking forward to.
It is a really important quality to be able to try things out even if you have no prior knowledge if it will work or how you are going to do it.
No Comments »
January 5th, 2010 by ofer
Posted in Coding, Software Design
Here is a neat little way I found to make one class access the privates of another class, without using friend or direct inheritance. Take a look at this code:
class A {
public:
class Observer {
protected:
int GetPrivate(A & a) {return a.ValueA;};
};
private:
int ValueA;
};
class B: public A::Observer {
public:
void Foo (A & a) {
cout<<GetPrivate(A);
}
};
Class B cannot access the privates of class A directly, but it inherits a subclass of A that can access the privates of A given as a parameter. Since I have just tried this “pattern” recently, I am not sure what is the direct benefit of this.
I believe a benefit can be in the sense of making a programmer’s life easier. Programming languages play several parts. They provide us powerful functionality, but they also suppose to give us ease of use. You can program anything on assembly, but it would be really difficult to write a big game in assembly.
If you do not expose privates via a getter, you give the programmer one less method to think about when he need to use the class’s instance for something.
Can you think how you would use this “pattern”? Do you think there is no use for it?
Tell me what you think.
7 Comments »
December 31st, 2009 by ofer
Posted in Other blogs
Well, it’s not new year yet but I would like to talk about “special dates”. I think some people like events, they like to have anticipation to something. An event is sometimes an opportunity to change, to start fresh.
People think that after new year they will change, they will break an old habit, they will do something new. Or people think that on the weekend they will have fun, while on working days they just count the days until weekend.
This can be good, an event can be an opportunity to do something new. But isn’t it better to just change or do something new the moment you want to? Instead of procrastinate to some event?
It is possible to get used to do new things, to learn new things, to change the moment you want to instead of waiting for some event to come.
It is also relevant to game development. Especially in terms of efficiency. You might procrastinate doing things because you need to finish some boring task first. But you end up delaying that boring task because it’s boring.
I think what tempt us to look to events is that we like linear advancement. We like to think we always walk straight and every step we make we get closer to our goal. This might be a good thing sometimes, but sometimes it also hold us back.
I am not entirely sure about this subject and what I wrote. I just had a thought of why we like events, why we have anticipation to these events and why we promise ourselves to change only at a certain event. What do you think?
Happy New Year.
1 Comment »