Exemple #1
0
        // figuring out a decent line width is tricky. Want to be responsive to camera
        //  pos, so line doesn't get super-thick when zoomed in. So we want to measure
        //  screen-space radius. But off-screen vertices are a problem. So, only consider
        //  vertices within a level, pointing-forward view cone (can't be actual view cone
        //  because then line thickness changes as you turn head!).
        //
        //  Also sub-sample verts for efficiency. Probably we don't need to do this
        //  every frame...but how to distribute?
        //
        //  ***returns 0*** if we couldn't find any points in view cone
        public static float EstimateStableCurveWidth(FScene scene,
                                                     Frame3f curveFrameS, DCurve3 curve, float fVisualAngleDeg)
        {
            // do computations in Scene coords..."safest"?

            Vector3f camPos     = scene.ActiveCamera.GetPosition();
            Vector3f camForward = scene.ActiveCamera.Forward();

            // use level-forward
            camForward[1] = 0; camForward.Normalize();

            camPos     = scene.ToSceneP(camPos);
            camForward = scene.ToSceneN(camForward);

            const float ViewConeDotThresh = 0.707106f;   // 45 degrees
            int         nSubSampleInc     = Math.Max(2, curve.VertexCount / 10);

            float rSum = 0; int iSum = 0;

            for (int k = 0; k < curve.VertexCount; k += nSubSampleInc)
            {
                Vector3f vS = (Vector3f)curve.GetVertex(k);
                vS = curveFrameS.FromFrameP(vS);
                Vector3f dv = (vS - camPos).Normalized;
                if (dv.Dot(camForward) < ViewConeDotThresh)
                {
                    continue;
                }

                float r = VRUtil.GetVRRadiusForVisualAngle(vS, camPos, fVisualAngleDeg);
                rSum += r; iSum++;
            }
            return((rSum == 0) ? 0 :  scene.ToWorldDimension(rSum / (float)iSum));
        }
Exemple #2
0
        /// <summary>
        /// Estimates the 3D centroid of a DCurve
        /// </summary>
        /// <param name="curve">DCurve</param>
        /// <returns>Vector3[]</returns>
        public static Vector3d Center(this DCurve3 curve)
        {
            Vector3d center = Vector3d.Zero;
            int      len    = curve.SegmentCount;

            if (!curve.Closed)
            {
                len++;
            }
            for (int i = 0; i < len; i++)
            {
                center += curve.GetVertex(i);
            }
            center /= len;
            return(center);
        }
Exemple #3
0
        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            if (deformer == null)
            {
                deformer = new ArcLengthSoftTranslation()
                {
                    Curve = curve.Curve, ArcRadius = 3.0f
                };
            }

            DCurve3 c  = curve.Curve;
            int     vi = (VertexIndex == LastIndex) ? c.VertexCount - 1 : 0;

            deformer.Handle = c.GetVertex(vi);
            deformer.UpdateROI(vi);
            deformer.BeginDeformation();

            targetW = target.GetLocalFrame(CoordSpace.WorldCoords);

            return(true);
        }