In application development 3D Objects can be displayed with 2D projection methods by using 2D / 3D mathematical calculations . That may be hard and needs much coding to display them. You can use OpenGL and DirectX with their own 3D commands to display them. You can also use and port a 3D Engine SDK. Simply, In C++ Builder 3D Objects can be easily displayed in the Viewport3D component. You can change their shape, position, color, materials etc. on design time or on runtime. You can add Texture Materials or Light Materials on them. You can group them by using Dummy objects. You can use all of these without any graphical engine API/SDK/DLL or Lib. You just need to drag one of the 3D objects listed below in to viewport, then you have windows applications which has 3D objects. Note that FireMonkey supports GPU usage on runtime. All basic 3d objects can be be found in 3D Shapes category of Tool Palette.
Table of Contents
Creating a 3D Object on Runtime
Simply, you can create these listed basic 3D shapes by dragging them into ViewPort3D component, you can also arrange their position, rotation, size and other properties in your application UI design. You can also create them on run time. Parent object must be given, it can be a ViewPort3D, Dummy object or other 3D Objects. here is a TCube sample given below;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
TCube *cube; void __fastcall TForm1::Button1Click(TObject *Sender) { if(cube==NULL) { cube=new TCube(Viewport3D1); cube->Parent=Viewport3D1; } } void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { cube->Free(); // must be removed from the memory at the end } |
Here are some of them listed below.
TPlane
The TPlane is used in Viewport3D component, it is a class implements a 2D plane that can be placed on a 3D FireMonkey form, it represents a 2D plane that can be employed in a 3D form. Planes support 3D rotation and alignment. TPlane is a visual object that can be added from the Tool Palette.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Plane1->BeginUpdate(); Plane1->Width=10; Plane1->Height=10; Plane1->SubDivisionsHeight=10; Plane1->SubDivisionsWidth=10; Plane1->Position->X=0; Plane1->Position->Y=0; Plane1->Position->Z=0; Plane1->Rotation->X=0; Plane1->Rotation->Y=0; Plane1->Rotation->Z=0; Plane1->MaterialSource =TextureMaterialSource1; //MaterialSources should be defined or dragged Plane1->EndUpdate(); |
TDisk
The TDisk is used in Viewport3D component, it is a class implements a 3D flat disk shape that can be placed on a 3D FireMonkey form. TDisk is a visual object that can be added from the Tool Palette. To change the color or add texture to the disk, use the MaterialSource property. Set SubdivisionsAxes and SubdivisionsCap to specify how smooth the disk’s surface is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Disk1->BeginUpdate(); Disk1->Width=10; Disk1->Height=10; Disk1->SubDivisionsHeight=10; Disk1->SubDivisionsWidth=10; Disk1->Position->X=0; Disk1->Position->Y=0; Disk1->Position->Z=0; Disk1->Rotation->X=0; Disk1->Rotation->Y=0; Disk1->Rotation->Z=0; Disk1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Disk1->EndUpdate(); |
TCube
The TCube is used in Viewport3D component, it is a class implements a 3D cube shape, built on a 3D wireframe, that can be placed on a 3D FireMonkey form. TCube is a visual object that can be added from the Tool Palette. To change the color or add texture to the cube, use the MaterialSource property. Set SubdivisionsDepth, SubdivisionsHeight and SubdivisionsWidth to specify how smooth the cube’s surfaces are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Cube1->BeginUpdate(); Cube1->Width=10; Cube1->Height=10; Cube1->Depth=10; Cube1->SubDivisionsHeight=10; Cube1->SubDivisionsWidth=10; Cube1->Position->X=0; Cube1->Position->Y=0; Cube1->Position->Z=0; Cube1->Rotation->X=0; Cube1->Rotation->Y=0; Cube1->Rotation->Z=0; Cube1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Cube1->EndUpdate(); |
TRectangle3D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Rectangle3D1->BeginUpdate(); Rectangle3D1->Width=10; Rectangle3D1->Height=10; Rectangle3D1->Depth=10; Rectangle3D1->SubDivisionsHeight=10; Rectangle3D1->SubDivisionsWidth=10; Rectangle3D1->Position->X=0; Rectangle3D1->Position->Y=0; Rectangle3D1->Position->Z=0; Rectangle3D1->Rotation->X=0; Rectangle3D1->Rotation->Y=0; Rectangle3D1->Rotation->Z=0; Rectangle3D1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Rectangle3D1->EndUpdate(); |
The TRectangle3D is used in Viewport3D component, it represents a 3D rectangle, it is a class implements an extruded 3D shape under the form of a 3D rectangle that can be placed on a 3D FireMonkey form. TRectangle3D is a visual object that can be added from the Tool Palette.
TSphere
The TSphere is is used in Viewport3D component, it is a 3D sphere, a class implements a 3D sphere shape built on a 3D wireframe, that can be placed on a 3D FireMonkey form. TSphere is a visual object that can be added from the Tool Palette. To change the color or add texture to the sphere, use the MaterialSource property. Set SubdivisionsAxes and SubdivisionsHeight to specify how smooth the sphere’s surfaces are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Sphere1->BeginUpdate(); Sphere1->Width=10; Sphere1->Height=10; Sphere1->Depth=10; Sphere1->SubDivisionsHeight=10; Sphere1->SubDivisionsWidth=10; Sphere1->Position->X=0; Sphere1->Position->Y=0; Sphere1->Position->Z=0; Sphere1->Rotation->X=0; Sphere1->Rotation->Y=0; Sphere1->Rotation->Z=0; Sphere1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Sphere1->EndUpdate(); |
TCylinder
The TCylinder is is used in Viewport3D component, it is a 3D cylinder, a class implements a 3D cylinder shape built on a 3D wireframe, that can be placed on a 3D FireMonkey form. TCylinder is a visual object that can be added from the Tool Palette. To change the color or add texture to the sphere, use the MaterialSource property. Set SubdivisionsAxes and SubdivisionsHeight to specify how smooth the sphere’s surfaces are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Cylinder1->BeginUpdate(); Cylinder1->Width=10; Cylinder1->Height=10; Cylinder1->Depth=10; Cylinder1->SubDivisionsWidth=10; Cylinder1->Position->X=0; Cylinder1->Position->Y=0; Cylinder1->Position->Z=0; Cylinder1->Rotation->X=0; Cylinder1->Rotation->Y=0; Cylinder1->Rotation->Z=0; Cylinder1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Cylinder1->EndUpdate(); |
TEllipse3D
The TEllipse3D is used in Viewport3D component, it is a 3D ellipse, an elliptic cylinder, class implements an extruded 3D shape under the form of a 3D ellipse that can be placed on a 3D FireMonkey form. TEllipse3D is a visual object that can be added from the Tool Palette.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Ellipse3D1->BeginUpdate(); Ellipse3D1->Width=10; Ellipse3D1->Height=10; Ellipse3D1->Depth=10; Ellipse3D1->SubDivisionsHeight=10; Ellipse3D1->SubDivisionsWidth=10; Ellipse3D1->Position->X=0; Ellipse3D1->Position->Y=0; Ellipse3D1->Position->Z=0; Ellipse3D1->Rotation->X=0; Ellipse3D1->Rotation->Y=0; Ellipse3D1->Rotation->Z=0; Ellipse3D1->MaterialSource = LightMaterialSource1; //MaterialSources should be defined or dragged on to form Ellipse3D1->EndUpdate(); |
TCone
The TCone is used in Viewport3D component, represents a 3D cone, class implements a 3D cone shape, built on a 3D wireframe, that can be placed on a 3D FireMonkey form. TCone is a visual object that can be added from the Tool Palette. To change the color or add texture to the cone, use the MaterialSource property. Set SubdivisionsAxes, SubdivisionsCap and SubdivisionsHeight to specify how smooth the cone’s surfaces are.
TText3D
The TText3D is used in Viewport3D component, it represents a 3D rendered text, it is a class implements an extruded 3D shape under the form of a 3D text rendition, that can be placed on a 3D FireMonkey form. TText3D is a visual object that can be added from the Tool Palette.
All 3D objects under this 3D Shapes category can be found here