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:)

x Includes.zip
x Libraries.zip
x 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)).

x BaseCode.zip (Win32 application, includes project file)

BaseCode Code Listing


x App.cpp, Web Version
x App.h, Web Version
x Config.h, Web Version
x Controller.cpp, Web Version
x Controller.h, Web Version
x Engine.cpp, Web Version
x Engine.h, Web Version
x Main.cpp, Web Version
x Main.h, Web Version
xAssets
xx TextureColor.ps, Web Version
xx TextureColor.vs, Web Version

Total lines of code: 954

x BaseCodeConsole.zip (Console application, includes project file)

BaseCodeConsole Code Listing


x App.cpp, Web Version
x App.h, Web Version
x Config.h, Web Version
x Engine.cpp, Web Version
x Engine.h, Web Version
x Main.cpp, Web Version
x Main.h, Web Version

Total lines of code: 513

x Engine.zip

Engine Code Listing


xAudio
xx AudioDevice.cpp, Web Version
xx AudioDevice.h, Web Version
xx WaveFile.cpp, Web Version
xx WaveFile.h, Web Version
xx WaveFileReader.cpp, Web Version
xx WaveFileReader.h, Web Version
xComplex Mesh
xx ComplexMesh.cpp, Web Version
xx ComplexMesh.h, Web Version
xx ComplexMesh.inl, Web Version
xx FullEdge.cpp, Web Version
xx FullEdge.h, Web Version
xx Triangle.cpp, Web Version
xx Triangle.h, Web Version
xx Vertex.cpp, Web Version
xx Vertex.h, Web Version
xCore
xx Asserts.h, Web Version
xx ClassList.h, Web Version
xx Compression.cpp, Web Version
xx Compression.h, Web Version
xx ExternalFiles.h, Web Version
xx Grid.cpp, Web Version
xx Grid.h, Web Version
xx InputDataStream.cpp, Web Version
xx InputDataStream.h, Web Version
xx KeyDefs.h, Web Version
xx MultiGrid.cpp, Web Version
xx MultiGrid.h, Web Version
xx OutputDataStream.cpp, Web Version
xx OutputDataStream.h, Web Version
xx Stdhdr.cpp, Web Version
xx Stdhdr.h, Web Version
xx String.cpp, Web Version
xx String.h, Web Version
xx UnicodeString.cpp, Web Version
xx UnicodeString.h, Web Version
xx Vector.cpp, Web Version
xx Vector.h, Web Version
xD3D9 Objects
xx D3D9Font.cpp, Web Version
xx D3D9Font.h, Web Version
xx D3D9PersistentMesh.cpp, Web Version
xx D3D9PersistentMesh.h, Web Version
xx D3D9PixelShader.cpp, Web Version
xx D3D9PixelShader.h, Web Version
xx D3D9Primitives.cpp, Web Version
xx D3D9Primitives.h, Web Version
xx D3D9RenderTargetSurface.cpp, Web Version
xx D3D9RenderTargetSurface.h, Web Version
xx D3D9RenderTargetTexture.cpp, Web Version
xx D3D9RenderTargetTexture.h, Web Version
xx D3D9Texture.cpp, Web Version
xx D3D9Texture.h, Web Version
xx D3D9VertexDeclaration.cpp, Web Version
xx D3D9VertexDeclaration.h, Web Version
xx D3D9VertexShader.cpp, Web Version
xx D3D9VertexShader.h, Web Version
xx GraphicsAsset.h, Web Version
xGraphics Devices
xx D3D9GraphicsDevice.cpp, Web Version
xx D3D9GraphicsDevice.h, Web Version
xx GraphicsDevice.cpp, Web Version
xx GraphicsDevice.h, Web Version
xGraphics Objects
xx Bitmap.cpp, Web Version
xx Bitmap.h, Web Version
xx Camera.cpp, Web Version
xx Camera.h, Web Version
xx KDTree3.cpp, Web Version
xx KDTree3.h, Web Version
xx KDTreeN.cpp, Web Version
xx KDTreeN.h, Web Version
xx MatrixController.cpp, Web Version
xx MatrixController.h, Web Version
xx MeshBVH.cpp, Web Version
xx MeshBVH.h, Web Version
xx MeshDistance.cpp, Web Version
xx MeshDistance.h, Web Version
xx MeshVertex.cpp, Web Version
xx MeshVertex.h, Web Version
xx PointSet.cpp, Web Version
xx PointSet.h, Web Version
xx PrimitiveRender.cpp, Web Version
xx PrimitiveRender.h, Web Version
xx RayIntersector.h, Web Version
xx RayIntersectorBruteForce.cpp, Web Version
xx RayIntersectorBruteForce.h, Web Version
xx RayIntersectorKDTree.cpp, Web Version
xx RayIntersectorKDTree.h, Web Version
xMachineLearning
xx BinaryClassifier.h, Web Version
xx BinaryClassifierAdaBoost.h, Web Version
xx BinaryClassifierBagged.h, Web Version
xx BinaryClassifierDecisionTree.h, Web Version
xx BinaryClassifierLogisticRegression.h, Web Version
xx BinaryClassifierMulticlass.h, Web Version
xx BinaryClassifierNaiveBayes.h, Web Version
xx BinaryClassifierSVM.h, Web Version
xx ClassifierDatasetTransformer.h, Web Version
xx ClassifierDatasetTransformerPCA.h, Web Version
xx MulticlassClassifier.h, Web Version
xx MulticlassClassifierAdaBoostM1.h, Web Version
xx MulticlassClassifierDecisionTree.h, Web Version
xx MulticlassClassifierGenerator.h, Web Version
xx MulticlassClassifierNearestNeighborANN.h, Web Version
xx MulticlassClassifierNearestNeighborBruteForce.h, Web Version
xx MulticlassClassifierOneVsAll.h, Web Version
xx MulticlassClassifierPairwiseCoupling.h, Web Version
xx RegressionLearner.h, Web Version
xx RegressionLearnerBagged.h, Web Version
xx RegressionLearnerDecisionTree.h, Web Version
xx RegressionLearnerNearestNeighbor.h, Web Version
xMath
xx BayesNet.cpp, Web Version
xx BayesNet.h, Web Version
xx BipartiteMatcher.cpp, Web Version
xx BipartiteMatcher.h, Web Version
xx ClusteringEvaluationMetric.cpp, Web Version
xx ClusteringEvaluationMetric.h, Web Version
xx DenseMatrix.cpp, Web Version
xx DenseMatrix.h, Web Version
xx DirectedGraph.h, Web Version
xx Distance.cpp, Web Version
xx Distance.h, Web Version
xx FourierTransform.cpp, Web Version
xx Gaussian1D.cpp, Web Version
xx Gaussian1D.h, Web Version
xx Graph.cpp, Web Version
xx Graph.h, Web Version
xx GraphicalModel.cpp, Web Version
xx GraphicalModel.h, Web Version
xx Intersect.cpp, Web Version
xx Intersect.h, Web Version
xx KMeansClustering.h, Web Version
xx KMeansClusteringFloat.h, Web Version
xx KMeansClusteringKDTree.cpp, Web Version
xx KMeansClusteringKDTree.h, Web Version
xx Line3D.cpp, Web Version
xx Line3D.h, Web Version
xx LinearSolver.cpp, Web Version
xx LinearSolver.h, Web Version
xx LineSegment2D.cpp, Web Version
xx LineSegment2D.h, Web Version
xx LineSegment3D.cpp, Web Version
xx LineSegment3D.h, Web Version
xx Matrix4.cpp, Web Version
xx Matrix4.h, Web Version
xx MixtureOfGaussians.h, Web Version
xx PCA.cpp, Web Version
xx PCA.h, Web Version
xx Plane.cpp, Web Version
xx Plane.h, Web Version
xx RandomNumbers.h, Web Version
xx Ray3D.cpp, Web Version
xx Ray3D.h, Web Version
xx Rectangle2f.inl, Web Version
xx Rectangle2i.inl, Web Version
xx Rectangle3f.inl, Web Version
xx RGBColor.cpp, Web Version
xx RGBColor.h, Web Version
xx SpaceVector.cpp, Web Version
xx SpaceVector.h, Web Version
xx SparseMatrix.cpp, Web Version
xx SparseMatrix.h, Web Version
xx SpectralClustering.cpp, Web Version
xx SpectralClustering.h, Web Version
xx TriangleIntersection.cpp, Web Version
xx Vec2f.inl, Web Version
xx Vec2i.inl, Web Version
xx Vec3f.inl, Web Version
xx Vec3i.inl, Web Version
xx Vec4f.inl, Web Version
xx VecNf.inl, Web Version
xMultithreading
xx Mutex.h, Web Version
xx TaskList.h, Web Version
xx Thread.cpp, Web Version
xx Thread.h, Web Version
xx ThreadPool.cpp, Web Version
xx ThreadPool.h, Web Version
xx WorkerThread.cpp, Web Version
xx WorkerThread.h, Web Version
xNetworking
xx Pipe.cpp, Web Version
xx Pipe.h, Web Version
xSimple Mesh
xx BaseMesh.cpp, Web Version
xx BaseMesh.h, Web Version
xx BaseMeshBounding.cpp, Web Version
xx BaseMeshFiles.cpp, Web Version
xx BaseMeshIndexing.cpp, Web Version
xx BaseMeshMemory.cpp, Web Version
xx BaseMeshShapes.cpp, Web Version
xx BaseMeshSplitting.cpp, Web Version
xx BaseMeshVertexModifiers.cpp, Web Version
xx D3D10Mesh.cpp, Web Version
xx D3D10Mesh.h, Web Version
xx D3D9Mesh.cpp, Web Version
xx D3D9Mesh.h, Web Version
xx Mesh.cpp, Web Version
xx Mesh.h, Web Version
xUtility
xx AudioCapture.cpp, Web Version
xx AudioCapture.h, Web Version
xx ColorGenerator.cpp, Web Version
xx ColorGenerator.h, Web Version
xx Console.cpp, Web Version
xx Console.h, Web Version
xx DialogBoxes.cpp, Web Version
xx DialogBoxes.h, Web Version
xx DialogInterface.cpp, Web Version
xx DialogInterface.h, Web Version
xx Directory.cpp, Web Version
xx Directory.h, Web Version
xx FileCollection.cpp, Web Version
xx FileCollection.h, Web Version
xx FrameTimer.cpp, Web Version
xx FrameTimer.h, Web Version
xx ImageCompressor.h, Web Version
xx ImageCompressorBlockPalette.cpp, Web Version
xx ImageCompressorJPEG.cpp, Web Version
xx ImageCompressorJPEG2000.cpp, Web Version
xx Indicator.cpp, Web Version
xx Indicator.h, Web Version
xx MenuInterface.cpp, Web Version
xx MenuInterface.h, Web Version
xx MeshSampler.cpp, Web Version
xx MeshSampler.h, Web Version
xx MovieExporter.cpp, Web Version
xx MovieExporter.h, Web Version
xx Palette.cpp, Web Version
xx Palette.h, Web Version
xx ParameterFile.cpp, Web Version
xx ParameterFile.h, Web Version
xx Profiler.cpp, Web Version
xx Profiler.h, Web Version
xx Stemmer.cpp, Web Version
xx Stemmer.h, Web Version
xx UVAtlas.cpp, Web Version
xx UVAtlas.h, Web Version
xx VideoCompressor.cpp, Web Version
xx VideoCompressor.h, Web Version
xx WindowsTasks.cpp, Web Version
xx WindowsTasks.h, Web Version
xx XMLFile.cpp, Web Version
xx XMLFile.h, Web Version
xx XMLNode.cpp, Web Version
xx XMLNode.h, Web Version
xWindows Controller
xx ApplicationWindow.cpp, Web Version
xx ApplicationWindow.h, Web Version
xx EventHandler.cpp, Web Version
xx EventHandler.h, Web Version
xx InputManager.cpp, Web Version
xx InputManager.h, Web Version
xx WinMain.cpp, Web Version

Total lines of code: 43556