Пример #1
0
        private unsafe float ConvertToSample(byte *buffer, int bitsPerSample, bool autoIncrementPtr = true, bool mindown = true)
        {
            float value;

            if (bitsPerSample == 8)
            {
                value = CSMath.Bit8ToFloat(buffer, mindown);
            }
            else if (bitsPerSample == 16)
            {
                value = CSMath.Bit16ToFloat(buffer, mindown);
            }
            else if (bitsPerSample == 24)
            {
                value = CSMath.Bit24ToFloat(buffer, mindown);
            }
            else if (bitsPerSample == 32)
            {
                value = CSMath.Bit32ToFloat(buffer, mindown);
            }
            else
            {
                throw new ArgumentOutOfRangeException("bitsPerSample");
            }

            if (autoIncrementPtr)
            {
                buffer += (bitsPerSample / 8);
            }

            return(value);
        }
Пример #2
0
    //player want to detect if an enemy is in front of it
    void Update()
    {
        ////ref http://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection

        ////how to define a plane:
        ////p,p0 are two points on plane, n is the normal of plane
        ////(p-p0)*n = 0 (* is dot)

        ////how to define a ray:
        ////l0 is the origin, p is the point intersect with plane, l is the direction of ray, t is the length of ray
        ////l0 + t*l = p

        ////(l0+t*l-p0)*n = 0
        ////t = (p0*n-l0*n)/(l*n)

        Vector3 p0 = planeTrans.position; //any point on plane would work
        Vector3 n  = -planeTrans.up;      //assume player is above plane

        Vector3 l0 = playerTrans.position;
        Vector3 l  = playerTrans.forward;



        ////take care the case when player face direction perpendicular to n, therefore no intersection
        //if(Mathf.Approximately(Vector3.Dot(l, n), 0))
        //{
        //    Debug.Log("no intersection");

        //}
        //else
        //{
        //    float t = (Vector3.Dot(p0, n) - Vector3.Dot(l0, n)) / Vector3.Dot(l, n);
        //    Vector3 p = l0 + t * l;
        //    lineRenderer.SetPosition(0, l0);
        //    lineRenderer.SetPosition(1, p);

        //    //unity version verify
        //    Ray ray = new Ray(l0, l);
        //    Plane plane = new Plane(n, p0);
        //    float distance;
        //    if (plane.Raycast(ray, out distance))
        //    {
        //        Debug.Assert(Mathf.Approximately(distance, t),"distance calculated from Unity "+distance +"does not equal to the one calculated from my math");
        //        //Debug.Log(distance+" "+t);
        //    }
        //}

        Vector3 intersection;

        if (CSMath.IsLineToPlaneIntersect(l0, l, n, p0, out intersection))
        {
            lineRenderer.SetPosition(0, l0);
            lineRenderer.SetPosition(1, intersection);
        }
    }
Пример #3
0
    //player want to detect if an enemy is in front of it
    void Update()
    {
        Vector3 intersection;

        if (line1.positionCount == 2 && line2.positionCount == 2)
        {
            if (CSMath.IsLineToLineIntersect(line1.GetPosition(0), line1.GetPosition(1), line2.GetPosition(0), line2.GetPosition(1), out intersection))
            {
                intersectionObject.SetActive(true);
                intersectionObject.transform.position = intersection;
            }
            else
            {
                intersectionObject.SetActive(false);
            }
        }
    }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (isMoving)
     {
         transform.position = transform.position + direction * speed * Time.deltaTime;
         if (CSMath.Vector3Equal(transform.position, target))
         {
             //CSUtil.LOG("Arrive target" + target);
             isMoving           = false;
             transform.position = target;
             if (player.willTeleportThis)
             {
                 player.TeleportArrived();
             }
             //achivement: keep jumping
         }
     }
 }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Invoke method in C# library by adding reference!");
            int[] array = { 1, 2, 3, 4, 5 };
            int   sum   = CSMath.sum(array);

            Console.WriteLine("Sum of array = {0}", sum);

            Console.WriteLine("Invoke method in C# library by loading dynamically!");
            Assembly   a   = Assembly.LoadFrom("../../../../CSharpLibrary/CSharpLibrary/bin/debug/netstandard2.0/CSharpLibrary.dll");
            Type       lib = a.GetType("CSharpLibrary.CSMath");
            MethodInfo mi  = lib.GetMethod("sum");
            object     o   = Activator.CreateInstance(lib);

            Object[] parameters = new Object[1];
            parameters[0] = array;
            sum           = (int)mi.Invoke(o, parameters);
            Console.WriteLine("Sum of array = {0}", sum);
            Console.WriteLine();


            Console.WriteLine("Invoke method in C++ library!");
            Console.WriteLine(getMax(1, 2));
            Console.WriteLine();


            // Referece
            // https://www.cnblogs.com/boby-/p/4724255.html

            Console.WriteLine("Registry Manipulation!");
            RegistryKey hklm = Registry.LocalMachine;

            Console.WriteLine("Create Entry");
            Console.WriteLine(hklm);
            RegistryKey hkSoftWare = hklm.CreateSubKey(@"SOFTWARE\test");

            hklm.Close();
            hkSoftWare.Close();

            Console.WriteLine("Open Entry");
            hklm       = Registry.LocalMachine;
            hkSoftWare = hklm.OpenSubKey(@"SOFTWARE\test", true);
            hklm.Close();
            hkSoftWare.Close();



            Console.WriteLine("Create Key-Value Pair");
            hklm       = Registry.LocalMachine;
            hkSoftWare = hklm.OpenSubKey(@"SOFTWARE\test", true);
            hkSoftWare.SetValue("MyKey", "MyValue", RegistryValueKind.String);
            hklm.Close();
            hkSoftWare.Close();

            Console.WriteLine("Open Key-Value Pair");
            hklm       = Registry.LocalMachine;
            hkSoftWare = hklm.OpenSubKey(@"SOFTWARE\test", true);
            string sValue = hkSoftWare.GetValue("MyKey").ToString();

            Console.WriteLine(sValue);
            hklm.Close();
            hkSoftWare.Close();

            Console.WriteLine("Delete Key-Value Pair");
            hklm       = Registry.LocalMachine;
            hkSoftWare = hklm.OpenSubKey(@"SOFTWARE\test", true);
            hkSoftWare.DeleteValue("MyKey", true);
            hklm.Close();
            hkSoftWare.Close();

            Console.WriteLine("Delete Entry");
            hklm = Registry.LocalMachine;
            hklm.DeleteSubKey(@"SOFTWARE\test", true);
            hklm.Close();
        }
Пример #6
0
        public unsafe FlacSubFrameLPC(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int bps, int order)
            : base(header)
        {
            //warmup
            _warmup = new int[FlacConstant.MAX_LPC_ORDER];
            for (int i = 0; i < order; i++)
            {
                _warmup[i] = data.residualBuffer[i] = reader.ReadBitsSigned(bps);
            }

            //header
            int u32 = (int)reader.ReadBits(FlacConstant.SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN);

            if (u32 == (1 << FlacConstant.SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1)
            {
                Debug.WriteLine("Invalid FlacLPC qlp coeff precision.");
                return; //return false;
            }
            _qlpCoeffPrecision = u32 + 1;

            int level = reader.ReadBitsSigned(FlacConstant.SUBFRAME_LPC_QLP_SHIFT_LEN);

            if (level < 0)
            {
                throw new Exception("negative shift");
            }
            _lpcShiftNeeded = level;

            _qlpCoeffs = new int[FlacConstant.MAX_LPC_ORDER];

            //qlp coeffs
            for (int i = 0; i < order; i++)
            {
                _qlpCoeffs[i] = reader.ReadBitsSigned(_qlpCoeffPrecision);
            }

            //QLPCoeffs = coeffs;

            Residual = new FlacResidual(reader, header, data, order);

            for (int i = 0; i < order; i++)
            {
                data.destBuffer[i] = data.residualBuffer[i];
            }

            if (bps + _qlpCoeffPrecision + CSMath.ILog(order) <= 32)
            {
                if (bps <= 16 && _qlpCoeffPrecision <= 16)
                {
                    RestoreLPCSignal(data.residualBuffer + order, data.destBuffer + order, header.BlockSize - order, order); //Restore(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order);
                }
                else
                {
                    RestoreLPCSignal(data.residualBuffer + order, data.destBuffer + order, header.BlockSize - order, order);
                }
            }
            else
            {
                RestoreLPCSignalWide(data.residualBuffer + order, data.destBuffer + order, header.BlockSize - order, order);//RestoreWide(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order);
            }

            //Warmup = warmup;
        }