Jeff さんのプロフィールGeeky Fantasiaフォトブログリストその他 ![]() | ヘルプ |
Geeky FantasiaDreams will come true. |
||||
|
8月7日 Recent Paitings5月22日 TripodsH.G. Wells is one of my favorite sci-fi writers. He is the originator of the fictions on the alien invasion. The famous book, The War of the Worlds (pub in 1898), depicted a kinda feracious war machine, named tripods. The tripods have three long limbs for walking and they emit a dreadly beam, called the Heat beam, which is commonly deemed as the prototype of laser.Below is an art work on the tripods. 5月20日 画了幅画,献丑一个。4月19日 Metaprogramming with C++ Template C++ template technology actually implies much flexibility than it seemed. From 1994, excellent programmers began to investigate the 'metaprogramming' and virtual compilation with C++ compilers. In fact due to the parsing structure of the C++ compiler (though there are differences among different vendors' implementations), we could make the compiler a good caculator with template syntax. Quite interesting, nah? Below I presents two examples. One is the famous Fibonacci sequence, and the other is the ordinary accumulation. Note that the calculations are all done at compile time. // Metaprogramming samples// Author: Jeffrey Bian// Date: April 19th, 2009#include <iostream> using std::cout;using std::endl; // Fibonacci sequence // @pr: // _num The number of items.template <int _num>struct C_FIB { template <int n> struct FIB { enum { v = FIB<n-1>::v + FIB<n-2>::v }; }; template <> struct FIB<0> { enum { v = 0 }; }; template <> struct FIB<1> { enum { v = 1 }; }; enum _Out { val = FIB<_num>::v };}; // Accumulation// @pr: // _initial The initial item.// _step Length of step// _num Item count.template <int _initial, int _step, int _num>struct C_ACC { template<int n> struct ADDER { enum { a = ADDER<n-1>::a + _step }; }; template<> struct ADDER<1> { enum { a = _initial }; }; template<int n> struct ACC { enum { v = ACC<n-1>::v + ADDER<n>::a }; }; template<> struct ACC<0> { enum { v = 0 }; }; enum _Out { val = ACC<_num>::v };}; int main(){ cout<<C_FIB<9>::val<<endl; cout<<C_ACC<1,1,10>::val<<endl; } In the snippet above, the C++ compiler, once meets C_FIB<9>, will try to instantiate it and then it finds that there is another reference to C_FIB<8>, then C_FIB<7> ... not until it reaches the termination condition, namely C_FIB<0> and C_FIB<1> could the compilation succeed. Still there is something worth noticing. All the code above got passed in VC2008 epxress (namely VC9), which no longer supports floating type argument as the non-type arguments in templates, although previous versions of MS' compilers do support. So an attempt to implement the square root with Newton method impose lots of ugly stuff (e.g., have to use reference double& instead of double ). So I just give it up. Virtually all the algebrac algorithm could be implemented with template technology, based on the assumption that any algorithm be expressed in a recursive way. 4月14日 双通道了!Yeah, 刚刚去村里淘了两条现代的DDR2 667 1G的内存条,终于双通道了。保留了原来那个小的512的Kingmax,发现可以一起工作的很好。所以,目前俺有2.5G内存了。再也不愁3ds max玩不起来了。 4月10日 CEGUI Study NoteCEGUI is an evolving GUI system often used in games and other applications that involve lots of graphical rendering. It is designed as multipurpose and could be mounted to a variety of graphical engines. The overall architecture is easy to understand, standing at a rather abstraction level. This study note will cover its the basic concept and major features. Overview of CEGUI CEGUI is very powerful in its extensibility and highly customizable design. Its concept is rather natural: first you have 'skin' definitions, then you take use of the 'skin' and apply it to your application in any way you want. The 'skin' definitions are all textual (actually XML) and could be worked out even in notepad; and as for applying the skins, you could either hard code it in C++ or just use a layout description file to describe it. I believe the latter way would save a lot of workload, since there is no re-compilation overhead. The relation of the basic component of CEGUI system is as below. We could see that a scheme file is the lead of a skin, it in turn depends on look and feel description, while the look and feel description file in turn depends on an image set. This reveals to us that, CEGUI system is in essence based on 'images', which is described fairly well with an image set file. An image set file could point to an image file (TGA, PNG and so on) and contains a sequence of element definition with their rectangle bounds with respect to the image file coordinates. Well maybe some of you might have guessed that the CEGUI system will index the element's bounds in the image file, and 'cut' it out. Bingo! That's exactly like HTML hotspot or any technique very commonly used in RPG games. Small GUI elements are stored in a rather big image and you later 'cut' what you need from the file with its location rectangle (top, left, with and height) with respect to the image coordinates. Other parts of CEGUI are even easier. In the scheme file, you could define your widgets and link its 'look and feel' property to a looknfeel element defined in your looknfeel file. And the looknfeel element, besides provding state information and layout information, link its visual presentation, namely image to some elements in the image set file. Above is the basic concept of CEGUI. And here I present a small demo of a 'main menu' in a spaceship related game. Note that I only made this a mockup to show CEGUI. 4月8日 Quaternion: Treasures from Sir W. R. Hamilton It seems a legend on the first look at 'quaternion'. What is it? Is it worthy of a thick book dedicated to it? After days of studying programming 3D games, I found this concept of quaternion much more interesting. It is decent, graceful and concise. Although lack of completeness, quaternions serve a good part of 3D spatial transformational utilities (this does not hinder its expressions of 4D transformations). Yes, things could be done in another way, that is, pure vector way, with transformation matrix; yet quaternions involve less storage space and clearer intuition. Over a hundred years mathematicians have argued upon the applications of quaternion and its necessity, nonetheless it is the same situation now, we find it a best candidate in 3D graphical algorithms in cyber world. Again what is a quaternion? By a most common explanation, it is an extension of complex number in 3 dimensional space. For complex number we are familarized with, there is an imaginary axis, denoted as i axis. Now imagine this situation in a 3D axial system (also Cartesian), we extend a j and k axis. So a quaternion takes the very form of, H = w + si + tj + uk Sir W.R. Hamilton might be delighted if he knew that his invention boomed in a fancy field after a century from his pass away.Hence the dot product, i * i = -1 j * j = -1 k * k = -1 And more, i * j = k j * k = i k * i = j j * i = -k k * j = -i i * k = -j There are some 'natural' deductions for the algebra of quaternions, which I will not duplicate them here, such as addition and multiplication, but a worth noticing point is the quaternion algebra system is not commutative, just like the vector algebra. For more information on quaternions, refer to the link below. http://easyweb.easynet.co.uk/~mrmeanie/quatern/quatern.htm |
||||
|
|