FMX.ViewPort3DTLightTexture3D Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample shows you how to use different FireMonkey classes that interact with 3D objects.

Location

You can find the ViewPort3DTLightTexture3D sample project at:

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:

Implementation

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

See Also

Samples