FMX.FirstApp3D Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample demonstrates how to animate a 3D object.

Location

You can find the FirstApp3D sample project at:

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

  1. Navigate to the location given above and open CppFMX3DFirstApp.cbproj.
  2. Select the target platform.
  3. Press F9 or choose Run > Run.
  4. 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:

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

Samples