傾斜情報を取得

構文 sensor.getOrient() 戻り値: d, p, r
説明 傾斜情報を取得します。
引数 なし
戻り値 d: 方位(北の方向)をDegreeで取得
p: 画面長編方向の傾斜成分を取得
r: 画面短辺方向の傾斜成分を取得
setdevOrient(1)をセットしないと取得できません。

------------------------------------------
-- 傾斜情報を取得するサンプル getOrient_sample.lua
------------------------------------------
function main()
 
  local w,h = canvas.getviewSize()
  local xx, yy = 0, 50
 
  canvas.drawCls(color(255,255,255))
  canvas.drawText("傾斜情報を取得するサンプル", 0, 0, 24, color(0,0,0))
  canvas.drawText("画面の右下の四角枠内のタッチで終了します。", 0, 30, 24, color( 0, 0, 0))
  canvas.drawRect( w-100, h-100, w-2, h-2, color( 0, 0, 0))
  sensor.setdevOrient(1)
 
  while not ((xx >= w-100 and xx <= w-2) and (yy >= h-100 and yy <= h-2)) do
    xx, yy,mode = touch(0)
      d, p, r = sensor.getOrient()
      canvas.drawText("方位(北の方向)をDegreeで取得 = " .. d .. "                ", 0, 80, 24, color(0,0,0), color(255,255,255))
      canvas.drawText("画面長編方向の傾斜成分を取得 = " .. p .. "                ", 0, 110, 24, color(0,0,0), color(255,255,255))
      canvas.drawText("画面短辺方向の傾斜成分を取得 = " .. r .. "                ", 0, 140, 24, color(0,0,0), color(255,255,255))
  end
 
  sensor.setdevOrient(0)
 
end
 
main()
 

1.傾斜情報を取得するサンプルです。右下の四角枠内タッチで終了します。


コメント(最大10行)
名前:
コメント

すべてのコメントを見る



タグ:

+ タグ編集
  • タグ:
最終更新:2011年12月25日 20:55
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。