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 | Appmethod 1.16 | Samples and then navigate to:
Object Pascal\Mobile Snippets\Gyroscope
- Subversion Repository:
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:
- Object Pascal: 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 Object Pascal||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