This sample demonstrates how to use the Gyroscope in order to rotate a 3D cube when your device is tilted.
You can find the Gyroscope sample project at:
- Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
Object Pascal\Mobile Snippets\Gyroscope
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
The Gyroscope sample demonstrates how to use the Gyroscope in order to rotate a 3D cube when your device is tilted. This sample suports both iOS or Android devices. The sample uses the TOrientationSensor component and the TCustomOrientationSensor class to act like a gyroscope that rotates a 3D cube while you tilt your device.
- Note: The TCustomOrientationSensor class supports Android, iOS and Windows platforms. However, each platform provides different orientation sensors and each type of sensor supports a different set of properties (see platform support for a completed list of platform, sensors and suported properties).
How to Use the Sample
- Navigate to one of the locations given above and open:
- Delphi: Gyroscope.dproj.
- C++: Gyroscope.cbproj.
- Select the target platform, iOS and Android supported.
- Press F9 or choose Run > Run.
- Interact with the sample:
- There is a 3D cube displayed in the screen.
- Tilt your device and see how the 3D cube rotates.
|File in Delphi||File in C++||Contains|
The project itself.
The main form where the components are located.
Used to define and implement the sample.
Further information about the sample.
TGyroscopeForm is the main form that represents the main window of the sample. It contains the following components:
- A TLight object.
- A TLightMaterialSource object.
- A TRectangle3D object.
- A TTimer object.
- A TLayer3D object with a TLabel object.
- A TOrientationSensor object.
- 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 TSensorManager to identify the sensor of your device.
- The sample uses TOrientationSensor to obtain information about the device inclination (tilt).
- The sample uses TTimer to repeat specific actions after a given time interval. TTimer specifies the time interval in wich TOrientationSensor offers the tilt information used to rotate the TRectangle3D.
- The sample uses TLight to imitate the rays of light and their propagation on the 3D object.
- The sample uses TLightMaterialSource to link a TLightMaterial to 3D objects. The link is made through MaterialSource property of the 3D object.
When you run the application, you see a 3D cube on the screen. If you tilt your device, the sample uses the TiltX, TiltY and TiltZ properties of TCustomOrientationSensor to obtain the angle that has to be used to rotate the 3D cube using the RotationAngle.X, RotationAngle.Y and RotationAngle.Z properties of TRectangle3D.
- FireMonkey 3D
- Tutorial: Creating a FireMonkey 3D Application
- FireMonkey Orientation Sensor sample
- FireMonkey Low Level 3D sample
- FireMonkey Model Viewer sample
- FireMonkey 3D Arrows sample
- FireMonkey First App3D sample