Ejemplo n.º 1
0
        public void CopyPixel(int destX, int destY, int srcX, int srcY, RenderBitmap src, float lightAmt)
        {
            int srcIndex = (srcY * src.m_width + srcX);

            unsafe
            {
                RGBColor *rgbColor = (RGBColor *)((byte *)(m_data.Scan0 + m_data.Stride * destY + destX * 4));
                fixed(RGBColor *color = &src.m_components[srcIndex])
                {
                    rgbColor->r = (byte)(color->r * lightAmt);
                    rgbColor->g = (byte)(color->g * lightAmt);
                    rgbColor->b = (byte)(color->b * lightAmt);
                }
            }
        }
Ejemplo n.º 2
0
        public void Draw(RenderContext context, Matrix viewProjection, Matrix transform, RenderBitmap texture)
        {
            Matrix mvp = viewProjection.Mul(transform);
            int    n   = m_indices.Count;

            Parallel.For(0, (n / 3), i =>
            {
                int k = i * 3;
                var a = m_vertices[m_indices[k]].Transform(mvp, transform);
                var b = m_vertices[m_indices[k + 1]].Transform(mvp, transform);
                var c = m_vertices[m_indices[k + 2]].Transform(mvp, transform);
                context.DrawTriangle(a, b, c, texture);
            });

            //for (int i = 0; i < n ; i = i + 3)
            //{
            //    var a = m_vertices[m_indices[i]].Transform(mvp, transform);
            //    var b = m_vertices[m_indices[i + 1]].Transform(mvp, transform);
            //    var c = m_vertices[m_indices[i + 2]].Transform(mvp, transform);
            //    context.DrawTriangle(a, b, c, texture);
            //}
        }
Ejemplo n.º 3
0
        private void MainForLoad(object sender, EventArgs e)
        {
            //m_Timer = new System.Timers.Timer(15);
            //m_Timer.Elapsed += OnTimer_Elapsed;
            //m_Timer.Start();

            m_IsRunning = true;

            stopWatch.Start();

            this.WindowState = FormWindowState.Maximized;

            this.target = new RenderContext(this.Width, this.Height);

            this.texture         = new Lib.RenderBitmap("Resource/bricks.jpg");
            this.texture2        = new Lib.RenderBitmap("Resource/bricks2.jpg");
            this.monkeyMesh      = new Mesh("Resource/monkey.obj");
            this.monkeyTransform = new Transform(new Vector(0, 0.0f, 3.0f));

            this.terrainMesh      = new Mesh("Resource/terrain.obj");
            this.terrainTransform = new Transform(new Vector(0, -1.0f, 0.0f));

            this.input  = new Input();
            this.camera = new Camera(new Matrix().InitPerspective(Utils.ToRadians(70.0f), ((float)target.m_width / target.m_height), 0.1f, 1000.0f));

            UpdateBitmapSize();

            m_Thread = new System.Threading.Thread(() =>
            {
                var sw        = new Stopwatch();
                long time     = 0;
                long endTime  = 0;
                long nextTime = 0;
                float fps     = 0.0f;

                using (var gx = this.CreateGraphics())
                {
                    sw.Start();

                    while (m_IsRunning)
                    {
                        time = sw.ElapsedMilliseconds;

                        if (time > nextTime)
                        {
                            nextTime = nextTime + 10;
                            Draw(gx);
                        }

                        //m_Counter++;

                        //if (m_Counter >= 15)
                        //{
                        //    endTime = sw.ElapsedMilliseconds;
                        //    this.BeginInvoke((Action)(() =>
                        //    {
                        //        this.Text = fps.ToString();
                        //    }));
                        //}
                    }
                }
            });
            m_Thread.Start();
        }