leapMotionFrameStore.cpp
Engine/source/platform/input/leapMotion/leapMotionFrameStore.cpp
Public Variables
Detailed Description
Public Variables
MODULE_END
MODULE_INIT
MODULE_SHUTDOWN
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/input/leapMotion/leapMotionFrameStore.h" 25#include "platform/input/leapMotion/leapMotionFrame.h" 26#include "core/module.h" 27#include "console/simSet.h" 28#include "console/consoleTypes.h" 29 30MODULE_BEGIN( LeapMotionFrameStore ) 31 32 MODULE_INIT_AFTER( LeapMotionDevice ) 33 MODULE_INIT_AFTER( Sim ) 34 MODULE_SHUTDOWN_BEFORE( Sim ) 35 MODULE_SHUTDOWN_BEFORE( LeapMotionDevice ) 36 37 MODULE_INIT 38 { 39 LeapMotionFrameStore::staticInit(); 40 ManagedSingleton< LeapMotionFrameStore >::createSingleton(); 41 } 42 43 MODULE_SHUTDOWN 44 { 45 ManagedSingleton< LeapMotionFrameStore >::deleteSingleton(); 46 } 47 48MODULE_END; 49 50S32 LeapMotionFrameStore::smMaximumFramesStored = 30; 51 52SimGroup* LeapMotionFrameStore::smFrameGroup = NULL; 53 54LeapMotionFrameStore::LeapMotionFrameStore() 55{ 56 // Set up the SimGroup to store our frames 57 smFrameGroup = new SimGroup(); 58 smFrameGroup->registerObject("LeapMotionFrameGroup"); 59 smFrameGroup->setNameChangeAllowed(false); 60 Sim::getRootGroup()->addObject(smFrameGroup); 61} 62 63LeapMotionFrameStore::~LeapMotionFrameStore() 64{ 65 if(smFrameGroup) 66 { 67 smFrameGroup->deleteObject(); 68 smFrameGroup = NULL; 69 } 70} 71 72void LeapMotionFrameStore::staticInit() 73{ 74 Con::addVariable("LeapMotion::MaximumFramesStored", TypeS32, &smMaximumFramesStored, 75 "@brief The maximum number of frames to keep when $LeapMotion::GenerateWholeFrameEvents is true.\n\n" 76 "@ingroup Game"); 77} 78 79S32 LeapMotionFrameStore::generateNewFrame(const Leap::Frame& frame, const F32& maxHandAxisRadius) 80{ 81 // Make sure our group has been created 82 if(!smFrameGroup) 83 return 0; 84 85 // Either create a new frame object or pull one off the end 86 S32 frameID = 0; 87 if(smFrameGroup->size() >= smMaximumFramesStored) 88 { 89 // Make the last frame the first and update 90 LeapMotionFrame* frameObj = static_cast<LeapMotionFrame*>(smFrameGroup->last()); 91 smFrameGroup->bringObjectToFront(frameObj); 92 frameObj->copyFromFrame(frame, maxHandAxisRadius); 93 frameID = frameObj->getId(); 94 } 95 else 96 { 97 // Create a new frame and add it to the front of the list 98 LeapMotionFrame* frameObj = new LeapMotionFrame(); 99 frameObj->registerObject(); 100 smFrameGroup->addObject(frameObj); 101 smFrameGroup->bringObjectToFront(frameObj); 102 frameObj->copyFromFrame(frame, maxHandAxisRadius); 103 frameID = frameObj->getId(); 104 } 105 106 return frameID; 107} 108