Beispiel #1
0
        override public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;

            Ray     sceneRay = GetScene().ToSceneRay(ray);
            Frame3f frameL   = GetLocalFrame(CoordSpace.ObjectCoords);
            Ray     localRay = frameL.ToFrame(sceneRay);

            float sceneWidth = GetScene().ToSceneDimension(visibleWidth);

            AxisAlignedBox3d hitBox = localBounds;

            hitBox.Expand(sceneWidth * 0.5f);
            Bounds hitBounds = new Bounds((Vector3)hitBox.Center, (Vector3)hitBox.Diagonal);

            if (hitBounds.IntersectRay(localRay) == false)
            {
                return(false);
            }

            double rayHitT;

            if (CurveUtils.FindClosestRayIntersection(curve, sceneWidth * 0.5f, localRay, out rayHitT))
            {
                hit           = new SORayHit();
                hit.fHitDist  = (float)rayHitT;
                hit.hitPos    = localRay.GetPoint(hit.fHitDist);
                hit.hitPos    = GetScene().ToWorldP(frameL.FromFrameP(hit.hitPos));
                hit.hitNormal = Vector3.zero;
                hit.hitGO     = root;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        override public bool FindRayIntersection(Ray3f worldRay, out SORayHit hit)
        {
            hit = null;

            // project world ray into local coords
            FScene scene    = GetScene();
            Ray3f  sceneRay = scene.ToSceneRay(worldRay);
            Ray3f  localRay = SceneTransforms.SceneToObject(this, sceneRay);

            // also need width in local coords
            float sceneWidth = scene.ToSceneDimension(visibleWidth);
            float localWidth = SceneTransforms.SceneToObject(this, sceneWidth) * HitWidthMultiplier;

            // bounding-box hit test (would be nice to do w/o object allocation...)
            AxisAlignedBox3d hitBox = localBounds;

            hitBox.Expand(localWidth);
            IntrRay3AxisAlignedBox3 box_test = new IntrRay3AxisAlignedBox3(localRay, hitBox);

            if (box_test.Find() == false)
            {
                return(false);
            }

            // raycast against curve (todo: spatial data structure for this? like 2D polycurve bbox tree?)
            double rayHitT;

            if (CurveUtils.FindClosestRayIntersection(curve, localWidth, localRay, out rayHitT))
            {
                hit = new SORayHit();
                // transform local hit point back into world coords
                Vector3f rayPos   = localRay.PointAt((float)rayHitT);
                Vector3f scenePos = SceneTransforms.ObjectToSceneP(this, rayPos);
                hit.hitPos    = SceneTransforms.SceneToWorldP(scene, scenePos);
                hit.fHitDist  = worldRay.Project(hit.hitPos);
                hit.hitNormal = Vector3f.Zero;
                hit.hitGO     = root;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }