FMX.FirstApp3D Sample
This sample demonstrates how to animate a 3D object.
Contents
Location
You can find the FirstApp3D sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
CPP\Multi-Device Samples\User Interface\FirstApp3D
- 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 FirstApp3D sample demonstrates how to use the TFloatAnimation class to animate a 3D object. The sample attaches a TFloatAnimation to a TRectangle3D object. Moreover, this sample also demonstrates how to specify a 3D object as the target that is being watched by the TCamera.
How to Use the Sample
- Navigate to the location given above and open CppFMX3DFirstApp.cbproj.
- Select the target platform.
- Press F9 or choose Run > Run.
- Interact with the sample:
- Left-click on the 3D rectangle to rotate it.
- Left-click on the 3D rectangle to stop the rotation.
Files
File in C++ | Contains |
---|---|
CppFMX3DFirstApp.cbproj |
The project itself. |
MainForm.fmx |
The main form where the components are located. |
CppFMX3DFirstAppPCH.h, MainForm.cpp |
Used to define and implement the sample. |
Classes
TForm3D4 is the main form that represents the main window of the sample. It contains the following components:
- A TCamera object.
- Three TColorMaterialSource objects.
- A TCube object
- A TCylinder object.
- A TRectangle3D object that contains a TFloatAnimation object.
- A TSphere object.
Implementation
- The sample uses TColorMaterialSource to change the color of 3D objects.
- The sample uses TCube to implement a 3D cube shape that can be placed on a 3D FireMonkey form.
- The sample uses TCylinder to implement a 3D cylinder shape that can be placed on a 3D FireMonkey form.
- The sample uses TRectangle3D to implement a 3D shape under the form of a 3D rectangle that can be placed on a 3D FireMonkey form.
- The sample uses TSphere to implement a 3D sphere shape that can be placed on a 3D FireMonkey form.
- The sample uses TCamera to define the scene perspective and projection of the objects in the scene to the viewport.
- The sample uses TFloatAnimation attached to a 3D object in order to animate it.
When you run the application, your FireMonkey form is focused on the 3D Rectangle. This is because the Target property of the TCamera is set to Rectangle3D
. Moreover, If you click on the 3D rectangle, a OnClick event occurs. The OnClick event enables the TFloatAnimation attached to it. The TFloatAnimation has the PropertyName and Loop properties set to RotationAngle.Y
and True
, respectively. Therefore, when you click on the 3D rectangle, it begins to rotate until you make another click on it.
Uses
See Also
- FireMonkey 3D
- Tutorial: Creating a FireMonkey 3D Application
- Tutorial: How to Use Cameras in a FireMonkey 3D Application