3-D in digital platforms are 2D projection drawings of 3D objects. We can mathematically calculate a solid object, its position, its projection on our 2D screen, we can add colors on it, light effects, textures, camera, movements and some other techniques to show our 3D object as good as possible. This may take a lot of time to develop all 2D and 3D mathematical operations. In C++ Builder we can use OpenGL, DirectX with their own methods. If we are developing a simple 3D application, we can also use its own 3D components. In this post we will list these 3D components.
Table of Contents
Viewport3D
Viewport3D (TViewport3D) is a 3Dcomponent to display 3D objects in its space. TViewport3D implements IViewport3D methods to describe how a 3D object is seen. It is really simple and nice to develop some small 3D games or adding some 3D features in your applications. Viewport3D is a component that shows the view port of the camera or default view. You can arrange it’s position, Width and Height on any place of your form or you can use it in client view to do full screen. We can use viewport3D without a 3D Camera, it is using its own design camera view. If you want to use camera and want to see view from the view of that camera you must set its UseDesignCamera property to false from its properties or as below;
1 2 3 |
Viewport3D1->UseDesignCamera=false; |
You can update any objects in Viewport3D with BeginUpdate(), EndUpdate() methods as given below;
1 2 3 4 5 |
Viewport3D1->BeginUpdate(); // Move or set Objects, Cameras, Lights here Viewport3D1->EndUpdate(); |
This will update full 3D matrix of Viewport3D in one time. You can also change background color of this Viewport3D component like this;
1 2 3 |
Viewport3D1->Color=claBlack; |
Camera
Camera (TCamera) is a 3D component that used to define the scene perspective and projection of the objects in the scene to the viewport. Use Target to set the object to be watched. You can set its position and view. Camera component can be found in 3D Scenes section of Tools Palette in C++ Builder.
You can set camera X Y Z positions or Rotations, you can also increase them with a Timer to move your camera around your scene as below
1 2 3 4 5 6 7 8 9 10 11 |
Camera1->BeginUpdate(); Camera1->Position->X+=0.2; Camera1->Position->Y+=0.2; Camera1->Position->Z+=0.2; Camera1->RotationAngle->X+=0.5; Camera1->RotationAngle->Y+=0.5; Camera1->RotationAngle->Z+=0.5; Camera1->EndUpdate(); |
Light
Light (TLight) is a 3D component that describes objects that are light sources. Use TLight to imitate the rays of light and their propagation on other 3D objects. Use Color to set the color of the rays of light. Use LightType to set how rays are propagated. SpotExponent specifies the intensity distribution of the light. Here is a example below;
1 2 3 4 5 6 7 |
Light1->BeginUpdate(); Light1->Color=claYellow; Light1->SpotCutOff=100; Light1->SpotExponent=0; Light1->EndUpdate(); |
Dummy Object
Dummy (TDummy) is generally used to define position and rotation of group of 3D objects, it is a class for 3D dummy objects. Dummy can be used as a container for 3D objects. Use a TDummy control to group other 3D controls so that they can be moved and rotated together. Dummy objects are good to do mechanical parts with different rotation point in 3D and object groups.
1 2 3 4 5 6 7 8 9 10 |
Dummy1->BeginUpdate(); Dummy1->Position->X=2; Dummy1->Position->Y=5; Dummy1->Position->Z=2; Dummy1->RotationAngle->X++; Dummy1->RotationAngle->Y++; Dummy1->EndUpdate(); |
Proxy Object
Proxy Object (TProxyObject) is a class for proxy objects. SourceObject is the object that this TProxyObject represents. It is used for mechanical parts.
TColorMaterialSource
TColorMaterialSource defines a source of TColorMaterial, it is used to link a TColorMaterial to 3D objects. The link is made through the MaterialSource property of the 3D object. To change the color of the material, set the Color property.
1 2 3 4 |
ColorMaterialSource1->Color=claLime; Sphere1->MaterialSource = ColorMaterialSource1; |
TTextureMaterialSource
TTextureMaterialSource to link a TTextureMaterial to 3D objects. The link is made through the MaterialSource property of the 3D object.
By default, TTextureMaterialSource has no texture specified. The object that links to an empty TTextureMaterialSource cannot be seen on the form. The material’s texture is specified as a TBitmap. Specify the texture by setting the Texture property of the TTextureMaterialSource.
1 2 3 |
TTextureMaterialSource1->Color=claLime; |
TLightMaterialSource
Use TLightMaterialSource to link a TLightMaterial to 3D objects. The link is made through MaterialSource property of the 3D object. By default, the color properties (Ambient, Emissive, Diffuse, Specular) are set to simulate the shadows added to the object by the source of light. The material’s texture is specified as a TBitmap. Specify the texture by setting the Texture property of the TLightMaterialSource.