Event Gyroscope
វាជា
event
ដែលមាននៃ gyroscope ដែលអាស្រ័យលើ device’s
hardware capabilities
ចំណាំះ
នៅលើ IOS
ត្រូវបញ្ចូលវា UIRequiredDeviceCapabilities
ខាងក្រោមនេះជា
Properties
របស់វា
event.name សំរាប់ gyroscope events នេះជា property
ត្រូវបានបញ្ចូលទៅជា gyroscope
សូមមើលកូដះ
--
Called when a new gyroscope measurement has been received.
local
function onGyroscopeDataReceived( event )
print( "Gyroscope name: " ..
event.name )
end
--
Set up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
event.yRotation
ប្រើសំរាប់
rotate
rate ជុំវិញ device’s y axis នៅក្នងradian
per second
ចំណាំះ
អាចបំលែង radian
ទៅ degree តាមរយះ formula: degree =
radins * (180/pi)
សូមមើលកូដះ
--
Called when a new gyroscope measurement has been received.
print
("this is me")
local
function onGyroscopeDataReceived( event )
-- Calculate approximate rotation traveled
via deltaTime.
-- Remember that rotation rate is in
radians per second.
local deltaRadians = event.yRotation *
event.deltaTime
local deltaDegrees = deltaRadians * (180 /
math.pi)
end
--
Set up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
event.xRotation
ប្រើសំរាប់
rotate
rate ជុំវិញ device’s x axis នៅក្នងradian
per second
ចំណាំះ
អាចបំលែង radian
ទៅ degree តាមរយះ formula: degree =
radins * (180/pi)
សូមមើលកូដះ
--
Called when a new gyroscope measurement has been received.
print
("this is me")
local
function onGyroscopeDataReceived( event )
-- Calculate approximate rotation traveled
via deltaTime.
-- Remember that rotation rate is in
radians per second.
local deltaRadians = event.yRotation *
event.deltaTime
local deltaDegrees = deltaRadians * (180 /
math.pi)
end
--
Set up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
event.yRotation
ប្រើសំរាប់
rotate
rate ជុំវិញ device’s y axis នៅក្នងradian
per second
ចំណាំះ
អាចបំលែង radian
ទៅ degree តាមរយះ formula: degree = radins
* (180/pi)
សូមមើលកូដះ
--
Called when a new gyroscope measurement has been received.
print
("this is me")
local
function onGyroscopeDataReceived( event )
-- Calculate approximate rotation traveled
via deltaTime.
-- Remember that rotation rate is in
radians per second.
local deltaRadians = event.yRotation *
event.deltaTime
local deltaDegrees = deltaRadians * (180 /
math.pi)
end
--
Set up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
event.zRotation
ប្រើសំរាប់
rotate
rate ជុំវិញ device’s z axis នៅក្នងradian
per second
ចំណាំះ
អាចបំលែង radian
ទៅ degree តាមរយះ formula: degree =
radins * (180/pi)
សូមមើលកូដះ
--
Called when a new gyroscope measurement has been received.
print
("this is me")
local
function onGyroscopeDataReceived( event )
-- Calculate approximate rotation traveled
via deltaTime.
-- Remember that rotation rate is in
radians per second.
local deltaRadians = event.yRotation *
event.deltaTime
local deltaDegrees = deltaRadians * (180 /
math.pi)
end
--
Set up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
event.deltaTime
វាជាពេលវេលាគិតជា
វិនាទីចាប់តាំងពី last gyroscope event
ចំណាំះ
សំរាប់រង្វាស់ Gyroscope
នឹងមិនចំលង់នៅម៉ោងពិតប្រាកដទេដោយសារ system.setGyroscopeInterval()function។ វាមានន័យថាអ្នកមិនអាច assume ថាវានឹង configured
interval នៃ 10Hz ex: 100milliseconds ដែលនឹង
yield measurements record ដូចគ្នានឹង 100
milliseconds apart។ នេះជាដែនកំនត់របស់ operating system នៅលើ IOS & Android។ សំរាប់ event.deltaTime
ផ្តល់ក្នុងការជួយធ្វើឪ្យវា rotational calculations ជាពេលដែលត្រឹមត្រូវ
អាចប្រើ
event.deltaTime
ក្នងការគិតនៅចំងាយវិលប្រហាក់ប្រហែលតាំងពីLast gyroscope
measurement ជាមួយនឹងសមីការខាងក្រោមនេះ
delta radians = rotation rate * delta time
delta radians = rotation rate * delta time
សូមចំណាំថា
នេះជាតំលៃប្រហែលពីព្រោះ device មិនត្រូវបាន rotated
ជា constant speed តាំងពីរង្វាស់ last
gyroscope។ វាមានន័យថា the summed distance over time will
grow in error។ ការបង្កើននៅរង្វាស់វានឹង update interval តាមរយះ system.setGyroscopeInterval() function ដែលនឹងបន្ថយការ
error
សូមមើលកូដះ
--
Called
when a new gyroscope measurement has been received.
local
function onGyroscopeDataReceived( event )
-- Calculate approximate rotation traveled
via deltaTime.
-- Remember that rotation rate is in
radians per second.
local deltaRadians = event.zRotation *
event.deltaTime
local deltaDegrees = deltaRadians * (180 / math.pi)
end
--
Set
up the above function to receive gyroscope events if the sensor exists.
if
system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener(
"gyroscope", onGyroscopeDataReceived )
end
No comments:
Post a Comment