PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ois/src/win32/extras/WiiMote/OISWiiMoteForceFeedback.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 76 lines | 35 code | 9 blank | 32 comment | 11 complexity | 788f445235957e5b03871d1bfc3b952f MD5 | raw file
 1#include "OISConfig.h"
 2#ifdef OIS_WIN32_WIIMOTE_SUPPORT
 3/*
 4The zlib/libpng License
 5
 6Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
 7
 8This software is provided 'as-is', without any express or implied warranty. In no event will
 9the authors be held liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose, including commercial 
12applications, and to alter it and redistribute it freely, subject to the following
13restrictions:
14
15    1. The origin of this software must not be misrepresented; you must not claim that 
16		you wrote the original software. If you use this software in a product, 
17		an acknowledgment in the product documentation would be appreciated but is 
18		not required.
19
20    2. Altered source versions must be plainly marked as such, and must not be 
21		misrepresented as being the original software.
22
23    3. This notice may not be removed or altered from any source distribution.
24*/
25#include "OISWiiMoteForceFeedback.h"
26#include "OISEffect.h"
27
28using namespace OIS;
29
30//-----------------------------------------------------------------------------------//
31WiiMoteForceFeedback::WiiMoteForceFeedback(cWiiMote &wiiMote) : mWiiMote(wiiMote), mHandle(-1)
32{
33	//One and only supported effect
34	_addEffectTypes( OIS::Effect::ConstantForce, OIS::Effect::Constant );
35}
36
37//-----------------------------------------------------------------------------------//
38WiiMoteForceFeedback::~WiiMoteForceFeedback()
39{
40	mWiiMote.SetVibration(false);
41}
42
43//-----------------------------------------------------------------------------------//
44void WiiMoteForceFeedback::upload( const Effect* effect )
45{
46	if( effect )
47	{
48		//Multiple effects are useless, just return
49		if( mHandle != -1 || effect->_handle != -1) return;
50		
51		//Ok, so we are uploading a fresh effect
52		effect->_handle = mHandle = 1;
53
54		mWiiMote.SetVibration(true);
55	}
56}
57
58//-----------------------------------------------------------------------------------//
59void WiiMoteForceFeedback::modify( const Effect* effect )
60{
61	//Nothing to modify
62}
63
64//-----------------------------------------------------------------------------------//
65void WiiMoteForceFeedback::remove( const Effect* effect )
66{
67	//We have no effects uploaded, so just return
68	if( mHandle == -1 || effect == 0) return;
69
70	if( mHandle == effect->_handle )
71	{
72		mWiiMote.SetVibration(false);
73		mHandle = effect->_handle = -1;
74	}
75}
76#endif