Runge-Kutta 4th order
Finally I got RK4 working. I never had highly sophisticated math and more then half of the books you come across start easy, telling you how to program (the part I do know) and then suddenly they shift in high gear and expect you to suddenly understand all the math that is throw at you.
It seems that most of these physics books are written for physics students and not for programmers. But also wikipedia assumes that I'm a math guru, which I'm not. In fact I like things that don't require me to think, you don't want to know how an engine exactly works if you only need to use it.
So I decided to post my own C++ implementation of RK4, which you are free to steal and use, but you can't hold me liable. I would like to hear if it worked for you or not, but don't feel obligated. My own version is a bit advancer than the one you will see, but that is only because I need to have drag, impulse, etc. I'm not going to explain as I simply don't understand every step, it is more stable than euler (read: it takes longer to break).
If you are really intersted in how RK4 works I suggest that you contact your math teacher and keep asking until you know the exact ins and outs of it.
struct Particle
{
Vec3f Position; // Vec3f is a vector (3d position) which should initilizes with all zero
Vec3f Velocity;
Vec3f Acceleration;
};
void EulerIntegration(Particle p)
{
p.Position += p.Velocity;
p.Velocity += p.Acceleration;
}
// We will use this function later, it's just to make it c++ correct
// DT is DeltaTime, just use 1.0f if you don't know what I mean with that.
void RK4Eval(const Particle p, float DT, const Vec3f d[2], Vec3f* output);
// DT can be 1.0f if you don't know what I mean with that
void RungeKuttaIntegrator(float DT, Particle& p)
{
Vec3f k0[2]; Vec3f k1[2]; Vec3f k2[2]; Vec3f k3[2]; Vec3f k4[2]; // remember all should be initiliazed zero
RK4Eval(p, 0.0f, k0, k1);
RK4Eval(p, DT*0.5f, k1, k2);
RK4Eval(p, DT*0.5f, k2, k3);
RK4Eval(p, DT , k3, k4);
const Vec3f dxdt = (1.0f/6.0f)*(k1[0] + 2.0f*(k2[0]+k3[0]) + k4[0] );
const Vec3f dvdt = (1.0f/6.0f)*(k1[1] + 2.0f*(k2[1]+k3[1]) + k4[1] );
p.Position = p.Position + dxdt * DT;
p.Velocity = p.Velocity + dvdt * DT;
}
inline void RK4Eval(const Particle p, float DT, const Vec3f d[2], Vec3f* output)
{
const int x = 0; const int v = 1; // otherwise I keep thinking arrays
Vec3f state[2];
state[x] = p->Position + d[x]*DT;
state[v] = p->Velocity + d[v]*DT;
output[x] = state[v];
output[v] = p->Acceleration;
}
Reading material
- Game Physics - A book recommend by my school, which I don't recommend, as it's a lot of math while the code is simple.
- Game Physics Engine Development - A book I do recommend, it's quite easy going and it brings you to a goal namely a physics engine. So far no complains.
- gaffer.org - It told me the step I was missing (the derivatives)
Fuzzy Logic
A while ago I was contacted with a question if someone I didn’t know (feel free to mail me, you could be the second person I haven’t met) could use my SSAO shader because he was in a desperate need for fuzzy logic. First of all the SSAO shader is free and second I don’t see where fuzzy logic is in my shader, but I wrote the code a long time ago so maybe I put it in without thinking too much of it.
However the term fuzzy logic is how do I put it… fuzzy for me as well. I have heard the term before and I can describe it, but what it exactly is? As I’m writing this post I already know what it is but just for fun I will describe my original explanation.
Old explanation:
Fuzzy logic is making a logical decision based on an inexact (or fuzzy) value. With an fuzzy value we refer to a value in a certain range.
The above is not correct, but not completely off. And how can a number something that we can measure (1, 2, 3, etc) be inexact? Anyway the second explanation is better and after you have read how I came to that explanation it will make sense.
New explanation:
Fuzzy logic is making a logical choice based on the range in which the value currently resides.
It’s a bit hard to explain with an example, but you will know after this most simple example. If you ask someone “how fast is your car?” he can answer with a number, if someone asked me that question I could answer that it max speed is 180 KM/H. However that is a quantity which is an exact number. However I could say that it is pretty fast and that is a fuzzy answer.
In code we could make it look like something:
[cc_cpp]
enum FUZZY_SPEED
{
FUZZY_SLOW = 0,
FUZZY_DECENT = 1,
FUZZY_FAST = 2,
FUZZY_LIGHTSPEED = 3,
};
FUZZY_SPEED GetSpeedOfCar(int Kmh)
{
if(Kmh <= 75) return FUZZY_SLOW;
if(Kmh <= 150) return FUZZY_DECENT;
if(Kmh <= 200) return FUZZY_FAST;
if(Kmh > 200) return FUZZY_LIGHTSPEED;
}[/cc_cpp]
However lets say this is the next version of GTA in which everybody is crazy about his car, including the character to which you told "My car is pretty fast, do you want to race?".
[cc_cpp]
bool ReactOnRaceChallange(FUZZY_SPEED playercar, FUZZY_SPEED aicar)
{
int FuzzyValue = aicar - playercar;
if(FuzzyValue < -1) return false; // Do not accept, noway the AI can beat the player
if(FuzzyValue <= 2) return false; // Do not accept, the player is not worthy to race with the AI
return true;
}[/cc_cpp]
The above is an example of fuzzy reasoning.
If you think about the answer you can find a lot of cases in which you can apply fuzzy logic.
- Freezing, cold, warm, hot
- Light, twilight, dark
- Young, grown up, old, ancient
Now one last example: Let's say we have a story teller which based on your character attributes tells something about it.
Intellect: 8 Charisma: 7 Luck: 8
"He was a good looking (based on charisma) student (smart people often study) who had girls waiting in line (based on charisma and luck)."
If you still have trouble understanding try to change the character attributes and change the sentence. Like what would happen if we would drop his luck to zero? Would it become "Who was so good looking that all the girl fainted and had therefor never had a date in his life" or would that only happen if we increase his charisma to 9 and drop luck to zero?
References:
Awesome shader debugger
Ok, this is totally awesome. So awesome that I have decided to write a short post about it.
Shaders are a pain in the ass since you can't debug them as you are used with C++. However there is a possibility for CG shaders. You can view a movie at youtube and download at nvidia.
I haven't actually used it myself, but I will soon. I think this piece of program will remove a lot of my resistance about shaders in general.
Shimmer shaders, practical jokes and farts…
"What? Farts in the title? I bet this must be interesting!"
And yes, it is interesting!
During one of the SFX lectures at school we were discussing shimmer shaders. Shimmering is an effect when something is extremely hot and you can see the air around it vibrate. In real life we have this with highway or deserts. The air above the ground is then so hot that it will hold a different density which causes the light to refract. In deserts you can get mirage where you think you see water in the desert, but in reality you are looking at the sky. This is because of light refraction.
In games we often use this for our lava monsters or on the lave itself or anything else that represents extreme heat. However as we were discussing this in the class I suddenly got this crazy idea of using to simulate a fart. Of course only suggesting this idea in class was good for a few laughs, but since I liked the idea, I actually made it and I'm ready to show it in class. Yes, I love practical jokes (the kind that don't piss anyone off).
The example is quite simple. Use WASD to move around and when you hold the left mouse button down you can use the mouse to rotate. Further you might notice that the girl is also shimmering. This is because she is hot as well.
PS: The fart sound is not mine
Download Fart.rar
Requirements: You need to have the latest DirectX 9.0 installed (June 2008) release
If you are missing something like [cci_text]"D3DX9_39.dll"[/cci_text] than you need to run the DirectX webupdate.
CV and Portfolio online
I have finally put my portfolio online, but the amok, the framework I told you about last time, is not there as I haven't checked it in a long time.
In the future when I have done something and I want to show it off I will most certainly put it up there.
Re-re-re-re-writing code
You should never rewrite code. Rewriting code is bad, instead you should improve your old code. The only time you should rewrite code is when it's such a mess you have difficutly making out what it was suppose to do. If you know what the code does and how it works but don't feel comfortable you should rewrite it as soon as you can.
The reason why I state the obvious (well, I hope it's obvious) is because I have a habbit of rewriting my own code. It's less severe as two years ago as I know have my own library which contains a majority of the functions I will ever need, but yesterday I caught myself wanting to rewrite my own code. Granted the new code had another purpose, namely be all purpose and extremly flexible (mete template programming) where my old code was inflexible, however I think I will abandon this code and instead shall be rewriting small part (which we should see as correcting) of my old library. I'm going to split that library in a section that has general functionaltiy (math and templates) and a section that is specific to an OS or API (DirectX or OpenGL). The specefic section should be made as abstract but not pure virtual so that I can easily port it to other systems (think game consoles).
I think I will recreate my project and then start copying everything to it. Doing so will give me that feeling of rewriting while I'm not actually doing it.
Health packs are licensed
I was reading the rescuetime blog and I came across an article about their new logo. Ok, that is not the interesting part, but their old logo was a red cross. Apparently this is licensed by the Red Cross health organization. If you read through the article you will see that they also make a reference to the logo on health packs in games and wonder why that is allowed.
It sounds just as stupid as that T-Mobile said that the color magenta is theirs alone and nobody else can use it.
I might be wrong here, but I don't think that this is the idea behind copyright and licenses.
Self-help books
To be honest I do not like the idea of a book helping me. But recently I have tried one about self-discipline and I decided to go one with a few. Most of them are of those "... within x days" books which feels like you are put on a time constraint. However after I put it off and off I decided to finally read the first book and go for it and in one of the paragraphs it told me that I shouldn't think of something not useful and that even if the book helps you a tiny bit then you could already consider it a success. At first I was skeptical about it but then the book told me that I would properly be skeptical about that previous sentence because how could a book help me? In which it answered why not?
Anyway to make a long story short, I decided to try out the book as I had nothing to lose.
I still think that self-help books are some form of a scam but that is because we all think we don't need help until it's too late. If you have a problem you should try to solve it before it becomes a real problem and if you need someone else his help then so be it. Asking for help is not a weakness, it's wise. There is of course a limit too it and you might even think that you should be able to solve it on your own but sooner or later you will come across something which just requires someone else his help. Once more it is a strength asking for help.
So back to self-help books, are they any good?
I would say "Yes, unless they talk you into something you don't want" and that is the difference between helping and scamming someone. If someone else talks you into something you don't want, then it's a scam.
Commercials are thus a scam, self-help books who tell you you need more are a scam.
People, books or any other media who give you an advise but tell you also to not do it if you don't feel comfortable are people, books or media that are helping you.
So try out a self help book. There are certainly a few of those in library and else you can look on the internet for semi-professionals who write free self help books. There is bound to be something for you around.
Pushing the customer

Today I decided to finally update Java (had put it off for a few days) and as I was saying "next, next, next..." until I found this.

I know that Apple has done the same with ITunes and Safari (a web browser). I don't really mind Safari as I do use it from time to time (though I prefer Opera) however Safari is 18.7 MB while OpenOffice is 127 MB. Both are too big if you ask me, but that is besides the point. What I'm really irritated by is the fact that the wink was filled in. If this was an online service asking you to send letters from a third party it would be explained as spam. (How many of you have installed google toolbar?)