FMX.CamerasTextures3D Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use TCamera and TTextureMaterialSource to interact with 3D objects.

Location

You can find the CamerasTextures3D sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
    • CPP\Multi-Device Samples\User Interface\CamerasTextures3D
  • 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 CamerasTextures3D sample uses the FireMonkey classes: TCamera and TTextureMaterialSource in order to demonstrate how to interact with 3D objects. The sample uses TCamera to define the scene perspective and TTextureMaterialSource to define the material's texture of the 3D objects. Moreover, the sample also uses TFloatAnimation to attach animations to the 3D objects.

How to Use the Sample

  1. Navigate to the location given above and open CppFMX3DCamerasTextures.cbproj.
  2. Select the target platform.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample: left-click on the checkbox labeled as Rotate 3D Shapes to enable the animations.

Files

File in C++ Contains

CppFMX3DCamerasTextures.cbproj

The project itself.

MainForm.fmx

The main form where the components are located.

CppFMX3DCamerasTexturesPCH.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 TLayer3D to hold any 2D object in a FireMonkey 3D form.
  • The sample uses TCheckBox to enable or disable the different TFloatAnimations. Select the box to turn on the animations or clear it to turn off the animations.
  • The sample uses TSphere to implement a 3D sphere shape that can be placed on a 3D FireMonkey form.
  • 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 TFloatAnimation attached to a 3D object in order to animate it.

When you run the application, you see a checkbox labeled as Rotate 3D Shapes and 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. On the other hand, there are three TFloatAnimations: TFloatAnimation1 attached to sphere1, TFloatAnimation2 attached to sphere2 and TFloatAnimation3 attached to Camera1. Both TFloatAnimation1 and TFloatAnimation2 have the PropertyName set to RotationAngle.Y, while the TFloatAnimation3 has the PropertyName set to Position.Z. When you check the checkbox labeled as Rotate 3D Objects, an OnChange event occurs. The OnChange event enables the animations. Therefore, when you check the checkbox, both spheres begin to rotate while the camera changes the zoom of your FireMonkey form.

Uses

See Also

Samples