FMX.ViewPort3DTLightTexture3D Sample
This sample shows you how to use different FireMonkey classes that interact with 3D objects.
Location
You can find the ViewPort3DTLightTexture3D sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
CPP\Multi-Device Samples\User Interface\ViewPort3DTLightTexture3D
- 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 ViewPort3DTLightTexture3D sample demonstrates how to use the TViewport3D, TColorMaterialSource and TLightMaterialSource classes. The sample uses TColorMaterialSource to link a TColorMaterial to a 3D object and TLightMaterialSource to link a TLightMaterial to a 3D object. Moreover, the sample attaches two different TFloatAnimations to two 3D objects.
Files
File in C++ | Contains |
---|---|
CppViewPort3DTLightTexture.cbproj |
The project itself. |
MainForm.fmx |
The main form where the components are located. |
MainForm.h, MainForm.cpp |
Used to define and implement the sample. |
Classes
TForm4 is the main form that represents the main window of the sample. It contains the following components:
- A TColorMaterialSource object.
- A TLightMaterialSource object.
- A TPanel object that contains:
- A TCheckBox object.
- A TViewport3D object that contains the following components:
- A TLight object.
- A TRectangle3D object that contains:
- A TFloatAnimation object.
- A TSphere object that contains:
- Two TFloatAnimation objects called as FloatAnimation1 and FloatAnimation2.
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 TLightMaterialSource to link a TLightMaterial to a 3D object. The link is made through the MaterialSource property of the 3D object.
- The sample uses Tpanel to hold multiple controls for organizing purposes.
- The sample uses TCheckBox to enable or disable TFloatAnimation. Select the box to turn on the animation or clear it to turn off the animation.
- 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 TFloatAnimation attached to a 3D object in order to animate it.
When you run the application, you see two 3D objects: a sphere and a 3D rectangle. On the one hand, the sphere is linked to the TLightMaterialSource object with the Texture property set to a map of the Earth. Therefore, the sphere object looks like the Earth. On the other hand, the 3D rectangle is linked to the TColorMaterialSource with the Color property set to Blue
. The link of TColorMaterialSource and TRectangle3D is made through the MaterialShaftSource property, which set the color for the shaft sides of the 3D rectangle.
- Note: To set the color for the front and back sides of the 3D rectangle, use the MaterialSource and MaterialBackSource properties.
Moreover, each TFloatAnimation is attached to each 3D object. When you click on the TCheckBox, it enables both animations. The sphere is attached to the FloatAnimation1, which has the PropertyName set to RotationAngle.Y
, while the 3D rectangle is attached to the FloatAnimation2, which has the PropertyName set to RotationAngle.Z
. Finally, both animations have the Loop property set to True
, so it repeats the animation until the TCheckBox is cleared.
Uses
- TColorMaterialSource
- TLightMaterialSource
- Tpanel
- TCheckBox
- TViewport3D
- TLight
- TRectangle3D
- TFloatAnimation
- TSphere
See Also
- FireMonkey 3D
- Tutorial: Creating a FireMonkey 3D Application
- Tutorial: How to Use Cameras in a FireMonkey 3D Application
Samples
- FireMonkey First App3D sample
- FireMonkey Model Viewer sample
- FireMonkey Arrows 3D sample
- FireMonkey TFmxObject AnimateFloat (C++)
- FireMonkey Attach TAnimation (C++)
- FireMonkey Timer Animation (C++)