FMX.Planets Sample
This sample demonstrates how to use some of the different FireMonkey classes that interact with 3D objects. For example: TCamera, TTextureMaterialSource or TFloatAnimation.
Contents
Location
You can find the Planets sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
CPP\Multi-Device Samples\User Interface\Planets
- Subversion Repository:
- You can find C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
The Planets sample uses different FireMonkey classes in order to demonstrate how to interact with 3D objects. The sample uses TSphere as the 3D objects. TCamera and TLight are used to define the scene perspective and the propagation of the rays of light on the 3D objects. Moreover, TColorMaterialSource and TTextureMaterialSource are used to define the color and the texture of the 3D objects. Finally, TFloatAnimation is used to attach animations to the 3D objects.
How to Use the Sample
- Navigate to the location given above and open PlanetsCPP.cbproj.
- Select the target platform.
- Press F9 or choose Run > Run.
- See the planets rotating.
Files
File in C++ | Contains |
---|---|
PlanetsCPP.cbproj |
The project itself. |
Unit1.fmx |
The main form where the components are located. |
PlanetsCPPPCH.h, Unit1.cpp |
Used to define and implement the sample. |
Classes
TForm3D1 is the main form that represents the main window of the sample. It contains the following components:
- A TCamera object.
- A TColorMaterialSource object.
- A TLight object.
- Two TSphere objects:
- The first TSphere object labeled as Sphere1 that contains:
- A TFloatAnimation object labeled as FloatAnimation1.
- The second TSphere object labeled as Sphere1 that contains:
- A TFloatAnimation object labeled as FloatAnimation2.
- The first TSphere object labeled as Sphere1 that contains:
- Two TTextureMaterialSource objects labeled as TextureMaterialSource1 and TexturematerialSource2.
Implementation
- The sample uses TColorMaterialSource to link a TColorMaterial to a 3D object. The link is made through the MaterialSource property of the 3D object.
- The sample uses TTextureMaterialSource to link a TTextureMaterial to a 3D object. The link is made through the MaterialSource property of the 3D object.
- The sample uses TCamera to define the scene perspective and projection of the objects in the scene to the viewport.
- The sample uses TLight to imitate the rays of light and their propagation on other 3D objects.
- The sample uses TSphere to implement a 3D sphere shape that can be placed on a 3D FireMonkey form.
- The sample uses TFloatAnimation attached to a 3D object in order to animate it.
When you run the application, you see two spheres. Each sphere is linked to each TTextureMaterialSource object. The Texture property of both TTextureMaterialSource objects is set to a map of a planet. Therefore, both sphere objects looks like planets. Moreover, the Position property of both the TCamera and the TLight objects is set so that you have a frontal view of the planets when you run the application. Finally, both animations have the PropertyName set to RotationAngle.Y
and the Enabled and Loop properties set to True
. Therefore, when you run the application the spheres rotate until you close the application.
Uses
See Also
- FireMonkey 3D
- Tutorial: Creating a FireMonkey 3D Application
- Tutorial: How to Use Cameras in a FireMonkey 3D Application