Matt's Source Code Portal

Home About Links Problems Contact

This is a collection of examples about using the BaseCode. To run these examples, get the BaseCode here, and replace the MainControl source and header file for each example with the one provided. If anything other files are needed, it will be specified under the example description.

General Examples

These examples should all run under DirectX, OpenGL or software (although software will not render textures, it will still compile and execute fine.) A project file that can easily switch between any of the four examples below (see Main.h for how to switch) and already contains all the necessary source, texture, and object files can be gotten below.

x BaseCodeExamples.zip

Using Meshes and Shapes

This demonstrates loading a variety of simple geometric shapes and rendering them in a rotating ring.

x MainControlShapes.h, Web Version
x MainControlShapes.cpp, Web Version

Shapes Example

Loading Textures

This demonstrates loading a variety of textures on some geometric shapes and rendering them in a rotating ring. It uses 4 textures, which can be gotten here.

x MainControlTextures.h, Web Version
x MainControlTextures.cpp, Web Version

Textures Example

Obj File Loading and Mesh Splitting

This demonstrates loading obj files, and performing mesh splitting operations, where a mesh is broken into two meshes according to an arbitrary function that defines two regions in space. It needs two obj files, bunny and feilne, which can be gotten here or on the Links page (along with several other obj files.)

x MainControlMeshes.h, Web Version
x MainControlMeshes.cpp, Web Version

Meshes Example

The Indicator Class and Using Multiple Cameras

This demonstrates using a simple class to render spheres or cylinders in only a few lines of code (for pointing out certain vectors in the scene, for example.) It also demonstrates using and switching between two (or more) cameras, and uses the Indicator class to render the other camera. Finally, it shows how to capture the screen to a file.

x MainControlCamera.h, Web Version
x MainControlCamera.cpp, Web Version

Camera Example

Video Capture

To enable video capture, just go into God.cpp and set CapturingScreen to true (in any project.) The file will be outputted to whatever string is in AVIFileName. When you run your code, it will give you your choice of a list of compressors currently on your computer (I usually use DivX.) Then when you press C, it will begin capturing the scene into the file. Works best in full screen mode. Here's a sample output from an automatic Rubik's Cube solving and rendering program I wrote a while back:

Cube Example
Click here to download the video of the cube being scrambled and solved (23 MB.)
Click here to download another video (18 MB) I did for my Astronomy 1 class showing a near-stellar collision between our sun and another star.

Using Multiple Control Classes (in AppInterface)

AppInterface exists to make it easy to pass rendering focus between very different elements of the application, such as a title screen and the 3D-intensive main window. To demonstate how to do this, the four examples above can be easily toggled between while the application is running in the following project file. Press 1, 2, 3, or 4 at any time to switch between the four examples.

x BaseCodeExamplesApp.zip

DirectX Only Examples

These examples show DirectX-only features. There are several other DirectX features, such as mesh simplification, and N-Patch ehancement, for which there aren't examples yet. I apologize if the examples aren't very well organized; I intend to rewrite them eventually.

X-File Loading

Loading and rendering X-Files is a relatively simple task, using the XFileRenderer class. This example demonstrates this class; however, I can't use any really good DirectX files (as they are all copyright) so I have to make do with ones I made myself (a king and queen Chess piece, and a model of my old dorm, Hunt, at NCSSM.) The XFiles used and their associated textures follow the code, as well as a complete project file with everything included.

x MainControlXFile.h, Web Version
x MainControlXFile.cpp, Web Version
x XFileResources.zip
x BaseCodeDXExample.zip

XFile Example

Video Textures

This demonstrates using video textures. They are relatively straightforward, but need a few variables set. First, USE_VIDEO_TEXTURES must be #defined in Main.h. Second, DShow.lib must be linked with the project. Third, SleepBetweenFrames must be set to some reasonable number (like 30,) so that the application will let the video decoder have some time to decode the video. Once that is set up, VideoTexture can be used much like a normal texture in 3-4 lines of code. A project that automatically does all this (and includes a test avi file) is given.

x MainControlVideo.h, Web Version
x MainControlVideo.cpp, Web Version
x BaseCodeVideo.zip

Video Example


last updated: May 13th, 2005   © 2005 by Matthew Fisher