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
App.cpp, Web Version
App.h, Web Version
Config.h, Web Version
Controller.cpp, Web Version
Controller.h, Web Version
Engine.cpp, Web Version
Engine.h, Web Version
Main.cpp, Web Version
Main.h, Web Version
Assets
TextureColor.ps, Web Version
TextureColor.vs, Web Version
Total lines of code: 954
BaseCodeConsole Code Listing
App.cpp, Web Version
App.h, Web Version
Config.h, Web Version
Engine.cpp, Web Version
Engine.h, Web Version
Main.cpp, Web Version
Main.h, Web Version
Total lines of code: 513
Engine Code Listing
Audio
AudioDevice.cpp, Web Version
AudioDevice.h, Web Version
WaveFile.cpp, Web Version
WaveFile.h, Web Version
WaveFileReader.cpp, Web Version
WaveFileReader.h, Web Version
Complex Mesh
ComplexMesh.cpp, Web Version
ComplexMesh.h, Web Version
ComplexMesh.inl, Web Version
FullEdge.cpp, Web Version
FullEdge.h, Web Version
Triangle.cpp, Web Version
Triangle.h, Web Version
Vertex.cpp, Web Version
Vertex.h, Web Version
Core
Asserts.h, Web Version
ClassList.h, Web Version
Compression.cpp, Web Version
Compression.h, Web Version
ExternalFiles.h, Web Version
Grid.cpp, Web Version
Grid.h, Web Version
InputDataStream.cpp, Web Version
InputDataStream.h, Web Version
KeyDefs.h, Web Version
MultiGrid.cpp, Web Version
MultiGrid.h, Web Version
OutputDataStream.cpp, Web Version
OutputDataStream.h, Web Version
Stdhdr.cpp, Web Version
Stdhdr.h, Web Version
String.cpp, Web Version
String.h, Web Version
UnicodeString.cpp, Web Version
UnicodeString.h, Web Version
Vector.cpp, Web Version
Vector.h, Web Version
D3D9 Objects
D3D9Font.cpp, Web Version
D3D9Font.h, Web Version
D3D9PersistentMesh.cpp, Web Version
D3D9PersistentMesh.h, Web Version
D3D9PixelShader.cpp, Web Version
D3D9PixelShader.h, Web Version
D3D9Primitives.cpp, Web Version
D3D9Primitives.h, Web Version
D3D9RenderTargetSurface.cpp, Web Version
D3D9RenderTargetSurface.h, Web Version
D3D9RenderTargetTexture.cpp, Web Version
D3D9RenderTargetTexture.h, Web Version
D3D9Texture.cpp, Web Version
D3D9Texture.h, Web Version
D3D9VertexDeclaration.cpp, Web Version
D3D9VertexDeclaration.h, Web Version
D3D9VertexShader.cpp, Web Version
D3D9VertexShader.h, Web Version
GraphicsAsset.h, Web Version
Graphics Devices
D3D9GraphicsDevice.cpp, Web Version
D3D9GraphicsDevice.h, Web Version
GraphicsDevice.cpp, Web Version
GraphicsDevice.h, Web Version
Graphics Objects
Bitmap.cpp, Web Version
Bitmap.h, Web Version
Camera.cpp, Web Version
Camera.h, Web Version
KDTree3.cpp, Web Version
KDTree3.h, Web Version
KDTreeN.cpp, Web Version
KDTreeN.h, Web Version
MatrixController.cpp, Web Version
MatrixController.h, Web Version
MeshBVH.cpp, Web Version
MeshBVH.h, Web Version
MeshDistance.cpp, Web Version
MeshDistance.h, Web Version
MeshVertex.cpp, Web Version
MeshVertex.h, Web Version
PointSet.cpp, Web Version
PointSet.h, Web Version
PrimitiveRender.cpp, Web Version
PrimitiveRender.h, Web Version
RayIntersector.h, Web Version
RayIntersectorBruteForce.cpp, Web Version
RayIntersectorBruteForce.h, Web Version
RayIntersectorKDTree.cpp, Web Version
RayIntersectorKDTree.h, Web Version
MachineLearning
BinaryClassifier.h, Web Version
BinaryClassifierAdaBoost.h, Web Version
BinaryClassifierBagged.h, Web Version
BinaryClassifierDecisionTree.h, Web Version
BinaryClassifierLogisticRegression.h, Web Version
BinaryClassifierMulticlass.h, Web Version
BinaryClassifierNaiveBayes.h, Web Version
BinaryClassifierSVM.h, Web Version
ClassifierDatasetTransformer.h, Web Version
ClassifierDatasetTransformerPCA.h, Web Version
MulticlassClassifier.h, Web Version
MulticlassClassifierAdaBoostM1.h, Web Version
MulticlassClassifierDecisionTree.h, Web Version
MulticlassClassifierGenerator.h, Web Version
MulticlassClassifierNearestNeighborANN.h, Web Version
MulticlassClassifierNearestNeighborBruteForce.h, Web Version
MulticlassClassifierOneVsAll.h, Web Version
MulticlassClassifierPairwiseCoupling.h, Web Version
RegressionLearner.h, Web Version
RegressionLearnerBagged.h, Web Version
RegressionLearnerDecisionTree.h, Web Version
RegressionLearnerNearestNeighbor.h, Web Version
Math
BayesNet.cpp, Web Version
BayesNet.h, Web Version
BipartiteMatcher.cpp, Web Version
BipartiteMatcher.h, Web Version
ClusteringEvaluationMetric.cpp, Web Version
ClusteringEvaluationMetric.h, Web Version
DenseMatrix.cpp, Web Version
DenseMatrix.h, Web Version
DirectedGraph.h, Web Version
Distance.cpp, Web Version
Distance.h, Web Version
FourierTransform.cpp, Web Version
Gaussian1D.cpp, Web Version
Gaussian1D.h, Web Version
Graph.cpp, Web Version
Graph.h, Web Version
GraphicalModel.cpp, Web Version
GraphicalModel.h, Web Version
Intersect.cpp, Web Version
Intersect.h, Web Version
KMeansClustering.h, Web Version
KMeansClusteringFloat.h, Web Version
KMeansClusteringKDTree.cpp, Web Version
KMeansClusteringKDTree.h, Web Version
Line3D.cpp, Web Version
Line3D.h, Web Version
LinearSolver.cpp, Web Version
LinearSolver.h, Web Version
LineSegment2D.cpp, Web Version
LineSegment2D.h, Web Version
LineSegment3D.cpp, Web Version
LineSegment3D.h, Web Version
Matrix4.cpp, Web Version
Matrix4.h, Web Version
MixtureOfGaussians.h, Web Version
PCA.cpp, Web Version
PCA.h, Web Version
Plane.cpp, Web Version
Plane.h, Web Version
RandomNumbers.h, Web Version
Ray3D.cpp, Web Version
Ray3D.h, Web Version
Rectangle2f.inl, Web Version
Rectangle2i.inl, Web Version
Rectangle3f.inl, Web Version
RGBColor.cpp, Web Version
RGBColor.h, Web Version
SpaceVector.cpp, Web Version
SpaceVector.h, Web Version
SparseMatrix.cpp, Web Version
SparseMatrix.h, Web Version
SpectralClustering.cpp, Web Version
SpectralClustering.h, Web Version
TriangleIntersection.cpp, Web Version
Vec2f.inl, Web Version
Vec2i.inl, Web Version
Vec3f.inl, Web Version
Vec3i.inl, Web Version
Vec4f.inl, Web Version
VecNf.inl, Web Version
Multithreading
Mutex.h, Web Version
TaskList.h, Web Version
Thread.cpp, Web Version
Thread.h, Web Version
ThreadPool.cpp, Web Version
ThreadPool.h, Web Version
WorkerThread.cpp, Web Version
WorkerThread.h, Web Version
Networking
Pipe.cpp, Web Version
Pipe.h, Web Version
Simple Mesh
BaseMesh.cpp, Web Version
BaseMesh.h, Web Version
BaseMeshBounding.cpp, Web Version
BaseMeshFiles.cpp, Web Version
BaseMeshIndexing.cpp, Web Version
BaseMeshMemory.cpp, Web Version
BaseMeshShapes.cpp, Web Version
BaseMeshSplitting.cpp, Web Version
BaseMeshVertexModifiers.cpp, Web Version
D3D10Mesh.cpp, Web Version
D3D10Mesh.h, Web Version
D3D9Mesh.cpp, Web Version
D3D9Mesh.h, Web Version
Mesh.cpp, Web Version
Mesh.h, Web Version
Utility
AudioCapture.cpp, Web Version
AudioCapture.h, Web Version
ColorGenerator.cpp, Web Version
ColorGenerator.h, Web Version
Console.cpp, Web Version
Console.h, Web Version
DialogBoxes.cpp, Web Version
DialogBoxes.h, Web Version
DialogInterface.cpp, Web Version
DialogInterface.h, Web Version
Directory.cpp, Web Version
Directory.h, Web Version
FileCollection.cpp, Web Version
FileCollection.h, Web Version
FrameTimer.cpp, Web Version
FrameTimer.h, Web Version
ImageCompressor.h, Web Version
ImageCompressorBlockPalette.cpp, Web Version
ImageCompressorJPEG.cpp, Web Version
ImageCompressorJPEG2000.cpp, Web Version
Indicator.cpp, Web Version
Indicator.h, Web Version
MenuInterface.cpp, Web Version
MenuInterface.h, Web Version
MeshSampler.cpp, Web Version
MeshSampler.h, Web Version
MovieExporter.cpp, Web Version
MovieExporter.h, Web Version
Palette.cpp, Web Version
Palette.h, Web Version
ParameterFile.cpp, Web Version
ParameterFile.h, Web Version
Profiler.cpp, Web Version
Profiler.h, Web Version
Stemmer.cpp, Web Version
Stemmer.h, Web Version
UVAtlas.cpp, Web Version
UVAtlas.h, Web Version
VideoCompressor.cpp, Web Version
VideoCompressor.h, Web Version
WindowsTasks.cpp, Web Version
WindowsTasks.h, Web Version
XMLFile.cpp, Web Version
XMLFile.h, Web Version
XMLNode.cpp, Web Version
XMLNode.h, Web Version
Windows Controller
ApplicationWindow.cpp, Web Version
ApplicationWindow.h, Web Version
EventHandler.cpp, Web Version
EventHandler.h, Web Version
InputManager.cpp, Web Version
InputManager.h, Web Version
WinMain.cpp, Web Version
Total lines of code: 43556