RTF to HTML converter 1.01
Avishkar Autar · Apr 11 2007 · Uncategorized
Rtf2Html Version 1.01
(Requires .NET Framework 2.0)
Avishkar Autar · Apr 11 2007 · Uncategorized
Avishkar Autar · Dec 7 2006 · Uncategorized
Avishkar Autar · Dec 2 2006 · C/C++
Enums in C++ can be a pain in the ass once a project starts to grow in size. Enums are typically defined globally or within a fairly wide scope such that there’s usually a pretty high probability that you’ll get name clashes between enums (remember that in C++ the enum block is not a scope, so enum members must be unique across multiple enum declarations) unless, like with the DirectX or Win32 APIs, you give your enum members names which are detailed, prefixed, and very ugly looking. For example here’s some of the enum members for Direct3D render states:
typedef enum _D3DRENDERSTATETYPE {
D3DRS_ZENABLE = 7,
D3DRS_FILLMODE = 8,
D3DRS_SHADEMODE = 9,
D3DRS_ZWRITEENABLE = 14,
D3DRS_ALPHATESTENABLE = 15,
...
Truthfully, the DirectX enums aren’t that bad, and most programmers (including myself) have seen worse, but is there a better way?
Recently, I’ve discovered a cool trick that I’ve started using in most of my C++ code. Just wrap the enum declaration inside of a namespace. So, as an example, you might have something like:
namespace Color
{
enum Color
{
Red,
Green,
Blue,
Orange,
Purple
}
}
… and, because of the namespace wrapper, it’s also perfectly valid to have the following within the same scope as the code above (note the Orange enum member in both declarations):
namespace Fruit
{
enum Fruit
{
Apple,
Orange,
Purple
}
}
You access an enum member by simply resolving the namespace first:
Color::Red
Color::Orange
Fruit::Orange
Simple and elegant!
The only oddity is that to declare variables that are of the enum type, you have a declaration that looks like:
Fruit::Fruit
or
Color::Color
… but overall I think that’s a small price to pay.
I am very surprised that this little trick is not mentioned much and in the few places where I have seen it mentioned (such as here), it is glossed over and its significance is not really highlighted.
EDIT: Note that C++11 introduces scoped enums which renders this trick unnecessary, if you have a compliant compiler.
Avishkar Autar · Dec 1 2006 · Uncategorized
Avishkar Autar · Oct 30 2006 · Win32 Platform
Seems like I’m talking too much about firesync in this blog, but anyway, another rare, but serious bug popped up in firesync on this special day. However, unlike the previous bug (see previous blog entry), this one doesn’t seem to be unique to firesync; it’s the daylight savings time bug (note: this article is informative, but some parts are not written too clearly and can be difficult to understand).
The bug popped up when I noticed firesync seemed to be thinking that all of my files were out-of-sync. I looked at the file modification times of a few files on the two PCs and noticed that modification, creation, and access times were off by 1 hour. The reason for this, as I discovered, is that the filesystem of one system was FAT32 while the other was NTFS. FAT32 time stamps are equal to the local time (so, inherently, DST information is contained within the time stamp). NTFS time stamps are based on UTC time and the local time is calculated as an offset from the UTC time. The problem (i.e. the daylight savings bug) results from the fact that Microsoft chose a somewhat odd way of handling conversion from UTC-to-local time. Instead of storing DST information as part of a time stamp (which would enable a correct conversion), NTFS systems will add 1 hour to the UTC time (during the UTC-to-local time conversion process) if daylight savings is currently in effect!
So, the solution seems to be to do all time stamp comparisons based on UTC time. Ahh, more work for firesync 2.
Avishkar Autar · Oct 6 2006 · Random
Avishkar Autar · Sep 14 2006 · Uncategorized
Avishkar Autar · Sep 6 2006 · Graphics and Rendering
Work on zerospace has finally picked up in the past few weeks and a few days ago I posted the first screenshot in the zerospace blog. Not much to see as yet, just an background, starfield, and untextured model. However, I did put in some major work on the lighting system, which is visible in the screenshot (to a certain extent; the specular highlights are dull and, although they’re there, they’re only apparent when the model rotates).
Anyway, what I wanted to discuss in this post is the lighting model, since I think it’s fairly unique and it gives some amazing results.
Ambient
The ambient component is done per-vertex (i.e. all computations are done in vertex shader and color is interpolated over the face of the triangle) and consists of 7 directional lights hitting the model from various directions. It’s sort of an ultra-simplified version of ambient occlusion mapping.
Diffuse
The diffuse component is sampled from a 2d texture. This texture is a scaled down and heavily blurred version of the background texture (done offline; a heavy blur, such as the one required would be too expensive in the pixel shader). Scaling it down is simply a matter of performance, as the background texture is large (2048×2048). Blurring (I do a guassian blur) is a trick to get the diffuse lighting from a scene (this is a bit difficult to explain, I’ll try to do later in another post).
So how how is the texture mapped onto the 3d model? Spherical texture mapping! (see this article for an explanation). Note that the normal vector used to computer the texture coordinates is the the normal vector transformed by the world matrix (since I don’t want to texture map the diffuse lighting onto the 3d model in model space; this will cause the lighting to be “static” – i.e. when the model rotates the lighting values won’t change to reflect the change in orientation).
Specular
The specular component is is done per-pixel because per-vertex specular highlights usually look terrible (there are some other issues in general, but this was the main one for zerospace). For the specular lighting there is really only 1 light, a single directional light pointing down the z-axis. However, there are 8 view vectors and the specular computation is done between the single light and each of the 8 view vectors. I came up with this hack as I found that experimenting with multiple lights was more difficult than experimenting with multiple view vectors (different light vectors would cause either a too extreme or too weak specular highlight). Anyway, I do the specular computation with an exponent of 7, and I them multiple the results by 0.075 to dull the highlights.
One final note, the screenshot is no longer 100% accurate of the lighting system . I just found a major (and stupid!) mistake where I was multiply the ambient and diffuse components together instead of adding them. However, what I described above should stay the same, I just have to tweak some values to prevent the lighting from being too bright or too dark.
Also, on a more final note, this is not the complete lighting model for zerospace. Lighting from weapons, particles, etc. will also be taken into account.
Avishkar Autar · Aug 31 2006 · Uncategorized
Not really sure where I fit in here. I guess I’d like to think of myself as a power gamer, but given the amount of time I usually spend writing code instead of playing games, I’m probably more of a dormant gamer, and I have found that when I have to or want to focus more on coding, school, etc. I tend to play games where I don’t need to spend hours to finish a level. So I usually play an FPS or some type of action game (Quake 4, UT2004, or, recently, Freespace 2) instead of an RPG (still haven’t finished Guild Wars: Factions or Planespace Torment, and I haven’t touched either lately) or RTS (I’m half-way through Homeworld 2 and I’ve had it for over a year; however, to my credit, it is a very difficult game).
- Power gamers: This group represent 11 percent of the gamer market, but accounts for 30 cents of every dollar spent on retail and online games.
- Social gamers: This group enjoys gaming as a way to interact with friends.
- Leisure gamers: This group spends 58 hours per month playing games but mainly on casual titles. Nevertheless, they prefer challenging titles and show high interest in new gaming services.
- Dormant gamers: This group loves gaming, but spends little time because of family, work, or school. They like to play with friends and family and prefer complex and challenging games.
- Incidental gamers: This group lacks motivation, and plays games mainly out of boredom. However, they spend more than 20 hours a month playing online games.
- Occasional gamers: This group plays puzzle, word, and board games almost exclusively.
Avishkar Autar · Jun 20 2006 · Uncategorized