Ejemplo n.º 1
0
        static void ButtonCB(String evt, uint obj, String thread, IntPtr cache, IntPtr pUserData)
        {
            uint             spring = (uint)pUserData;
            HLCallbackEvents cEvent = (HLCallbackEvents)Enum.Parse(typeof(HLCallbackEvents), evt);

            if (cEvent == HLCallbackEvents.HL_EVENT_1BUTTONDOWN)
            {
                double[] anchor = new double[3];
                HLAPI.hlCacheGetDoublev(cache, HLCacheGetParameters.HL_PROXY_POSITION, anchor);

                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_GAIN, 0.8);
                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_MAGNITUDE, 1.0);
                HLAPI.hlEffectdv(HLEffectParams.HL_EFFECT_PROPERTY_POSITION, anchor);
                HLAPI.hlStartEffect(HLStartEffectTypes.HL_EFFECT_SPRING, spring);     //弹力
                //HLAPI.hlStartEffect(HLStartEffectTypes.HL_EFFECT_FRICTION, friction);     //摩擦力
                //HLAPI.hlStartEffect(HLStartEffectTypes.HL_EFFECT_VISCOUS, viscous);     //粘滞效果
            }
            else if (cEvent == HLCallbackEvents.HL_EVENT_1BUTTONUP)
            {
                HLAPI.hlStopEffect(spring);
            }
        }
Ejemplo n.º 2
0
        static void ButtonCB(String evt, uint obj, String thread, IntPtr cache, IntPtr pUserData)
        {
            //Console.WriteLine(Marshal.PtrToStringAnsi(evt));
            Console.WriteLine("{0}  {1}  {2}", obj, (uint)pUserData, evt);
            Console.WriteLine("{0}  {1}", evt, thread);

            uint              spring    = (uint)pUserData;
            HLCallbackEvents  cb_event  = (HLCallbackEvents)Enum.Parse(typeof(HLCallbackEvents), evt);
            HLCallbackThreads cb_thread = (HLCallbackThreads)Enum.Parse(typeof(HLCallbackThreads), thread);

            if (cb_event == HLCallbackEvents.HL_EVENT_1BUTTONDOWN)
            {
                double[] anchor = new double[3];
                HLAPI.hlCacheGetDoublev(cache, HLCacheGetParameters.HL_PROXY_POSITION, anchor);

                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_GAIN, 0.8);
                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_MAGNITUDE, 1.0);
                HLAPI.hlEffectdv(HLEffectParams.HL_EFFECT_PROPERTY_POSITION, anchor);
                HLAPI.hlStartEffect(HLStartEffectTypes.HL_EFFECT_SPRING, spring);
            }
            else if (cb_event == HLCallbackEvents.HL_EVENT_1BUTTONUP)
            {
                HLAPI.hlStopEffect(spring);
            }
            else if (cb_event == HLCallbackEvents.HL_EVENT_2BUTTONDOWN)
            {
                double[] direction = new double[3] {
                    0.0, 0.0, 1.0
                };
                double duration = 100; //持续 100ms

                //通过在短时间内指挥具有方向和大小的力来触发脉冲。
                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_DURATION, duration);
                HLAPI.hlEffectd(HLEffectParams.HL_EFFECT_PROPERTY_MAGNITUDE, 0.8);
                HLAPI.hlEffectdv(HLEffectParams.HL_EFFECT_PROPERTY_DIRECTION, direction);
                HLAPI.hlTriggerEffect(HLTriggerEffectTypes.HL_EFFECT_CONSTANT);
            }
        }