Exemple #1
0
        private void RenderParticleSystem(int w, int h, TimeSpan renderTime)
        {
            Device.BeginScene();
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new ColorBGRA(0, 0, 0, 255), 1, 0);

            if (_timeSinceLastSimul.HasValue)
            {
                var simulTime = (float)(renderTime.TotalSeconds - _timeSinceLastSimul.Value.TotalSeconds);
                if (simulTime > 1 / 60.0f)
                {
                    _previewModel.AdvanceTime(simulTime);

                    if (!_model.Paused)
                    {
                        if (_activeSystem != null)
                        {
                            _activeSystem.Simulate(simulTime);
                            UpdateParticleStatistics();
                        }
                    }
                    _timeSinceLastSimul = renderTime;
                }
            }
            else
            {
                _timeSinceLastSimul = renderTime;
            }

            _previewModel?.Render(Device, w, h, _model.Scale);
            _activeSystem?.Render(Device, w, h, 0, 0, _model.Scale);

            Device.EndScene();
            Device.Present();
        }
Exemple #2
0
        private void DoRender(IntPtr surface, bool isNewSurface)
        {
            if (DisableRendering)
            {
                return;
            }

            var w = _outputWidth;
            var h = _outputHeight;

            if (w <= 0 || h <= 0)
            {
                return;
            }

            if (_activeSystem == null && ActiveSystem != null)
            {
                _activeSystem = ParticleSystem.FromSpec(ActiveSystem.ToSpec());
            }


            if (_timeSinceLastSimul.HasValue)
            {
                var simulTime = (float)(_lastRender.TotalSeconds - _timeSinceLastSimul.Value.TotalSeconds);
                if (simulTime > 1 / 60.0f)
                {
                    _previewModel?.AdvanceTime(simulTime);

                    if (!_model.Paused)
                    {
                        if (_activeSystem != null)
                        {
                            _activeSystem.Simulate(simulTime);
                            UpdateParticleStatistics();
                        }
                    }
                    _timeSinceLastSimul = _lastRender;
                }
            }
            else
            {
                _timeSinceLastSimul = _lastRender;
            }

            _templeDll.SetRenderTarget(surface);

            _templeDll.Scale = _model.Scale;
            _templeDll.CenterOn(0, 0, 0);

            _previewModel?.Render(TempleDll.Instance);
            _activeSystem?.Render();

            _templeDll.Flush();
        }