Building Direct3D Application from C++ Builder
This article just remind me to my final college comprehensive exam on year 2002 (tugas akhir/skripsi, see it in my personal biodata page). I was picked up a rarely caption titled DirectX game programming which never exists yet before on my campus in that time. Majority, many of final exams submited had titled around of databases applications and I was challanged to create something differents.
Basically, I was inspired from a popular game called Quake III Arena releases by Id software. So, I was purposed to create a 3rd person shooting game just like that one. I used the Borland C++ Builder 4 (BCB4) compiler since its powered by open wide library such as DirectX header files which was supported by microsoft.
What you need to create this kind of application is just more than BCB familiarly used up. But, there are lots of extras thing you should know, such:
1. Some knowledges about physics and science like matrix operations, vectors and cartezian triple point coordinates. See this explanation.
2. Skills about how to create meshes with 3DStudioMax (or others similar tools which could create a 3DS file format)
3. Skills about how to create plain pictures (skin textures) with image editor (or others similar tools which could create a BMP file format - I usually used Adobe Photoshop)
4. A converter tools named conv3ds.exe used to re-convert 3DS files into a standard Direct3D .x extension.
5. Direct3D C++ headers file named d3dapi.h. Just make a search on google.
Okay, first of all, you have to create a 3D object from tools (such 3DStudioMax) that can export the files into 3DS format (eg: from 3DStudioMax, save the file with name my_object.max then export it into name my_object.3ds). Convert the my_object.3ds file by conv3ds.exe until a new file created with name my_object.x.
Create a 256x256 pixel pictures from image editor and save it with name my_pic.bmp. This picture made to texturizing the my_object.x file later from the BCB4 editor so that the 3D object in application will looked wearing a "clothes".
Continued to the BCB4 compiler. There are lots of procedures to define the Direct3D application. But, I'll give you a short resume step by step how to make it done.
1. Include the d3dapi.h from the cpp unit file.
2. Create a Direct3D initialization to recognize the inherited objects from the header file.
// scene initialization
if (!scene)
{
scene=new TScene;
scene->Create();
}
// camera initialization
if (!camera)
{
camera=new TCamera;
camera->Create(Display->Handle);
scene->Add(camera);
camera->…
}
// lighting effect initialization
if (!light)
{
light=new TLight;
light->Create(D3DRMLIGHT_AMBIENT,color,color,color);
scene->Add(light);
camera->Add(light);
light->…
}
// load the my_object.x file
if (!map)
{
map=new T3DObject;
map->Load("my_object.x");
map->…
// and give it clothes
map->AddTexture("my_pic.bmp",D3DRMWRAP_FLAT,
0,0,0,
0,1,0,
0,0,1,
0,0,
0.05,0.05);
if (scene) scene->Add(map);
}
Application->OnIdle=&OnIdle;
3. Finally, add this syntax to show it on the form
void __fastcall TForm::OnIdle(TObject *Sender, bool &Done)
{
Done=False;
scene->Tick();
camera->ShowImage();
}
4. That's all.
Okay, what you will see below is just the screenshoot about my application named "Electraglide Zone".
The application packaged with bundled CD installation approximately sized about 250Mb. Perhaps you would like to try out and make a reviews?
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Post a Comment
Leave comments here...