예제 #1
0
        public void TestProcess()
        {
            using Cheetah cheetah = Cheetah.Create(ACCESS_KEY, null, 0.2f);
            string       testAudioPath = Path.Combine(_relativeDir, "resources/audio_samples/test.wav");
            List <short> pcm           = GetPcmFromFile(testAudioPath, cheetah.SampleRate);

            int frameLen   = cheetah.FrameLength;
            int framecount = (int)Math.Floor((float)(pcm.Count / frameLen));

            string transcript = "";
            bool   isEndpoint = false;

            for (int i = 0; i < framecount; i++)
            {
                int               start         = i * cheetah.FrameLength;
                List <short>      frame         = pcm.GetRange(start, frameLen);
                CheetahTranscript transcriptObj = cheetah.Process(frame.ToArray());
                transcript += transcriptObj.Transcript;
                isEndpoint  = transcriptObj.IsEndpoint;
            }
            CheetahTranscript finalTranscriptObj = cheetah.Flush();

            transcript += finalTranscriptObj.Transcript;
            Assert.AreEqual(transcript, REF_TRANSCRIPT);
            Assert.IsTrue(isEndpoint);
        }
예제 #2
0
    static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.SayMyaau();

        // This wil not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
예제 #3
0
        public void TestCustomModel()
        {
            string testModelPath = Path.Combine(_relativeDir, "lib/common/cheetah_params.pv");

            using Cheetah cheetah = Cheetah.Create(ACCESS_KEY, testModelPath);
            string       testAudioPath = Path.Combine(_relativeDir, "resources/audio_samples/test.wav");
            List <short> pcm           = GetPcmFromFile(testAudioPath, cheetah.SampleRate);

            int frameLen   = cheetah.FrameLength;
            int framecount = (int)Math.Floor((float)(pcm.Count / frameLen));

            string transcript = "";

            for (int i = 0; i < framecount; i++)
            {
                int               start         = i * cheetah.FrameLength;
                List <short>      frame         = pcm.GetRange(start, frameLen);
                CheetahTranscript transcriptObj = cheetah.Process(frame.ToArray());
                transcript += transcriptObj.Transcript;
            }
            CheetahTranscript finalTranscriptObj = cheetah.Flush();

            transcript += finalTranscriptObj.Transcript;
            Assert.AreEqual(transcript, REF_TRANSCRIPT);
        }
    public static void Main()
    {
        Turtle turtle = new Turtle();
        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();
        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();
        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();
        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.SayMyaau();

        // This will not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
예제 #5
0
        public void TestFrameLength()
        {
            using Cheetah cheetah = Cheetah.Create(ACCESS_KEY);
            int Num = 0;

            Assert.IsTrue(int.TryParse(cheetah.FrameLength.ToString(), out Num), "Cheetah did not return a valid frame length.");
        }
예제 #6
0
        public void TestSampleRate()
        {
            using Cheetah cheetah = Cheetah.Create(ACCESS_KEY);
            int Num = 0;

            Assert.IsTrue(int.TryParse(cheetah.SampleRate.ToString(), out Num), "Cheetah did not return a valid sample rate.");
        }
    public static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.Breed = "siamska";//Ot dopalnitelnoto Property ot Cat
        Console.WriteLine("The breed of the {0} is {1}", kitten.GetName(), kitten.Breed);
        kitten.SayMyaau();

        // This will not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
예제 #8
0
        /// <summary>
        /// Creates an input audio stream and instantiates an instance of Cheetah object.
        /// </summary>
        /// <param name="accessKey">AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).</param>
        /// <param name="modelPath">Absolute path to the file containing model parameters. If not set it will be set to the default location.</param>
        /// <param name="endpointDurationSec">
        /// Duration of endpoint in seconds. A speech endpoint is detected when there is a segment of audio(with a duration specified herein) after
        /// an utterance without any speech in it. Set to `0` to disable
        /// </param>
        /// <param name="audioDeviceIndex">Optional argument. If provided, audio is recorded from this input device. Otherwise, the default audio input device is used.</param>
        public static void RunDemo(
            string accessKey,
            string modelPath,
            float endpointDurationSec,
            int audioDeviceIndex)
        {
            Cheetah cheetah = null;

            cheetah = Cheetah.Create(
                accessKey,
                modelPath,
                endpointDurationSec);

            PvRecorder recorder = PvRecorder.Create(audioDeviceIndex, cheetah.FrameLength);

            recorder.Start();
            List <short> audioFrame = new List <short>();


            Console.CancelKeyPress += (s, o) =>
            {
                Console.WriteLine("Stopping...");
            };


            Console.WriteLine($"\nUsing device: {recorder.SelectedDevice}");
            Console.WriteLine(">>> Press `CTRL+C` to exit:\n");

            try
            {
                while (true)
                {
                    short[] pcm = recorder.Read();

                    CheetahTranscript transcriptObj = cheetah.Process(pcm);
                    if (!String.IsNullOrEmpty(transcriptObj.Transcript))
                    {
                        Console.Write(transcriptObj.Transcript);
                    }
                    if (transcriptObj.IsEndpoint)
                    {
                        CheetahTranscript finalTranscriptObj = cheetah.Flush();
                        Console.WriteLine(finalTranscriptObj.Transcript);
                    }
                }
            }
            catch (CheetahActivationLimitException)
            {
                Console.WriteLine($"AccessKey '{accessKey}' has reached its processing limit.");
            }
            finally
            {
                cheetah.Dispose();
                recorder.Dispose();
            }
        }
    static void Main()
    {
        Turtle turtle = new Turtle();
        Console.WriteLine("The {0} can go {1} km/h ",
            turtle.GetName(), turtle.Speed);
        Cheetah cheetah = new Cheetah();
        Console.WriteLine("The {0} can go {1} km/h ",
            cheetah.GetName(), cheetah.Speed);

        System.Collections.Generic.List<int> l;
        System.DateTime dt;
    }
예제 #10
0
        /// <summary>
        /// Reads through input file and prints the transcription returned by Cheetah.
        /// </summary>
        /// <param name="inputAudioPath">Required argument. Absolute path to input audio file.</param>
        /// <param name="accessKey">AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).</param>
        /// <param name="modelPath">Absolute path to the file containing model parameters. If not set it will be set to the default location.</param>
        /// <param name="endpointDurationSec">
        /// Duration of endpoint in seconds. A speech endpoint is detected when there is a segment of audio(with a duration specified herein) after
        /// an utterance without any speech in it. Set to `0` to disable
        /// </param>
        /// </param>
        public static void RunDemo(
            string accessKey,
            string inputAudioPath,
            string modelPath)
        {
            // init Cheetah speech-to-text engine
            using Cheetah cheetah = Cheetah.Create(
                      accessKey,
                      modelPath);

            using BinaryReader reader = new BinaryReader(File.Open(inputAudioPath, FileMode.Open));
            ValidateWavFile(reader, cheetah.SampleRate, 16, out short numChannels);

            short[] cheetahFrame = new short[cheetah.FrameLength];
            int     frameIndex   = 0;

            while (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                cheetahFrame[frameIndex++] = reader.ReadInt16();

                if (frameIndex == cheetahFrame.Length)
                {
                    try
                    {
                        CheetahTranscript transcriptObj = cheetah.Process(cheetahFrame);
                        if (!String.IsNullOrEmpty(transcriptObj.Transcript))
                        {
                            Console.Write(transcriptObj.Transcript);
                        }
                    }
                    catch (CheetahActivationLimitException)
                    {
                        cheetah.Dispose();
                        Console.WriteLine($"AccessKey '{accessKey}' has reached its processing limit.");
                    }

                    frameIndex = 0;
                }

                // skip right channel
                if (numChannels == 2)
                {
                    reader.ReadInt16();
                }
            }
            CheetahTranscript finalTranscriptObj = cheetah.Flush();
            string            transcript         = finalTranscriptObj.Transcript;

            if (!String.IsNullOrEmpty(transcript))
            {
                Console.WriteLine(transcript);
            }
        }
    static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine("The {0} can go {1} km/h ",
                          turtle.GetName(), turtle.Speed);
        Cheetah cheetah = new Cheetah();

        Console.WriteLine("The {0} can go {1} km/h ",
                          cheetah.GetName(), cheetah.Speed);

        System.Collections.Generic.List <int> l;
        System.DateTime dt;
    }
        public static void Start()
        {
            PlayerBase playerA = new PlayerA();

            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            PlayerBase playerB = new PlayerB();

            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();

            Console.WriteLine("-------------With Decorators-----------");

            playerA = new Tiger(playerA);
            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            playerA = new Cheetah(playerA);
            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            playerB = new Kangaroo(playerB);
            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();

            playerB = new Tiger(playerB);
            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();
        }
예제 #13
0
    static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);                         //I am turtle
        Console.WriteLine("The {0} can go {1} km/h ",
                          turtle.GetName(), turtle.Speed); //The turtle can go 1 km/h

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);                          //I am cheetah
        Console.WriteLine("The {0} can go {1} km/h ",
                          cheetah.GetName(), cheetah.Speed); //The cheetah can go 100 km/h

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);                         //I am tomcat
        Console.WriteLine("The {0} can go {1} km/h ",
                          tomcat.GetName(), tomcat.Speed); //The tomcat can go 20 km/h
        tomcat.SayMyaau();                                 //Tomcat muaaaaaaaau

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);                         //I am kitten
        Console.WriteLine("The {0} can go {1} km/h ",
                          kitten.GetName(), kitten.Speed); //The kitten can go 5 km/h
        kitten.SayMyaau();                                 //Kitten miau, miaau

        // This wil not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
예제 #14
0
        protected unsafe void DrawSlow(Cheetah.Graphics.VertexBuffer vertices, PrimitiveType type, int offset, int count, IndexBuffer ib)
        {
            VertexFormat format = vertices.Format;
            CheckError();

            Array a;
            if (vertices is SlowVertexBuffer)
                a = (Array)((SlowVertexBuffer)vertices).data;
            else if (vertices is SlowDynamicVertexBuffer)
                a = (Array)((SlowDynamicVertexBuffer)vertices).data;
            else
                throw new Exception();

            IntPtr p = Marshal.UnsafeAddrOfPinnedArrayElement(a, 0);

            int offset2 = 0;
            byte* buffer = (byte*)p.ToPointer();
            int vertexsize = format.Size;

            for (int i = 0; i < format.Count; ++i)
            {
                VertexFormat.Element e = format[i];
                int datatype;
                int elementsize = e.Size;
                switch (e.Type)
                {
                    case VertexFormat.ElementType.Float:
                        datatype = (int)ColorPointerType.Float;
                        break;
                    case VertexFormat.ElementType.Byte:
                        datatype = (int)ColorPointerType.Byte;
                        break;
                    case VertexFormat.ElementType.Int:
                        datatype = (int)ColorPointerType.Int;
                        break;
                    default:
                        throw new Exception();
                }

                switch (e.Name)
                {
                    case VertexFormat.ElementName.Color:
                        GL.ColorPointer(e.Count, (ColorPointerType)datatype, vertexsize, (IntPtr)(buffer + offset2));
                        States.EnableClientState((int)GetPName.ColorArray);
                        break;
                    case VertexFormat.ElementName.Position:
                        GL.VertexPointer(e.Count, (VertexPointerType)datatype, vertexsize, (IntPtr)(buffer + offset2));
                        States.EnableClientState((int)GetPName.VertexArray);
                        break;
                    case VertexFormat.ElementName.Texture0:
                        GL.TexCoordPointer(e.Count, (TexCoordPointerType)datatype, vertexsize, (IntPtr)(buffer + offset2));
                        States.EnableClientState((int)GetPName.TextureCoordArray);
                        break;
                    case VertexFormat.ElementName.Normal:
                        GL.NormalPointer((NormalPointerType)datatype, vertexsize, (IntPtr)(buffer + offset2));
                        States.EnableClientState((int)GetPName.NormalArray);
                        break;
                    default:
                        throw new Exception();
                }

                offset2 += elementsize;
            }

            BeginMode gltype;
            switch (type)
            {
                case PrimitiveType.QUADS:
                    gltype = BeginMode.Quads;
                    break;
                case PrimitiveType.TRIANGLESTRIP:
                    gltype = BeginMode.TriangleStrip;
                    break;
                case PrimitiveType.TRIANGLES:
                    gltype = BeginMode.Triangles;
                    break;
                case PrimitiveType.LINES:
                    gltype = BeginMode.Lines;
                    break;
                case PrimitiveType.LINESTRIP:
                    gltype = BeginMode.LineStrip;
                    break;
                case PrimitiveType.POINTS:
                    gltype = BeginMode.Points;
                    break;
                default:
                    throw new Exception();
            }

            if (ib == null)
            {
                GL.DrawArrays(gltype, offset, count);
            }
            else
            {
                GL.DrawElements(gltype, count, DrawElementsType.UnsignedInt, ib.buffer);
            }
            States.DisableClientState((int)GetPName.ColorArray);
            States.DisableClientState((int)GetPName.VertexArray);
            States.DisableClientState((int)GetPName.TextureCoordArray);
            States.DisableClientState((int)GetPName.NormalArray);
            CheckError();
        }
예제 #15
0
        public void UseShader(Cheetah.Graphics.Shader s)
        {
            CheckError();
            if (s != null)
            {
                CurrentShader = ((Shader)s);
                int id = CurrentShader.ProgramId;

                GL.UseProgram(id);
            }
            else
            {
                CurrentShader = null;
                GL.UseProgram(0);
            }
            CheckError();
        }
예제 #16
0
 public void BindTexture(Cheetah.TextureId t, int unit)
 {
     //
     Device.Textures[unit] = ((TextureId)t).XnaTexture;
 }
예제 #17
0
 public HeightMapImage(Cheetah.Graphics.Image _img)
 {
     size=new Point(_img.Width,_img.Width);
     img=_img;
 }
예제 #18
0
 public RenderTarget CreateRenderTarget(Cheetah.TextureId texture, Cheetah.TextureId depth)
 {
     throw new System.Exception("The method or operation is not implemented.");
 }
예제 #19
0
        public void CheetahTest()
        {
            Cheetah cheetah = new Cheetah();

            Console.WriteLine(cheetah.IsFast);
        }
예제 #20
0
 public void BindTexture(Cheetah.TextureId t)
 {
     BindTexture(t, 0);
     /*if (t != null)
     {
         t.LastBind = Root.Instance.Time;
         States.Enable(TextureTarget.Texture2D);
         GL.BindTexture(TextureTarget.Texture2D, ((TextureId)t).id);
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, -1);
         States.Disable(TextureTarget.Texture2D);
     }*/
 }
예제 #21
0
 public void FreeShader(Cheetah.Shader s)
 {
 }
예제 #22
0
        public void TestCheetahInheritedBehavior()
        {
            Cheetah cheetah = new Cheetah();

            Assert.True(cheetah.CanFloat);
        }
예제 #23
0
        public void Draw(string text, float x, float y, float sx, float sy, Cheetah.Texture t, Color4f color, float width, RectangleF scissor)
        {
            int c = 16;
            float f = 1 / (float)c;
            BindTexture(t.Id);

            //if (CompabilityMode)
            //{
            //    GL.PushMatrix();
            //    GL.LoadIdentity();
            //    GL.MatrixMode(GL._PROJECTION);
            //    GL.PushMatrix();
            //    GL.LoadIdentity();
            //    GL.Ortho(0, 1, 1, 0, -1, 10);
            //    GL.Color4f(color.r, color.g, color.b, color.a);

            //    for (int i = 0; i < text.Length; ++i)
            //    {
            //        int a = text[i];
            //        float xf = a % c, yf = a / c;

            //        GL.Begin(GL._QUADS);

            //        GL.TexCoord2f(xf * f, yf * f);
            //        GL.Vertex2f(x + (float)i * sx, y);

            //        GL.TexCoord2f(xf * f + f, yf * f);
            //        GL.Vertex2f(x + sx + (float)i * sx, y);

            //        GL.TexCoord2f(xf * f + f, yf * f + f);
            //        GL.Vertex2f(sx + x + (float)i * sx, sy + y);

            //        GL.TexCoord2f(xf * f, yf * f + f);
            //        GL.Vertex2f(x + (float)i * sx, y + sy);

            //        GL.End();
            //    }
            //    GL.PopMatrix();
            //    GL.MatrixMode(GL._MODELVIEW);
            //    GL.PopMatrix();
            //}
            //else
            {
                UseShader(TextShader);

                int fontsizeindex = TextShader.GetUniformLocation("FontSize");
                int colorindex = TextShader.GetUniformLocation("Color");
                int charsizeindex = TextShader.GetUniformLocation("CharSize");
                int textureindex = TextShader.GetUniformLocation("Texture");
                int scissorindex = TextShader.GetUniformLocation("Scissor");

                SetUniform(fontsizeindex, new float[] { sx, sy });
                SetUniform(colorindex, new float[] { color.r, color.g, color.b, color.a });
                SetUniform(charsizeindex, new float[] { f });
                if(scissorindex>=0)
                    SetUniform(scissorindex, new float[] { scissor.Left,scissor.Top,scissor.Right,scissor.Bottom });

                int charposindex = TextShader.GetAttributeLocation("CharPos");
                int posindex = TextShader.GetAttributeLocation("Pos");

                for (int i = 0; i < text.Length; ++i)
                {
                    int a = text[i];
                    float xf = a % c, yf = a / c;

                    SetAttribute(charposindex, new float[] { xf, yf });
                    SetAttribute(posindex, new float[] { x + ((float)i) * width, y });

                    GL.Begin(BeginMode.Quads);
                    GL.Vertex2(0, 0);
                    GL.Vertex2(1, 0);
                    GL.Vertex2(1, 1);
                    GL.Vertex2(0, 1);
                    GL.End();
                }

                UseShader(null);
            }

            BindTexture(null);
        }
예제 #24
0
 public void FreeTexture(Cheetah.TextureId t)
 {
     ((TextureId)t).XnaTexture.Dispose();
     ((TextureId)t).XnaTexture = null;
 }
예제 #25
0
 public void UpdateTexture(Cheetah.TextureId t, byte[] rgba)
 {
     ((TextureId)t).XnaTexture.SetData<byte>(rgba, 0, rgba.Length, SetDataOptions.Discard);
 }
예제 #26
0
 public void UseShader(Cheetah.Shader s)
 {
     Device.VertexShader = ((Shader)s).XnaVertexShader;
     Device.PixelShader = ((Shader)s).XnaPixelShader;
 }
예제 #27
0
 public void BindRenderTarget(Cheetah.RenderTarget target)
 {
     CheckError();
     if (target != null)
     {
         currentwidth=((TextureId)target.Texture).w;
         currentheight = ((TextureId)target.Texture).h;
         GL.BindFramebuffer(FramebufferTarget.FramebufferExt, ((RenderTarget)target).id);
     }
     else
     {
         currentwidth = width;
         currentheight = height;
         GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
     }
     CheckError();
 }
예제 #28
0
        //VertexFormat lastformat = null;
        //Cheetah.VertexBuffer lastbuffer = null;
        //Cheetah.Shader lastshader = null;
        public void Draw(Cheetah.Graphics.VertexBuffer vertices, PrimitiveType type, int offset, int count, IndexBuffer ib, int indexoffset)
        {
            if (vertices is SlowVertexBuffer || vertices is SlowDynamicVertexBuffer)
            {
                DrawSlow(vertices, type, offset, count, ib);
                return;
            }
            CheckError();

            VertexFormat format;
            if (vertices is VertexBuffer)
            {
                VertexBuffer vb = (VertexBuffer)vertices;
                format = vertices.Format;
                GL.BindBuffer(BufferTarget.ArrayBuffer, vb.id);
            }
            else if (vertices is DynamicVertexBuffer)
            {
                DynamicVertexBuffer vb = (DynamicVertexBuffer)vertices;
                format = vertices.Format;
                GL.BindBuffer(BufferTarget.ArrayBuffer, vb.id);
            }
            else
                throw new Exception("wrong vertexbuffer type: "+vertices.GetType().ToString());

            if (format == null)
                throw new Exception("no vertex format.");

            int vertexsize = format.Size;

            //if (lastformat == null || format != lastformat || lastbuffer==null||vertices!=lastbuffer || lastshader==null||lastshader!=CurrentShader)
            {
                bool[] attribs = new bool[16];
                for (int i = 0; i < attribs.Length; ++i)
                    attribs[i] = false;

                bool GL_COLOR_ARRAY = false;
                bool GL_VERTEX_ARRAY = false;
                bool GL_NORMAL_ARRAY = false;
                bool GL_TEXTURE_COORD_ARRAY = false;

                int start = 0;
                for (int i = 0; i < format.Count; ++i)
                {
                    VertexFormat.Element e = format[i];
                    int datatype;
                    int elementsize = e.Size;
                    switch (e.Type)
                    {
                        case VertexFormat.ElementType.Float:
                            datatype = (int)ColorPointerType.Float;
                            break;
                        case VertexFormat.ElementType.Byte:
                            datatype = (int)ColorPointerType.Byte;
                            break;
                        case VertexFormat.ElementType.Int:
                            datatype = (int)ColorPointerType.Int;
                            break;
                        default:
                            throw new Exception();
                    }

                    int startwithoffset = start;
                    if (ib != null)
                        startwithoffset += offset * format.Size;

                    switch (e.Name)
                    {
                        case VertexFormat.ElementName.Color:
                            GL.ColorPointer(e.Count, (ColorPointerType)datatype, vertexsize, new IntPtr(startwithoffset));
                            GL_COLOR_ARRAY = true;
                            //States.EnableClientState(GL._COLOR_ARRAY);
                            break;
                        case VertexFormat.ElementName.Position:
                            GL.VertexPointer(e.Count, (VertexPointerType)datatype, vertexsize, new IntPtr(startwithoffset));
                            GL_VERTEX_ARRAY = true;
                            //States.EnableClientState(GL._VERTEX_ARRAY);
                            break;
                        case VertexFormat.ElementName.Texture0:
                            GL_TEXTURE_COORD_ARRAY = true;
                            States.ClientActiveTexture((int)TextureUnit.Texture0);
                            GL.TexCoordPointer(e.Count, (TexCoordPointerType)datatype, vertexsize, new IntPtr(startwithoffset));
                            States.EnableClientState((int)GetPName.TextureCoordArray);
                            /*States.ClientActiveTexture(GL._TEXTURE1);
                            GL.TexCoordPointer(e.Count, datatype, vertexsize, new IntPtr(startwithoffset));
                            States.EnableClientState(GL._TEXTURE_COORD_ARRAY);
                            States.ClientActiveTexture(GL._TEXTURE0);*/
                            break;
                        case VertexFormat.ElementName.Normal:
                            GL.NormalPointer((NormalPointerType)datatype, vertexsize, new IntPtr(startwithoffset));
                            GL_NORMAL_ARRAY = true;
                            //GL.VertexAttribPointer(14, 3, GL._FLOAT, false, vertexsize, new IntPtr(start));
                            //GL.EnableVertexAttribArray(14);
                            break;
                        case VertexFormat.ElementName.Tangent:
                            if (CurrentShader != null)
                            {
                                int loc = CurrentShader.GetAttributeLocation("tangent");
                                if (loc >= 0)
                                {
                                    GL.VertexAttribPointer(loc, e.Count, VertexAttribPointerType.Float, false, vertexsize, new IntPtr(startwithoffset));
                                    attribs[loc]=true;
                                }
                            }
                            break;
                        case VertexFormat.ElementName.Binormal:
                            if (CurrentShader != null)
                            {
                                int loc = CurrentShader.GetAttributeLocation("binormal");
                                if (loc >= 0)
                                {
                                    GL.VertexAttribPointer(loc, e.Count, VertexAttribPointerType.Float, false, vertexsize, new IntPtr(startwithoffset));
                                    attribs[loc] = true;
                                }
                            }
                            break;
                        case VertexFormat.ElementName.Texture1:
                            States.ClientActiveTexture((int)TextureUnit.Texture1);
                            GL.TexCoordPointer(e.Count, (TexCoordPointerType)datatype, vertexsize, new IntPtr(startwithoffset));
                            GL_TEXTURE_COORD_ARRAY = true;
                            States.EnableClientState((int)GetPName.TextureCoordArray);
                            States.ClientActiveTexture((int)TextureUnit.Texture0);
                            break;
                        /*case VertexFormat.ElementName.None:
                            if (CurrentShader == null)
                                throw new Exception("");
                            int loc=CurrentShader.GetAttributeLocation(e.Attrib);
                            GL.VertexAttribPointer(loc, e.Count, GL._FLOAT, false, vertexsize, new IntPtr(start));
                            GL.EnableVertexAttribArray(loc);
                            break;*/
                        default:
                            throw new Exception("unknown vertexformat name.");
                    }
                    if (e.Attrib != null && e.Attrib != "")
                    {
                        //if (CurrentShader == null)
                        //    throw new Exception("");
                        int loc = CurrentShader.GetAttributeLocation(e.Attrib);
                        if (loc >= 0)
                        {
                            GL.VertexAttribPointer(loc, e.Count, VertexAttribPointerType.Float, false, vertexsize, new IntPtr(startwithoffset));
                            attribs[loc] = true;
                        }
                    }
                    else if (e.Name == VertexFormat.ElementName.None)
                    {
                        throw new Exception("no name and no attrib");
                    }

                    start += elementsize;
                }

                for (int i = 0; i < 16; ++i)
                {
                    if(attribs[i])
                        States.EnableVertexAttribArray(i);
                    else
                        States.DisableVertexAttribArray(i);
                }

                if(GL_COLOR_ARRAY)
                    States.EnableClientState((int)GetPName.ColorArray);
                else
                    States.DisableClientState((int)GetPName.ColorArray);
                if (GL_VERTEX_ARRAY)
                    States.EnableClientState((int)GetPName.VertexArray);
                else
                    States.DisableClientState((int)GetPName.VertexArray);
                if (GL_NORMAL_ARRAY)
                    States.EnableClientState((int)GetPName.NormalArray);
                else
                    States.DisableClientState((int)GetPName.NormalArray);

                CheckError();

            }

            BeginMode gltype;
            switch (type)
            {
                case PrimitiveType.QUADS:
                    gltype = BeginMode.Quads;
                    break;
                case PrimitiveType.TRIANGLESTRIP:
                    gltype = BeginMode.TriangleStrip;
                    break;
                case PrimitiveType.TRIANGLES:
                    gltype = BeginMode.Triangles;
                    break;
                case PrimitiveType.LINES:
                    gltype = BeginMode.Lines;
                    break;
                case PrimitiveType.LINESTRIP:
                    gltype = BeginMode.LineStrip;
                    break;
                case PrimitiveType.POINTS:
                    gltype = BeginMode.Points;
                    break;
                default:
                    throw new Exception();
            }

            if (ib == null)
            {
                GL.DrawArrays(gltype, offset, count);
            }
            else
            {
                //GL.DrawElements(gltype, count, GL._UNSIGNED_INT, ib.buffer);
                //fixed (int* startindex = ib.buffer)
                IntPtr startindex = Marshal.UnsafeAddrOfPinnedArrayElement(ib.buffer, indexoffset);
                {
                    //GL.DrawElements(gltype, count, GL._UNSIGNED_INT, new IntPtr(startindex+indexoffset));
                    GL.DrawElements(gltype, count, DrawElementsType.UnsignedInt, startindex);
                }
            }

            CheckError();
        }
예제 #29
0
        public void BindTexture(Cheetah.TextureId t, int unit)
        {
            unit += (int)TextureUnit.Texture0;
            CheckError();

            if (t != null)
            {
                t.LastBind = Root.Instance.Time;
                TextureId t2 = (TextureId)t;

                States.ActiveTexture(unit);
                //States.Disable(TextureTarget.Texture2D);

                TextureTarget x = t2.cube ? TextureTarget.TextureCubeMap : TextureTarget.Texture2D;
                States.Enable((int)x);
                GL.BindTexture(x, t2.id);
            }
            else
            {
                States.ActiveTexture(unit);
                //GL.BindTexture(TextureTarget.Texture2D,-1);
                States.Disable((int)TextureTarget.Texture2D);
                States.Disable((int)TextureTarget.TextureCubeMap);
            }
            States.ActiveTexture((int)TextureUnit.Texture0);

            CheckError();
        }
예제 #30
0
 public void FreeShader(Cheetah.Graphics.Shader s)
 {
 }
예제 #31
0
        public Cheetah.RenderTarget CreateRenderTarget(Cheetah.TextureId texture, Cheetah.TextureId depth)
        {
            if (texture == null && depth == null)
            {
                if (fbo_disabled)
                    throw new Exception();
                return null;
            }
            CheckError();

            int index;
            int[] tmp = new int[1];
            GL.GenFramebuffers(1, tmp);
            index = tmp[0];
            if (index <= 0)
                throw new Exception("cant create framebuffer.");

            GL.BindFramebuffer(FramebufferTarget.FramebufferExt, index);

            //GL.FramebufferTexture2DEXT(GL._FRAMEBUFFER_EXT, GL._DEPTH_ATTACHMENT_EXT, TextureTarget.Texture2D, d, 0);
            if (depth != null)
            {
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt,TextureTarget.Texture2D, ((TextureId)depth).id, 0);
            }

            GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, ((TextureId)texture).id, 0);

            FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.FramebufferExt);
            if (status == FramebufferErrorCode.FramebufferCompleteExt)
            {
            }
            else
            {
                throw new Exception("framebuffer check failed.");
            }

            GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

            CheckError();
            return new RenderTarget(index, (TextureId)texture);
        }
예제 #32
0
 public void FreeTexture(Cheetah.TextureId t)
 {
     int[] i = new int[] { ((TextureId)t).id };
     GL.DeleteTextures(1, i);
     Textures.Remove(i[0]);
     CheckError();
 }
예제 #33
0
        public void Draw(Cheetah.VertexBuffer vertices, PrimitiveType type, int offset, int count, IndexBuffer ib, int indexoffset)
        {
            Device.BeginScene();

            XnaVertexBuffer vb;
            if (vertices is StaticVertexBuffer)
                vb = ((StaticVertexBuffer)vertices).XnaBuffer;
            else
                vb = ((DynamicVertexBuffer)vertices).XnaBuffer;

            Microsoft.Xna.Framework.Graphics.PrimitiveType pt;
            int primcount;
            switch (type)
            {
                case PrimitiveType.LINES:
                    pt = Microsoft.Xna.Framework.Graphics.PrimitiveType.LineList;
                    primcount = count / 2;
                    break;
                case PrimitiveType.LINESTRIP:
                    pt = Microsoft.Xna.Framework.Graphics.PrimitiveType.LineStrip;
                    primcount = count - 1;
                    break;
                case PrimitiveType.POINTS:
                    pt = Microsoft.Xna.Framework.Graphics.PrimitiveType.PointList;
                    primcount = count;
                    break;
                case PrimitiveType.QUADS:
                    throw new System.Exception("no QUADS!");
                    break;
                case PrimitiveType.TRIANGLES:
                    pt = Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList;
                    primcount = count / 3;
                    break;
                case PrimitiveType.TRIANGLESTRIP:
                    pt = Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleStrip;
                    primcount = count - 2;
                    break;
                case PrimitiveType.TRIANGLEFAN:
                    throw new System.Exception("no TRIANGLEFAN!");
                    break;
                default:
                    throw new System.Exception("??");

            }

            Device.Vertices[0].SetSource(vb, 0, vertices.Format.Size);
            VertexElement[] ve = new VertexElement[vertices.Format.Count];
            int eoffset=0;
            for (int i = 0; i < ve.Length; ++i)
            {
                switch (vertices.Format[i].Count)
                {
                    case 1:
                        ve[i].VertexElementFormat = VertexElementFormat.Single;
                        break;
                    case 2:
                        ve[i].VertexElementFormat = VertexElementFormat.Vector2;
                        break;
                    case 3:
                        ve[i].VertexElementFormat = VertexElementFormat.Vector3;
                        break;
                    case 4:
                        ve[i].VertexElementFormat = VertexElementFormat.Vector4;
                        break;
                    default:
                        throw new System.Exception("???");
                }

                ve[i].Offset = (short)eoffset;
                //ve[i].UsageIndex

                eoffset+=vertices.Format[i].Count*4;
            }

            Device.VertexDeclaration=new VertexDeclaration(Device,ve);

            Device.DrawIndexedPrimitives(pt, offset, 0, vertices.Count, indexoffset, primcount);

            Device.EndScene();
        }
예제 #34
0
 public void FreeVertexBuffer(Cheetah.Graphics.VertexBuffer b)
 {
     FreeQueue.Enqueue(b);
 }
예제 #35
0
 public void TestVersion()
 {
     using Cheetah cheetah = Cheetah.Create(ACCESS_KEY);
     Assert.IsFalse(string.IsNullOrWhiteSpace(cheetah?.Version), "Cheetah did not return a valid version number.");
 }
예제 #36
0
 public void UpdateTexture(Cheetah.TextureId t, byte[] rgba)
 {
     CheckError();
     TextureId t1 = (TextureId)t;
     GL.BindTexture(TextureTarget.Texture2D, t1.id);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
     GL.TexImage2D<byte>(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, t1.w, t1.h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, rgba);
     CheckError();
 }
예제 #37
0
 public void Draw(string text, float x, float y, float sx, float sy, Cheetah.Texture t,Color4f color,float width)
 {
     Draw(text, x, y, sx, sy, t, color, width, new RectangleF(0, 0, 1, 1));
 }
예제 #38
0
 public void BindTexture(Cheetah.TextureId t)
 {
     BindTexture(t, 0);
 }
예제 #39
0
 public void Draw(Cheetah.Graphics.VertexBuffer vertices, PrimitiveType type, int offset, int count, IndexBuffer ib)
 {
     Draw(vertices, type, offset, count, ib, 0);
 }
예제 #40
0
        public void TestMethod1()
        {
            Animal firstAnimal = new Animal();

            firstAnimal.LegCount = 4; //cannot access sloth props, only its own


            Sloth sloth = new Sloth();

            sloth.LegCount = 4;        //CAN access animal props and its own
            bool value = sloth.IsSlow; //cant declare, must set to variable as it already has a unchanging value

            Megatherium giantSloth = new Megatherium();

            giantSloth.HasTail   = false;
            giantSloth.IsExtinct = true;

            Cat firstCat = new Cat();

            firstCat.MakeSound(); //Meow

            Liger liger = new Liger();

            liger.MakeSound(); //hover shows Liger.MakeSound only, not Cat.MakeSound
            Cheetah chee = new Cheetah();

            chee.MakeSound(); //Purr.
            //chee is purr here, but not below as a Cat type

            List <Cat> catList = new List <Cat>(); //works with Animal too, but not Sloths

            catList.Add(firstCat);
            catList.Add(liger);
            catList.Add(chee);                              //works, happy

            List <Animal> animalList = new List <Animal>(); //works with cats, and sloths

            animalList.Add(firstCat);
            animalList.Add(liger);
            animalList.Add(chee);
            animalList.Add(giantSloth);

            foreach (Animal animal in animalList)
            {
                //cant call MakeSound() because not all animals have MakeSound
                //can only call Animal properties, not children properties
            }

            //foreach(Cat animal in animalList) //doesnt work, gets stuck at non-Cats
            //{
            //    animal.MakeSound();
            //}
            foreach (Animal animal in animalList)
            {
                //if(animal.GetType() == typeof(Cat)) //Must be Cat type! Liger and Cheetah types wont count as Cat! and skips
                if (animal is Cat) //works with Cat and children of Cat (ie Liger and Cheetah) but not Sloth etc
                {
                    //casting yay!
                    Cat cat = (Cat)animal;
                    //cant do above if type isnt already Cat (ex. sloths)
                    //if using (animal is Cat), casting still retains Liger as Liger, etc
                    cat.MakeSound(); //so cat meows and liger still roars
                    //Cheetah didnt purr, because it called original MakeSound, not new MakeSound
                    //new made method unrelated to original MakeSound;
                }
            }
        }