2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
25 #include "CustomForce.h"
\r
27 using namespace System;
\r
31 namespace DirectInput
\r
33 CustomForce::CustomForce()
\r
37 CustomForce^ CustomForce::FromData( void *data, int size )
\r
39 if( size != sizeof( DICUSTOMFORCE ) )
\r
42 CustomForce^ force = gcnew CustomForce();
\r
43 DICUSTOMFORCE *ptr = reinterpret_cast<DICUSTOMFORCE*>( data );
\r
45 force->Channels = ptr->cChannels;
\r
46 force->SamplePeriod = ptr->dwSamplePeriod;
\r
47 force->Samples = ptr->cSamples;
\r
48 force->ForceData = gcnew array<int>( ptr->cSamples );
\r
50 pin_ptr<int> pinnedData = &force->ForceData[0];
\r
51 memcpy( pinnedData, ptr->rglForceData, sizeof( int ) * force->ForceData->Length );
\r
56 int CustomForce::Size::get()
\r
58 return sizeof( DICUSTOMFORCE );
\r
61 void *CustomForce::ToUnmanaged()
\r
63 // Manual Allocation: released in Release function
\r
64 DICUSTOMFORCE *result = new DICUSTOMFORCE();
\r
66 result->cChannels = Channels;
\r
67 result->dwSamplePeriod = SamplePeriod;
\r
68 result->cSamples = Samples;
\r
70 // Manual Allocation: released in Release function
\r
71 result->rglForceData = new LONG[ForceData->Length];
\r
73 pin_ptr<int> pinnedData = &ForceData[0];
\r
74 memcpy( result->rglForceData, pinnedData, sizeof( int ) * ForceData->Length );
\r
79 void CustomForce::Release( void* data )
\r
81 DICUSTOMFORCE *result = reinterpret_cast<DICUSTOMFORCE*>( data );
\r
83 delete[] result->rglForceData;
\r
87 ConstantForce^ CustomForce::AsConstantForce()
\r
92 CustomForce^ CustomForce::AsCustomForce()
\r
97 PeriodicForce^ CustomForce::AsPeriodicForce()
\r
102 RampForce^ CustomForce::AsRampForce()
\r
107 ConditionSet^ CustomForce::AsConditionSet()
\r