关于体感互动Airkinect研究-《案例篇1》
目录:
案例一:
目标:实现kinect 控制Air制作的互动。手虚拟控制 移动到“播放影片”,“沙盘体验”上的时候时候,出现水波效果,当水波满后,进入对应页面
初步完成,稍后奉上源码,后期更新 kinect手势控制沙盘。
package { import flash.display.Sprite; import flash.events.Event; import flash.ui.Mouse; import flash.display.StageDisplayState; import com.as3nui.nativeExtensions.air.kinect.Kinect; import com.as3nui.nativeExtensions.air.kinect.KinectSettings; import com.as3nui.nativeExtensions.air.kinect.events.CameraImageEvent; import com.as3nui.nativeExtensions.air.kinect.constants.CameraResolution; import flash.display.Bitmap; import com.as3nui.nativeExtensions.air.kinect.data.User; import com.as3nui.nativeExtensions.air.kinect.data.SkeletonJoint; import com.as3nui.nativeExtensions.air.kinect.events.UserEvent; public class Main extends Sprite { private var device:Kinect; private var bmp:Bitmap; private var skeletonContainer:Sprite; private var circle:Circle; public function Main() { if (Kinect.isSupported()) { bmp = new Bitmap ; addChild(bmp); skeletonContainer = new Sprite ; addChild(skeletonContainer); /*circle = new Circle ; circle.x = -100; circle.y = -100; skeletonContainer.addChild(circle);*/ device = Kinect.getDevice(); device.addEventListener(CameraImageEvent.DEPTH_IMAGE_UPDATE, rgbImageUpdateHandler); device.addEventListener(UserEvent.USERS_WITH_SKELETON_ADDED, skeletonsAddedHandler, false, 0, true); device.addEventListener(UserEvent.USERS_WITH_SKELETON_REMOVED, skeletonsRemovedHandler, false, 0, true); var settings:KinectSettings = new KinectSettings(); settings.depthEnabled = true; settings.skeletonEnabled = true; addEventListener(Event.ENTER_FRAME,loop); device.start(settings); } } public function skeletonsAddedHandler(event:UserEvent):void { circle = new Circle ; circle.x = -100; circle.y = -100; skeletonContainer.addChild(circle); } public function skeletonsRemovedHandler(event:UserEvent):void { clearContainer(); } public function loop(e:Event):void { //clearContainer(); for each (var user:User in device.usersWithSkeleton) { var head:SkeletonJoint = user.getJointByName("right_hand"); circle.x = head.position.depthRelative.x * stage.stageWidth; circle.y = head.position.depthRelative.y * stage.stageHeight; /*for each (var joint:SkeletonJoint in user.skeletonJoints) { skeletonContainer.graphics.beginFill(0xff0000) skeletonContainer.graphics.drawCircle(joint.position.depth.x,joint.position.depth.y,3) skeletonContainer.graphics.endFill() var circle:Circle = new Circle ; circle.x = joint.position.depth.x; circle.y = joint.position.depth.y; skeletonContainer.addChild(circle); }*/ } } public function rgbImageUpdateHandler(event:CameraImageEvent):void { bmp.bitmapData = event.imageData; } public function clearContainer():void { while (skeletonContainer.numChildren != 0) { skeletonContainer.removeChildAt(0); } } } }
剩下的就只是碰撞检测去进行判断是否选中。