Ejemplo n.º 1
0
        public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords)
        {
            nearest = null;

            // convert to local
            Vector3f local_pt = SceneTransforms.TransformTo((Vector3f)point, this, eInCoords, CoordSpace.ObjectCoords);

            AxisAlignedBox3f bounds        = GetLocalBoundingBox();
            float            local_dist    = bounds.Distance(local_pt);
            float            dist_incoords = SceneTransforms.TransformTo(local_dist, this, CoordSpace.ObjectCoords, eInCoords);

            if (dist_incoords > maxDist)
            {
                return(false);
            }

            nearest          = new SORayHit();
            nearest.fHitDist = dist_incoords;
            Vector3f nearPt = bounds.NearestPoint(local_pt);

            nearest.hitPos    = SceneTransforms.TransformTo(nearPt, this, CoordSpace.ObjectCoords, eInCoords);
            nearest.hitNormal = Vector3f.Zero;
            nearest.hitGO     = RootGameObject;
            nearest.hitSO     = this;
            return(true);
        }
Ejemplo n.º 2
0
        void project_to_target()
        {
            PolyCurveSO sourceSO = targets[0];
            DCurve3     curve    = sourceSO.Curve;
            int         N        = curve.VertexCount;

            for (int i = 0; i < N; ++i)
            {
                Vector3f v  = (Vector3f)curve[i];
                Vector3f vW = SceneTransforms.TransformTo(v, sourceSO, CoordSpace.ObjectCoords, CoordSpace.WorldCoords);
                vW       = (Vector3f)ProjectionTarget.Project(vW);
                curve[i] = SceneTransforms.TransformTo(vW, sourceSO, CoordSpace.WorldCoords, CoordSpace.ObjectCoords);
            }
        }
Ejemplo n.º 3
0
        public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords)
        {
            nearest = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            if (spatial == null)
            {
                spatial = new DMeshAABBTree3(mesh);
                spatial.Build();
            }

            // convert to local
            Vector3f local_pt = SceneTransforms.TransformTo((Vector3f)point, this, eInCoords, CoordSpace.ObjectCoords);

            if (mesh.CachedBounds.Distance(local_pt) > maxDist)
            {
                return(false);
            }

            int tid = spatial.FindNearestTriangle(local_pt);

            if (tid != DMesh3.InvalidID)
            {
                DistPoint3Triangle3 dist = MeshQueries.TriangleDistance(mesh, tid, local_pt);

                nearest          = new SORayHit();
                nearest.fHitDist = (float)Math.Sqrt(dist.DistanceSquared);

                Frame3f f_local = new Frame3f(dist.TriangleClosest, mesh.GetTriNormal(tid));
                Frame3f f       = SceneTransforms.TransformTo(f_local, this, CoordSpace.ObjectCoords, eInCoords);

                nearest.hitPos    = f.Origin;
                nearest.hitNormal = f.Z;
                nearest.hitGO     = RootGameObject;
                nearest.hitSO     = this;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Find intersection of *WORLD* ray with Mesh
        /// </summary>
        override public bool FindRayIntersection(Ray3f rayW, out SORayHit hit)
        {
            hit = null;
            if (enable_spatial == false)
            {
                return(false);
            }

            if (spatial == null)
            {
                spatial = new DMeshAABBTree3(mesh);
                spatial.Build();
            }

            // convert ray to local
            Frame3f f = new Frame3f(rayW.Origin, rayW.Direction);

            f = SceneTransforms.TransformTo(f, this, CoordSpace.WorldCoords, CoordSpace.ObjectCoords);
            Ray3d local_ray = new Ray3d(f.Origin, f.Z);

            int hit_tid = spatial.FindNearestHitTriangle(local_ray);

            if (hit_tid != DMesh3.InvalidID)
            {
                IntrRay3Triangle3 intr = MeshQueries.TriangleIntersection(mesh, hit_tid, local_ray);

                Frame3f hitF = new Frame3f(local_ray.PointAt(intr.RayParameter), mesh.GetTriNormal(hit_tid));
                hitF = SceneTransforms.TransformTo(hitF, this, CoordSpace.ObjectCoords, CoordSpace.WorldCoords);

                hit           = new SORayHit();
                hit.hitPos    = hitF.Origin;
                hit.hitNormal = hitF.Z;
                hit.hitIndex  = hit_tid;
                hit.fHitDist  = hit.hitPos.Distance(rayW.Origin);   // simpler than transforming!
                hit.hitGO     = RootGameObject;
                hit.hitSO     = this;
                return(true);
            }
            return(false);
        }