コード例 #1
0
ファイル: MathUtil.cs プロジェクト: MoysheBenRabi/setp
 public static float Distance(MsdVector3f v1, MsdVector3f v2)
 {
     return((float)Math.Sqrt(
                (v2.X - v1.X) * (v2.X - v1.X) +
                (v2.Y - v1.Y) * (v2.Y - v1.Y) +
                (v2.Z - v1.Z) * (v2.Z - v1.Z)));
 }
コード例 #2
0
        public void EvaluateHandoverNeed(CloudObject cloudObject)
        {
            if (cloudObject.BubbleId != bubble.BubbleId)
            {
                throw new Exception("Remote objects can not need to be handed over.");
            }

            MsdVector3f origo = new MsdVector3f();

            // Evaluating if object center is inside bubble range
            float distanceFromCenter = MathUtil.Distance(cloudObject.Location, origo);

            if (distanceFromCenter < bubble.BubbleRange)
            {
                return;
            }

            foreach (Handover handover in handovers)
            {
                if (handover.ObjectId == cloudObject.ObjectId)
                {
                    // Object is already in handover process.
                    return;
                }
            }

            // Object is not inside bubble radius
            // Evaluate if there is another linked bubble where object center would be inside bubble range
            float      shortestDistance  = float.MaxValue;
            BubbleLink closestBubbleLink = null;

            foreach (BubbleLink bubbleLink in bubble.GetBubbleLinks().Values)
            {
                float distanceFromRemoteCenter = MathUtil.Distance(cloudObject.Location, bubbleLink.RemoteBubbleCenter);
                if (distanceFromRemoteCenter < bubble.BubbleRange && distanceFromCenter < shortestDistance)
                {
                    shortestDistance  = distanceFromRemoteCenter;
                    closestBubbleLink = bubbleLink;
                }
            }

            if (closestBubbleLink != null)
            {
                RequestIdentify(closestBubbleLink, cloudObject);
            }
        }
コード例 #3
0
        public void PerceptionMessageEncoding()
        {
            PerceptionEventMessage originalMessage = new PerceptionEventMessage();

            originalMessage.ObjectFragment.ObjectId              = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectIndex           = 1;
            originalMessage.ObjectFragment.TypeId                = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectName            = "TestObjectName";
            originalMessage.ObjectFragment.TypeName              = "TestTypeName";
            originalMessage.ObjectFragment.OwnerId               = Guid.NewGuid();
            originalMessage.ObjectFragment.Location.X            = 1; originalMessage.ObjectFragment.Location.Y = 2; originalMessage.ObjectFragment.Location.Z = 3;
            originalMessage.ObjectFragment.Velocity.X            = 4; originalMessage.ObjectFragment.Velocity.Y = 5; originalMessage.ObjectFragment.Velocity.Z = 6;
            originalMessage.ObjectFragment.Acceleration.X        = 7; originalMessage.ObjectFragment.Acceleration.Y = 8; originalMessage.ObjectFragment.Acceleration.Z = 9;
            originalMessage.ObjectFragment.Orientation.X         = 10; originalMessage.ObjectFragment.Orientation.Y = 11; originalMessage.ObjectFragment.Orientation.Z = 12; originalMessage.ObjectFragment.Orientation.W = 13;
            originalMessage.ObjectFragment.AngularVelocity.X     = 14; originalMessage.ObjectFragment.AngularVelocity.Y = 15; originalMessage.ObjectFragment.AngularVelocity.Z = 16; originalMessage.ObjectFragment.AngularVelocity.W = 17;
            originalMessage.ObjectFragment.AngularAcceleration.X = 18; originalMessage.ObjectFragment.AngularAcceleration.Y = 19; originalMessage.ObjectFragment.AngularAcceleration.Z = 20; originalMessage.ObjectFragment.AngularAcceleration.W = 21;
            originalMessage.ObjectFragment.BoundingSphereRadius  = 22;
            originalMessage.ObjectFragment.Mass = 23;

            OmSlPrimitiveExt originalExtensionFragment = new OmSlPrimitiveExt();

            originalExtensionFragment.State     = 24;
            originalExtensionFragment.NameValue = "TestExtensionNameValue";
            MsdVector3f scale = new MsdVector3f();

            scale.X = 1;
            scale.Y = 2;
            scale.Z = 3;
            originalExtensionFragment.Scale = scale;

            originalMessage.SetExtension <OmSlPrimitiveExt>(originalExtensionFragment);
            originalMessage.PrepareEncoding();

            byte[] encodedBytes = new byte[MxpConstants.MaxPacketSize];

            Assert.AreEqual(originalMessage.FrameCount, 2);
            Assert.AreEqual(originalMessage.FrameDataSize(0), 255);
            Assert.AreEqual(originalMessage.FrameDataSize(1), 49);

            int currentIndex = originalMessage.EncodeFrameData(0, encodedBytes, 0);

            currentIndex = originalMessage.EncodeFrameData(1, encodedBytes, currentIndex);

            PerceptionEventMessage decodedMessage = new PerceptionEventMessage();

            int currentDecodeIndex = decodedMessage.DecodeFrameData(0, encodedBytes, 0, originalMessage.FrameDataSize(0));

            currentDecodeIndex = decodedMessage.DecodeFrameData(1, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(1));

            decodedMessage.MessageId = originalMessage.MessageId;

            String originalMessageString = originalMessage.ToString();
            String decodedMessageString  = decodedMessage.ToString();

            Assert.AreEqual(originalMessageString, decodedMessageString);

            OmSlPrimitiveExt decodedExtensionFragmet = decodedMessage.GetExtension <OmSlPrimitiveExt>();

            Assert.AreEqual(originalExtensionFragment.State, decodedExtensionFragmet.State);
            Assert.AreEqual(originalExtensionFragment.NameValue, decodedExtensionFragmet.NameValue);
        }
コード例 #4
0
ファイル: MathUtil.cs プロジェクト: MoysheBenRabi/setp
 public static float Length(MsdVector3f vector)
 {
     return((float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z));
 }