Ejemplo n.º 1
0
        private RenderedPrimitives GetPixelSpacePrimitives(PerspectiveType perspectiveType)
        {
            if (Renderer == null)
            {
                return(new RenderedPrimitives());
            }

            var renderedPrimitives = Renderer.GetRenderedPrimitives(perspectiveType, this);

            var trasnformedPoints = renderedPrimitives.Points
                                    .Select(point => new Vertex2D(
                                                ConvertPointToPixelSpace(point.Position),
                                                point.Color
                                                )).ToList();

            var trasnformedPixels = renderedPrimitives.RawPixels
                                    .Select(point => new Vertex2D(
                                                ConvertPointToPixelSpace(point.Position),
                                                point.Color
                                                )).ToList();

            var transformedLines = renderedPrimitives.Lines
                                   .Select(line => new Line2D(
                                               ConvertPointToPixelSpace(line.From),
                                               ConvertPointToPixelSpace(line.To),
                                               line.Color
                                               )).ToList();

            return(new RenderedPrimitives()
            {
                RawPixels = trasnformedPixels,
                Points = trasnformedPoints,
                Lines = transformedLines,
            });
        }
Ejemplo n.º 2
0
        protected override void OnDrawAfterInterfaceMoveLine()
        {
            base.OnDrawAfterInterfaceMoveLine();

            EditorGUILayout.BeginHorizontal();

            EditorStatics.CreateLabelField("Display", string.Empty, EditorStatics.Width_70);

            viewType = (ViewType)EditorGUILayout.EnumPopup(
                string.Empty,
                viewType,
                EditorStatics.Width_90
                );

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            EditorStatics.CreateLabelField("Perspective", string.Empty, EditorStatics.Width_70);

            perspectiveType = (PerspectiveType)EditorGUILayout.EnumPopup(
                string.Empty,
                perspectiveType,
                EditorStatics.Width_90
                );

            EditorGUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        private Matrix4X4 GetProjectionMatrix(PerspectiveType perspectiveType)
        {
            var camera = Scene?.Camera;

            if (camera == null)
            {
                return(Matrix4X4.Identity);
            }

            var aspectMatrix = Transformations3D.Scaling(new Vector3D(1.0 / _aspectRatio, 1.0, 1.0));

            Matrix4X4 projection;

            switch (perspectiveType)
            {
            case PerspectiveType.Standard:
                projection = aspectMatrix * camera.GetPerspectiveMatrix();
                break;

            case PerspectiveType.LeftEye:
                projection = aspectMatrix * camera.GetPerspectiveMatrix(-EyeDistance);
                break;

            case PerspectiveType.RightEye:
                projection = aspectMatrix * camera.GetPerspectiveMatrix(+EyeDistance);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(perspectiveType), perspectiveType, null);
            }
            return(projection);
        }
Ejemplo n.º 4
0
 /**
  * Provides the point in the image corresponding to a ray projecting
  * from the camera.
  *
  * Given a ray projected from the camera in the specified direction, ``RectilinearToPixel()``
  * corrects for camera distortion and returns the corresponding pixel
  * coordinates in the image.
  *
  * The ray direction is specified in relationship to the camera. The first
  * vector element corresponds to the "horizontal" view angle; the second
  * corresponds to the "vertical" view angle.
  *
  * \include Image_warp_1.txt
  *
  * The ``RectilinearToPixel()`` function returns pixel coordinates outside of the image bounds
  * if you project a ray toward a point for which there is no recorded data.
  *
  * ``RectilinearToPixel()`` is typically not fast enough for realtime distortion correction.
  * For better performance, use a shader program exectued on a GPU.
  *
  * **Note:** This function should be called immediately after an image is obtained. Incorrect
  * results will be returned if the image orientation has changed or a different device is plugged
  * in between the time the image was received and the time this function is called.
  *
  * Note, this function was formerly named Warp().
  *
  * @param camera whether the ray parameter intercepts the left or the right stereo image.
  * @param ray A Vector containing the ray direction.
  * @returns A Vector containing the pixel coordinates [x, y, 1] (with z always one).
  * @since 2.1.0
  */
 public Vector RectilinearToPixel(PerspectiveType camera, Vector ray)
 {
     if (this.IsValid && imageData.isComplete)
     {
         Connection connection = Connection.GetConnection();
         return(connection.RectilinearToPixel(camera, ray));
     }
     return(Vector.Zero);
 }
Ejemplo n.º 5
0
 /**
  * Provides the corrected camera ray intercepting the specified point on the image.
  *
  * Given a point on the image, ``PixelToRectilinear()`` corrects for camera distortion
  * and returns the true direction from the camera to the source of that image point
  * within the Leap Motion field of view.
  *
  * This direction vector has an x and y component [x, y, 1], with the third element
  * always one. Note that this vector uses the 2D camera coordinate system
  * where the x-axis parallels the longer (typically horizontal) dimension and
  * the y-axis parallels the shorter (vertical) dimension. The camera coordinate
  * system does not correlate to the 3D Leap Motion coordinate system.
  *
  * \include Image_rectify_1.txt
  *
  * **Note:** This function should be called immediately after an image is obtained. Incorrect
  * results will be returned if the image orientation has changed or a different device is plugged
  * in between the time the image was received and the time this function is called.
  *
  * Note, this function was formerly named Rectify().
  *
  * @param camera whether the pixel parameter is a pixel in the left or the right stereo image.
  * @param pixel A Vector containing the position of a pixel in the image.
  * @returns A Vector containing the ray direction (the z-component of the vector is always one).
  * @since 2.1.0
  */
 public Vector PixelToRectilinear(PerspectiveType camera, Vector pixel)
 {
     if (this.IsValid && imageData.isComplete)
     {
         Connection connection = Connection.GetConnection();
         return(connection.PixelToRectilinear(camera, pixel));
     }
     return(Vector.Zero);
 }
        private PerspectiveInterval ExpectedInterval(int startOffsetInMinutes,
                                                     int endOffsetInMinutes,
                                                     PerspectiveType type)
        {
            var interval = base.ExpectedInterval(startOffsetInMinutes, endOffsetInMinutes);

            interval.Perspective = type;
            return(interval);
        }
Ejemplo n.º 7
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
//  public override void _Process(float delta)
//  {
//
//  }
    /// <summary>
    /// Sets the viewport's camera to the perspective specified by the button press id
    /// passed by the button connection signal.
    /// </summary>
    /// <param name = "id">The PerspectiveTypeEmun value for the camera perspective associated with the toolbar button</param>
    ///
    private void toolbarChangePerspective(int id)
    {
        currentPerspective = (PerspectiveType)id;
        Node tmp = this.GetNode("../Viewport/Camera/CameraObj");

        GD.Print(tmp.Name);
        GD.Print(tmp.GetType());
        Godot.Camera tmp2 = (Godot.Camera)tmp;

        Godot.Camera subCam  = (Godot.Camera)GetNode("../Viewport/Camera/CameraObj");
        Script       gdClass = ResourceLoader.Load("res://src/CameraObj.gd") as Script;
        Object       gdCam   = new Object();

        gdCam = (Godot.Object)gdClass.Call("new");
        gdCam.SetScript(gdClass);


        switch (currentPerspective)
        {
        case PerspectiveType.Front:

            //GD.Print(subCam.GetClass() + subCam.GetFilename());

            Vector3 newLook = new Vector3(5, 1, 0);
            subCam.LookAtFromPosition(newLook, new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.Back:
            //subCam = GetNode<Camera>("../Viewport/Camera/CameraObj");
            newLook = new Vector3(-5, 1, 0);
            subCam.LookAtFromPosition(newLook, new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.Orthogonal:
            //subCam = GetNode<Camera>("../Viewport/Camera/CameraObj");
            subCam.SetOrthogonal(3, 1, 10);
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.NOrthogonal:
            subCam.Projection = 0;
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        default:
            GD.Print("Unrecognized Menu Item");
            break;
        }
    }
Ejemplo n.º 8
0
 public void InitPerspective(PerspectiveType type)
 {
     if (selectedPespective == PerspectiveType.none)
     {
         selectedPespective = type;
     }
     else
     {
         Debug.LogError("try to change perspective in an unproper case");
     }
 }
Ejemplo n.º 9
0
        private static Color?GetPerspectiveColorOverride(PerspectiveType perspectiveType)
        {
            Color?perspectiveColorOverride = null;

            switch (perspectiveType)
            {
            case PerspectiveType.LeftEye:
                perspectiveColorOverride = RightEyeFilteredColor;
                break;

            case PerspectiveType.RightEye:
                perspectiveColorOverride = LeftEyeFilteredColor;
                break;
            }
            return(perspectiveColorOverride);
        }
Ejemplo n.º 10
0
 public void Rotate(double x, double y, double z)
 {
     m_editableHull.Rotate(x, y, z);
     _perspective = PerspectiveType.PERSPECTIVE;
     IsEditable   = false;
 }
Ejemplo n.º 11
0
        public RenderedPrimitives GetRenderedPrimitives(PerspectiveType perspectiveType, RenderTarget renderTarget)
        {
            // todo: fixme
            _aspectRatio = (float)renderTarget.OutputBitmap.PixelWidth
                           / renderTarget.OutputBitmap.PixelHeight;

            var projection = GetProjectionMatrix(perspectiveType);
            var viewProj   = projection * Scene.Camera.GetViewMatrix();

            var rasterizedLines          = new List <Line2D>();
            var perspectiveColorOverride =
                GetPerspectiveColorOverride(perspectiveType);

            foreach (var worldObject in Scene.Objects)
            {
                worldObject.PrerenderUpdate();
            }

            if (Scene.GrabbedObjects.Count > 0)
            {
                Scene.Manipulator.Position =
                    Scene.GrabbedObjects.First().WorldPosition;
            }

            foreach (var worldObject in Scene.Objects)
            {
                var shape          = worldObject.Shape;
                var transformation = viewProj * worldObject.GetWorldMatrix();

                var dynamicShape = shape as IDynamicShape;
                dynamicShape?.UpdateGeometry(

                    /*(p1, p2) => // calculate with clip (only visible length)
                     * {
                     *  var v1 = ((Vector3D) p1).ExtendTo4D();
                     *  var v2 = ((Vector3D) p2).ExtendTo4D();
                     *  if (!TransformLineWithClip(transformation, ref v1, ref v2))
                     *      return 0.0;
                     *  var pt1 = renderTarget.ConvertPointToPixelSpace((Point) v1);
                     *  var pt2 = renderTarget.ConvertPointToPixelSpace((Point) v2);
                     *  return (pt1-pt2).Length;
                     * },*/
                    (p1, p2) =>
                {
                    var v1 = (Point)((Vector3D)p1).ExtendTo4D().Transform(transformation).WDivide();
                    var v2 = (Point)((Vector3D)p2).ExtendTo4D().Transform(transformation).WDivide();
                    return((renderTarget.ConvertPointToPixelSpace(v1) - renderTarget.ConvertPointToPixelSpace(v2)).Length);
                },
                    p => IsPositionInsideProjectiveCube(((Vector3D)p).ExtendTo4D().Transform(transformation))
                    );

                foreach (var segment in shape.Lines)
                {
                    var firstIndex  = segment.First;
                    var secondIndex = segment.Second;

                    var v1 = shape.Vertices[firstIndex];
                    var v2 = shape.Vertices[secondIndex];

                    var segmentColor = ColorHelpers.Lerp(v1.Color, v2.Color, 0.5);

                    var firstPos  = ((Vector3D)v1.Position).ExtendTo4D();
                    var secondPos = ((Vector3D)v2.Position).ExtendTo4D();
                    if (!TransformLineWithClip(transformation, ref firstPos, ref secondPos))
                    {
                        continue;
                    }

                    rasterizedLines.Add(new Line2D((Point)firstPos, (Point)secondPos, perspectiveColorOverride ?? segmentColor));
                }
            }

            var rasterizedMarkerPoints = RasterizePoints(viewProj, perspectiveColorOverride, t => t.MarkerPoints);
            var rasterizedRawPixels    = RasterizePoints(viewProj, perspectiveColorOverride, t => t.RawPoints);

            return(new RenderedPrimitives()
            {
                Points = rasterizedMarkerPoints,
                Lines = rasterizedLines,
                RawPixels = rasterizedRawPixels,
            });
        }