myo + oculus rift tutorial

Download Myo + Oculus Rift Tutorial

Post on 21-Apr-2017

4.023 views

Category:

Devices & Hardware

0 download

Embed Size (px)

TRANSCRIPT

PowerPoint Presentation

Myo + Oculus Rift TutorialChris Zaharia @chrisjz

ContentDevelop simple mage game in virtual realityShoot magic projectiles using hand gesturesAim by rotating armDefeat hoard of spidersDownload the game at chrisjz.github.io/myogic

2

Myo Dev KitEMG sensors for gesture detectionGyroscopeAccelerometerMagnetometerBluetoothFull day battery charge

Download link to Myogic alpha version:https://www.dropbox.com/s/f255fdzd8zgtliv/myogic-alpha.zip?dl=03

Myo Dev Kit vs Leap MotionMDKLeap MotionFixed gestures (six)2D arm trackingWirelessFinger tracking3D hand trackingHMD Mountable

Myo developers did mention that a future release would provide developers with raw EMG data which will open up possibilities for many more gestures.4

Wireless VR

Why Myo?Allows for wireless VR with motion controlsI.e. Gear VR + Myo5

RequirementsIDEUnity Pro 4.6+MyoMyo Connect 0.7.0+ (Win/Mac)SDK Beta 7+ (Win/Mac)Rift DK2Unity 4 Integration 0.4.4+

Unity package is included in the SDK.6

ScopeIntegrate Oculus VR player into game sceneAttach Myo controller to arm-hand modelMap several magic attacks to hand gestures

Getting StartedDownload the source code for Myogic at github.com/chrisjz/myogicCreate a folder in the Assets directory called TutorialScenes.Copy the scene and corresponding folder from Palace of Orinthalian > [Scenes] to TutorialScenes.Open the copied scene.

Download the game at chrisjz.github.io/myogic

Create OVR PlayerAdd the OVRPlayerController prefab into the root [Character] gameobject.Disable the existing First Person Controller gameobject.

Feel free to place the player anywhere in the scene.OVRPlayerController prefab is located at OVR > Prefabs.9

Hand Model PositioningIn the gameobject OVRCameraRig create the gameobjects Hands > Right.Place the prefab GlowRobotFullRightHand in Right and position it on the right of the players view.Set scale of the right hand to 5x5x5.

GlowRobotFullRightHand prefab is located in LeapMotion > Prefabs > HandGraphics.10

Integrate Myo Controls with HandPlace the Hub 1 Myo prefab in the root of the hierarchy.Attach the script JointOrientation to the OVRCameraRig > Hands > Right gameobject.Drag the Myo gameobject into the Myo variable in the JointOrientation script.Bug fix: Set Rotation Amount to 0 in OVRPlayerController as JointOrientation has an existing bug where the arm rotates incorrectly when the player rotates.

The JointOrientation script will map Myos gyroscope based movements to the arm model.Hub 1 Myo prefab is located in Myo > Prefabs.The bug fix though has a setback where the player wont be able to rotate and can only move forwards, backwards and strafe sideways.11

Setup Magic PowersCreate a Plane object under Right gameobject and position in front of the hand models index finger.Name the plane object MagicLauncher and disable its Mesh Collider and Mesh Renderer and ensure its X axis faces forward from finger.Attach a new C# script called MagicController on Right gameobject.

Resize the plane to the dimensions of a finger to make it easier to place it.12

MagicController.cs (1)using UnityEngine;using System.Collections;

using Pose = Thalmic.Myo.Pose;

public class MagicController : MonoBehaviour {// Myo game object to connect with.// This object must have a ThalmicMyo script attached.public GameObject myo = null;

// Point from where magic projectiles will launch from the hand.// This object must be a plane placed either in front of the palm or at the tip of the hand's fingers.public GameObject handMagicLauncher;

public GameObject fistProjectile;public GameObject waveInProjectile;public GameObject waveOutProjectile;// Speed of projectilepublic float fistSpeed = 1000;public float waveInSpeed = 1000;public float waveOutSpeed = 1000;

// Cooldown until next projectile can be launchedpublic float projectileCooldown = 1;

protected ThalmicMyo myoController = null;private float projectileTimer = 0;

Setup variables for the scenes myo object, the hand magic launcher and the projectile attributes that map to the 3 used myo gestures.13

MagicController.cs (2)void Start () {myoController = myo.GetComponent ();}

void Update () {if (!myo && !myoController)return;if (projectileTimer > 0) {projectileTimer -= Time.deltaTime;return;} else {projectileTimer = projectileCooldown;}

switch (myoController.pose) {case Pose.Fist:Attack (fistProjectile, fistSpeed);break;case Pose.WaveIn:Attack (waveInProjectile, waveInSpeed);break;case Pose.WaveOut:Attack (waveOutProjectile, waveOutSpeed);break;}}

Projectiles will have a cooldown before they are re-launched, which you can set with the public variable projectileCooldown.The Attack function will be called based on which of the 3 myo gestures are detected, with the magic projectile object (a prefab we will set soon) and the speed of the projectile passed into this object.14

MagicController.cs (3)protected void Attack(GameObject projectilePrefab, float speed) {GameObject projectile;

projectile = (GameObject) Instantiate (projectilePrefab.gameObject, handMagicLauncher.transform.position, Quaternion.identity);projectile.rigidbody.AddForce (handMagicLauncher.gameObject.transform.forward * speed);}}

The Attack method handles all the magic shooting itself.An instance of the projectile object will be created at the position of the MagicLauncher object we positioned in front of the hand earlier.The Quaternion.identity parameter will ensure the projectile faces the default X axis direction.Now we will throw the projectile by adding force in the forward direction of the handMagicLauncher at the projectiles defined speed.15

Set Magic Public VariablesIn the MagicController script, set the following for the public variables:Myo Drop in the scenes Myo object.HandMagicLauncher Drop the MagicLauncher object under the Right gameobject. Projectiles Set as any of the projectile prefabs in Projectiles > Prefabs.Optionally you can also change the speed of each projectile and the cooldown period.

16

ExtrasAdd enemy spiders to the scene from Enemies > Spider > Prefabs and play around with its health, speed, FOV, size etc.Add new magic attacks and change their attributes.Add player health and damage to make the game more challenging.

For new magic projectiles, you can find more in KY_magicEffectsFree > prefab. Just make sure you add a rigidbody, collider and at least the MagicProjectile.cs script. See the existing projectile prefabs in Projectiles > Prefabs for guidance.When playing the game, you can re-calibrate the arms position by pressing the r key or doing the fingers spread gesture.There are currently no scripts to add health and damage to the player, this is for you to figure out!17

Good Luck!