Example #1
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        protected override void Draw()
        {
            if (cameraConfig != null)
            {
                float averageX = cameraConfig.Cameras.Select(x => x.PositionVector.X).Average();
                float averageY = cameraConfig.Cameras.Select(x => x.PositionVector.Y).Average();
                float averageZ = cameraConfig.Cameras.Select(x => x.PositionVector.Z).Average();

                if (IRLocationRender)
                {
                    //ViewMatrix = Matrix.CreateTranslation(-currentTrackX, -currentTrackY, -currentTrackZ);
                    //ViewMatrix = ViewMatrix;// * Matrix.CreateFromYawPitchRoll(yaw * dragSensitivity, roll * dragSensitivity, pitch * dragSensitivity);
                    ViewMatrix = Matrix.Identity;

                    if (ViewTrackModel)
                    {
                        ViewMatrix = ViewMatrix * Matrix.CreateLookAt(new Vector3(currentTrackX, currentTrackY, currentTrackZ), new Vector3(ModelX, ModelY, ModelZ), new Vector3(customUpX, customUpY, customUpZ));
                    }
                    else
                    {
                        ViewMatrix = Matrix.CreateTranslation(-currentTrackX, -currentTrackY, -currentTrackZ);
                        ViewMatrix = ViewMatrix * Matrix.CreateFromYawPitchRoll(yaw * dragSensitivity, roll * dragSensitivity, pitch * dragSensitivity);
                    }
                }
                else
                {
                    ViewMatrix = Matrix.CreateTranslation(-averageX, -averageY, -averageZ);
                    ViewMatrix = ViewMatrix * Matrix.CreateFromYawPitchRoll(yaw * dragSensitivity, roll * dragSensitivity, pitch * dragSensitivity);
                    ViewMatrix = ViewMatrix * Matrix.CreateTranslation(0, 0, -(5 * globalScaling));// *Matrix.CreateReflection(new Plane(new Vector4(1, 1, 0, 0)));
                }
                GraphicsDevice.Clear(Color.CornflowerBlue);

                try
                {
                    if (cameraConfig != null)
                    {
                        IntersectionLines.Clear();

                        for (int i = 0; i < cameraConfig.Cameras.Count; i++)
                        {
                            RegisteredCamera thisCamera = cameraConfig.Cameras[i];
                            drawCamera(thisCamera);
                            //drawCamera2(thisCamera);
                            drawRays(thisCamera, i);
                        }
                        //drawPoints(cameraConfig);
                        drawIntersections();
                        if (ShowModel)
                        {
                            drawModel(ModelX, ModelY, ModelZ);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Example #2
0
        private void drawRays(RegisteredCamera thisCamera, int i)
        {
            //for each tracked point project from the camera centre to the point:

            float aspect = GraphicsDevice.Viewport.AspectRatio;

            effect.World = Matrix.Identity * Matrix.CreateTranslation(viewTranslationVector);

            //effect.World = effect.World * Matrix.CreateTranslation(thisCamera.PositionVector);

            //effect.World = effect.World * Matrix.CreateFromYawPitchRoll(yaw * dragSensitivity, pitch * dragSensitivity, roll * dragSensitivity);

            //effect.World = effect.World * Matrix.CreateScale(globalScaling);

            //effect.View = Matrix.CreateFromYawPitchRoll(yaw * dragSensitivity, pitch * dragSensitivity, roll * dragSensitivity) * Matrix.CreateLookAt(new Vector3(0, 0, -5 * globalScaling),
            //                                  Vector3.Zero, Vector3.Up);

            effect.View = ViewMatrix;

            effect.Projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 0.01f, 100);



            //for (int i = 0; i < thisCamera.TrackedPoints.Count; i++)
            //{

            //int i = (int)rotAngleX;
            //if (i < thisCamera.TrackedPoints.Count)
            //{


            //TrackedImagePoint thisPoint = thisCamera.TrackedPoints[i];
            int testy = 0;

            //if (WebCamPermute != null)
            //{
            //int thisCamIndex = WebCamPermute[i];
            int thisCamIndex = i;

            if (thisCamIndex < WebCamsEye.Count)
            {
                if (WebCamsEye[thisCamIndex].FilteredTrackedPoints != null)
                {
                    if (WebCamsEye[thisCamIndex].FilteredTrackedPoints.TrackedPoints != null)
                    {
                        if (WebCamsEye[thisCamIndex].FilteredTrackedPoints.TrackedPoints.Count > 0)
                        {
                            //if (WebCamPermute.Count > 0)
                            // {
                            try
                            {
                                for (int r = 0; r < WebCamsEye[thisCamIndex].FilteredTrackedPoints.TrackedPoints.Count; r++)
                                {
                                    WebCamTrack thisTrack = WebCamsEye[thisCamIndex].FilteredTrackedPoints.TrackedPoints[r];

                                    if (thisTrack.Points.Count > 0)
                                    {
                                        Vector3 WordCoordinates = thisCamera.ImageToWorld(thisTrack.Points.Select(x => x.X).Average(), thisTrack.Points.Select(x => x.Y).Average(), -100, transposeRot, negateRot, invertRot, invertZ, rotAngleX, rotAngleY, rotAngleZ);
                                        //Vector3 WordCoordinates = thisCamera.ImageToWorld(thisTrack.Points[0].X, thisTrack.Points[0].Y, -100, transposeRot, negateRot, invertRot, invertZ, rotAngleX, rotAngleY, rotAngleZ);

                                        Vector3 startPoint = new Vector3(thisCamera.PositionVector.X, thisCamera.PositionVector.Y, thisCamera.PositionVector.Z);
                                        Vector3 endPoint   = new Vector3(WordCoordinates.X, (float)WordCoordinates.Y, (float)WordCoordinates.Z);

                                        //trackInCamera.Add(thisCamIndex);
                                        IntersectionLines.Add(new Line3D {
                                            LineStart = new Point3D(startPoint.X, startPoint.Y, startPoint.Z), LineEnd = new Point3D(endPoint.X, endPoint.Y, endPoint.Z)
                                        });

                                        effect.CurrentTechnique.Passes[0].Apply();
                                        var vertices = new[] { new VertexPositionColor(startPoint, Microsoft.Xna.Framework.Color.Red), new VertexPositionColor(endPoint, Microsoft.Xna.Framework.Color.Red) };
                                        effect.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
                                    }
                                    else
                                    {
                                        //trackInCamera[thisCamIndex] = false;
                                    }
                                }
                            }
                            catch (Exception test)
                            {
                                testy = 1;
                            }
                            return;
                            //}
                        }
                        else
                        {
                            //trackInCamera[thisCamIndex] = false;
                        }
                    }
                }
                //}
                //IntersectionLines[thisCamIndex].Displ
            }
        }