Exemplo n.º 1
0
        private void renderedControl1_Rendered(object sender, RenderEventArgs e)
        {
            int   tickCount = Environment.TickCount;
            float deltaTime = (tickCount - _previousTickCount) / 1000f;

            _previousTickCount = tickCount;

            _simulator.Update(deltaTime);
            _framesCount++;
            int secondsCount = (tickCount - _startTickCount) / 1000;

            if (secondsCount != 0)
            {
                label.Text = String.Format("FPS: {0}", _framesCount / secondsCount);
            }

            //draw scene
            var render = e.Render;

            render.BeginScene();

            render.Draw(() =>
            {
                _simulator.ActorsFactory.AcceptVisit(_renderingVisitor);
            },
                        Lights.Point(new Vector3(0, 5, -6), new Vector3(1, 1, 1)),
                        Cameras.LookAt(new Vector3(0, 15, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0)),
                        Cameras.Perspective(render.GetAspectRatio()),
                        Buffers.Clear(0.2f, 0.2f, 0.4f, 1),
                        Buffers.ClearDepth(),
                        Shaders.Phong
                        );
            render.EndScene();
            renderedControl1.Invalidate();
        }
Exemplo n.º 2
0
        private void renderedControl1_Rendered(object sender, RenderEventArgs e)
        {
            //update simulation

            int   tickCount = Environment.TickCount;
            float deltaTime = (tickCount - _previousTickCount) / 1000f;

            _previousTickCount = tickCount;

            _simulator.Update(deltaTime);
            _framesCount++;
            int secondsCount = (tickCount - _startTickCount) / 1000;

            if (secondsCount != 0)
            {
                label.Text = String.Format("FPS: {0}", _framesCount / secondsCount);
            }
            //add forces
            //foreach (IRigidBody forceRigidBody in _forceBodies)
            //{
            //    forceRigidBody.Forces.AddForce(1000 * Vectors.ZAxis);
            //}


            //draw scene
            var render = e.Render;

            render.BeginScene();

            render.Draw(() =>
            {
                foreach (IRigidBody rigidBody in _simulator.ActorsFactory.Elements)
                {
                    if (rigidBody.FixtureFactory.Element is ISimpleFixture)
                    {
                        var simpleFixture = (ISimpleFixture)rigidBody.FixtureFactory.Element;
                        DrawSimpleFixture(simpleFixture, render, rigidBody);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            },
                        Lights.Point(new Vector3(0, 5, -6), new Vector3(1, 1, 1)),
                        Cameras.LookAt(new Vector3(0, 15, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0)),
                        Cameras.Perspective(render.GetAspectRatio()),
                        Buffers.Clear(0.2f, 0.2f, 0.4f, 1),
                        Buffers.ClearDepth(),
                        Shaders.Phong
                        );

            render.EndScene();

            renderedControl1.Invalidate();
        }
Exemplo n.º 3
0
        private void DrawScene(RenderEventArgs e)
        {
            var render = e.Render;

            render.Draw(() =>
            {
                DrawScene(render);
            },
                        Lights.Point(new Vector3(0, 5, -6), new Vector3(1, 1, 1)),
                        Cameras.LookAt(new Vector3(0, 15, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0)),
                        Cameras.Perspective(render.GetAspectRatio()),
                        Buffers.Clear(0.2f, 0.2f, 0.4f, 1),
                        Buffers.ClearDepth(), Shaders.Phong
                        );
        }
Exemplo n.º 4
0
        private void DrawScene(RenderEventArgs e)
        {
            var render = e.Render;

            render.Draw(() =>
            {
                foreach (RigidBody rigidBody in _simulation.RigidBodies)
                {
                    render.Draw((IModel)rigidBody.UserData,
                                new Transforming(rigidBody.Pose.ToStandard()),
                                Materials.DeepPink.Glossy.Shinness.Glossy.Shinness);
                }
            },
                        Lights.Point(new Vector3(0, 5, -6), new Vector3(1, 1, 1)),
                        Cameras.LookAt(new Vector3(0, 15, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0)),
                        Cameras.Perspective(render.GetAspectRatio()),
                        Buffers.Clear(0.2f, 0.2f, 0.4f, 1),
                        Buffers.ClearDepth(), Shaders.Phong
                        );
        }