Merhaba.
- Cevapsız başka bir konu :
Kodu videodan doğru takip etmemiş olabilir misiniz ? Örnek kodu burada yazmış olsaydınız videodan okuyup yeniden yazmak zorunda kalmayıp daha kolay yardımcı olurduk.
Yine de vaktim uygundu sizin için kodları videodakine göre oluşturup örnek proje halinde download linkini veriyorum.
Bu linke tıklayarak indirebilirsiniz.
Kaynak kod aşağıdaki şekilde. Bana öyle geliyor ki olası yanlış aktarım söz konusu...
type
TForm1 = class(TForm)
Viewport3D1: TViewport3D;
Light1: TLight;
Dummy1: TDummy;
Cone1: TCone;
LightMaterialSource1: TLightMaterialSource;
LightMaterialSource2: TLightMaterialSource;
LightMaterialSource3: TLightMaterialSource;
Sphere1: TSphere;
Disk1: TDisk;
Dummy2: TDummy;
Dummy3: TDummy;
Cone2: TCone;
Camera1: TCamera;
MotionSensor1: TMotionSensor;
OrientationSensor1: TOrientationSensor;
Timer1: TTimer;
Switch1: TSwitch;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Switch1Switch(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Heading,
Acceleration : TPoint3D;
Orientation : TScreenOrientation;
ScreenService : IFMXScreenService;
IsScreen : Boolean;
procedure UpdateSensor;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
Uses Math;
procedure TForm1.FormCreate(Sender: TObject);
begin
IsScreen := TPlatformServices.Current.SupportsPlatformService( IFMXScreenService, IInterface(ScreenService));
end;
procedure TForm1.Switch1Switch(Sender: TObject);
begin
MotionSensor1.Active := Switch1.IsChecked;
OrientationSensor1.Active := Switch1.IsChecked;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
UpdateSensor;
end;
procedure TForm1.UpdateSensor;
Var
A, C, H, R, P : TPoint3D;
Z : Single;
Hour, Min, Sec, MSec : Word;
Const
NordenAngle : Array[TScreenOrientation] of Single = ( 90, 180, 270, 0);
AccAngle : Array[TScreenOrientation] of Single = ( 0, 270, 180, 90);
begin
if IsScreen then Orientation := ScreenService.GetScreenOrientation;
if Assigned( MotionSensor1 ) and Assigned( MotionSensor1.Sensor )
then With MotionSensor1.Sensor
do Acceleration := Point3D( AccelerationX, AccelerationY, AccelerationZ )
else Acceleration := NullPoint3D;
if Assigned( OrientationSensor1 ) and Assigned( OrientationSensor1.Sensor )
then With OrientationSensor1.Sensor
do Heading := Point3D( HeadingX, HeadingY, HeadingZ )
else Heading := NullPoint3D;
P := NullPoint3D;
R := NullPoint3D;
A := Acceleration.Normalize;
if TOSVersion.Platform = pfiOS then A:= -A;
P := Point3D( A.Y, A.X, 0 ) * TMatrix3D.CreateRotationZ( AccAngle[Orientation] * cPIdiv180 );
P := P * (-90);
if Heading.Length < Epsilon then
begin
DecodeTime( Now(), Hour, Min, Sec, MSec );
R.Y := Sec / 60 * 360;
end else
begin
H := Heading.Normalize;
C := H.CrossProduct(A).Normalize;
if A.Z.Sign then Z := cPI else Z := 0;
try
R.Y := ( ArcTan2(C.X, C.Y) - NordenAngle[Orientation] * cPIdiv180 + Z ) * c180divPI;
except
R.Y := 0;
end;
end;
Dummy1.ResetRotationAngle;
Dummy1.RotationAngle.Point := P;
Sphere1.ResetRotationAngle;
Sphere1.RotationAngle.Point := R;
end;