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


C# OpenMetaverse.Ray类代码示例

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


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

示例1: ObjectIntersection

        private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
        {
            Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
            List<ContactResult> contacts = new List<ContactResult>();

            Vector3 ab = rayEnd - rayStart;

            World.ForEachSOG(delegate(SceneObjectGroup group)
            {
                if (m_host.ParentGroup == group)
                    return;

                if (group.IsAttachment)
                    return;

                if (group.RootPart.PhysActor == null)
                {
                    if (!includePhantom)
                        return;
                }
                else
                {
                    if (group.RootPart.PhysActor.IsPhysical)
                    {
                        if (!includePhysical)
                            return;
                    }
                    else
                    {
                        if (!includeNonPhysical)
                            return;
                    }
                }

                // Find the radius ouside of which we don't even need to hit test
                float minX;
                float maxX;
                float minY;
                float maxY;
                float minZ;
                float maxZ;

                float radius = 0.0f;

                group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);

                if (Math.Abs(minX) > radius)
                    radius = Math.Abs(minX);
                if (Math.Abs(minY) > radius)
                    radius = Math.Abs(minY);
                if (Math.Abs(minZ) > radius)
                    radius = Math.Abs(minZ);
                if (Math.Abs(maxX) > radius)
                    radius = Math.Abs(maxX);
                if (Math.Abs(maxY) > radius)
                    radius = Math.Abs(maxY);
                if (Math.Abs(maxZ) > radius)
                    radius = Math.Abs(maxZ);
                radius = radius*1.413f;
                Vector3 ac = group.AbsolutePosition - rayStart;
//                Vector3 bc = group.AbsolutePosition - rayEnd;

                double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));

                // Too far off ray, don't bother
                if (d > radius)
                    return;

                // Behind ray, drop
                double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
                if (d2 > 0)
                    return;

                ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
                EntityIntersection intersection = group.TestIntersection(ray, true, false);
                // Miss.
                if (!intersection.HitTF)
                    return;

                Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
                Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
                //m_log.DebugFormat("[LLCASTRAY]: min<{0},{1},{2}>, max<{3},{4},{5}> = hitp<{6},{7},{8}>", b1.X,b1.Y,b1.Z,b2.X,b2.Y,b2.Z,intersection.ipoint.X,intersection.ipoint.Y,intersection.ipoint.Z);
                if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
                    intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
                    intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
                    return;

                ContactResult result = new ContactResult ();
                result.ConsumerID = group.LocalId;
                result.Depth = intersection.distance;
                result.Normal = intersection.normal;
                result.Pos = intersection.ipoint;

                contacts.Add(result);
            });

            return contacts.ToArray();
        }
开发者ID:Barosonix,项目名称:Barosonix-Core,代码行数:98,代码来源:LSL_Api.cs

示例2: GetNewRezLocation

        /// <summary>
        /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
        /// </summary>
        /// <param name="RayStart"></param>
        /// <param name="RayEnd"></param>
        /// <param name="RayTargetID"></param>
        /// <param name="rot"></param>
        /// <param name="bypassRayCast"></param>
        /// <param name="RayEndIsIntersection"></param>
        /// <param name="frontFacesOnly"></param>
        /// <param name="scale"></param>
        /// <param name="FaceCenter"></param>
        /// <returns></returns>
        public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
        {

            Vector3 dir = RayEnd - RayStart;

            float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
            Vector3 wpos = Vector3.Zero;
            // Check for water surface intersection from above
            if ((RayStart.Z > wheight) && (RayEnd.Z < wheight))
            {
                float ratio = (wheight - RayStart.Z) / dir.Z;
                wpos.X = RayStart.X + (ratio * dir.X);
                wpos.Y = RayStart.Y + (ratio * dir.Y);
                wpos.Z = wheight;
            }

            Vector3 pos = Vector3.Zero;

            if (RayEndIsIntersection != (byte)1)
            {
                float dist = dir.Length();
                if (dist != 0)
                {
                    Vector3 direction = dir * (1 / dist);

                    dist += 1.0f;

                    if (SupportsRayCastFiltered())
                    {
                        RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
                        rayfilter |= RayFilterFlags.land;
                        rayfilter |= RayFilterFlags.physical;
                        rayfilter |= RayFilterFlags.nonphysical;
                        rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors

                        // get some more contacts ???
                        int physcount = 4;

                        List<ContactResult> physresults =
                            (List<ContactResult>)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter);
                        if (physresults != null && physresults.Count > 0)
                        {
                            // look for terrain ?
                            if(RayTargetID == UUID.Zero)
                            {
                                foreach (ContactResult r in physresults)
                                {
                                    if (r.ConsumerID == 0)
                                    {
                                        pos = r.Normal * scale;
                                        pos *= 0.5f;
                                        pos = r.Pos + pos;

                                        if (wpos.Z > pos.Z) pos = wpos;
                                        return pos;
                                    }
                                }
                            }
                            else
                            {
                                foreach (ContactResult r in physresults)
                                {
                                    SceneObjectPart part = GetSceneObjectPart(r.ConsumerID);
                                    if (part == null)
                                        continue;
                                    if (part.UUID == RayTargetID)
                                    {
                                        pos = r.Normal * scale;
                                        pos *= 0.5f;
                                        pos = r.Pos + pos;

                                        if (wpos.Z > pos.Z) pos = wpos;
                                        return pos;
                                    }
                                }                          
                            }
                            // else the first we got
                            pos = physresults[0].Normal * scale;
                            pos *= 0.5f;
                            pos = physresults[0].Pos + pos;

                            if (wpos.Z > pos.Z)
                                pos = wpos;
                            return pos;
                        }

                    }
//.........这里部分代码省略.........
开发者ID:emperorstarfinder,项目名称:Opensim2,代码行数:101,代码来源:Scene.cs

示例3: getLineOfSight

 public void getLineOfSight()
 {
     string pathID = getPathID();
     PathFromTxToRy path = new PathFromTxToRy(this, transmitter.RootPart.AbsolutePosition, pathID);
     //Direction from transmitter to the reciever 
     Vector3 direction = receiver.RootPart.AbsolutePosition - transmitter.RootPart.AbsolutePosition;
     //Ray vector from transmitter to the receiver
     Ray ray = new Ray(transmitter.RootPart.AbsolutePosition, direction);
     //Get the first object the ray hit
     EntityIntersectionWithPart intersection = findNextHit(ray, transmitter.RootPart);
     path.addNextPoint(receiver.RootPart.AbsolutePosition, receiver.RootPart.Material);
     path.reachesReceiver = true;
     if (!checkPathIsDrawn(path))
     {
         pathHits[0].Add(pathID, path);
     }
 }
开发者ID:TheCoffeeTime,项目名称:Opensim,代码行数:17,代码来源:RayTracer.cs

示例4: TestIntersection

        public EntityIntersection TestIntersection(Ray hRay, bool frontFacesOnly, bool faceCenters)
        {
            // We got a request from the inner_scene to raytrace along the Ray hRay
            // We're going to check all of the prim in this group for intersection with the ray
            // If we get a result, we're going to find the closest result to the origin of the ray
            // and send back the intersection information back to the innerscene.

            EntityIntersection result = new EntityIntersection();

            SceneObjectPart[] parts = m_parts.GetArray();

            // Find closest hit here
            float idist = float.MaxValue;

            for (int i = 0; i < parts.Length; i++)
            {
                SceneObjectPart part = parts[i];

                // Temporary commented to stop compiler warning
                //Vector3 partPosition =
                //    new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
                Quaternion parentrotation = GroupRotation;

                // Telling the prim to raytrace.
                //EntityIntersection inter = part.TestIntersection(hRay, parentrotation);

                EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);

                if (inter.HitTF)
                {
                    // We need to find the closest prim to return to the testcaller along the ray
                    if (inter.distance < idist)
                    {
                        result.HitTF = true;
                        result.ipoint = inter.ipoint;
                        result.obj = part;
                        result.normal = inter.normal;
                        result.distance = inter.distance;

                        idist = inter.distance;
                    }
                }
            }
            return result;
        }
开发者ID:emperorstarfinder,项目名称:Opensim2,代码行数:45,代码来源:SceneObjectGroup.cs

示例5: doObjectDuplicateOnRay

        /// <summary>
        /// Duplicates object specified by localID at position raycasted against RayTargetObject using 
        /// RayEnd and RayStart to determine what the angle of the ray is
        /// </summary>
        /// <param name="localID">ID of object to duplicate</param>
        /// <param name="dupeFlags"></param>
        /// <param name="AgentID">Agent doing the duplication</param>
        /// <param name="GroupID">Group of new object</param>
        /// <param name="RayTargetObj">The target of the Ray</param>
        /// <param name="RayEnd">The ending of the ray (farthest away point)</param>
        /// <param name="RayStart">The Beginning of the ray (closest point)</param>
        /// <param name="BypassRaycast">Bool to bypass raycasting</param>
        /// <param name="RayEndIsIntersection">The End specified is the place to add the object</param>
        /// <param name="CopyCenters">Position the object at the center of the face that it's colliding with</param>
        /// <param name="CopyRotates">Rotate the object the same as the localID object</param>
        public void doObjectDuplicateOnRay(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
                                           UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart,
                                           bool BypassRaycast, bool RayEndIsIntersection, bool CopyCenters, bool CopyRotates)
        {
            Vector3 pos;
            const bool frontFacesOnly = true;
            //m_log.Info("HITTARGET: " + RayTargetObj.ToString() + ", COPYTARGET: " + localID.ToString());
            SceneObjectPart target = GetSceneObjectPart(localID);
            SceneObjectPart target2 = GetSceneObjectPart(RayTargetObj);

            if (target != null && target2 != null)
            {
                Vector3 direction = Vector3.Normalize(RayEnd - RayStart);
                Vector3 AXOrigin = new Vector3(RayStart.X, RayStart.Y, RayStart.Z);
                Vector3 AXdirection = new Vector3(direction.X, direction.Y, direction.Z);

                pos = target2.AbsolutePosition;
                //m_log.Info("[OBJECT_REZ]: TargetPos: " + pos.ToString() + ", RayStart: " + RayStart.ToString() + ", RayEnd: " + RayEnd.ToString() + ", Volume: " + Util.GetDistanceTo(RayStart,RayEnd).ToString() + ", mag1: " + Util.GetMagnitude(RayStart).ToString() + ", mag2: " + Util.GetMagnitude(RayEnd).ToString());

                // TODO: Raytrace better here

                //EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection));
                Ray NewRay = new Ray(AXOrigin, AXdirection);

                // Ray Trace against target here
                EntityIntersection ei = target2.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, CopyCenters);

                // Un-comment out the following line to Get Raytrace results printed to the console.
                //m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
                float ScaleOffset = 0.5f;

                // If we hit something
                if (ei.HitTF)
                {
                    Vector3 scale = target.Scale;
                    Vector3 scaleComponent = new Vector3(ei.AAfaceNormal.X, ei.AAfaceNormal.Y, ei.AAfaceNormal.Z);
                    if (scaleComponent.X != 0) ScaleOffset = scale.X;
                    if (scaleComponent.Y != 0) ScaleOffset = scale.Y;
                    if (scaleComponent.Z != 0) ScaleOffset = scale.Z;
                    ScaleOffset = Math.Abs(ScaleOffset);
                    Vector3 intersectionpoint = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
                    Vector3 normal = new Vector3(ei.normal.X, ei.normal.Y, ei.normal.Z);
                    Vector3 offset = normal * (ScaleOffset / 2f);
                    pos = intersectionpoint + offset;

                    // stick in offset format from the original prim
                    pos = pos - target.ParentGroup.AbsolutePosition;
                    SceneObjectGroup copy;
                    if (CopyRotates)
                    {
                        Quaternion worldRot = target2.GetWorldRotation();

                        // SceneObjectGroup obj = m_sceneGraph.DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
                        copy = m_sceneGraph.DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
                        //obj.Rotation = worldRot;
                        //obj.UpdateGroupRotationR(worldRot);
                    }
                    else
                    {
                        copy = m_sceneGraph.DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, Quaternion.Identity);
                    }
                    if (copy != null)
                        EventManager.TriggerObjectAddedToScene(copy);
                }
            }
        }
开发者ID:CCIR,项目名称:opensim,代码行数:81,代码来源:Scene.cs

示例6: TestIntersectionOBB

        public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
        {
            // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
            // This breaks down into the ray---> plane equation.
            // TODO: Change to take shape into account
            Vector3[] vertexes = new Vector3[8];

            // float[] distance = new float[6];
            Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
            Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
            Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
            Vector3[] FaceD = new Vector3[6]; // vertex D for Facei

            Vector3[] normals = new Vector3[6]; // Normal for Facei
            Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals

            AAfacenormals[0] = new Vector3(1, 0, 0);
            AAfacenormals[1] = new Vector3(0, 1, 0);
            AAfacenormals[2] = new Vector3(-1, 0, 0);
            AAfacenormals[3] = new Vector3(0, -1, 0);
            AAfacenormals[4] = new Vector3(0, 0, 1);
            AAfacenormals[5] = new Vector3(0, 0, -1);

            Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
            Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
            Vector3 cross = new Vector3();

            Vector3 pos = GetWorldPosition();
            Quaternion rot = GetWorldRotation();

            // Variables prefixed with AX are Axiom.Math copies of the LL variety.

            Quaternion AXrot = rot;
            AXrot.Normalize();

            Vector3 AXpos = pos;

            // tScale is the offset to derive the vertex based on the scale.
            // it's different for each vertex because we've got to rotate it
            // to get the world position of the vertex to produce the Oriented Bounding Box

            Vector3 tScale = Vector3.Zero;

            Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);

            //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
            //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));

            // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
            Vector3 rScale = new Vector3();

            // Get Vertexes for Faces Stick them into ABCD for each Face
            // Form: Face<vertex>[face] that corresponds to the below diagram
            #region ABCD Face Vertex Map Comment Diagram
            //                   A _________ B
            //                    |         |
            //                    |  4 top  |
            //                    |_________|
            //                   C           D

            //                   A _________ B
            //                    |  Back   |
            //                    |    3    |
            //                    |_________|
            //                   C           D

            //   A _________ B                     B _________ A
            //    |  Left   |                       |  Right  |
            //    |    0    |                       |    2    |
            //    |_________|                       |_________|
            //   C           D                     D           C

            //                   A _________ B
            //                    |  Front  |
            //                    |    1    |
            //                    |_________|
            //                   C           D

            //                   C _________ D
            //                    |         |
            //                    |  5 bot  |
            //                    |_________|
            //                   A           B
            #endregion

            #region Plane Decomposition of Oriented Bounding Box
            tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
            rScale = tScale * AXrot;
            vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
               // vertexes[0].X = pos.X + vertexes[0].X;
            //vertexes[0].Y = pos.Y + vertexes[0].Y;
            //vertexes[0].Z = pos.Z + vertexes[0].Z;

            FaceA[0] = vertexes[0];
            FaceB[3] = vertexes[0];
            FaceA[4] = vertexes[0];

            tScale = AXscale;
            rScale = tScale * AXrot;
            vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
//.........这里部分代码省略.........
开发者ID:justasabc,项目名称:opensim,代码行数:101,代码来源:SceneObjectPart.cs

示例7: GetClosestIntersectingPrim

 protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
 {
     // Primitive Ray Tracing
     float closestDistance = 280f;
     EntityIntersection returnResult = new EntityIntersection();
     List<EntityBase> EntityList = GetEntities();
     foreach (EntityBase ent in EntityList)
     {
         if (ent is SceneObjectGroup)
         {
             SceneObjectGroup reportingG = (SceneObjectGroup)ent;
             EntityIntersection result = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
             if (result.HitTF)
             {
                 if (result.distance < closestDistance)
                 {
                     closestDistance = result.distance;
                     returnResult = result;
                 }
             }
         }
     }
     return returnResult;
 }
开发者ID:BogusCurry,项目名称:halcyon,代码行数:24,代码来源:SceneGraph.cs

示例8: doObjectDuplicateOnRay

        /// <summary>
        ///     Duplicates object specified by localID at position raycasted against RayTargetObject using
        ///     RayEnd and RayStart to determine what the angle of the ray is
        /// </summary>
        /// <param name="localID">ID of object to duplicate</param>
        /// <param name="dupeFlags"></param>
        /// <param name="AgentID">Agent doing the duplication</param>
        /// <param name="GroupID">Group of new object</param>
        /// <param name="RayTargetObj">The target of the Ray</param>
        /// <param name="RayEnd">The ending of the ray (farthest away point)</param>
        /// <param name="RayStart">The Beginning of the ray (closest point)</param>
        /// <param name="BypassRaycast">Bool to bypass raycasting</param>
        /// <param name="RayEndIsIntersection">The End specified is the place to add the object</param>
        /// <param name="CopyCenters">Position the object at the center of the face that it's colliding with</param>
        /// <param name="CopyRotates">Rotate the object the same as the localID object</param>
        public void doObjectDuplicateOnRay(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
                                           UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart,
                                           bool BypassRaycast, bool RayEndIsIntersection, bool CopyCenters,
                                           bool CopyRotates)
        {
            const bool frontFacesOnly = true;
            //MainConsole.Instance.Info("HITTARGET: " + RayTargetObj.ToString() + ", COPYTARGET: " + localID.ToString());
            ISceneChildEntity target = m_parentScene.GetSceneObjectPart(localID);
            ISceneChildEntity target2 = m_parentScene.GetSceneObjectPart(RayTargetObj);
            IScenePresence Sp = GetScenePresence(AgentID);
            if (target != null && target2 != null)
            {
                Vector3 pos;
                if (EnableFakeRaycasting)
                {
                    RayStart = Sp.CameraPosition;
                    RayEnd = pos = target2.AbsolutePosition;
                }
                Vector3 direction = Vector3.Normalize(RayEnd - RayStart);
                Vector3 AXOrigin = new Vector3(RayStart.X, RayStart.Y, RayStart.Z);
                Vector3 AXdirection = new Vector3(direction.X, direction.Y, direction.Z);

                if (target2.ParentEntity != null)
                {
                    pos = target2.AbsolutePosition;
                    // TODO: Raytrace better here

                    //EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), false, false);
                    Ray NewRay = new Ray(AXOrigin, AXdirection);

                    // Ray Trace against target here
                    EntityIntersection ei = target2.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly,
                                                                        CopyCenters);

                    // Un-comment out the following line to Get Raytrace results printed to the console.
                    //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
                    float ScaleOffset = 0.5f;

                    // If we hit something
                    if (ei.HitTF)
                    {
                        Vector3 scale = target.Scale;
                        Vector3 scaleComponent = new Vector3(ei.AAfaceNormal.X, ei.AAfaceNormal.Y, ei.AAfaceNormal.Z);
                        if (scaleComponent.X != 0) ScaleOffset = scale.X;
                        if (scaleComponent.Y != 0) ScaleOffset = scale.Y;
                        if (scaleComponent.Z != 0) ScaleOffset = scale.Z;
                        ScaleOffset = Math.Abs(ScaleOffset);
                        Vector3 intersectionpoint = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
                        Vector3 normal = new Vector3(ei.normal.X, ei.normal.Y, ei.normal.Z);
                        Vector3 offset = normal*(ScaleOffset/2f);
                        pos = intersectionpoint + offset;

                        // stick in offset format from the original prim
                        pos = pos - target.ParentEntity.AbsolutePosition;
                        if (CopyRotates)
                        {
                            Quaternion worldRot = target2.GetWorldRotation();

                            // SceneObjectGroup obj = m_sceneGraph.DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
                            DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
                            //obj.Rotation = worldRot;
                            //obj.UpdateGroupRotationR(worldRot);
                        }
                        else
                        {
                            DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID,
                                            Quaternion.Identity);
                        }
                    }

                    return;
                }

                return;
            }
        }
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:91,代码来源:SceneGraph.cs

示例9: RezObjectHandler

        void RezObjectHandler(Packet packet, LLAgent agent)
        {
            RezObjectPacket rez = (RezObjectPacket)packet;

            // Find the target position
            Vector3 position = Vector3.Zero;
            Vector3 linksetScale = Vector3.Zero;
            bool bypassRaycast = (rez.RezData.BypassRaycast == 1);
            //bool rayEndIsIntersection = rez.RezData.RayEndIsIntersection;

            #region Position Calculation

            if (bypassRaycast || m_physics == null)
            {
                position = rez.RezData.RayEnd;
            }
            else
            {
                Vector3 direction = (rez.RezData.RayEnd - rez.RezData.RayStart);
                direction /= direction.Length();
                Ray ray = new Ray(rez.RezData.RayStart, direction);

                ISceneEntity collisionObj;
                float collisionDist;
                if (m_physics.FullSceneCollisionTest(true, ray, null, out collisionObj, out collisionDist))
                {
                    position = ray.GetPoint(collisionDist);
                }
                else
                {
                    m_log.Warn("Full scene collision test for ray " + ray + " failed");
                    position = agent.ScenePosition + Vector3.UnitZ;
                }
            }

            position.Z += linksetScale.Z * 0.5f;

            #endregion Position Calculation

            InventoryBase invObject;
            if (m_inventoryClient.TryGetInventory(agent.ID, rez.InventoryData.ItemID, out invObject) & invObject is InventoryItem)
            {
                InventoryItem item = (InventoryItem)invObject;

                Asset asset;
                if (m_assetClient.TryGetAsset(item.AssetID, item.ContentType, out asset))
                {
                    #region Object Deserialization/Rezzing

                    // Deserialize the asset data into a linkset
                    using (MemoryStream stream = new MemoryStream(asset.Data))
                    {
                        OSDMap linksetMap = OSDParser.DeserializeJson(stream) as OSDMap;
                        if (linksetMap != null)
                        {
                            IList<LLPrimitive> linkset = LLPrimitive.DeserializeLinkset(linksetMap, m_scene, m_primMesher, true);

                            // Rez the parent(s) first
                            for (int i = 0; i < linkset.Count; i++)
                            {
                                LLPrimitive prim = linkset[i];

                                // Make sure the ownerID is set correctly
                                prim.OwnerID = agent.ID;

                                if (prim.Parent == null)
                                {
                                    RezSinglePrim(prim, rez.RezData, position);
                                    m_log.Debug("Deserialized root prim " + prim.ID + " (" + prim.LocalID + ") from inventory");
                                }
                            }

                            // Rez the children
                            for (int i = 0; i < linkset.Count; i++)
                            {
                                if (linkset[i].Parent != null)
                                    RezSinglePrim(linkset[i], rez.RezData, position);
                            }

                            // FIXME: Use these to determine if we need to delete the source inventory or task item
                            //rez.RezData.FromTaskID
                            //rez.RezData.RemoveItem
                        }
                        else
                        {
                            m_log.WarnFormat("Failed to deserialize asset {0} ({1} bytes, Content-Type: {2}) into a linkset",
                                asset.ID, asset.Data.Length, asset.ContentType);
                        }
                    }

                    #endregion Object Deserialization/Rezzing
                }
                else
                {
                    m_log.Warn(agent.Name + "'s RezObject failed to retrieve asset " + item.AssetID);
                }
            }
            else
            {
                m_log.Warn(agent.Name + " called RezObject for unknown item " + rez.InventoryData.ItemID);
//.........这里部分代码省略.........
开发者ID:thoys,项目名称:simian,代码行数:101,代码来源:Inventory.cs

示例10: ObjectAddHandler

        void ObjectAddHandler(Packet packet, LLAgent agent)
        {
            if (!agent.IsVerified)
            {
                m_scene.PresenceAlert(this, agent, "You are logged in with an unverified account. Object creation is disabled.");
                return;
            }

            ObjectAddPacket add = (ObjectAddPacket)packet;

            Vector3 position = Vector3.Zero;
            Vector3 scale = add.ObjectData.Scale;
            PCode pcode = (PCode)add.ObjectData.PCode;
            PrimFlags flags = (PrimFlags)add.ObjectData.AddFlags;
            bool bypassRaycast = (add.ObjectData.BypassRaycast == 1);
            //bool rayEndIsIntersection = (add.ObjectData.RayEndIsIntersection == 1);

            #region Position Calculation

            if (bypassRaycast)
            {
                position = add.ObjectData.RayEnd;
            }
            else if (m_physics != null)
            {
                Vector3 direction = (add.ObjectData.RayEnd - add.ObjectData.RayStart);
                direction /= direction.Length();
                Ray ray = new Ray(add.ObjectData.RayStart, direction);

                ISceneEntity collisionObj;
                float collisionDist;
                if (m_physics.FullSceneCollisionTest(true, ray, null, out collisionObj, out collisionDist))
                {
                    position = ray.GetPoint(collisionDist);
                }
                else
                {
                    m_log.Warn("Full scene collision test for ray " + ray + " failed");
                    position = agent.ScenePosition + Vector3.UnitZ;
                }
            }

            position.Z += scale.Z * 0.5f;

            #endregion Position Calculation

            if (!CanAddPrims(agent, position, 1))
                return;

            #region Foliage Handling

            // Set all foliage to phantom
            if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
            {
                flags |= PrimFlags.Phantom;

                if (pcode != PCode.Grass)
                {
                    // Resize based on the foliage type
                    Tree tree = (Tree)add.ObjectData.State;

                    switch (tree)
                    {
                        case Tree.Cypress1:
                        case Tree.Cypress2:
                            scale = new Vector3(4f, 4f, 10f);
                            break;
                        default:
                            scale = new Vector3(4f, 4f, 4f);
                            break;
                    }
                }
            }

            #endregion Foliage Handling

            #region Prim Creation

            // Create an object
            Primitive prim = new Primitive();

            prim.Flags = PrimFlags.CastShadows | PrimFlags.InventoryEmpty;
            prim.Flags |= (PrimFlags)add.ObjectData.AddFlags;

            // TODO: Security check
            prim.GroupID = add.AgentData.GroupID;
            prim.ID = UUID.Random();
            prim.MediaURL = String.Empty;
            prim.OwnerID = agent.ID;
            prim.Position = position;

            prim.PrimData.Material = (Material)add.ObjectData.Material;
            prim.PrimData.PathCurve = (PathCurve)add.ObjectData.PathCurve;
            prim.PrimData.ProfileCurve = (ProfileCurve)add.ObjectData.ProfileCurve;
            prim.PrimData.PathBegin = Primitive.UnpackBeginCut(add.ObjectData.PathBegin);
            prim.PrimData.PathEnd = Primitive.UnpackEndCut(add.ObjectData.PathEnd);
            prim.PrimData.PathScaleX = Primitive.UnpackPathScale(add.ObjectData.PathScaleX);
            prim.PrimData.PathScaleY = Primitive.UnpackPathScale(add.ObjectData.PathScaleY);
            prim.PrimData.PathShearX = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearX);
            prim.PrimData.PathShearY = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearY);
//.........这里部分代码省略.........
开发者ID:osgrid,项目名称:openmetaverse,代码行数:101,代码来源:Objects.cs

示例11: GetNewRezLocation

        /// <summary>
        ///     Gets a new rez location based on the raycast and the size of the object that is being rezzed.
        /// </summary>
        /// <param name="RayStart"></param>
        /// <param name="RayEnd"></param>
        /// <param name="RayTargetID"></param>
        /// <param name="rot"></param>
        /// <param name="bypassRayCast"></param>
        /// <param name="RayEndIsIntersection"></param>
        /// <param name="frontFacesOnly"></param>
        /// <param name="scale"></param>
        /// <param name="FaceCenter"></param>
        /// <returns></returns>
        public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot,
            byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly,
            Vector3 scale, bool FaceCenter)
        {
            Vector3 pos = Vector3.Zero;
            if (RayEndIsIntersection == 1)
            {
                pos = RayEnd;
                return pos;
            }

            if (RayTargetID != UUID.Zero)
            {
                ISceneChildEntity target = m_parentScene.GetSceneObjectPart(RayTargetID);

                Vector3 direction = Vector3.Normalize(RayEnd - RayStart);
                Vector3 AXOrigin = new Vector3(RayStart.X, RayStart.Y, RayStart.Z);
                Vector3 AXdirection = new Vector3(direction.X, direction.Y, direction.Z);

                if (target != null)
                {
                    pos = target.AbsolutePosition;
                    //MainConsole.Instance.Info("[OBJECT_REZ]: TargetPos: " + pos.ToString() + ", RayStart: " + RayStart.ToString() + ", RayEnd: " + RayEnd.ToString() + ", Volume: " + Util.GetDistanceTo(RayStart,RayEnd).ToString() + ", mag1: " + Util.GetMagnitude(RayStart).ToString() + ", mag2: " + Util.GetMagnitude(RayEnd).ToString());

                    // TODO: Raytrace better here

                    Ray NewRay = new Ray(AXOrigin, AXdirection);

                    // Ray Trace against target here
                    EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly,
                                                                       FaceCenter);

                    // Un-comment out the following line to Get Raytrace results printed to the console.
                    //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
                    float ScaleOffset = 0.5f;

                    // If we hit something
                    if (ei.HitTF)
                    {
                        Vector3 scaleComponent = new Vector3(ei.AAfaceNormal.X, ei.AAfaceNormal.Y, ei.AAfaceNormal.Z);
                        if (scaleComponent.X != 0) ScaleOffset = scale.X;
                        if (scaleComponent.Y != 0) ScaleOffset = scale.Y;
                        if (scaleComponent.Z != 0) ScaleOffset = scale.Z;
                        ScaleOffset = Math.Abs(ScaleOffset);
                        Vector3 intersectionpoint = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
                        Vector3 normal = new Vector3(ei.normal.X, ei.normal.Y, ei.normal.Z);
                        // Set the position to the intersection point
                        Vector3 offset = (normal*(ScaleOffset/2f));
                        pos = (intersectionpoint + offset);
                    }

                    return pos;
                }
                else
                {
                    // We don't have a target here, so we're going to raytrace all the objects in the scene.

                    EntityIntersection ei = GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);

                    // Un-comment the following line to print the raytrace results to the console.
                    //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());

                    pos = ei.HitTF ? new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z) : RayEnd;

                    return pos;
                }
            }
            // fall back to our stupid functionality
            pos = RayEnd;

            //increase height so its above the ground.
            //should be getting the normal of the ground at the rez point and using that?
            pos.Z += scale.Z/2f;
            return pos;
        }
开发者ID:emperorstarfinder,项目名称:Virtual-Universe,代码行数:88,代码来源:SceneGraph.cs

示例12: findNextHit

        /// <summary>
        /// A method which find the first object the ray hit. This is done by comparing distances. 
        /// The smallest distance is the distance between the intersection point and the ray start point. 
        /// </summary>
        /// <param name="ray">The ray which will be used to test the intersection against each part in the scene</param>
        /// <param name="source">An object which the ray start from. We need this to make sure that the shortest
        /// distance isn't zero (from itself to itself)</param>
        /// <returns>Intersection point with True if this ray intersect something, or false if nothing at all</returns>
        public EntityIntersectionWithPart findNextHit(Ray ray, SceneObjectPart source)
        {
            float smallestDistance = 1000000f;
            EntityIntersection closestIntersection = new EntityIntersection();
            SceneObjectPart closestPart = new SceneObjectPart();
            foreach (SceneObjectPart part in worldObjects)
            {
                if (!part.Equals(source)) //Cannot intersect itself (i.e. ignore/do nothing when it is itself)
                {
                    //Test if the ray intersect this part. 
                    EntityIntersection intersection;
                    if (part.GetPrimType() == OpenSim.Region.Framework.Scenes.PrimType.SPHERE)
                    {
                        intersection = part.TestIntersection(ray, part.ParentGroup.GroupRotation);
                    }
                    else
                    {
                        intersection = part.TestIntersectionOBB(ray, part.ParentGroup.GroupRotation, true, false);
                    }

                    //If it intersects, then check again with another method checkPointIntersectPrim().
                    if (intersection.HitTF && checkPointIntersectPrim(intersection.ipoint, part, 0.1f))
                    {
                        //If yes, then remember this distance and this intersection as the current 'return' candidate
                        if (intersection.distance < smallestDistance)
                        {
                            smallestDistance = intersection.distance;
                            closestIntersection = intersection;
                            closestPart = part;
                        }//if
                    }//if
                }//if
            }//foreach
            return new EntityIntersectionWithPart(closestIntersection, closestPart);
        }
开发者ID:TheCoffeeTime,项目名称:Opensim,代码行数:43,代码来源:RayTracer.cs

示例13: traceRay

        /// <summary>
        /// A recursive method which trace a ray until its power is less than ray-minimum power thershold
        /// </summary>
        /// <param name="path">New PathFromTxToRy object.</param>
        /// <param name="ray">A starting ray (first ray)</param>
        /// <param name="lastIntersectPart">A world object which this ray last intersect, or start</param>
        /// <returns>PathFromTxToRy with True if it reaches receiver and False if it did not reach the receiver.</returns>
        public PathFromTxToRy traceRay(PathFromTxToRy path, Ray ray, SceneObjectPart lastIntersectPart)
        {
            EntityIntersectionWithPart nextHit = findNextHit(ray, transmitter.RootPart);

            if (nextHit.intersection.HitTF)
            {
                //Check for limit number of reflection allowed.
                if(path.getNoOfReflection() >= MAX_REFLECTIONS)
                {
                    path.reachesReceiver = false;
                    return path;
                }
                //drawRay(ray.Origin, nextHit.intersection.ipoint);
                else if (nextHit.intersectPart.Equals(receiver.RootPart)) //If it reaches the receiver
                {
                    path.reachesReceiver = true;
                    path.addNextPoint(nextHit.intersection.ipoint, receiver.RootPart.Material);
                    return path;
                }//if

                //recursive case, keep tracing this ray.
                else
                {
                    path.addNextPoint(nextHit.intersection.ipoint, nextHit.intersectPart.Material);
                    Vector3 reflectedVector = getReflectedVector(ray.Direction, nextHit.intersection.normal);
                    Ray newRay = new Ray(nextHit.intersection.ipoint, reflectedVector);
                    return traceRay(path, newRay, nextHit.intersectPart);
                }//else if
            }
            else //It didn't hit anything
            {
                path.reachesReceiver = false;
                return path;
            }//else
        }
开发者ID:TheCoffeeTime,项目名称:Opensim,代码行数:42,代码来源:RayTracer.cs

示例14: GetClosestIntersectingPrim

 /// <summary>
 ///     Get a scene object group that contains the prim with the given uuid
 /// </summary>
 /// <param name="hray"></param>
 /// <param name="frontFacesOnly"></param>
 /// <param name="faceCenters"></param>
 /// <returns>null if no scene object group containing that prim is found</returns>
 protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
 {
     // Primitive Ray Tracing
     float closestDistance = 280f;
     EntityIntersection result = new EntityIntersection();
     ISceneEntity[] EntityList = Entities.GetEntities(hray.Origin, closestDistance);
     foreach (ISceneEntity ent in EntityList)
     {
         if (ent is SceneObjectGroup)
         {
             SceneObjectGroup reportingG = (SceneObjectGroup) ent;
             EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
             if (inter.HitTF && inter.distance < closestDistance)
             {
                 closestDistance = inter.distance;
                 result = inter;
             }
         }
     }
     return result;
 }
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:28,代码来源:SceneGraph.cs

示例15: EntityCollisionTest

 public bool EntityCollisionTest(Ray ray, IPhysical obj, out float distance)
 {
     float unused;
     return RayAABB.CollisionTestSmits(obj.SceneAABB, ray, out distance, out unused);
 }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:5,代码来源:SimplePhysics.cs


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