Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ar_volunteer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈创杰
ar_volunteer
Commits
0d32c53e
Commit
0d32c53e
authored
Sep 03, 2017
by
Liang JingQiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增陀螺仪控制脚本,GyroController , 陀螺仪控制AR摄像机已实现
parent
78874908
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
221 additions
and
3 deletions
+221
-3
GyroController.cs
Assets/GyroController.cs
+196
-0
GyroController.cs.meta
Assets/GyroController.cs.meta
+12
-0
HelloAR.unity
Assets/HelloAR/Scenes/HelloAR.unity
+0
-0
bubble.mat
Assets/Jiggly Bubble Free/bubble.mat
+0
-0
bubble1.png
Assets/Jiggly Bubble Free/bubble1.png
+0
-0
mv.mp4
Assets/StreamingAssets/mv.mp4
+0
-0
TuoLuoYi.cs
Assets/TuoLuoYi.cs
+9
-0
ImageTarget-JsonFile-idback (1).prefab
Assets/预置/temp/ImageTarget-JsonFile-idback (1).prefab
+0
-0
ImageTarget-JsonFile-idback (1).prefab.meta
Assets/预置/temp/ImageTarget-JsonFile-idback (1).prefab.meta
+4
-3
No files found.
Assets/GyroController.cs
0 → 100644
View file @
0d32c53e
using
UnityEngine
;
/// <summary>
/// Gyroscope controller that works with any device orientation.
/// </summary>
public
class
GyroController
:
MonoBehaviour
{
#
region
[
Private
fields
]
private
bool
gyroEnabled
=
true
;
private
const
float
lowPassFilterFactor
=
0.2f
;
private
readonly
Quaternion
baseIdentity
=
Quaternion
.
Euler
(
90
,
0
,
0
);
private
readonly
Quaternion
landscapeRight
=
Quaternion
.
Euler
(
0
,
0
,
90
);
private
readonly
Quaternion
landscapeLeft
=
Quaternion
.
Euler
(
0
,
0
,
-
90
);
private
readonly
Quaternion
upsideDown
=
Quaternion
.
Euler
(
0
,
0
,
180
);
private
Quaternion
cameraBase
=
Quaternion
.
identity
;
private
Quaternion
calibration
=
Quaternion
.
identity
;
private
Quaternion
baseOrientation
=
Quaternion
.
Euler
(
90
,
0
,
0
);
private
Quaternion
baseOrientationRotationFix
=
Quaternion
.
identity
;
private
Quaternion
referanceRotation
=
Quaternion
.
identity
;
private
bool
debug
=
true
;
#
endregion
#
region
[
Unity
events
]
protected
void
Start
()
{
AttachGyro
();
}
protected
void
Update
()
{
if
(!
gyroEnabled
)
return
;
transform
.
rotation
=
Quaternion
.
Slerp
(
transform
.
rotation
,
cameraBase
*
(
ConvertRotation
(
referanceRotation
*
Input
.
gyro
.
attitude
)
*
GetRotFix
()),
lowPassFilterFactor
);
}
protected
void
OnGUI
()
{
if
(!
debug
)
return
;
GUILayout
.
Label
(
"Orientation: "
+
Screen
.
orientation
);
GUILayout
.
Label
(
"Calibration: "
+
calibration
);
GUILayout
.
Label
(
"Camera base: "
+
cameraBase
);
GUILayout
.
Label
(
"input.gyro.attitude: "
+
Input
.
gyro
.
attitude
);
GUILayout
.
Label
(
"transform.rotation: "
+
transform
.
rotation
);
if
(
GUILayout
.
Button
(
"On/off gyro: "
+
Input
.
gyro
.
enabled
,
GUILayout
.
Height
(
100
)))
{
Input
.
gyro
.
enabled
=
!
Input
.
gyro
.
enabled
;
}
if
(
GUILayout
.
Button
(
"On/off gyro controller: "
+
gyroEnabled
,
GUILayout
.
Height
(
100
)))
{
if
(
gyroEnabled
)
{
DetachGyro
();
}
else
{
AttachGyro
();
}
}
if
(
GUILayout
.
Button
(
"Update gyro calibration (Horizontal only)"
,
GUILayout
.
Height
(
80
)))
{
UpdateCalibration
(
true
);
}
if
(
GUILayout
.
Button
(
"Update camera base rotation (Horizontal only)"
,
GUILayout
.
Height
(
80
)))
{
UpdateCameraBaseRotation
(
true
);
}
if
(
GUILayout
.
Button
(
"Reset base orientation"
,
GUILayout
.
Height
(
80
)))
{
ResetBaseOrientation
();
}
if
(
GUILayout
.
Button
(
"Reset camera rotation"
,
GUILayout
.
Height
(
80
)))
{
transform
.
rotation
=
Quaternion
.
identity
;
}
}
#
endregion
#
region
[
Public
methods
]
/// <summary>
/// Attaches gyro controller to the transform.
/// </summary>
private
void
AttachGyro
()
{
gyroEnabled
=
true
;
ResetBaseOrientation
();
UpdateCalibration
(
true
);
UpdateCameraBaseRotation
(
true
);
RecalculateReferenceRotation
();
}
/// <summary>
/// Detaches gyro controller from the transform
/// </summary>
private
void
DetachGyro
()
{
gyroEnabled
=
false
;
}
#
endregion
#
region
[
Private
methods
]
/// <summary>
/// Update the gyro calibration.
/// </summary>
private
void
UpdateCalibration
(
bool
onlyHorizontal
)
{
if
(
onlyHorizontal
)
{
var
fw
=
(
Input
.
gyro
.
attitude
)
*
(-
Vector3
.
forward
);
fw
.
z
=
0
;
if
(
fw
==
Vector3
.
zero
)
{
calibration
=
Quaternion
.
identity
;
}
else
{
calibration
=
(
Quaternion
.
FromToRotation
(
baseOrientationRotationFix
*
Vector3
.
up
,
fw
));
}
}
else
{
calibration
=
Input
.
gyro
.
attitude
;
}
}
/// <summary>
/// Update the camera base rotation.
/// </summary>
/// <param name='onlyHorizontal'>
/// Only y rotation.
/// </param>
private
void
UpdateCameraBaseRotation
(
bool
onlyHorizontal
)
{
if
(
onlyHorizontal
)
{
var
fw
=
transform
.
forward
;
fw
.
y
=
0
;
if
(
fw
==
Vector3
.
zero
)
{
cameraBase
=
Quaternion
.
identity
;
}
else
{
cameraBase
=
Quaternion
.
FromToRotation
(
Vector3
.
forward
,
fw
);
}
}
else
{
cameraBase
=
transform
.
rotation
;
}
}
/// <summary>
/// Converts the rotation from right handed to left handed.
/// </summary>
/// <returns>
/// The result rotation.
/// </returns>
/// <param name='q'>
/// The rotation to convert.
/// </param>
private
static
Quaternion
ConvertRotation
(
Quaternion
q
)
{
return
new
Quaternion
(
q
.
x
,
q
.
y
,
-
q
.
z
,
-
q
.
w
);
}
/// <summary>
/// Gets the rot fix for different orientations.
/// </summary>
/// <returns>
/// The rot fix.
/// </returns>
private
Quaternion
GetRotFix
()
{
#if UNITY_3_5
if
(
Screen
.
orientation
==
ScreenOrientation
.
Portrait
)
return
Quaternion
.
identity
;
if
(
Screen
.
orientation
==
ScreenOrientation
.
LandscapeLeft
||
Screen
.
orientation
==
ScreenOrientation
.
Landscape
)
return
landscapeLeft
;
if
(
Screen
.
orientation
==
ScreenOrientation
.
LandscapeRight
)
return
landscapeRight
;
if
(
Screen
.
orientation
==
ScreenOrientation
.
PortraitUpsideDown
)
return
upsideDown
;
return
Quaternion
.
identity
;
#else
return
Quaternion
.
identity
;
#endif
}
/// <summary>
/// Recalculates reference system.
/// </summary>
private
void
ResetBaseOrientation
()
{
baseOrientationRotationFix
=
GetRotFix
();
baseOrientation
=
baseOrientationRotationFix
*
baseIdentity
;
}
/// <summary>
/// Recalculates reference rotation.
/// </summary>
private
void
RecalculateReferenceRotation
()
{
referanceRotation
=
Quaternion
.
Inverse
(
baseOrientation
)
*
Quaternion
.
Inverse
(
calibration
);
}
#
endregion
}
Assets/GyroController.cs.meta
0 → 100644
View file @
0d32c53e
fileFormatVersion: 2
guid: 4ae49a2826c584c4dbf73b8da2842739
timeCreated: 1504445964
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/HelloAR/Scenes/HelloAR.unity
View file @
0d32c53e
No preview for this file type
Assets/Jiggly Bubble Free/bubble.mat
View file @
0d32c53e
No preview for this file type
Assets/Jiggly Bubble Free/bubble1.png
View replaced file @
78874908
View file @
0d32c53e
9.08 KB
|
W:
|
H:
26 KB
|
W:
|
H:
2-up
Swipe
Onion skin
Assets/StreamingAssets/mv.mp4
deleted
100644 → 0
View file @
78874908
File deleted
Assets/TuoLuoYi.cs
View file @
0d32c53e
...
...
@@ -3,6 +3,12 @@ using System.Collections;
public
class
TuoLuoYi
:
MonoBehaviour
{
private
Quaternion
cameraBase
=
Quaternion
.
identity
;
private
Quaternion
calibration
=
Quaternion
.
identity
;
private
Quaternion
baseOrientation
=
Quaternion
.
Euler
(
90
,
0
,
0
);
private
Quaternion
baseOrientationRotationFix
=
Quaternion
.
identity
;
private
Quaternion
referanceRotation
=
Quaternion
.
identity
;
private
const
float
lowPassFilterFactor
=
0.2f
;
protected
void
Start
()
...
...
@@ -26,6 +32,9 @@ public class TuoLuoYi : MonoBehaviour
//Input.gyro.attitude 返回值为 Quaternion类型,即设备旋转欧拉角
// transform.rotation = Quaternion.Slerp(transform.rotation, Input.gyro.attitude, lowPassFilterFactor);
transform
.
rotation
=
Quaternion
.
Slerp
(
Input
.
gyro
.
attitude
,
transform
.
rotation
,
lowPassFilterFactor
);
// transform.rotation = Quaternion.Slerp(transform.rotation,
// cameraBase * (ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor);
}
void
OnGUI
()
...
...
Assets/预置/temp/ImageTarget-JsonFile-idback (1).prefab
0 → 100644
View file @
0d32c53e
File added
Assets/
StreamingAssets/mv.mp4
.meta
→
Assets/
预置/temp/ImageTarget-JsonFile-idback (1).prefab
.meta
View file @
0d32c53e
fileFormatVersion: 2
guid:
22fb2ee263a0486458a1df8eb1e08bdb
timeCreated: 1504
151351
guid:
7846200f0d41224409df825f7ac9bdd8
timeCreated: 1504
443209
licenseType: Pro
DefaultImporter:
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment