Leap Motion - Siv3D/Reference-JP GitHub Wiki
コンパイル・実行のために以下の手順が必要です。
- Leap Motion SDK を Leap Motion 公式 Web サイトからダウンロードする
- プロジェクトのプロパティを開き [VC++ ディレクトリ] から、インクルードディレクトリに Leap Motion SDK の
include
ディレクトリへのパスを追加する - 同様にライブラリディレクトリに、プロジェクトのターゲットプラットフォームに応じて Leap Motion SDK の
lib/x86
またはlib/x64
ディレクトリへのパスを追加する - 実行ファイルのカレントディレクトリに Leap Motion SDK の Leap.dll を配置する
# include <Siv3D.hpp>
# include <Siv3DAddon/LeapMotion.hpp>
void Main()
{
Window::Resize(1024, 640);
LeapMotion::RegisterAddon();
const Font font(36), font2(18);
while (System::Update())
{
Graphics3D::FreeCamera();
for (const auto& hand : LeapMotion::Hands())
{
const Vec3 scaledPos = hand.pos*0.05;
Sphere(scaledPos, 0.5).draw(HSV(hand.id * 30).toColor());
const Vec2 screenBase = Graphics3D::ToScreenPos(scaledPos).xy();
font(hand.isLeft ? L"Left" : L"Right").drawCenter(screenBase.movedBy(20, -160));
const Circle pinchCircle(screenBase.movedBy(-60, -260), 60);
const Circle grabCircle(screenBase.movedBy(100, -260), 60);
pinchCircle.draw(HSV(hand.id * 30).toColor(60));
pinchCircle.drawPie(0.0, hand.pinchStrength * TwoPi, HSV(hand.id * 30));
grabCircle.draw(HSV(hand.id * 30).toColor(60));
grabCircle.drawPie(0.0, hand.grabStrength * TwoPi, HSV(hand.id * 30));
font2(L"Pinch").drawCenter(pinchCircle.center);
font2(L"Grab").drawCenter(grabCircle.center);
for (const auto& finger : hand.fingers)
{
for (const auto& joint : finger.joints)
{
Sphere(joint*0.05, 0.2).draw(HSV(finger.id * 10).toColor());
}
}
}
Box(1).draw();
}
}
# include <Siv3D.hpp>
# include <Siv3DAddon/LeapMotion.hpp>
void Main()
{
Window::Resize(1024, 640);
LeapMotion::RegisterAddon();
const Font font(36), font2(18);
while (System::Update())
{
Graphics3D::FreeCamera();
for (const auto& hand : LeapMotion::Hands())
{
const Vec3 scaledPos = hand.pos*0.05;
Sphere(scaledPos, 0.5).draw(HSV(hand.id * 30).toColor());
const Vec2 screenBase = Graphics3D::ToScreenPos(scaledPos).xy();
font(hand.isLeft ? L"Left" : L"Right").drawCenter(screenBase.movedBy(20, -160));
const Circle pinchCircle(screenBase.movedBy(-60, -260), 60);
const Circle grabCircle(screenBase.movedBy(100, -260), 60);
pinchCircle.draw(HSV(hand.id * 30).toColor(60));
pinchCircle.drawPie(0.0, hand.pinchStrength * TwoPi, HSV(hand.id * 30));
grabCircle.draw(HSV(hand.id * 30).toColor(60));
grabCircle.drawPie(0.0, hand.grabStrength * TwoPi, HSV(hand.id * 30));
font2(L"Pinch").drawCenter(pinchCircle.center);
font2(L"Grab").drawCenter(grabCircle.center);
for (const auto& finger : hand.fingers)
{
for (const auto& joint : finger.joints)
{
Sphere(joint*0.05, 0.2).draw(HSV(finger.id * 10).toColor());
}
const int32 begin = (finger.type == LeapMotion::FingerType::Thumb)
|| (finger.type == LeapMotion::FingerType::Pinky) ? 0 : 1;
for (int32 i = begin; i < 4; ++i)
{
Cylinder(finger.joints[i] * 0.05, finger.joints[i + 1] * 0.05, 0.1).draw();
}
}
for (auto i : step(Min(4, static_cast<int32>(hand.fingers.size()))))
{
Cylinder(hand.fingers[i].joints[1] * 0.05, hand.fingers[i + 1].joints[1] * 0.05, 0.1).draw();
}
Cylinder(hand.fingers[0].joints[0] * 0.05, hand.fingers[hand.fingers.size() - 1].joints[0] * 0.05, 0.1).draw();
}
Box(1).draw();
}
}
# include <Siv3D.hpp>
# include <Siv3DAddon/LeapMotion.hpp>
void Main()
{
Window::Resize(1024, 640);
LeapMotion::RegisterAddon();
// ジェスチャーを有効に
LeapMotion::EnableGesture(LeapMotion::GestureType::Circle);
LeapMotion::EnableGesture(LeapMotion::GestureType::Swipe);
LeapMotion::EnableGesture(LeapMotion::GestureType::KeyTap);
LeapMotion::EnableGesture(LeapMotion::GestureType::ScreenTap);
while (System::Update())
{
Graphics3D::FreeCamera();
for (const auto& gesture : LeapMotion::Gestures())
{
Println(gesture.gestureName);
if (gesture.type == LeapMotion::GestureType::Circle)
{
Println(gesture.pos);
Println(gesture.direction);
Println(gesture.progress);
Println(gesture.radius);
Println(gesture.clockwiseness == LeapMotion::CircleClockwiseness::Clockwise);
}
else if (gesture.type == LeapMotion::GestureType::Swipe)
{
Println(gesture.pos);
Println(gesture.direction);
Println(gesture.speed);
Println(gesture.startPos);
}
else if (gesture.type == LeapMotion::GestureType::KeyTap)
{
Println(gesture.pos);
// Siv3DAddon/LeapMotion.hpp (572) を g.direction = ToVec3(keytapGesture.direction()); に修正!
Println(gesture.direction);
}
else if (gesture.type == LeapMotion::GestureType::ScreenTap)
{
Println(gesture.pos);
Println(gesture.direction);
}
}
for (const auto& hand : LeapMotion::Hands())
{
const Vec3 scaledPos = hand.pos*0.05;
Sphere(scaledPos, 0.5).draw(HSV(hand.id * 30).toColor());
const Vec2 screenBase = Graphics3D::ToScreenPos(scaledPos).xy();
for (const auto& finger : hand.fingers)
{
for (const auto& joint : finger.joints)
{
Sphere(joint*0.05, 0.2).draw(HSV(finger.id * 10).toColor());
}
}
}
Box(1).draw();
}
}