コード例 #1
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        /// <summary>
        /// Determines whether the object represented by the OverlayShape item can be
        /// given a reference to. This is the case, e.g., for standard coordinates. It is
        /// however not the case for the coordinates in a smooth curve.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected bool IsReferenceable(OverlayShape item)
        {
            if (!(item is OverlayNode))
            {
                return(false);
            }

            Tikz_XYItem it = (item as OverlayNode).tikzitem;

            // check whether item occurs in smooth curve
            // we check whether the parent's parent has the word "coordinates" preceding the parent (this is a bit of a hack)
            if (it is Tikz_Coord && (it.parent.parent is Tikz_Path))
            {
                Tikz_Path grandpa = it.parent.parent as Tikz_Path;
                for (int i = grandpa.Children.IndexOf(it.parent) - 1; i > 0; i--)
                {
                    if (!(grandpa.Children[i] is Tikz_Something))
                    {
                        break;
                    }
                    if (grandpa.Children[i].text.ToLower().Contains("coordinates"))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #2
0
 public OverlayShapeModel(OverlayShape overlayShape)
 {
     this.Id         = overlayShape.Id;
     this.Title      = overlayShape.Title;
     this.Properties = overlayShape.Properties;
     this.Type       = overlayShape.Type;
 }
コード例 #3
0
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
            {
                originRef = item;
            }
            else
            {
                originRef = null;
            }

            PreviewEllipse.SetPosition(origin.X, origin.Y, 0, 0);

            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;

            PreviewEllipse.Rotation = angle;

            PreviewEllipse.Visible = true;

            overlay.MouseCaptured = true;
        }
コード例 #4
0
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
            {
                originRef = item;
            }
            else
            {
                originRef = null;
            }

            PreviewRect.SetPosition(origin.X, origin.Y, 0, 0);

            // adjust rotation in case we are in a rotated frame
            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;

            PreviewRect.Rotation = angle;

            ////if (!overlay.canvas.Children.Contains(PreviewRect))
            ////    overlay.canvas.Children.Add(PreviewRect);
            /////PreviewRect.Visibility = Visibility.Visible;
            PreviewRect.Visible = true;

            overlay.MouseCaptured = true;
        }
コード例 #5
0
 void RemoveItem(OverlayShape o)
 {
     if (SelectedItems.Contains(o))
     {
         SelectedItems.Remove(o);
         o.SetStdColor();
     }
 }
コード例 #6
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            // find next tikzpicture and add
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict != null)
            {
                Parser.Tikz_Node tn = new Parser.Tikz_Node();
                tn.label = "";
                tn.coord = new Parser.Tikz_Coord();
                if (overlay.NodeStyle != "")
                {
                    tn.options = "[" + overlay.NodeStyle + "]";
                }

                Parser.Tikz_Path tp = new Parser.Tikz_Path();
                tp.starttag = @"\node ";
                tp.endtag   = ";";

                tp.AddChild(tn);
                if (overlay.CurEditing != null)
                {
                    overlay.CurEditing.tikzitem.AddChild(tp);
                    overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                else
                {
                    tpict.AddChild(tp);
                    tpict.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                // do it here since the coordinate calculation needs the parents' coord. transform
                tn.SetAbsPos(new Point(p.X, p.Y)); //hack

                //tn.UpdateText();
                tp.UpdateText();
                //tpict.UpdateText();

                //RedrawObjects();
                overlay.AddToDisplayTree(tp);
            }

            overlay.EndUpdate();
        }
コード例 #7
0
ファイル: OVROverlay.cs プロジェクト: byronap120/OculusGoGame
    private bool SubmitLayer(bool overlay, bool headLocked, OVRPose pose, Vector3 scale, int frameIndex)
    {
        int  rightEyeIndex    = (texturesPerStage >= 2) ? 1 : 0;
        bool isOverlayVisible = OVRPlugin.EnqueueSubmitLayer(overlay, headLocked, layerTextures[0].appTexturePtr, layerTextures[rightEyeIndex].appTexturePtr, layerId, frameIndex, pose.flipZ().ToPosef(), scale.ToVector3f(), layerIndex, (OVRPlugin.OverlayShape)currentOverlayShape);

        prevOverlayShape = currentOverlayShape;

        return(isOverlayVisible);
    }
コード例 #8
0
        public override async Task <object> Handle(AddOverlayShapeCommand request, CancellationToken cancellationToken)
        {
            var overlayShape = new OverlayShape(request.Title, request.Properties, request.Type);

            await this.context.OverlayShapes.AddAsync(overlayShape, cancellationToken);

            await this.context.SaveChangesAsync(cancellationToken);

            return(overlayShape.Id);
        }
コード例 #9
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnRightMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            //base.OnRightMouseButtonDown(item, p, e);

            // if a node is selected, unselect it
            if (curSel != null)
            {
                curSel    = null;
                e.Handled = true;   // we don't want anything else to happen (contextmenu opening etc)
            }
        }
コード例 #10
0
ファイル: ArcEditTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (item != null)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShape)item;
                DragOrigin = (new Point(item.View.GetLeft(), item.View.GetBottom())) - (Vector)p;
                ////DragOrigin = e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.View.GetLeft(), curDragged.View.GetBottom());
                movedenough = false;
                //MessageBox.Show(o.ToString());

                // select the clicked shape

                /*          if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                 *        {
                 *            if (!ToggleItem(curDragged))
                 *            {
                 *                // unselected -> start no drag operation
                 *                curDragged = null;
                 *            }
                 *        }
                 *        else
                 *        {
                 *            AddItem(curDragged, !IsItemSelected(curDragged));
                 *        }*/

                // adjust raster origin/scale/polar/cartesian
                overlay.SetCorrectRaster(curDragged);

                // for an arc, display preview
                //if (curDragged.item is Tikz_Arc)
                //{
                FillNodesOnArc();
                //check whether starting moving arc was successful
                if (PreviewArc.Spokes == null)
                {
                    SetCursorNo();
                    curDragged = null;
                    return;
                }
                AdjustPreviewPos(p);
                PreviewArc.Visible = true;
                //}

                // capture mouse. this is important if the user drags sth. outside canvas1's bounds
                if (curDragged != null)
                {
                    overlay.MouseCaptured = true;
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Adds an item to the list of selected items.
 /// </summary>
 /// <param name="o">The item to add.</param>
 /// <param name="Exclusive">If Exclusive is set, all other items are unselected.</param>
 public void AddItem(OverlayShape o, bool Exclusive = false)
 {
     if (Exclusive)
     {
         Clear(o);
     }
     if (!SelectedItems.Contains(o))
     {
         o.SetSelectedColor();
         SelectedItems.Add(o);
     }
 }
コード例 #12
0
 /// <summary>
 /// Clears the list, except possibly the item "except".
 /// </summary>
 /// <param name="except">The thing not to remove.</param>
 void Clear(OverlayShape except = null)
 {
     foreach (OverlayShape o in SelectedItems)
     {
         if (o != except)
         {
             o.SetStdColor();
         }
     }
     SelectedItems.RemoveWhere(o => (o != except));
     //SelectedItems.Clear();
 }
コード例 #13
0
 /// <summary>
 /// Toggles selection state, returns new selection state.
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public bool ToggleItem(OverlayShape o)
 {
     if (SelectedItems.Contains(o))
     {
         RemoveItem(o);
         return(false);
     }
     else
     {
         AddItem(o);
         return(true);
     }
 }
コード例 #14
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (SelectionRect.Visible)
            {
                SelectionRect.Visible = false;
            }

            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough)
            {
                overlay.BeginUpdate();
                // determine the relative shift
                Point relshift      = new Point(curDragged.View.GetLeft() - DragOriginO.X, curDragged.View.GetBottom() - DragOriginO.Y);
                Point relshift_tikz = new Point(relshift.X / overlay.Resolution, relshift.Y / overlay.Resolution);
                ShiftSelItemsInParseTree(relshift_tikz, overlay.TopLevelItems);

                /*
                 * Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                 * pp = ScreenToTikz(pp);
                 * if (curDragged is OverlayNode)
                 * {
                 *  (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                 *  (curDragged as OverlayNode).tikzitem.UpdateText();
                 *
                 * }
                 * else if (curDragged is OverlayScope)
                 * {
                 *  Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                 *  pdiff = rasterizer.RasterizePixel(pdiff);
                 *
                 *  double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;
                 *
                 *  curDragged.ShiftItemRelative(pdiff);
                 * }*/
                // update all item's positions
                foreach (OverlayShape o in overlay.TopLevelItems)
                {
                    o.AdjustPosition(overlay.Resolution);
                }

                // update raster in case it has changed
                overlay.SetCorrectRaster(curDragged);

                curDragged = null;

                overlay.EndUpdate();
            }
        }
コード例 #15
0
ファイル: OVROverlay.cs プロジェクト: boadle/CCTV-VR
    private bool SubmitLayer(bool overlay, bool headLocked, bool noDepthBufferTesting, OVRPose pose, Vector3 scale, int frameIndex)
    {
        int rightEyeIndex = (texturesPerStage >= 2) ? 1 : 0;

        if (overrideTextureRectMatrix)
        {
            UpdateTextureRectMatrix();
        }
        bool isOverlayVisible = OVRPlugin.EnqueueSubmitLayer(overlay, headLocked, noDepthBufferTesting,
                                                             isExternalSurface ? System.IntPtr.Zero : layerTextures[0].appTexturePtr,
                                                             isExternalSurface ? System.IntPtr.Zero : layerTextures[rightEyeIndex].appTexturePtr,
                                                             layerId, frameIndex, pose.flipZ().ToPosef(), scale.ToVector3f(), layerIndex, (OVRPlugin.OverlayShape)currentOverlayShape,
                                                             overrideTextureRectMatrix, textureRectMatrix, overridePerLayerColorScaleAndOffset, colorScale, colorOffset, useExpensiveSuperSample);

        prevOverlayShape = currentOverlayShape;

        return(isOverlayVisible);
    }
コード例 #16
0
 private static bool NeedsTexturesForShape(OverlayShape shape)
 {
     return(!IsPassthroughShape(shape));
 }
コード例 #17
0
    public static bool SetOverlayQuad(bool onTop, bool headLocked, IntPtr leftTexture, IntPtr rightTexture, IntPtr device, Posef pose, Vector3f scale, int layerIndex = 0, OverlayShape shape = OverlayShape.Quad)
    {
        if (version >= OVRP_1_6_0.version)
        {
            uint flags = (uint)OverlayFlag.None;
            if (onTop)
            {
                flags |= (uint)OverlayFlag.OnTop;
            }
            if (headLocked)
            {
                flags |= (uint)OverlayFlag.HeadLocked;
            }

            if (shape == OverlayShape.Cylinder || shape == OverlayShape.Cubemap)
            {
#if UNITY_ANDROID
                if (version >= OVRP_1_7_0.version)
                {
                    flags |= (uint)(shape) << OverlayShapeFlagShift;
                }
                else
#endif
                return(false);
            }

            return(OVRP_1_6_0.ovrp_SetOverlayQuad3(flags, leftTexture, rightTexture, device, pose, scale, layerIndex) == Bool.True);
        }

        if (layerIndex != 0)
        {
            return(false);
        }

        return(OVRP_0_1_1.ovrp_SetOverlayQuad2(ToBool(onTop), ToBool(headLocked), leftTexture, device, pose, scale) == Bool.True);
    }
コード例 #18
0
        private void InitializeBuffer()
        {
            layerID++;
            layerIndex = layerID;
            if (overlayShape == 0)
            {
                overlayShape = OverlayShape.Quad;
            }

            layerParam.layerId    = layerIndex;
            layerParam.layerShape = overlayShape;
            layerParam.layerType  = overlayType;
            layerParam.format     = (UInt64)RenderTextureFormat.Default;

            if (layerTextures[0] == null && layerTextures[1] != null)
            {
                layerTextures[0] = layerTextures[1];
            }

            if (layerTextures[1] != null)
            {
                layerParam.width  = (uint)layerTextures[1].width;
                layerParam.height = (uint)layerTextures[1].height;
            }
            else
            {
                layerParam.width  = (uint)PXR_Plugin.System.UPxr_GetConfigInt(ConfigType.RenderTextureWidth);
                layerParam.height = (uint)PXR_Plugin.System.UPxr_GetConfigInt(ConfigType.RenderTextureHeight);
            }

            layerParam.sampleCount = 1;
            layerParam.faceCount   = 1;
            layerParam.arraySize   = 1;
            layerParam.mipmapCount = 1;

            if (isExternalAndroidSurface)
            {
                layerParam.width       = 1024;
                layerParam.height      = 1024;
                layerParam.layerFlags  = (UInt32)PxrLayerCreateFlags.PxrLayerFlagAndroidSurface;
                layerParam.layerLayout = LayerLayout.Mono;
                IntPtr layerParamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(layerParam));
                Marshal.StructureToPtr(layerParam, layerParamPtr, false);
                PXR_Plugin.Render.UPxr_CreateLayer(layerParamPtr);
                Marshal.FreeHGlobal(layerParamPtr);
            }
            else
            {
                if (isDynamic)
                {
                    layerParam.layerFlags = 0;
                }
                else
                {
                    layerParam.layerFlags = (UInt32)PxrLayerCreateFlags.PxrLayerFlagStaticImage;
                }

                if ((layerTextures[0] != null && layerTextures[1] != null && layerTextures[0] == layerTextures[1]) || layerTextures[1] == null)
                {
                    eyeCount = 1;
                    layerParam.layerLayout = LayerLayout.Mono;
                }
                else
                {
                    eyeCount = 2;
                    layerParam.layerLayout = LayerLayout.Stereo;
                }

                PXR_Plugin.Render.UPxr_CreateLayerParam(layerParam);
                toCreateSwapChain = true;
                CreateLayerTexture();
            }
        }
コード例 #19
0
ファイル: ArcTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            Point ptikz = overlay.Rasterizer.RasterizePixelToTikz(p);

            p = overlay.Rasterizer.RasterizePixel(p);
            if (ContinueWithBigImage(ptikz) == false)
            {
                return;
            }

            if (pointcount == 0)
            {
                //overlay.SetCorrectRaster(overlay.CurEditing, true);
                center = ptikz;

                // set raster to polar, and such that origin is at center
                overlay.Rasterizer.View.IsCartesian = false;
                TikzMatrix M = overlay.Rasterizer.View.CoordinateTransform;
                M.m[0, 2] = center.X;
                M.m[1, 2] = center.Y;
                overlay.Rasterizer.View.CoordinateTransform = M;
                pointcount = 1;

                PreviewPie.center = PreviewArc.center = new Point(p.X, overlay.Height - p.Y);

                ////if (!overlay.canvas.Children.Contains(PreviewArc))
                ////    overlay.canvas.Children.Add(PreviewArc);
                ////if (!overlay.canvas.Children.Contains(PreviewPie))
                ////    overlay.canvas.Children.Add(PreviewPie);
            }
            else if (pointcount == 1)
            {
                p1            = ptikz;
                pointcount    = 2;
                PreviewPie.p1 = PreviewArc.p2 = new Point(p.X, overlay.Height - p.Y);

                // compute radius
                TikzMatrix M    = overlay.Rasterizer.View.CoordinateTransform;
                Point      ploc = M.Inverse().Transform(p1);
                overlay.Rasterizer.View.ForceRadiusTo = (ploc - (new Point(0, 0))).Length;
            }
            else if (pointcount == 2)
            {
                // **** create arc / pie ****
                overlay.BeginUpdate();
                // find next tikzpicture and add
                if (AddNewCurAddTo()) //(EnsureCurAddToExists(out lcreated))
                {
                    // Pie?
                    if (IsPie)
                    {
                        // create new coordinate
                        Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(center);
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                    }

                    Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    if (IsPie)
                    {
                        tc1.type = Tikz_CoordType.Polar;
                        tc1.deco = "++";
                    }
                    curAddTo.AddChild(tc1);
                    tc1.SetAbsPos(p1);
                    curAddTo.AddChild(new Parser.Tikz_Something(" "));

                    // create arc
                    Tikz_Arc ta = new Tikz_Arc();
                    curAddTo.AddChild(ta);
                    ta.SetFromPoints(center, ptikz, IsLargeArc);

                    if (IsPie)
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                    }

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    overlay.AddToDisplayTree(curAddTo);
                }

                overlay.EndUpdate();

                // reset everything
                pointcount = 0;
                overlay.Rasterizer.View.ForceRadiusTo = -1;
                overlay.SetCorrectRaster(overlay.CurEditing, true);
            }
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            UpdatePreviewDisplay(p);
        }
コード例 #20
0
    void Awake()
    {
        Debug.Log("Overlay Awake");

        if (premultiplyMaterial == null)
        {
            premultiplyMaterial = new Material(Shader.Find("Oculus/Alpha Premultiply"));
        }

        rend = GetComponent <Renderer>();

        if (textures.Length == 0)
        {
            textures = new Texture[] { null }
        }
        ;

        // Backward compatibility
        if (rend != null && textures[0] == null)
        {
            textures[0] = rend.material.mainTexture;
        }

        if (textures[0] != null)
        {
            cachedTextures[0] = textures[0];
            texNativePtrs[0]  = textures[0].GetNativeTexturePtr();
        }

#if UNITY_ANDROID && !UNITY_EDITOR
        if (textures.Length == 2 && textures[1] != null)
        {
            layout = (isMultiviewEnabled) ? OVRPlugin.LayerLayout.Array : OVRPlugin.LayerLayout.Stereo;
        }
        texturesPerStage = (layout == OVRPlugin.LayerLayout.Stereo) ? 2 : 1;
#endif
    }

    void OnEnable()
    {
        if (!OVRManager.isHmdPresent)
        {
            enabled = false;
            return;
        }

        OnDisable();

        for (int i = 0; i < maxInstances; ++i)
        {
            if (instances[i] == null || instances[i] == this)
            {
                layerIndex   = i;
                instances[i] = this;
                break;
            }
        }

        layerIdHandle = GCHandle.Alloc(layerId, GCHandleType.Pinned);
        layerIdPtr    = layerIdHandle.AddrOfPinnedObject();
    }

    void OnDisable()
    {
        if (layerIndex != -1)
        {
            // Turn off the overlay if it was on.
            OVRPlugin.EnqueueSubmitLayer(true, false, IntPtr.Zero, IntPtr.Zero, -1, 0, OVRPose.identity.ToPosef(), Vector3.one.ToVector3f(), layerIndex, (OVRPlugin.OverlayShape)_prevOverlayShape);
            instances[layerIndex] = null;
        }

        if (layerIdPtr != IntPtr.Zero)
        {
            OVRPlugin.EnqueueDestroyLayer(layerIdPtr);
            layerIdPtr = IntPtr.Zero;
            layerIdHandle.Free();
        }

        layerIndex = -1;
    }

    int prevFrameIndex = -1;

    void OnRenderObject()
    {
        // The overlay must be specified every eye frame, because it is positioned relative to the
        // current head location.  If frames are dropped, it will be time warped appropriately,
        // just like the eye buffers.
        if (!Camera.current.CompareTag("MainCamera") || Camera.current.cameraType != CameraType.Game || layerIndex == -1 || currentOverlayType == OverlayType.None || textures.Length < texturesPerStage)
        {
            return;
        }


        // Don't submit the same frame twice.
        if (Time.frameCount <= prevFrameIndex)
        {
            return;
        }
        prevFrameIndex = Time.frameCount;

#if !UNITY_ANDROID || UNITY_EDITOR
        if (currentOverlayShape == OverlayShape.OffcenterCubemap)
        {
            Debug.LogWarning("Overlay shape " + currentOverlayShape + " is not supported on current platform");
        }
#endif

        for (int i = 0; i < texturesPerStage; ++i)
        {
            if (textures[i] != cachedTextures[i])
            {
                cachedTextures[i] = textures[i];
                if (cachedTextures[i] != null)
                {
                    texNativePtrs[i] = cachedTextures[i].GetNativeTexturePtr();
                }
            }

            if (currentOverlayShape == OverlayShape.Cubemap)
            {
                if (textures[i] != null && textures[i].GetType() != typeof(Cubemap))
                {
                    Debug.LogError("Need Cubemap texture for cube map overlay");
                    return;
                }
            }
        }

        if (cachedTextures[0] == null || texNativePtrs[0] == IntPtr.Zero)
        {
            return;
        }

        bool overlay    = (currentOverlayType == OverlayType.Overlay);
        bool headLocked = false;
        for (var t = transform; t != null && !headLocked; t = t.parent)
        {
            headLocked |= (t == Camera.current.transform);
        }

        OVRPose pose  = (headLocked) ? transform.ToHeadSpacePose() : transform.ToTrackingSpacePose();
        Vector3 scale = transform.lossyScale;
        for (int i = 0; i < 3; ++i)
        {
            scale[i] /= Camera.current.transform.lossyScale[i];
        }
#if !UNITY_ANDROID
        if (currentOverlayShape == OverlayShape.Cubemap)
        {
            pose.position = Camera.current.transform.position;
        }
#endif
        // Pack the offsetCenter directly into pose.position for offcenterCubemap
        if (currentOverlayShape == OverlayShape.OffcenterCubemap)
        {
            pose.position = transform.position;
            if (pose.position.magnitude > 1.0f)
            {
                Debug.LogWarning("your cube map center offset's magnitude is greater than 1, which will cause some cube map pixel always invisible .");
            }
        }
        // Cylinder overlay sanity checking
        if (currentOverlayShape == OverlayShape.Cylinder)
        {
            float arcAngle = scale.x / scale.z / (float)Math.PI * 180.0f;
            if (arcAngle > 180.0f)
            {
                Debug.LogError("Cylinder overlay's arc angle has to be below 180 degree, current arc angle is " + arcAngle + " degree.");
                return;
            }
        }

        OVRPlugin.Sizei size = new OVRPlugin.Sizei()
        {
            w = textures[0].width, h = textures[0].height
        };
        int           flags                 = (int)OVRPlugin.LayerFlags.TextureOriginAtBottomLeft;
        int           mipLevels             = 1;
        int           sampleCount           = 1;
        TextureFormat txFormat              = TextureFormat.BGRA32;
        OVRPlugin.EyeTextureFormat etFormat = OVRPlugin.EyeTextureFormat.B8G8R8A8_sRGB;
        RenderTextureFormat        rtFormat = RenderTextureFormat.BGRA32;

        var tex2D = textures[0] as Texture2D;
        if (tex2D != null)
        {
            if (tex2D.format == TextureFormat.RGBAHalf || tex2D.format == TextureFormat.RGBAFloat)
            {
                txFormat = TextureFormat.RGBAHalf;
                etFormat = OVRPlugin.EyeTextureFormat.R16G16B16A16_FP;
                rtFormat = RenderTextureFormat.ARGBHalf;
            }
        }

        var rt = textures[0] as RenderTexture;
        if (rt != null)
        {
            sampleCount = rt.antiAliasing;

            if (rt.format == RenderTextureFormat.ARGBHalf)
            {
                txFormat = TextureFormat.RGBAHalf;
                etFormat = OVRPlugin.EyeTextureFormat.R16G16B16A16_FP;
                rtFormat = RenderTextureFormat.ARGBHalf;
            }
        }

        bool needsSetup = (
            !layerDesc.TextureSize.Equals(size) ||
            layerDesc.SampleCount != sampleCount ||
            layerDesc.LayerFlags != flags ||
            layerDesc.Shape != (OVRPlugin.OverlayShape)currentOverlayShape ||
            layerDesc.Layout != layout ||
            layerDesc.Format != etFormat);

        OVRPlugin.LayerDesc desc = new OVRPlugin.LayerDesc();

        if (layerIdPtr != IntPtr.Zero && needsSetup)
        {
            if ((int)layerIdHandle.Target != 0)
            {
                OVRPlugin.EnqueueDestroyLayer(layerIdPtr);
            }

            desc = OVRPlugin.CalculateLayerDesc((OVRPlugin.OverlayShape)currentOverlayShape, layout, size, mipLevels, sampleCount, etFormat, flags);
            OVRPlugin.EnqueueSetupLayer(desc, layerIdPtr);
            layerId = (int)layerIdHandle.Target;

            if (layerId > 0)
            {
                layerDesc = desc;
            }
        }

        if (layerId > 0)
        {
            // For newer SDKs, blit directly to the surface that will be used in compositing.

            int stageCount = OVRPlugin.GetLayerTextureStageCount(layerId);

            if (externalTextures == null)
            {
                frameIndex       = 0;
                externalTextures = new Texture[texturesPerStage][];
            }

            for (int eyeId = 0; eyeId < texturesPerStage; ++eyeId)
            {
                if (externalTextures[eyeId] == null)
                {
                    externalTextures[eyeId] = new Texture[stageCount];
                }

                int stage = frameIndex % stageCount;

                IntPtr externalTex = OVRPlugin.GetLayerTexture(layerId, stage, (OVRPlugin.Eye)eyeId);

                if (externalTex == IntPtr.Zero)
                {
                    continue;
                }

                bool needsCopy = isDynamic;

                Texture et = externalTextures[eyeId][stage];
                if (et == null)
                {
                    bool isSrgb = (etFormat == OVRPlugin.EyeTextureFormat.B8G8R8A8_sRGB || etFormat == OVRPlugin.EyeTextureFormat.R8G8B8A8_sRGB);

                    if (currentOverlayShape != OverlayShape.Cubemap && currentOverlayShape != OverlayShape.OffcenterCubemap)
                    {
                        et = Texture2D.CreateExternalTexture(size.w, size.h, txFormat, mipLevels > 1, isSrgb, externalTex);
                    }
#if UNITY_2017_1_OR_NEWER
                    else
                    {
                        //et = Cubemap.CreateExternalTexture(size.w, size.h, txFormat, mipLevels > 1, isSrgb, externalTex);
                        et = Cubemap.CreateExternalTexture(size.w, txFormat, isSrgb, externalTex);
                    }
#endif

                    externalTextures[eyeId][stage] = et;
                    needsCopy = true;
                }

                if (needsCopy)
                {
                    // The compositor uses premultiplied alpha, so multiply it here.
                    if (currentOverlayShape != OverlayShape.Cubemap && currentOverlayShape != OverlayShape.OffcenterCubemap)
                    {
                        var tempRT = RenderTexture.GetTemporary(size.w, size.h, 0, rtFormat, RenderTextureReadWrite.Default, sampleCount);
#if UNITY_ANDROID && !UNITY_EDITOR
                        Graphics.Blit(textures[eyeId], tempRT);                         //Resolve, decompress, swizzle, etc not handled by simple CopyTexture.
#else
                        Graphics.Blit(textures[eyeId], tempRT, premultiplyMaterial);
#endif
                        Graphics.CopyTexture(tempRT, 0, 0, et, 0, 0);
                        RenderTexture.ReleaseTemporary(tempRT);
                    }
#if UNITY_2017_1_OR_NEWER
                    else
                    {
                        var tempRTSrc = RenderTexture.GetTemporary(size.w, size.h, 0, rtFormat, RenderTextureReadWrite.Default, sampleCount);
                        var tempRTDst = RenderTexture.GetTemporary(size.w, size.h, 0, rtFormat, RenderTextureReadWrite.Default, sampleCount);

                        for (int face = 0; face < 6; ++face)
                        {
                            //HACK: It would be much more efficient to blit directly from textures[eyeId] to et, but Unity's API doesn't support that.
                            //Suggest using a native plugin to render directly to a cubemap layer for 360 video, etc.
                            Graphics.CopyTexture(textures[eyeId], face, 0, tempRTSrc, 0, 0);
                            Graphics.Blit(tempRTSrc, tempRTDst, premultiplyMaterial);
                            Graphics.CopyTexture(tempRTDst, 0, 0, et, face, 0);
                        }
                        RenderTexture.ReleaseTemporary(tempRTSrc);
                        RenderTexture.ReleaseTemporary(tempRTDst);
                    }
#endif
                }
            }

            bool isOverlayVisible = OVRPlugin.EnqueueSubmitLayer(overlay, headLocked, texNativePtrs[0], texNativePtrs[1], layerId, frameIndex, pose.flipZ().ToPosef(), scale.ToVector3f(), layerIndex, (OVRPlugin.OverlayShape)currentOverlayShape);
            if (isDynamic)
            {
                ++frameIndex;
            }
            _prevOverlayShape = currentOverlayShape;
            if (rend)
            {
                rend.enabled = !isOverlayVisible;
            }
        }
    }
}
コード例 #21
0
ファイル: ArcEditTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (PreviewArc.Spokes == null)
            {
                SetCursorDefault();
                return;
            }

            PreviewArc.Visible = false;
            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough && curDragged.item is Tikz_XYItem)
            {
                overlay.BeginUpdate();
                // determine the relative shift
                Vector relshift      = new Vector(curDragged.View.GetLeft() - DragOriginO.X, curDragged.View.GetBottom() - DragOriginO.Y);
                Vector relshift_tikz = relshift / overlay.Resolution;

                // compute new radius
                Point pold;
                (curDragged.item as Tikz_XYItem).GetAbsPos(out pold);
                Point  pnew = pold + relshift_tikz;
                double Rnew = (pnew - center_tikz).Length;

                // adjust all position accordingly...
                for (int i = 0; i < nodesOnArc.Count; i++)
                {
                    Point newp = center_tikz + Rnew * (new Vector(Math.Cos(PreviewArc.Spokes[i]), Math.Sin(PreviewArc.Spokes[i])));

                    if (i == 0)
                    {
                        nodesOnArc[i].SetAbsPos(newp);
                    }
                    else
                    {
                        //if (nodesOnArc[i] == curDragged.item)
                        //(nodesOnArc[i] as Tikz_Arc).SetAbsPosRandPhi2(Rnew, PreviewArc.Spokes[i]);
                        (nodesOnArc[i] as Tikz_Arc).SetFromPoints(center_tikz, newp, PreviewArc.Spokes[i - 1], PreviewArc.Spokes[i]);
                        //else
                        //    (nodesOnArc[i] as Tikz_Arc).SetAbsPosOnlyR(newp);
                    }

                    nodesOnArc[i].UpdateText();
                }



                // set first angle of arc segment directly after curDragged
                //if (curDraggedInd + 1 < nodesOnArc.Count)
                //{
                //    (nodesOnArc[curDraggedInd + 1] as Tikz_Arc).SetAbsPosRandPhi1(pnew);
                //}

                // ShiftSelItemsInParseTree(relshift_tikz, overlay.TopLevelItems);

                /*
                 * Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                 * pp = ScreenToTikz(pp);
                 * if (curDragged is OverlayNode)
                 * {
                 *  (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                 *  (curDragged as OverlayNode).tikzitem.UpdateText();
                 *
                 * }
                 * else if (curDragged is OverlayScope)
                 * {
                 *  Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                 *  pdiff = rasterizer.RasterizePixel(pdiff);
                 *
                 *  double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;
                 *
                 *  curDragged.ShiftItemRelative(pdiff);
                 * }*/
                // update all item's positions
                foreach (OverlayShape o in overlay.TopLevelItems)
                {
                    o.AdjustPosition(overlay.Resolution);
                }

                curDragged        = null;
                PreviewArc.Spokes = null;

                overlay.EndUpdate();
            }
            else if (curDragged != null && curDragged.item is Tikz_XYItem)
            { //if not movedenough, reset all "moving variables" anyways
                curDragged        = null;
                PreviewArc.Spokes = null;
            }
        }
コード例 #22
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewRect.Visible)
            {
                if (!EnsureParseTreeExists())
                {
                    return;
                }

                Point firstpoint  = overlay.ScreenToTikz(origin, true);
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p);

                double     angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R     = TikzMatrix.RotationMatrix(angle);
                TikzMatrix RI    = R.Inverse();

                Point firstpointR = R.Transform(firstpoint), secondpointR = R.Transform(secondpoint);

                if (ForcePointsBLTR)
                {
                    // ensure first pt is bottom left, second top right
                    Rect r = new Rect(firstpointR, secondpointR);
                    firstpointR  = r.TopLeft; // note that we use upside down coordinates, so the c# notations are different
                    secondpointR = r.BottomRight;
                    firstpoint   = RI.Transform(firstpointR);
                    secondpoint  = RI.Transform(secondpointR);
                }

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    double sidelength = Math.Max(Math.Abs(firstpointR.X - secondpointR.X), Math.Abs(firstpointR.Y - secondpointR.Y));
                    secondpointR = new Point(
                        firstpointR.X + Math.Sign(secondpointR.X - firstpointR.X) * sidelength,
                        firstpointR.Y + Math.Sign(secondpointR.Y - firstpointR.Y) * sidelength);
                    secondpoint = RI.Transform(secondpointR);
                }

                overlay.BeginUpdate();

                if (AddNewCurAddTo())
                {
                    Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    tc1.type = overlay.UsePolarCoordinates? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                    tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    curAddTo.AddChild(new Parser.Tikz_Something(codeToInsert));
                    curAddTo.AddChild(tc2);

                    if (originRef == null)
                    {
                        tc1.SetAbsPos(firstpoint);
                    }
                    else
                    {
                        Tikz_Node tn = MakeReferenceableNode((originRef as OverlayNode).tikzitem);
                        tc1.type    = Tikz_CoordType.Named;
                        tc1.nameref = tn.name;
                    }

                    OverlayShape hit = overlay.ObjectAtCursor;
                    if ((hit is OverlayNode) && IsReferenceable(hit as OverlayNode))
                    {
                        Tikz_Node tn = MakeReferenceableNode((hit as OverlayNode).tikzitem);
                        tc2.type    = Tikz_CoordType.Named;
                        tc2.nameref = tn.name;
                    }
                    else
                    {
                        tc2.SetAbsPos(secondpoint);
                    }

                    overlay.AddToDisplayTree(tc1);
                    overlay.AddToDisplayTree(tc2);

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewRect.Visible = false;
            }
        }
コード例 #23
0
ファイル: OVROverlay.cs プロジェクト: Masami1221/RotateMaze
 private static bool NeedsTexturesForShape(OverlayShape shape)
 {
     return(true);
 }
コード例 #24
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            overlay.BeginUpdate();

            //overlay.SetCorrectRaster(overlay.CurEditing, true);
            UpdateRaster();
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        //if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                        //else
                        //    curAddTo.AddChild(new Parser.Tikz_Something(" cycle"));
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        if (!overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                        {
                            // add an edge
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                        }
                        else
                        {
                            curAddTo.AddChild(new Parser.Tikz_Something(" "));
                        }
                    }

                    // create new coordinate. If some node was clicked, set a reference to that node. Otherwise, just make new coordinates
                    Tikz_Coord tc = new Tikz_Coord();
                    curAddTo.AddChild(tc);
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type    = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated)
                        {
                            tc.deco = overlay.NewNodeModifier; // first node should always be in absolute coordinates
                        }
                        tc.SetAbsPos(new Point(p.X, p.Y));     //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (overlay.NodeStyle.Trim() != "")
                        {
                            Tikz_Node tn = new Tikz_Node()
                            {
                                options = "[" + overlay.NodeStyle + "]",
                                coord   = null,
                                text    = ""
                            };
                            curAddTo.AddChild(new Tikz_Something(" "));
                            curAddTo.AddChild(tn);
                        }
                    }
                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    overlay.AddToDisplayTree(tc);
                }
            }

            overlay.EndUpdate();
            UpdateRaster();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
            {
                overlay.ActivateDefaultTool();
            }
        }
コード例 #25
0
ファイル: OVRPlugin.cs プロジェクト: ranguera/tron-trails
    public static bool SetOverlayQuad(bool onTop, bool headLocked, IntPtr texture, IntPtr device, Posef pose, Vector3f scale, int layerIndex=0, OverlayShape shape=OverlayShape.Quad)
    {
        if (version >= OVRP_1_6_0.version)
        {
            uint flags = (uint)OverlayFlag.None;
            if (onTop)
                flags |= (uint)OverlayFlag.OnTop;
            if (headLocked)
                flags |= (uint)OverlayFlag.HeadLocked;

            if (shape == OverlayShape.Cylinder || shape == OverlayShape.Cubemap)
            {
        #if UNITY_ANDROID
                if (version >= OVRP_1_7_0.version)
                    flags |= (uint)(shape) << OverlayShapeFlagShift;
                else
        #endif
                    return false;
            }
            return OVRP_1_6_0.ovrp_SetOverlayQuad3(flags, texture, IntPtr.Zero, device, pose, scale, layerIndex) == Bool.True;
        }

        if (layerIndex != 0)
            return false;

            return OVRP_0_1_1.ovrp_SetOverlayQuad2(ToBool(onTop), ToBool(headLocked), texture, device, pose, scale) == Bool.True;
    }
コード例 #26
0
ファイル: OVROverlay.cs プロジェクト: Masami1221/RotateMaze
    void LateUpdate()
    {
        if (!OVRManager.OVRManagerinitialized)
        {
            return;
        }
        if (!xrDeviceConstructed)
        {
            InitOVROverlay();
        }

        if (OVRManager.loadedXRDevice != constructedOverlayXRDevice)
        {
            Debug.LogError("Warning-XR Device was switched during runtime with overlays still enabled. When doing so, all overlays constructed with the previous XR device must first be disabled.");
            return;
        }
        // The overlay must be specified every eye frame, because it is positioned relative to the
        // current head location.  If frames are dropped, it will be time warped appropriately,
        // just like the eye buffers.
        bool requiresTextures = !isExternalSurface && NeedsTexturesForShape(currentOverlayShape);

        if (currentOverlayType == OverlayType.None ||
            (requiresTextures && (textures.Length < texturesPerStage || textures[0] == null)))
        {
            return;
        }

        OVRPose pose       = OVRPose.identity;
        Vector3 scale      = Vector3.one;
        bool    overlay    = false;
        bool    headLocked = false;

        if (!ComputeSubmit(ref pose, ref scale, ref overlay, ref headLocked))
        {
            return;
        }

        if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR)
        {
            if (currentOverlayShape == OverlayShape.Quad)
            {
                OpenVROverlayUpdate(scale, pose);
            }
            //No more Overlay processing is required if we're on OpenVR
            return;
        }

        OVRPlugin.LayerDesc newDesc = GetCurrentLayerDesc();
        bool isHdr = (newDesc.Format == OVRPlugin.EyeTextureFormat.R16G16B16A16_FP);

        // If the layer and textures are created but sizes differ, force re-creating them.
        // If the layer needed textures but does not anymore (or vice versa), re-create as well.
        bool textureSizesDiffer  = !layerDesc.TextureSize.Equals(newDesc.TextureSize) && layerId > 0;
        bool needsTextures       = NeedsTexturesForShape(currentOverlayShape);
        bool needsTextureChanged = NeedsTexturesForShape(prevOverlayShape) != needsTextures;

        if (textureSizesDiffer || needsTextureChanged)
        {
            DestroyLayerTextures();
            DestroyLayer();
        }

        bool createdLayer = CreateLayer(newDesc.MipLevels, newDesc.SampleCount, newDesc.Format, newDesc.LayerFlags, newDesc.TextureSize, newDesc.Shape);


        if (layerIndex == -1 || layerId <= 0)
        {
            if (createdLayer)
            {
                // Propagate the current shape and avoid the permanent state of "needs texture changed"
                prevOverlayShape = currentOverlayShape;
            }
            return;
        }

        if (needsTextures)
        {
            bool useMipmaps = (newDesc.MipLevels > 1);

            createdLayer |= CreateLayerTextures(useMipmaps, newDesc.TextureSize, isHdr);

            if (!isExternalSurface && (layerTextures[0].appTexture as RenderTexture != null))
            {
                isDynamic = true;
            }

            if (!LatchLayerTextures())
            {
                return;
            }

            // Don't populate the same frame image twice.
            if (frameIndex > prevFrameIndex)
            {
                int stage = frameIndex % stageCount;
                if (!PopulateLayer(newDesc.MipLevels, isHdr, newDesc.TextureSize, newDesc.SampleCount, stage))
                {
                    return;
                }
            }
        }


        bool isOverlayVisible = SubmitLayer(overlay, headLocked, noDepthBufferTesting, pose, scale, frameIndex);

        prevFrameIndex = frameIndex;
        if (isDynamic)
        {
            ++frameIndex;
        }

        // Backward compatibility: show regular renderer if overlay isn't visible.
        if (rend)
        {
            rend.enabled = !isOverlayVisible;
        }
    }
コード例 #27
0
ファイル: OVROverlay.cs プロジェクト: teresa-van/NovaProject
        void OnRenderObject()
        {
            // The overlay must be specified every eye frame, because it is positioned relative to the
            // current head location.  If frames are dropped, it will be time warped appropriately,
            // just like the eye buffers.
            if (!Camera.current.CompareTag("MainCamera") || Camera.current.cameraType != CameraType.Game || layerIndex == -1 || currentOverlayType == OverlayType.None)
            {
                return;
            }

#if !UNITY_ANDROID || UNITY_EDITOR
            if (currentOverlayShape == OverlayShape.Cylinder || currentOverlayShape == OverlayShape.OffcenterCubemap)
            {
                Debug.LogWarning("Overlay shape " + currentOverlayShape + " is not supported on current platform");
            }
#endif

            for (int i = 0; i < 2; ++i)
            {
                if (i >= textures.Length)
                {
                    continue;
                }

                if (textures[i] != cachedTextures[i])
                {
                    cachedTextures[i] = textures[i];
                    if (cachedTextures[i] != null)
                    {
                        texNativePtrs[i] = cachedTextures[i].GetNativeTexturePtr();
                    }
                }

                if (currentOverlayShape == OverlayShape.Cubemap)
                {
                    if (textures[i] != null && textures[i].GetType() != typeof(Cubemap))
                    {
                        Debug.LogError("Need Cubemap texture for cube map overlay");
                        return;
                    }
                }
            }

            if (cachedTextures[0] == null || texNativePtrs[0] == IntPtr.Zero)
            {
                return;
            }

            bool overlay    = (currentOverlayType == OverlayType.Overlay);
            bool headLocked = false;
            for (var t = transform; t != null && !headLocked; t = t.parent)
            {
                headLocked |= (t == Camera.current.transform);
            }

            OVRPose pose  = (headLocked) ? transform.ToHeadSpacePose() : transform.ToTrackingSpacePose();
            Vector3 scale = transform.lossyScale;
            for (int i = 0; i < 3; ++i)
            {
                scale[i] /= Camera.current.transform.lossyScale[i];
            }



#if !UNITY_ANDROID
            if (currentOverlayShape == OverlayShape.Cubemap)
            {
                pose.position = Camera.current.transform.position;
            }
#endif
            // Pack the offsetCenter directly into pose.position for offcenterCubemap

            if (currentOverlayShape == OverlayShape.OffcenterCubemap)

            {
                pose.position = transform.position;



                if (pose.position.magnitude > 1.0f)

                {
                    Debug.LogWarning("your cube map center offset's magnitude is greater than 1, which will cause some cube map pixel always invisible .");
                }
            }



            // Cylinder overlay sanity checking

            if (currentOverlayShape == OverlayShape.Cylinder)
            {
                float arcAngle = scale.x / scale.z / (float)Math.PI * 180.0f;
                if (arcAngle > 180.0f)
                {
                    Debug.LogError("Cylinder overlay's arc angle has to be below 180 degree, current arc angle is " + arcAngle + " degree.");
                    return;
                }
            }

            bool isOverlayVisible = OVRPlugin.SetOverlayQuad(overlay, headLocked, texNativePtrs[0], texNativePtrs[1], IntPtr.Zero, pose.flipZ().ToPosef(), scale.ToVector3f(), layerIndex, (OVRPlugin.OverlayShape)currentOverlayShape);
            _prevOverlayShape = currentOverlayShape;
            if (rend)
            {
                rend.enabled = !isOverlayVisible;
            }
        }
コード例 #28
0
ファイル: SmoothCurveTool.cs プロジェクト: wilsoc5/tikzedt
        Tikz_Option smoothOption; // this has to be changed to smooth cycle for closed curve

        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        smoothOption.key = "smooth cycle";
                        smoothOption.UpdateText();
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        // for prettier formatting
                        curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    }

                    // create new coordinate
                    Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                    tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    curAddTo.AddChild(tc);
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type    = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y));
                    }

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    overlay.AddToDisplayTree(tc);
                }
            }

            overlay.EndUpdate();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
            {
                overlay.ActivateDefaultTool();
            }
        }
コード例 #29
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!(item is OverlayNode))
            {
                curSel = null;
                return;
            }
            OverlayNode n = item as OverlayNode;

            // make sure a referenceable item is selected... otherwise we cannot add an edge
            if (!IsReferenceable(item))
            {
                MainWindow.AddStatusLine("Only items that are referenceable (=can be given names) can be connected with the edge tool.");
                return;
            }

            if (curSel == null)
            {
                curSel = n;
                return;
            }

            // make sure both nodes involved are nodes

            /*  if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node))
             * {
             *    String which = ""; String verb = "is";
             *    if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node))
             *    { which = "Both"; verb = "are"; }
             *    else if (!(curSel.tikzitem is Tikz_Node))
             *        which = "The first";
             *    else if (!(n.tikzitem is Tikz_Node))
             *        which = "The second";
             *    MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true);
             *    curSel = null;
             *    return; // hack
             * } */

            //the return from above must not interfere with BeginModify()
            overlay.BeginUpdate();

            // add an edge curSel to n
            //bool lcreated;
            //if (EnsureCurAddToExists(out lcreated))

            //always create new \draw command. otherwise it can happen that the \draw-command
            //is above the \node-definition which causes an error while compiling the latex code.
            if (AddNewCurAddTo())
            {
                // make sure both nodes involved have names
                Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem),
                                 t2 = MakeReferenceableNode(n.tikzitem);

                Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                tc1.type = Parser.Tikz_CoordType.Named;
                Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                tc2.type = Parser.Tikz_CoordType.Named;

                curAddTo.AddChild(new Parser.Tikz_Something(" "));
                curAddTo.AddChild(tc1);
                if (t1 == t2)
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] "));
                }
                else
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge "));
                }
                curAddTo.AddChild(tc2);
                //tpict.AddChild(tp);

                // make sure both nodes have names

                /*              Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
                 *            if (t1.name == "")
                 *            {
                 *                t1.SetName(tpict.GetUniqueName());
                 *                t1.UpdateText();
                 *            }
                 *            if (t2.name == "")
                 *            {
                 *                t2.SetName(tpict.GetUniqueName());
                 *                t2.UpdateText();
                 *            }
                 */
                tc1.nameref = t1.name;
                tc2.nameref = t2.name;
                //tc1.UpdateText();
                curAddTo.UpdateText();
                //tpict.UpdateText();
                //                    txtCode_TextChanged

                //RedrawObjects();
                //if (OnModified != null)
                //    OnModified.Invoke();

                //edge was drawn. release currently selected node.
                curSel = null;

                //will neither want to path tool to start from this last select nodes.
                curAddTo = null;
            }
            //forgetting to call EndModify causes weird "No undo group should be open at this point"-message.
            overlay.EndUpdate();
        }
コード例 #30
0
 public static bool IsPassthroughShape(OverlayShape shape)
 {
     return(shape == OverlayShape.ReconstructionPassthrough ||
            shape == OverlayShape.SurfaceProjectedPassthrough);
 }
コード例 #31
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// Set e.Handled if you want to turn off the default handling... like opening the context menu etc.
 /// </summary>
 /// <param name="item">The item on which the event occurred.</param>
 /// <param name="p">The cursor position, in BOTTOM LEFT CENTERED pixel coordinates.</param>
 ///
 public virtual void OnRightMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
 {
 }