BaseCode
All the projects I write by myself use a common framework that I've been developing since I started programming in C++ in high school. Unfortunately, since it's been developed over such a long time it was never completely planned out and has a wide range of coding styles and consistency. One of the main reasons I code this way is that I tend to work on graphics projects, which have a significant amount of "overhead" code and it is much simpler to base new projects off an existing project than start a new one. This way, all my libraries, headers, etc. are already setup each time I start a project. Over time I have been updating all my old code to have a more consistent and professional style but unfortunately I haven't completed this yet.
External Libraries
External libraries are included or excluded by #define's in the file Config.h. The external libraries I work with currently are:
Direct3D 9, 10, and 11 - 3D graphics APIs for Windows.OpenGL - A cross-platform 3D graphics API.
DirectSound - An audio API for Windows.
libpng - A library to handle reading from and writing to PNG files, a popular lossless image format.
ZLib - A library for losslessly compressing and decompressing a stream of bytes. Required by libpng.
ANN (Approximate Nearest Neighbor) - Approximate nearest neighbor library for reasonably high dimensional spaces.
SDL (Simple Directmedia Layer) - I use this library for loading and saving to all file formats that are not PNG.
TAUCS - A library of sparse linear solvers.
You can get all of the DirectX libraries (Direct3D and DirectSound) in the DirectX SDK. This SDK also has excellent documentation and library samples, and the demos are useful to look at.
Development
I have been using Microsoft Visual Studio for all my C++ development since MSVC++ 5.0. Currently all my code uses Microsoft Visual Studio Express 2010 which you can download from Microsoft for free. I use Subversion for version control. TortoiseSVN is my favorite Win32 shell interface to Subversion.
Getting Things Working
The BaseCode project and associated code are given below. All code that is shared between all projects goes in the Engine folder, which must be on your include path. You can get all the other libraries and necessary includes from their respective sites above, or just disable them in Config.h. However for simplicity I have also included my libraries, includes, and DLL directories here (excludes the DirectX headers:)
Includes.zip
Libraries.zip
DLLs.zip
You will need to add the libraries and includes to your Visual Studio "VC++ directories" path; in VS2008 go to Tools->Options->Project and Solutions->VC++ directories. Change "show directories for:" to "Include files" and add the folder inside Includes.zip, and then change it to "Library files" and add the folder inside Libraries.zip. In VS2010 you will find these under Project->Properties->VC++ directories. You will need to put the DLLs somewhere that is accessible on your system path. You could either dump them into C:\Windows\System32 or put them in your own folder and add this folder to your path; this page describes how to change your system path.
If everything works you should see a window with a sphere and the frames-per-second
counter in the upper left:
Features
This is a summary of the more useful classes:
General
Vector - Wrapper that encapsulates std::vector functionality and adds a few more useful functions.Grid - The 2D or "matrix" analog of a 1D std::vector.
String - Wrapper that encapsulates std::string functionality and adds a few more useful functions.
InputDataStream - Exactly like an ifstream, but for binary data.
OutputDataStream - Exactly like an ofstream, but for binary data.
Math
DenseMatrix - A dense matrix of real numbers.SparseMatrix - A matrix of real numbers where most entries are 0.
Vec2f, Vec3f, Vec4f - 2D, 3D, and 4D vectors of real numbers.
Rectangle2f, Rectangle3f - 2D and 3D rectangular regions.
Matrix4 - A 4x4 matrix and associated transforms often used in graphics.
LinearSolver - Abstract class for solving large linear systems. Currently supports (bi-)conjugate gradient descent and the TAUCS library.
KMeansClustering - A templated K-means clustering implementation. Templated on the base entity type and a metric defined over this entity.
Graphics
BaseMesh - A mesh represented by a list of vertices and faces. Useful for fast rendering. Mesh is the name of the software implementation, while D3D9Mesh and D3D10Mesh are designed to live in video memory.ComplexMesh - An edge-based mesh with a large amount of connectivity information. Used for advanced operations like subdivision, but overkill for just rendering.
GraphicsDevice - Wrapper around 3D APIs. Currently supports OpenGL, D3D9, D3D10, and software.
Bitmap - A 2D image. Supports loading from and saving to a variety of formats.
Texture - An abstract texture class on a GraphicsDevice. D3D9Texture, D3D10Texture, and OpenGLTexture are graphics API specific implementations.
KDTree - A KDTree for querying large sets of points in an arbitrary number of dimensions.
Machine Learning
BinaryClassifier - An abstract class for training a classifier that can separate an input element into two categories. Base learners exist for decision trees, logistic regression, nearest neighbor, naive Bayes, and support vector machines. Meta-learners include AdaBoost and bagging.MulticlassClassifier - An abstract class for training a classifier that can separate an input element into any number of categories. Has many of the same learners as BinaryClassifier, and additional meta-learners include one vs. all and pairwise coupling.
RegressionLearner - An abstract class for training a classifier that can separate an input element into a set of arbitrary real numbers (rather than just a finite set of categories.)
Utility
AudioDevice - Handles loading and playing multiple WAV files in DirectSound.Pipe - A connection between two programs (possibly on different computers.)
Directory - Reads the list of files and subdirectories within a directory.
MenuInterface - Creates and modifies the menu bar in the application.
FrameTimer - Maintains a frames-per-second counter.
ParameterFile - Loads a set of parameters from a file. I generally use these instead of command line arguments.
Color Generator - Generates N colors that are visually distinct (much better results than RGBColor(rand() & 255, rand() & 255, rand() & 255)).

BaseCode Code Listing














Total lines of code: 954

BaseCodeConsole Code Listing







Total lines of code: 513

Engine Code Listing























































































































































































































































































































































































































































































































Total lines of code: 43556