Chong Jiayi's Bolt3D engine




Viewer source Tutorial
This tutorial will take you through the source code of viewer.exe. For all of you who find it confusing... pls don't feel that way! All you need to do is to look at the contents of viewerdlg.cpp which contains all code needed for a bolt3d app. The rest of the files are just generated by microsoft's appwizard. You needn't worry about them. Ok, let's get started.
Look at the code in the

void CViewerDlg::OnLButtonDown(UINT nFlags, CPoint point)

handler.
What it does is that when the mouse is clicked, the program starts rendering the objects.

Firstly, the image buffer is created:

::inibufferCPP(currentdc,1,(int)(rect.Width()),(int)(rect.Height()));

Here, we are creating a sweep object. Thus, we need to initialize the 2D point array:

btfvertex sweepvertex[7];
sweepvertex[0].x = 0;
sweepvertex[0].y = .5 ;
sweepvertex[0].z = 0;
sweepvertex[1].x = .3;
sweepvertex[1].y = .2;
sweepvertex[1].z = 0;
sweepvertex[2].x = .7;
sweepvertex[2].y = -0.5;
sweepvertex[2].z = 0;
sweepvertex[3].x = 0.9;
sweepvertex[3].y = 0.3;//-0.1;
sweepvertex[3].z = 0;
sweepvertex[4].x = 0.4;
sweepvertex[4].y = -0.3;
sweepvertex[4].z = 0;
sweepvertex[5].x = 0.2;
sweepvertex[5].y = -1.9;
sweepvertex[5].z = 0;
sweepvertex[6].x = 0;
sweepvertex[6].y = -2.2;
sweepvertex[6].z = 0;

Then we create the sweep object:

::CreateSweep(RGB(255, 126, 27), 1, &sweepvertex[0], 7);

Of course, you can change it to any other object you want like a sphere or cone. There will be no need to initialize the point array. Your code will then be:

::CreateSphere(RGB(255,0,0),1);

Read bolt3d.doc for more info.
After the object is created, set the light source:

//set light source
::setlightCPP(20,60,-220);

You can then map a texture to the object by calling:
::CreateTexture(currentdc,310,190,"c:\\windows\\viewtest.bmp",TRUE);
::MapTexturetoObject(0,1,1,0,1.2,1.2);

Read my updated questions and answers on my web page for more info.
The program then enters into a loop to display an animation of the sweep object.
In the loop, the object is transformed:

::SelectObj(0); //object 1, index starts from 0
::inittransCPP();
::scaleobjCPP(90, 130, 90);
::rotateCPP(angx, angy, angz);
::translateCPP(0, - 20, 150);
::ApplyTransform();

The viewer is set:

::setTHEviewer(0,0,vtz,0,0,0);

Then, blt the image buffer to screen by calling:

::RenderAll(currentdc);

OR

::RenderObjects();
::CopytoScreen(currentdc);

(This code is used in conjunction with particle systems.)



Continue to visit this page for I'll answer more of your questions on the engine soon
Back to Main Page... 1