R3DEngine

R3DEngine stands for (imaginatively) Rob's 3D Engine. It's all part of my work towards my final year university project. By putting what I've done so far here, I hope to give others some ideas, and maybe receive some constructive criticism! The documentation so far consists only of this page, but I plan to do more complete documentation before too long.

Download the Source

The source *.h and *.cpp files are in zipped into a 25K file. You must first agree to the terms and conditions.

Using the Source

First put all the files into some directory. To access all the R3D classes, just include the file "R3DEngine.h". This contains #includes for all the other files. Also, you will need to add all the files to your project so that they are compiled. To get an idea of how the engine works, have a look at this example. The example renders a cylinder and some other shapes, and then rotates them all over the place before reporting the number of frames per second. A more complete example is the Traffic3D workspace.

The R3DEngine Classes

The R3DEngine provides a number of classes that work together to generate a 3D scene.

R3DfxHardware

This class encapsulates some of the functionality of the 3Dfx card. It is used mainly to initialise and shutdown the card. It's member functions include:

Other functions are present, but most shouldn't really be in the public interface of the class. In particular, the texture manipulation functions should be avoided as the R3DTexture class handles all this. At some point I will make these functions private and have friend functions in R3DTexture.

R3DVector

This class is used everywhere. It's my implementation of a vector, and includes various operators like += and -=. Not all of the operators are fully functional yet, particularly ^ which was supposed to return the angle between two vectors but doesn't work. The data members m_vx, m_vy, and m_vz can all be accessed publicly. Member functions include:

R3DVertex

This class encapsulates Glide's GrVertex structure. You shouldn't have to use it directly as the R3DShape derived classes all handle their own vertexes.

R3DShape

All drawable, transformable shapes are derived from this. It is a pure virtual class that defines an interface to provide RotateX/Y/Z functions, a Move(R3DVector &v) function, and a SetTexture(R3DTexture &t) function.

R3DTexture

Encapsulates the notion of a texture. So far only the texture information is present, I plan to add a choice of shading methods (Phong for shiny objects and Gouraud for dull objects). The member functions of note are:

R3DTriangle

Finally a real drawable object! This is a simple texture mapped triangle that can be rotated and moved. Triangles have the following member functions:

R3DRectangle

Made up from two triangles, but a little quicker to transform than two triangles would be. Used in almost the same way as a R3DTriangle.

R3DCuboid

A real 3D shape. This draws all the triangles necessary to make up a 6 sided shape.

R3DCylinder

This is a 10 sided cylinder shape.

R3DGroup

Use this to group R3DShapes together for translation and rotation.

R3DModel

This class is used to build models out of Triangles, Rectangles, Cuboids and Cylinders. The Triangles and Rectangles are aligned on a mesh of Vectors so that when a model is transformed only the vectors have to be actually transformed - the shapes are simply glued onto the mesh. This approach reduces the number of calculations. Models can be saved to disk and reloaded. Note that all the textures used currently have to be loaded in the same order for the correct textures to appear on the model when it is reloaded. In the future I plan to save the filenames of the textures with the models, instead of just the texture id number.

R3DCuboid mycube(v1, v2); // create a cuboid

mymodel.AddCuboid(mycube);

mycube.Move(R3DVector(10.f, 20.f, 0.f); // move to a new position

mymodel.AddCuboid(mycube); // adds a second cube in the new position

mymodel.Draw(); // draws the model (both cubes)

R3DCamera

This class encapsulates the notion of a camera that is positioned somewhere in the world co-ordinate system. When an object is Draw()n, it uses the global pointer R3DCAM to transform from world to screen co-ordinates. When R3DfxHardware::InitHardware() is called, a default camera is created. This camera is positioned at (320, 240, -640). In this way, objects at (0, 0, 0) appear in the top left of the screen, and (640, 480, 0) appear at the bottom right. The camera can be Moved just like an R3DShape. Other transformations are available:

R3DCalc

A calculator object that provides quick Sin and Cos functions. When R3DfxHardware::InitHardware() is called, an R3DCalc object is created which is pointed to by R3DCALC. The Cos() and Sin() functions take a floating point angle in degrees which is rounded down to the nearest degree.

 

I can be reached by email on [email protected]


[Home][3Dfx Programming]

Hosted by www.Geocities.ws

1