Exemple #1
0
        void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (control.IsHandleCreated == false || control.IsDisposed)
            {
                renderTimer.Enabled = false;
                return;
            }
            if (isAlreadyRendering)
            {
                return;
            }
            isAlreadyRendering = true;
            control.BeginInvoke(new MethodInvoker(delegate
            {
                if (BeforeRendering != null)
                {
                    BeforeRendering(this, null);
                }
                w.ScreenSize  = control.Size;
                w.CenterPoint = new PointF(translation.X + xOff, translation.Y + yOff);

                lock (renderLock)
                {
                    Gl.glLoadIdentity();
                    GLUtility.SetClearColor(clearColor);
                    camCurrent.UpdateWithWorldTransform(w);
                    camPrev.UpdateWithWorldTransform(w);
                    double camT = 1.0;
                    GLUtility.InitScene(camCurrent, camPrev, camT, control.Size);
                    GLUtility.DrawGrid3D(1, w, -0.1f, Color.LightGray, Color.Black, Color.Red);

                    //make sure everything in the rendering chain gets rendered....
                    Dictionary <IRender, bool> didRender = new Dictionary <IRender, bool>(drawables.Count);
                    foreach (IRender r in drawables)
                    {
                        didRender.Add(r, false);
                    }
                    foreach (IRender r in drawables)
                    {
                        if (r != null && !r.VehicleRelative)
                        {
                            r.Draw(this);
                            if (didRender.ContainsKey(r))
                            {
                                didRender[r] = true;
                            }
                        }
                    }

                    lock (robotPoseLock)
                    {
                        foreach (KeyValuePair <int, RobotPose> kvp in robotPoses)
                        {
                            GLUtility.GoToVehicleCoordinates((float)kvp.Value.yaw, new PointF((float)kvp.Value.x, (float)kvp.Value.y), false);
                            foreach (IRender r in drawables)
                            {
                                if (r != null && r.VehicleRelative && r.VehicleRelativeID == kvp.Key)
                                {
                                    r.Draw(this); if (didRender.ContainsKey(r))
                                    {
                                        didRender[r] = true;
                                    }
                                }
                            }
                            GLUtility.ComeBackFromVehicleCoordinates();
                        }
                    }
                    //check we rendered everytihng!
                    foreach (KeyValuePair <IRender, bool> kvp in didRender)
                    {
                        if (kvp.Value == false)
                        {
                            //Console.WriteLine("Renderer warning: did not render " + kvp.Key.GetName() + " correctly becuase robot " + kvp.Key.VehicleRelativeID + " has no pose in the renderer. Rendering at Pose (0,0,0)");
                            if (kvp.Key != null)
                            {
                                kvp.Key.Draw(this);
                            }
                        }
                    }

                    //draw the tools....
                    foreach (IRenderTool tool in tools)
                    {
                        if (tool.IsActive)
                        {
                            tool.Draw(this);
                        }
                    }


                    control.SwapBuffers();
                    if (AfterRendering != null)
                    {
                        AfterRendering(this, null);
                    }
                    isAlreadyRendering = false;
                }
            }));
        }