Example #1
0
        protected override unsafe MyEntity DestroyItem(int itemInstanceId)
        {
            int      num;
            MyEntity entity;

            if (!base.m_localIdToPhysicsShapeInstanceId.TryGetValue(itemInstanceId, out num))
            {
                num = -1;
            }
            MyEnvironmentItems.MyEnvironmentItemData data = base.m_itemsData[itemInstanceId];
            base.RemoveItem(itemInstanceId, num, false, true);
            Vector3D position   = data.Transform.Position;
            string   modelAsset = data.Model.AssetName.Insert(data.Model.AssetName.Length - 4, "_broken");
            bool     flag       = false;

            if (MyModels.GetModelOnlyData(modelAsset) == null)
            {
                entity = MyDebris.Static.CreateDebris(data.Model.AssetName);
            }
            else
            {
                flag   = true;
                entity = MyDebris.Static.CreateDebris(modelAsset);
            }
            MyDebrisBase.MyDebrisBaseLogic gameLogic = entity.GameLogic as MyDebrisBase.MyDebrisBaseLogic;
            gameLogic.LifespanInMiliseconds = 0x4e20;
            MatrixD  xd     = MatrixD.CreateFromQuaternion(data.Transform.Rotation);
            MatrixD *xdPtr1 = (MatrixD *)ref xd;

            xdPtr1.Translation = position + (xd.Up * (flag ? ((double)0) : ((double)5)));
            gameLogic.Start(xd, Vector3.Zero, false);
            return(entity);
        }
Example #2
0
 public void DebugDraw()
 {
     if (((IMyUtilities)MyAPIUtilities.Static).IsDedicated)
     {
         return;
     }
     if (!RailConstants.Debug.DrawBendyPhysics)
     {
         return;
     }
     if (Vector3D.DistanceSquared(MyCameraComponent.ActiveCamera.GetPosition(), Entity.GetPosition()) > 50 * 50)
     {
         return;
     }
     foreach (var k in _boxes)
     {
         var box      = new BoundingBoxD(-k.HalfExtent, k.HalfExtent);
         var m        = MatrixD.CreateFromQuaternion(k.Orientation) * MatrixD.CreateTranslation(k.Center) * Entity.WorldMatrix;
         var queryBox = box;
         queryBox = queryBox.TransformFast(m);
         if (Vector3D.DistanceSquared(queryBox.Center, MyCameraComponent.ActiveCamera.GetPosition()) >
             25 * 25 ||
             !MyCameraComponent.ActiveCamera.GetCameraFrustum().Intersects(queryBox))
         {
             continue;
         }
         var c = new Color(1, 0, 0, 0.25f);
         MySimpleObjectDraw.DrawTransparentBox(ref m, ref box, ref c, MySimpleObjectRasterizer.Solid, 1, .01f,
                                               _debugMaterialId, _debugMaterialId);
         var cWif = Color.White;
         MySimpleObjectDraw.DrawTransparentBox(ref m, ref box, ref cWif, MySimpleObjectRasterizer.Wireframe, 1,
                                               .01f, _debugMaterialId, _debugMaterialId);
     }
 }
Example #3
0
        public override IEnumerable <ProceduralObject> Generate(BoundingSphereD include, BoundingSphereD?exclude)
        {
            var mult = _config.ViewDistance / include.Radius;

            include.Radius *= mult;
            if (exclude.HasValue)
            {
                exclude = new BoundingSphereD(exclude.Value.Center, exclude.Value.Radius * mult);
            }

            var min = Vector3D.Floor((include.Center - include.Radius) / _config.SystemSpacing);
            var max = Vector3D.Floor(((include.Center + include.Radius) / _config.SystemSpacing) + 1.0D);

            for (var x = min.X; x < max.X; x++)
            {
                for (var y = min.Y; y < max.Y; y++)
                {
                    for (var z = min.Z; z < max.Z; z++)
                    {
                        var seedVec = new Vector3I(x, y, z);
                        var seed    = seedVec.GetHashCode();
                        var rand    = new Random(seed);
                        if (rand.NextDouble() >= _config.SystemProbability)
                        {
                            continue;
                        }
                        if (_systems.ContainsKey(seedVec))
                        {
                            continue;
                        }
                        var world = (new Vector3D(x, y, z) + 0.5) * _config.SystemSpacing + rand.NextVector3D() * (_config.SystemSpacing / 8);
                        if (include.Contains(world) == ContainmentType.Disjoint || (exclude.HasValue && exclude.Value.Contains(world) != ContainmentType.Disjoint))
                        {
                            continue;
                        }

                        var list = _config.Systems.Where(s => s.MinDistanceFromOrigin <= world.Length()).ToList();
                        var ttl  = list.Sum(s => s.Probability);
                        foreach (var s in list)
                        {
                            if (ttl <= s.Probability)
                            {
                                var position = MatrixD.CreateFromQuaternion(rand.NextQuaternion());
                                position.Translation = world;
                                var result = new ProceduralSystem(this, s, rand.NextLong(), position);
                                _systems.Add(seedVec, result);
                                foreach (var b in result.Bodies)
                                {
                                    _addQueue.Enqueue(b);
                                }
                                yield return(result);

                                break;
                            }
                            ttl -= s.Probability;
                        }
                    }
                }
            }
        }
Example #4
0
        private Vector3D WorldPositionToLocalNavmeshPosition(Vector3D position, float heightIncrease)
        {
            Vector3D v      = -Vector3D.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(this.Center));
            MatrixD  matrix = MatrixD.CreateFromQuaternion(Quaternion.Inverse(Quaternion.CreateFromForwardUp((Vector3)Vector3D.CalculatePerpendicularVector(v), (Vector3)v)));

            return(Vector3D.Transform((position - this.Center) + (heightIncrease * v), matrix));
        }
Example #5
0
        //local avoidance
        private Vector3 getIntermediateMovementTarget(IMyCubeGrid grid, Vector3 target, double initialRange)
        {
            if (initialRange > 250f)
            {
                initialRange = 250;
            }
            var castFrom = grid.GetPosition() + grid.WorldMatrix.Up * 0.3f;
            //var dir = grid.WorldMatrix.Backward;
            var dir = target - castFrom;

            dir.Normalize();

            var plane            = Vector3.Cross(dir, grid.WorldMatrix.Right);
            var projectedForward = projectOnPlane(dir, plane);

            projectedForward.Normalize();

            for (int i = 0; i <= 330; i += 30)
            {
                var degInRad = (float)(i * Math.PI / 180f);

                var newDir = Vector3D.Rotate(projectedForward,
                                             MatrixD.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(grid.WorldMatrix.Up, degInRad)));
                newDir.Normalize();
                var   targetPos = target;
                float castRange = (float)(initialRange + (3 * i / 30f));
                if (validDir(castFrom, newDir, grid, ref targetPos, castRange))
                {
                    return(i == 0 ? target : targetPos);
                }
            }

            return(target);
        }
        public override void Received(ref RelayMode relay, ulong senderSteamId)
        {
            relay = RelayMode.RelayOriginal;

            if (!Networking.IsPlayer)
            {
                return;
            }

            Vector3D camPos = MyAPIGateway.Session.Camera.WorldMatrix.Translation;

            if (Vector3D.DistanceSquared(camPos, Position) > MaxDistanceSq)
            {
                return;
            }

            MatrixD worldMatrix = MatrixD.CreateFromQuaternion(Orientation);

            worldMatrix.Translation = Position;

            MyEntity3DSoundEmitter emitter = new MyEntity3DSoundEmitter(null);

            emitter.CustomVolume = 0.9f;
            emitter.SetPosition(Position);
            emitter.PlaySingleSound(new MySoundPair("PrgDeconstrPh03Fin"));

            // TODO: spawn smoke or something only from where the block was mounted
            CreateConstructionSmokes(worldMatrix);
        }
        private MyEntity CreateDebris(int itemId)
        {
            ProfilerShort.Begin("Spawning tree");
            var itemData = m_sector.DataView.Items[itemId];

            Vector3D worldPos = itemData.Position + m_sector.SectorCenter;

            var model = m_sector.Owner.GetModelForId(itemData.ModelIndex);

            var      brokenModel = model.Model.Insert(model.Model.Length - 4, "_broken");
            MyEntity debris;
            bool     hasBrokenModel = false;

            if (MyModels.GetModelOnlyData(brokenModel) != null)
            {
                hasBrokenModel = true;
                debris         = MyDebris.Static.CreateDebris(brokenModel);
            }
            else
            {
                debris = MyDebris.Static.CreateDebris(model.Model);
            }

            var debrisLogic = (MyDebrisBase.MyDebrisBaseLogic)debris.GameLogic;

            debrisLogic.RandomScale           = 1;
            debrisLogic.LifespanInMiliseconds = BrokenItemLifeSpan;
            var m = MatrixD.CreateFromQuaternion(itemData.Rotation);

            m.Translation = worldPos + m.Up * (hasBrokenModel ? 0 : 5);
            debrisLogic.Start(m, Vector3.Zero, 1, false);
            ProfilerShort.End();
            return(debris);
        }
            internal void ExecuteSpawn()
            {
                lock (this)
                {
                    if (m_removeQueued || !m_spawnQueued)
                    {
                        return;
                    }
                    if (VoxelMap == null)
                    {
                        var mat = MatrixD.CreateFromQuaternion(Rotation);
                        mat.Translation = WorldPosition;
                        var genSeed = WorldPosition.GetHashCode();
                        if (VoxelUtility.TryFindAsteroidSeed(ref genSeed, Size, SeedSpecs.ProhibitsOre, SeedSpecs.RequiresOre, 10) || !SeedSpecs.ExcludeInvalid)
                        {
                            VoxelMap = VoxelUtility.SpawnAsteroid(new MyPositionAndOrientation(mat),
                                                                  VoxelUtility.CreateProceduralAsteroidProvider(genSeed, Size));
                            VoxelMap.OnPhysicsChanged += MarkForSave;
                        }
                    }

                    m_spawnQueued  = false;
                    m_removeQueued = false;
                }
            }
Example #9
0
        public static void DrawOBB(MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f)
        {
            var box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            var wm  = MatrixD.CreateFromQuaternion(obb.Orientation);

            wm.Translation = obb.Center;
            MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, MySimpleObjectRasterizer.Solid, 1);
        }
Example #10
0
        public static void DrawObb(MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f)
        {
            BoundingBoxD box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            MatrixD      wm  = MatrixD.CreateFromQuaternion(obb.Orientation);

            wm.Translation = obb.Center;
            MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, MyStringId.GetOrCompute("Square"), MyStringId.GetOrCompute("Square"));
        }
Example #11
0
    public Vector3D quaternionToYPR(Quaternion rotation)
    {
        MatrixD  transform = MatrixD.CreateFromQuaternion(rotation);
        Vector3D result    = new Vector3D();

        MatrixD.GetEulerAnglesXYZ(ref transform, out result);
        return(result);
    }
        static bool ReadTransform(BitStream stream, MyEntity entity, Vector3D?deltaPosBase, bool applyWhenReading, bool movingOnServer, ref Vector3D outPosition, ref Quaternion outOrientation, ref MatrixD outWorldMartix, Func <MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            Vector3D position;

            if (stream.ReadBool())
            {
                position = stream.ReadVector3D(); // 24 B
            }
            else
            {
                HalfVector3 pos = stream.ReadHalfVector3(); // 6 B
                if (deltaPosBase != null)
                {
                    position = pos + deltaPosBase.Value;
                }
                else
                {
                    position = pos.ToVector3();
                }
            }
            Quaternion orientation;
            bool       lowPrecisionOrientation = stream.ReadBool();

            if (lowPrecisionOrientation)
            {
                orientation = stream.ReadQuaternionNormCompressed(); // 29b
            }
            else
            {
                orientation = stream.ReadQuaternionNorm(); // 52b
            }

            if (entity != null)
            {
                movingOnServer |= (entity.PositionComp.GetPosition() - position).LengthSquared() > epsilonSq;

                if (movingOnServer && applyWhenReading && (posValidation == null || posValidation(entity, position)))
                {
                    {
                        var old = entity.PositionComp.WorldMatrix;

                        MatrixD matrix = MatrixD.CreateFromQuaternion(orientation);
                        if (matrix.IsValid())
                        {
                            matrix.Translation = position;

                            outPosition    = matrix.Translation;
                            outOrientation = orientation;
                            outWorldMartix = matrix;
                            return(true);
                        }
                        return(false);
                    }
                }
            }
            return(false);
        }
        public bool Intersects(ref BoundingBoxD box)
        {
            Vector3D vectord = (Vector3D)((box.Max + box.Min) * 0.5);
            Vector3D hA      = (Vector3D)((box.Max - box.Min) * 0.5);
            MatrixD  mB      = MatrixD.CreateFromQuaternion(this.Orientation);

            mB.Translation = this.Center - vectord;
            return(ContainsRelativeBox(ref hA, ref this.HalfExtent, ref mB) != ContainmentType.Disjoint);
        }
        private MatrixD LocalNavmeshPositionToWorldPositionTransform(MyOrientedBoundingBoxD obb, Vector3D center)
        {
            // TODO: should use the obb?

            Vector3D   gravityVector = -Vector3D.Normalize(GameSystems.MyGravityProviderSystem.CalculateTotalGravityInPoint(center));
            var        fwd           = Vector3D.CalculatePerpendicularVector(gravityVector);
            Quaternion quaternion    = Quaternion.CreateFromForwardUp(fwd, gravityVector);

            return(MatrixD.CreateFromQuaternion(quaternion));
        }
Example #15
0
        public void Apply(MyEntity entity, bool applyRotation = true, bool applyPhysics = true, bool reset = false)
        {
            VRage.Profiler.ProfilerShort.Begin("Matrix calc");
            var     oldMat = entity.WorldMatrix;
            MatrixD mat    = oldMat;

            if (applyRotation)
            {
                mat = MatrixD.CreateFromQuaternion(Rotation);
            }
            else
            {
                mat = oldMat;
            }
            mat.Translation = Position;
            VRage.Profiler.ProfilerShort.End();

            VRage.Profiler.ProfilerShort.Begin("WorldMatrix update");
            if (Sandbox.Engine.Utils.MyFakes.MULTIPLAYER_CLIENT_PHYSICS)
            {
                entity.SetWorldMatrix(mat, true, reset);
                entity.m_positionResetFromServer = reset;
            }
            else
            {
                entity.Physics.ServerWorldMatrix = mat;
            }
            VRage.Profiler.ProfilerShort.End();

            VRage.Profiler.ProfilerShort.Begin("Physics update");
            if (applyPhysics && entity.Physics != null)
            {
                if (entity.Physics.LinearVelocity != LinearVelocity)
                {
                    entity.Physics.LinearVelocity = LinearVelocity;
                }
                if (applyRotation && entity.Physics.AngularVelocity != AngularVelocity)
                {
                    entity.Physics.AngularVelocity = AngularVelocity;
                }
                var rb = entity.Physics.RigidBody;
                if (rb != null && rb.IsActive != Active)
                {
                    if (Active)
                    {
                        rb.Activate();
                    }
                    else
                    {
                        rb.Deactivate();
                    }
                }
            }
            VRage.Profiler.ProfilerShort.End();
        }
Example #16
0
        public bool Intersects(ref BoundingBoxD box)
        {
            Vector3D boxCenter     = (box.Max + box.Min) * 0.5;
            Vector3D boxHalfExtent = (box.Max - box.Min) * 0.5;

            MatrixD mb = MatrixD.CreateFromQuaternion(Orientation);

            mb.Translation = Center - boxCenter;

            return(ContainsRelativeBox(ref boxHalfExtent, ref HalfExtent, ref mb) != ContainmentType.Disjoint);
        }
Example #17
0
            } // GyroControl constructor

            // Public Methods --------------------------------------------------
            public double Align(IMyRemoteControl rc, List <IMyTerminalBlock> gyroList)
            {
                Vector3D rotAxis = new Vector3D(0, 0, 0);              // rotation axis
                double   angle = 0;                                    // rotation angle
                double   fdot = 0, udot = 0;                           // forward vector dot product result, up vector dot product result

                cM = rc.WorldMatrix;                                   // get rotation matrix from RC block
                cM = MatrixD.Transpose(cM);                            // rotate matrix into local co-ords

                if (reset)                                             // check if recently reset
                {
                    tM = MatrixD.CreateFromQuaternion(targetRotation); // get rotation matrix from saved rotation

                    if (reverse)                                       // If we want to maintain up vector, but reverse heading 180 degrees
                    {
                        tM.M11 *= -1;                                  // reverse x axis (right vector) before rotation
                        tM.M12 *= -1;
                        tM.M13 *= -1;

                        tM.M31 *= -1; // reverse z axis (forward vector) before rotation
                        tM.M32 *= -1;
                        tM.M33 *= -1;
                    } // if reverse

                    tM = MatrixD.Transpose(tM); // rotate matrix into local co-ords

                    reset = false; // we are now set, clear the reset flag
                } // if reset

                GetChangeInPose(cM.Forward, cM.Up, tM.Forward, tM.Up, out rotAxis, out angle); // get axis and angle of rotation

                fdot = Vector3D.Dot(cM.Forward, tM.Forward);                                   // forward vector dot product (cos(theta) of angle between vectors)
                udot = Vector3D.Dot(cM.Up, tM.Up);                                             // up vector dot product (cos(theta) of angle between vectors)

                if (fdot < rotAErr || udot < rotAErr)                                          // check dot products against error
                {
                    EnableOverride(gyroList, true);                                            //enable the gyros for override
                    TurnGyros(gyroList, rotAxis, angle);                                       // set the gyros to turn
                }
                else
                {
                    EnableOverride(gyroList, false); // disable gyro override
                }

                // return the smaller dot product
                if (fdot > udot)
                {
                    return(udot); // up vector dot product is less
                }
                else
                {
                    return(fdot); // forward vector dot product is less
                }
            } // Align method
        public ContainmentType Contains(ref BoundingBoxD box)
        {
            Quaternion quaternion;
            Vector3D   vectord = (Vector3D)((box.Max + box.Min) * 0.5);
            Vector3D   hB      = (Vector3D)((box.Max - box.Min) * 0.5);

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            MatrixD matrix = MatrixD.CreateFromQuaternion(quaternion);

            matrix.Translation = Vector3D.TransformNormal(vectord - this.Center, matrix);
            return(ContainsRelativeBox(ref this.HalfExtent, ref hB, ref matrix));
        }
        public ContainmentType Contains(ref MyOrientedBoundingBoxD other)
        {
            Quaternion quaternion;
            Quaternion quaternion2;

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            Quaternion.Multiply(ref quaternion, ref other.Orientation, out quaternion2);
            MatrixD mB = MatrixD.CreateFromQuaternion(quaternion2);

            mB.Translation = Vector3D.Transform(other.Center - this.Center, quaternion);
            return(ContainsRelativeBox(ref this.HalfExtent, ref other.HalfExtent, ref mB));
        }
        private static IMyEntity GetOverlappingEntity(MyOrientedBoundingBoxD obb, IMyEntity original = null, HashSet <long> entityIds = null)
        {
            BoundingBoxD localAABB            = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            MatrixD      localAABBOrientation = MatrixD.CreateFromQuaternion(obb.Orientation);

            localAABBOrientation.Translation = obb.Center;

            List <MyEntity> entities = new List <MyEntity>();

            MyGamePruningStructure.GetAllEntitiesInOBB(ref obb, entities);
            if (entities.Count > 0)
            {
                foreach (MyEntity entity in entities)
                {
                    IMyEntity e = entity;
                    if (e.Physics != null && e.Physics.Enabled)
                    {
                        if (e is IMyCubeGrid)
                        {
                            if ((entityIds == null || !entityIds.Contains(e.EntityId)) && HasBlocksInside((MyCubeGrid)e, ref obb))
                            {
                                return(e);
                            }
                        }
                        else if (e is MyVoxelBase)
                        {
                            if (IsCollidingWith((MyVoxelBase)e, localAABB, localAABBOrientation))
                            {
                                return(e);
                            }
                        }
                        else if (e is MySafeZone)
                        {
                            if (!IsAllowed((MySafeZone)e, obb, original))
                            {
                                return(e);
                            }
                        }
                        else
                        {
                            MyOrientedBoundingBoxD eObb;
                            GetOBB(e, out eObb);
                            if (eObb.Contains(ref obb) != ContainmentType.Disjoint)
                            {
                                return(e);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Example #21
0
        internal override unsafe void DebugDraw(ref MatrixD worldTranslation, Color color)
        {
            MatrixD xd2;
            MatrixD xd   = MatrixD.CreateTranslation(this.m_translation) * worldTranslation;
            float   num  = (this.m_primaryRadius + this.m_secondaryRadius) * 2f;
            float   num2 = this.m_secondaryRadius * 2f;

            MatrixD.CreateFromQuaternion(ref this.m_invRotation, out xd2);
            MatrixD *xdPtr1 = (MatrixD *)ref xd2;

            MatrixD.Transpose(ref (MatrixD) ref xdPtr1, out xd2);
            MyRenderProxy.DebugDrawCylinder((MatrixD.CreateScale((double)num, (double)num2, (double)num) * xd2) * xd, color.ToVector3(), 0.5f, true, false, false);
        }
        internal override void DebugDraw(ref Vector3D worldTranslation, Color color)
        {
            var     translation = MatrixD.CreateTranslation(worldTranslation + m_translation);
            var     primary     = (m_primaryRadius + m_secondaryRadius) * 2;
            var     secondary   = m_secondaryRadius * 2;
            var     scale       = MatrixD.CreateScale(primary, secondary, primary);
            MatrixD rotation;

            MatrixD.CreateFromQuaternion(ref m_invRotation, out rotation);
            MatrixD.Transpose(ref rotation, out rotation); // inverse
            var mat = scale * rotation * translation;

            VRageRender.MyRenderProxy.DebugDrawCylinder(mat, color.ToVector3(), 0.5f, true, false);
        }
        public CubicSphericalCurve(Vector3D center, MatrixD from, MatrixD to)
        {
            var tmp          = new CubicCurve(from, to);
            var avgSpherical = Vector3D.Normalize((from.Translation + to.Translation) / 2 - center);
            var quat         = QuaternionD.CreateFromTwoVectors(avgSpherical, new Vector3D(1, 0, 0));
            var m            = MatrixD.CreateFromQuaternion(quat);

            m       = MatrixD.CreateTranslation(-center) * m;
            _matrix = MatrixD.Invert(m);
            _curve  = new CubicCurve(SphericalExtensions.ToSpherical(Vector3D.Transform(tmp.P0, m)),
                                     SphericalExtensions.ToSpherical(Vector3D.Transform(tmp.P1, m)),
                                     SphericalExtensions.ToSpherical(Vector3D.Transform(tmp.P2, m)),
                                     SphericalExtensions.ToSpherical(Vector3D.Transform(tmp.P3, m)));
        }
        private static void OnCharacterInput(MySyncCharacter sync, ref CharacterInputMsg msg, MyNetworkClient sender)
        {
            sender.ClientFrameId     = msg.ClientFrameId;
            sync.CachedMovementState = msg;

            var matrix = MatrixD.CreateFromQuaternion(msg.Orientation);

            matrix.Translation      = msg.Position;
            sync.Entity.WorldMatrix = matrix;

            if (Sync.IsServer)
            {
                Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId);
            }
        }
Example #25
0
        // Determine if this box contains, intersects, or is disjoint from the given BoundingBox.
        public ContainmentType Contains(ref BoundingBox box)
        {
            Vector3D boxCenter     = (box.Max + box.Min) * 0.5f;
            Vector3D boxHalfExtent = (box.Max - box.Min) * 0.5f;

            // Build the 3x3 rotation matrix that defines the orientation of 'other' relative to this box
            Quaternion relOrient;

            Quaternion.Conjugate(ref Orientation, out relOrient);

            MatrixD relTransform = MatrixD.CreateFromQuaternion(relOrient);

            relTransform.Translation = Vector3D.TransformNormal(boxCenter - Center, relTransform);

            return(ContainsRelativeBox(ref HalfExtent, ref boxHalfExtent, ref relTransform));
        }
Example #26
0
        // Determine whether this box contains, intersects, or is disjoint from
        // the given other box.
        public ContainmentType Contains(ref MyOrientedBoundingBoxD other)
        {
            // Build the 3x3 rotation matrix that defines the orientation of 'other' relative to this box
            Quaternion invOrient;

            Quaternion.Conjugate(ref Orientation, out invOrient);
            Quaternion relOrient;

            Quaternion.Multiply(ref invOrient, ref other.Orientation, out relOrient);

            MatrixD relTransform = MatrixD.CreateFromQuaternion(relOrient);

            relTransform.Translation = Vector3D.Transform(other.Center - Center, invOrient);

            return(ContainsRelativeBox(ref HalfExtent, ref other.HalfExtent, ref relTransform));
        }
    // Copy/pasted/edited from basmissileguidance. Refactor?
    public void HandleRemoteCommand(ZACommons commons, EventDriver eventDriver, string argument)
    {
        var parts = argument.Split(';');

        switch (parts[0])
        {
        case "tupdate":
        {
            if (parts.Length != 12)
            {
                return;
            }
            var targetID = long.Parse(parts[1]);
            // Ignore if it's an update for another target
            if (targetID != TargetID)
            {
                return;
            }
            break;
        }

        default:
            return;
        }
        var targetPosition = new Vector3D();

        for (int i = 2; i < 5; i++)
        {
            targetPosition.SetDim(i - 2, double.Parse(parts[i]));
        }
        TargetVelocity = new Vector3D();
        for (int i = 5; i < 8; i++)
        {
            TargetVelocity.SetDim(i - 5, double.Parse(parts[i]));
        }
        var orientation = new QuaternionD();

        orientation.X = double.Parse(parts[8]);
        orientation.Y = double.Parse(parts[9]);
        orientation.Z = double.Parse(parts[10]);
        orientation.W = double.Parse(parts[11]);
        var targetOrientation = MatrixD.CreateFromQuaternion(orientation);

        // Re-derive aim point
        TargetAimPoint   = targetPosition + Vector3D.TransformNormal(TargetOffset, targetOrientation);
        LastTargetUpdate = eventDriver.TimeSinceStart;
    }
        public void GetCorners(Vector3D[] corners, int startIndex)
        {
            MatrixD  xd       = MatrixD.CreateFromQuaternion(this.Orientation);
            Vector3D vectord  = (Vector3D)(xd.Left * this.HalfExtent.X);
            Vector3D vectord2 = (Vector3D)(xd.Up * this.HalfExtent.Y);
            Vector3D vectord3 = (Vector3D)(xd.Backward * this.HalfExtent.Z);
            int      num      = startIndex;

            corners[num++] = ((this.Center - vectord) + vectord2) + vectord3;
            corners[num++] = ((this.Center + vectord) + vectord2) + vectord3;
            corners[num++] = ((this.Center + vectord) - vectord2) + vectord3;
            corners[num++] = ((this.Center - vectord) - vectord2) + vectord3;
            corners[num++] = ((this.Center - vectord) + vectord2) - vectord3;
            corners[num++] = ((this.Center + vectord) + vectord2) - vectord3;
            corners[num++] = ((this.Center + vectord) - vectord2) - vectord3;
            corners[num++] = ((this.Center - vectord) - vectord2) - vectord3;
        }
Example #29
0
        private Vector3D WorldPositionToLocalNavmeshPosition(Vector3D position, float heightIncrease)
        {
            MyOrientedBoundingBoxD?oBB = this.m_navmeshOBBs.GetOBB(position);

            if (oBB != null)
            {
                MyOrientedBoundingBoxD local1 = oBB.Value;
            }
            else
            {
                Vector3D meshCenter = this.m_meshCenter;
            }
            Vector3D v      = -Vector3D.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(this.m_meshCenter));
            MatrixD  matrix = MatrixD.CreateFromQuaternion(Quaternion.Inverse(Quaternion.CreateFromForwardUp((Vector3)Vector3D.CalculatePerpendicularVector(v), (Vector3)v)));

            return(Vector3D.Transform((position - this.m_meshCenter) + (heightIncrease * v), matrix));
        }
Example #30
0
        /*
         * // Return the 8 corner positions of this bounding box.
         * //
         * //     ZMax    ZMin
         * //    0----1  4----5
         * //    |    |  |    |
         * //    |    |  |    |
         * //    3----2  7----6
         * //
         * // The ordering of indices is a little strange to match what BoundingBox.GetCorners() does.
         * public Vector3[] GetCorners()
         * {
         *  throw new Exception("Don't use this method because it will generate garbage!");
         *  Vector3[] corners = new Vector3[CornerCount];
         *  GetCorners(corners, 0);
         *  return corners;
         * }*/

        // Return the 8 corner positions of this bounding box.
        //
        //     ZMax    ZMin
        //    0----1  4----5
        //    |    |  |    |
        //    |    |  |    |
        //    3----2  7----6
        //
        // The ordering of indices is a little strange to match what BoundingBox.GetCorners() does.
        public void GetCorners(Vector3D[] corners, int startIndex)
        {
            MatrixD  m  = MatrixD.CreateFromQuaternion(Orientation);
            Vector3D hX = m.Left * HalfExtent.X;
            Vector3D hY = m.Up * HalfExtent.Y;
            Vector3D hZ = m.Backward * HalfExtent.Z;

            int i = startIndex;

            corners[i++] = Center - hX + hY + hZ;
            corners[i++] = Center + hX + hY + hZ;
            corners[i++] = Center + hX - hY + hZ;
            corners[i++] = Center - hX - hY + hZ;
            corners[i++] = Center - hX + hY - hZ;
            corners[i++] = Center + hX + hY - hZ;
            corners[i++] = Center + hX - hY - hZ;
            corners[i++] = Center - hX - hY - hZ;
        }