当前位置: 首页>>代码示例>>C#>>正文


C# Ray.GetPoint方法代码示例

本文整理汇总了C#中Ray.GetPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.GetPoint方法的具体用法?C# Ray.GetPoint怎么用?C# Ray.GetPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray.GetPoint方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getBlockOnRay

        public static float getBlockOnRay(Island island, Ray ray, float distMax, float minDist,
                                          out Vector3 relBlockPos, out Block actBlock)
        {
            float distance = minDist;
            relBlockPos = MainWorld.AbsToRelative(ray.GetPoint(distance));

            do
            {
                Vector3 prevRelBlockPos = relBlockPos;
                while (prevRelBlockPos == relBlockPos)
                {
                    distance += 3;
                    relBlockPos = MainWorld.AbsToRelative(ray.GetPoint(distance));
                }
                actBlock = island.getBlock(relBlockPos, false);
            } while (actBlock is Air && distance < distMax);

            return distance;
        }
开发者ID:RenaudWasTaken,项目名称:SkyLands,代码行数:19,代码来源:VanillaBlock.cs

示例2: Intersect

        public override bool Intersect(Ray ray, out Intersection intersection)
        {
            var t = -(Vector3.Dot(ray.Origin, _normal) + _height)/Vector3.Dot(ray.Direction, _normal);
            if (t >= 0)
            {
                var loc = ray.GetPoint(t);
                intersection = new Intersection(this, ray, _normal, loc, t, Material);
                return true;
            }

            intersection = null;
            return false;
        }
开发者ID:tincann,项目名称:AGR,代码行数:13,代码来源:Plane.cs

示例3: RaycastFromPoint

        // raycast from a point in to the scene.
        // returns success or failure.
        // on success the point is returned in the result.
        public bool RaycastFromPoint(Vector3 point, Vector3 normal, ref Vector3 result, ref Vector3 resNormal)
        {
            // create the ray to test
            Ray ray = new Ray(point, normal);

            // check we are initialised
            if (raySceneQuery != null) {
                // create a query object
                raySceneQuery.Ray = ray;

                // execute the query, returns a vector of hits
                RaySceneQueryResult rayresult = raySceneQuery.Execute();
                if (rayresult.Count <= 0) {
                    rayresult.Dispose();
                    // raycast did not hit an objects bounding box
                    return false;
                }

                rayresult.Dispose();
            }
            else {
                return false;
            }

            // at this point we have raycast to a series of different objects bounding boxes.
            // we need to test these different objects to see which is the first polygon hit.
            // there are some minor optimizations (distance based) that mean we wont have to
            // check all of the objects most of the time, but the worst case scenario is that
            // we need to test every triangle of every object.
            float closest_distance = -1.0f;
            Vector3 closest_result = Vector3.ZERO;
            Vector3 vNormal = Vector3.ZERO;
            RaySceneQueryResult query_result = raySceneQuery.GetLastResults();

            foreach (RaySceneQueryResultEntry this_result in query_result) {
                // stop checking if we have found a raycast hit that is closer
                // than all remaining entities
                if ((closest_distance >= 0.0f) &&
                    (closest_distance < this_result.distance)) {
                    break;
                }

                // only check this result if its a hit against an entity
                if ((this_result.movable != null) && (this_result.movable.MovableType == "Entity")) {
                    // get the entity to check
                    Entity pentity = (Entity) this_result.movable;

                    // mesh data to retrieve
                    uint vertex_count = 0;
                    uint index_count = 0;
                    Vector3[] vertices = new Vector3[0];
                    uint[] indices = new uint[0];

                    // get the mesh information
                    OgreToBulletMesh.GetMeshInformation(pentity.GetMesh(),
                        ref vertex_count, ref vertices, ref index_count, ref indices,
                        pentity.ParentNode._getDerivedPosition(),    // WorldPosition
                        pentity.ParentNode._getDerivedOrientation(), // WorldOrientation
                        pentity.ParentNode.GetScale());

                    int ncf = -1; // new_closest_found

                    // test for hitting individual triangles on the mesh
                    for (int i = 0; i < (int) index_count; i += 3) {
                        // check for a hit against this triangle
                        Pair<bool, float> hit = Mogre.Math.Intersects(ray, vertices[indices[i]],
                            vertices[indices[i + 1]], vertices[indices[i + 2]], true, false);

                        // if it was a hit check if its the closest
                        if (hit.first) {
                            if ((closest_distance < 0.0f) ||
                                (hit.second < closest_distance)) {
                                // this is the closest so far, save it off
                                closest_distance = hit.second;
                                ncf = i;
                            }
                        }
                    }

                    if (ncf > -1) {
                        closest_result = ray.GetPoint(closest_distance);
                        // if you don't need the normal, comment this out; you'll save some CPU cycles.
                        Vector3 v1 = vertices[indices[ncf]] - vertices[indices[ncf + 1]];
                        Vector3 v2 = vertices[indices[ncf + 2]] - vertices[indices[ncf + 1]];
                        vNormal = v1.CrossProduct(v2);
                    }

                    // free the verticies and indicies memory
                    vertices = null;
                    indices = null;
                }
            }

            query_result.Dispose();

            // if we found a new closest raycast for this object, update the
            // closest_result before moving on to the next object.
//.........这里部分代码省略.........
开发者ID:CisciarpMaster,项目名称:PonyKart,代码行数:101,代码来源:MogreRaycaster.cs

示例4: Intersect

        public override bool Intersect(Ray ray, out Intersection intersection)
        {
            intersection = null;

            var C = ray.Origin - Center;
            float t;
            //inside sphere
            var dotC = Vector3.Dot(C, C);
            var insideSphere = dotC <= _rad2;
            if (insideSphere)
            {
                //slow way to calculate
                var a = Vector3.Dot(ray.Direction, ray.Direction);
                var b = Vector3.Dot(2*ray.Direction, C);
                var c = dotC - _rad2;
                var d = b*b - 4*a*c;

                //no intersection
                if (d < 0)
                {
                    return false;
                }

                var sd = (float)Math.Sqrt(d);
                var t1 = (-b + sd)/2*a;
                var t2 = (-b - sd)/2*a;
                t = Math.Max(t1, t2);
            }
            else
            {
                //fast way to calculate
                t = Vector3.Dot(-C, ray.Direction);
                var q = -C - t*ray.Direction;
                float p2 = Vector3.Dot(q, q);
                if (p2 > _rad2) return false;
                t -= (float) Math.Sqrt(_rad2 - p2);
            }

            if (t > float.Epsilon)
            {
                var intersectionPoint = ray.GetPoint(t);
                var normal = (intersectionPoint - Center).Normalized();
                if (insideSphere)
                {
                    normal *= -1;
                }
                var mat = insideSphere ? Material.Air : Material;
                intersection = new Intersection(this, ray, normal, intersectionPoint, t, mat, insideSphere);
                return true;
            }

            return false;
        }
开发者ID:tincann,项目名称:AGR,代码行数:53,代码来源:Sphere.cs

示例5: RaycastToPlane

        private RaycastResult RaycastToPlane(Ray ray, Plane plane)
        {
            Pair<bool, float> pair = ray.Intersects(plane);

            if (pair.first)
            {
                RaycastResult result = new RaycastResult(ray);
                result.Distance = pair.second;
                result.Normal = plane.normal;
                result.Position = ray.GetPoint(pair.second);
                return result;
            }

            return null;
        }
开发者ID:andyhebear,项目名称:glueeengine,代码行数:15,代码来源:ViewportController.cs

示例6: GetGizmoIntersect

        public Vector3 GetGizmoIntersect(Ray pickRay, Plane planetous, AxisType translationAxis, Vector3 vLastPosition)
        {
            var result = pickRay.Intersects(planetous);

            if (result.first)
            {
                Vector3 axisX = Vector3.ZERO;
                Vector3 axisY = Vector3.ZERO;
                Vector3 axisZ = Vector3.ZERO;

                if (translationAxis != AxisType.None)
                {
                    if ((int)(translationAxis & AxisType.X) != 0)
                        axisX = Selected.DerivedOrientation.XAxis;
                    if ((int)(translationAxis & AxisType.Y) != 0)
                        axisY = Selected.DerivedOrientation.YAxis;
                    if ((int)(translationAxis & AxisType.Z) != 0)
                        axisZ = Selected.DerivedOrientation.ZAxis;
                }
                else
                {
                    axisX = Selected.DerivedOrientation.XAxis;
                    axisY = Selected.DerivedOrientation.YAxis;
                    axisZ = Selected.DerivedOrientation.ZAxis;
                }

                Vector3 proj = pickRay.GetPoint(result.second) - vLastPosition;
                Vector3 vPos1 = (axisX.DotProduct(proj) * axisX);
                Vector3 vPos2 = (axisY.DotProduct(proj) * axisY);
                Vector3 vPos3 = (axisZ.DotProduct(proj) * axisZ);
                Vector3 vPos = vPos1 + vPos2 + vPos3;

                this.lastTranslationDelta = vPos;
                return vPos;
            }
            return this.lastTranslationDelta;
        }
开发者ID:andyhebear,项目名称:likeleon,代码行数:37,代码来源:MogitorsRoot.Gizmo.cs

示例7: Intersect

        //https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
        public override bool Intersect(Ray ray, out Intersection intersection)
        {
            Statistics.Add("Triangle test");

            intersection = null;

            //don't intersect backside
            if (Vector3.Dot(ray.Direction, Normal) > 0)
            {
                return false;
            }

            var P = Vector3.Cross(ray.Direction, _e2);

            var det = Vector3.Dot(_e1, P);

            //if determinant is near zero, then there is no intersection
            if (det > -float.Epsilon && det < float.Epsilon)
            {
                return false;
            }

            var invDet = 1/det;

            var T = Vector3.Subtract(ray.Origin, _p1);

            //calculate u coordinate of triangle
            var u = Vector3.Dot(T, P)*invDet;

            //if it lies outside the triangle
            if (u < 0 || u > 1)
            {
                return false;
            }

            var Q = Vector3.Cross(T, _e1);

            //calculate v coordinate of triangle
            var v = Vector3.Dot(ray.Direction, Q)*invDet;

            //if it lies outside the triangle
            if (v < 0 || u + v > 1)
            {
                return false;
            }

            //t parameter of ray
            float t = Vector3.Dot(_e2, Q)*invDet;

            if (t > Constants.MinimumRayT && t <= ray.T)
            {
                var intersectionPoint = ray.GetPoint(t);
                ray.SetLength(t);
                intersection = new Intersection(this, ray, Normal, intersectionPoint, t, Material);
                Statistics.Add("Triangle test success");
                return true;
            }

            return false;
        }
开发者ID:tincann,项目名称:AGR,代码行数:61,代码来源:Triangle.cs

示例8: Raycast


//.........这里部分代码省略.........
                                // get the entity to check
                                Entity entity = (Entity)queryResult[qridx].movable;

                                // mesh data to retrieve
                                Vector3[] vertices;
                                int[] indices;
                                RenderOperation.OperationTypes opType;

                                // get the mesh information
                                using (MeshPtr mesh = entity.GetMesh())
                                {
                                    opType = mesh.GetSubMesh(0).operationType;

                                    Debug.Assert(CheckSubMeshOpType(mesh, opType));

                                    GetMeshInformation(
                                        mesh,
                                        out vertices,
                                        out indices,
                                        entity.ParentNode._getDerivedPosition(),
                                        entity.ParentNode._getDerivedOrientation(),
                                        entity.ParentNode._getDerivedScale());
                                }

                                int vertexCount = vertices.Length;
                                int indexCount = indices.Length;

                                // test for hitting individual triangles on the mesh
                                bool newClosestFound = false;
                                Pair<bool, float> hit;
                                switch (opType)
                                {
                                    case RenderOperation.OperationTypes.OT_TRIANGLE_LIST:
                                        for (int i = 0; i < indexCount; i += 3)
                                        {
                                            hit = Mogre.Math.Intersects(ray, vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]], true, false);

                                            if (CheckDistance(rr, hit))
                                            {
                                                newClosestFound = true;
                                            }
                                        }
                                        break;
                                    case RenderOperation.OperationTypes.OT_TRIANGLE_STRIP:
                                        for (int i = 0; i < indexCount - 2; i++)
                                        {
                                            hit = Mogre.Math.Intersects(ray, vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]], true, true);

                                            if (CheckDistance(rr, hit))
                                            {
                                                newClosestFound = true;
                                            }
                                        }
                                        break;
                                    case RenderOperation.OperationTypes.OT_TRIANGLE_FAN:
                                        for (int i = 0; i < indexCount - 2; i++)
                                        {
                                            hit = Mogre.Math.Intersects(ray, vertices[indices[0]], vertices[indices[i + 1]], vertices[indices[i + 2]], true, true);

                                            if (CheckDistance(rr, hit))
                                            {
                                                newClosestFound = true;
                                            }
                                        }
                                        break;
                                    default:
                                        throw new Exception("invalid operation type");
                                }

                                // if we found a new closest raycast for this object, update the
                                // closest_result before moving on to the next object.
                                if (newClosestFound)
                                {
                                    rr.Target = entity;
                                    closestResult = ray.GetPoint(rr.Distance);
                                }
                            }
                        }

                        this.sceneMgr.DestroyQuery(raySceneQuery);
                        raySceneQuery.Dispose();

                        // return the result
                        if (rr.Distance >= 0.0f)
                        {
                            // raycast success
                            rr.Position = closestResult;
                            return rr;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
                else
                {
                    return null;
                }
        }
开发者ID:aRkker,项目名称:Survival,代码行数:101,代码来源:CollisionTools.cs

示例9: GetSubmeshFromRay

            public SubMesh GetSubmeshFromRay(Ray ray)
            {
                // Check we are initialised
                if (raySceneQuery != null)
                {
                  // create a query object
                  raySceneQuery.Ray = ray;

                  // execute the query, returns a vector of hits
                  RaySceneQueryResult rayresult = raySceneQuery.Execute();
                  if (rayresult.Count <= 0)
                // raycast did not hit an objects bounding box
                return null;
                }
                else
                  return null;

                SubMesh resultSub = null;
                // at this point we have raycast to a series of different objects bounding boxes.
                // we need to test these different objects to see which is the first polygon hit.
                // there are some minor optimizations (distance based) that mean we wont have to
                // check all of the objects most of the time, but the worst case scenario is that
                // we need to test every triangle of every object.
                float closest_distance = -1.0f;
                Mogre.Vector3 closest_result = Mogre.Vector3.ZERO;
                Mogre.Vector3 vNormal = Mogre.Vector3.ZERO;
                RaySceneQueryResult query_result = raySceneQuery.GetLastResults();

                foreach (RaySceneQueryResultEntry this_result in query_result)
                {
                  // stop checking if we have found a raycast hit that is closer
                  // than all remaining entities
                  if ((closest_distance >= 0.0f) &&
                  (closest_distance < this_result.distance))
                break;

                  // only check this result if its a hit against an entity
                  if ((this_result.movable != null) &&
                  (this_result.movable.MovableType == "Entity"))
                  {
                // get the entity to check
                Entity pentity = (Entity)this_result.movable;

                // mesh data to retrieve
                List<uint> vertex_count = new List<uint>((int)pentity.NumSubEntities);
                List<uint> index_count = new List<uint>((int)pentity.NumSubEntities);
                List<Mogre.Vector3[]> vertices = new List<Mogre.Vector3[]>((int)pentity.NumSubEntities);
                List<UInt64[]> indices = new List<UInt64[]>((int)pentity.NumSubEntities);

                int ncf = -1; // new_closest_found

                for (ushort sm = 0; sm < pentity.NumSubEntities; sm++)
                {
                  // get the mesh information
                  /*
                  GetMeshInformation(pentity.GetMesh().GetSubMesh(sm),
                  ref vertex_count[sm], ref vertices[sm], ref index_count[sm], ref indices[sm],
                  pentity.ParentNode._getDerivedPosition(),    // WorldPosition
                  pentity.ParentNode._getDerivedOrientation(), // WorldOrientation
                  pentity.ParentNode.GetScale());*/
                  vertex_count.Add(new uint());
                  uint vcount_ref = vertex_count[sm];
                  vertices.Add(new Mogre.Vector3[0]);
                  Mogre.Vector3[] v_ref = vertices[sm];
                  index_count.Add(new uint());
                  uint icount_ref = index_count[sm];
                  indices.Add(new UInt64[0]);
                  UInt64[] i_ref = indices[sm];
                  GetSubMeshInformation(pentity.GetMesh(), ref vcount_ref, ref v_ref, ref icount_ref, ref i_ref,
                pentity.ParentNode._getDerivedPosition(),   // World Position
                pentity.ParentNode._getDerivedOrientation(),  // WorldOrientation
                pentity.ParentNode.GetScale(), sm);

                  // test for hitting individual triangles on the mesh
                  for (int i = 0; i < (int)icount_ref; i += 3)
                  {
                // check for a hit against this triangle
                Mogre.Pair<bool, float> hit = Mogre.Math.Intersects(ray, v_ref[i_ref[i]],
                    v_ref[i_ref[i + 1]], v_ref[i_ref[i + 2]], true, false);

                // if it was a hit check if its the closest
                if (hit.first)
                {
                  if ((closest_distance < 0.0f) ||
                      (hit.second < closest_distance))
                  {
                    // this is the closest so far, save it off
                    closest_distance = hit.second;
                    ncf = i;
                    resultSub = pentity.GetMesh().GetSubMesh(sm);
                  }
                }
                  }
                }

                if (ncf > -1)
                {
                  closest_result = ray.GetPoint(closest_distance);
                  // if you don't need the normal, comment this out; you'll save some CPU cycles.
                  //Mogre.Vector3 v1 = vertices[indices[ncf]] - vertices[indices[ncf + 1]];
//.........这里部分代码省略.........
开发者ID:aczarno,项目名称:StickMagik,代码行数:101,代码来源:OgreForm.cs


注:本文中的Ray.GetPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。