Пример #1
0
        static void Main(string[] args)
        {
            uint hHD = HDAPI.hdInitDevice(null);

            Console.WriteLine(HLAPI.hlGetString(HLGetStringParameters.HL_VENDOR));

            HDAPI.hdMakeCurrentDevice(hHD);

            IntPtr hHLRC = HLAPI.hlCreateContext(hHD);

            HLAPI.hlMakeCurrent(hHLRC);
            //禁用GL
            HLAPI.hlDisable(HLCapabilityParameters.HL_USE_GL_MODELVIEW);

            uint spring = HLAPI.hlGenEffects(1);

            Console.WriteLine("spring:{0}", spring);
            //添加回调处理按扭按下
            HLAPI.hlAddEventCallback(HLCallbackEvents.HL_EVENT_1BUTTONDOWN, HLAPI.HL_OBJECT_ANY, HLCallbackThreads.HL_CLIENT_THREAD, ButtonCB, new IntPtr(spring));
            HLAPI.hlAddEventCallback(HLCallbackEvents.HL_EVENT_1BUTTONUP, HLAPI.HL_OBJECT_ANY, HLCallbackThreads.HL_CLIENT_THREAD, ButtonCB, new IntPtr(spring));
            HLAPI.hlAddEventCallback(HLCallbackEvents.HL_EVENT_2BUTTONDOWN, HLAPI.HL_OBJECT_ANY, HLCallbackThreads.HL_CLIENT_THREAD, ButtonCB, new IntPtr(0));

            uint friction = HLAPI.hlGenEffects(1);

            HLAPI.hlBeginFrame();
            HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_GAIN, 0.2);
            HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_MAGNITUDE, 0.5);
            HLAPI.hlStartEffect(HLStartEffectTypes.HL_EFFECT_FRICTION, friction);
            HLAPI.hlEndFrame();

            HLError error;

            while (true)
            {
                HLAPI.hlBeginFrame();
                //轮询事件。请注意,客户端线程事件回调是从这里的一个框架内分派的,因此我们可以安全地直接启动/停止事件回调的效果
                HLAPI.hlCheckEvents();
                HLAPI.hlEndFrame();

                error = HLAPI.hlGetError();
                if (error.CheckedError())
                {
                    Console.WriteLine("HL Error:{0}", error.GetErrorCodeString());
                }
            }

            //Stop the friction effect.
            HLAPI.hlBeginFrame();
            HLAPI.hlStopEffect(friction);
            HLAPI.hlEndFrame();

            HLAPI.hlDeleteEffects(friction, 1);
            HLAPI.hlDeleteEffects(spring, 1);

            HLAPI.hlDeleteContext(hHLRC);
            HDAPI.hdDisableDevice(hHD);

            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            uint        hHD   = HDAPI.hdInitDevice(null);
            HDErrorInfo error = HDAPI.hdGetError();

            if (error.CheckedError())
            {
                Console.WriteLine("Initialize Device Failed.");
                Console.ReadKey();
                return;
            }

            HDAPI.hdMakeCurrentDevice(hHD);
            IntPtr hHLRC = HLAPI.hlCreateContext(hHD);

            HLAPI.hlMakeCurrent(hHLRC);

            HLAPI.hlDisable(HLCapabilityParameters.HL_USE_GL_MODELVIEW);
            uint   spring = HLAPI.hlGenEffects(1);
            IntPtr ptr    = new IntPtr(spring);

            HLAPI.hlAddEventCallback(HLCallbackEvents.HL_EVENT_1BUTTONDOWN, HLAPI.HL_OBJECT_ANY, HLCallbackThreads.HL_CLIENT_THREAD, ButtonCB, ptr);
            HLAPI.hlAddEventCallback(HLCallbackEvents.HL_EVENT_1BUTTONUP, HLAPI.HL_OBJECT_ANY, HLCallbackThreads.HL_CLIENT_THREAD, ButtonCB, ptr);

            while (true)
            {
                HLAPI.hlBeginFrame();
                //轮询事件。请注意,客户端线程事件回调是从这里的一个框架内分派的,因此我们可以安全地直接启动/停止事件回调的效果。
                HLAPI.hlCheckEvents();
                HLAPI.hlEndFrame();
            }

            HLAPI.hlDeleteEffects(spring, 1);
            HLAPI.hlDeleteContext(hHLRC);
            HDAPI.hdDisableDevice(hHD);
        }