示例#1
0
        public void Update(float updateStepTime)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyCamera-Update");
            Zoom.Update(updateStepTime);
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            Vector3 newCameraPosOffset = Vector3.Zero;

            // spring
            if (CameraSpring.Enabled)
            {
                CameraSpring.Update(updateStepTime, out newCameraPosOffset);
            }
            // shake
            if (CameraShake.ShakeEnabled)
            {
                Vector3 shakePos, shakeDir;
                CameraShake.UpdateShake(updateStepTime, out shakePos, out shakeDir);
                newCameraPosOffset += shakePos;
            }
            // apply
            if (newCameraPosOffset != Vector3.Zero)
            {
                Vector3D newCameraPosOffsetD = newCameraPosOffset;
                Vector3D newCameraPosOffsetRotatedD;
                Vector3D.Rotate(ref newCameraPosOffsetD, ref ViewMatrix, out newCameraPosOffsetRotatedD);
                ViewMatrix.Translation += newCameraPosOffsetRotatedD;
            }

            UpdatePropertiesInternal(ViewMatrix);
        }
示例#2
0
 public BindablePoint3DModel(VRageMath.Vector3D vector)
     : this()
 {
     X = vector.X;
     Y = vector.Y;
     Z = vector.Z;
 }
示例#3
0
        public static bool IsInhibited(VRageMath.Vector3D pos)
        {
            VRageMath.BoundingSphereD searchRange = new VRageMath.BoundingSphereD(pos, 1000000);
            List <IMyEntity>          entities    = MyAPIGateway.Entities.GetEntitiesInSphere(ref searchRange);

            foreach (var entity in entities)
            {
                if (entity is IMyFunctionalBlock && (entity as IMyFunctionalBlock).BlockDefinition.SubtypeId == "FTLInhibitor")
                {
                    var ent = entity as IMyFunctionalBlock;

                    // We found an inhibitor, check if has enough range
                    if (ent != null)
                    {
                        if (!ent.IsWorking || !ent.IsFunctional)
                        {
                            continue;
                        }

                        if ((ent.CubeGrid.GridIntegerToWorld(ent.Position) - pos).Length() <= (ent.GameLogic.GetAs <FTLInhibitor>().Range))
                        {
                            if (FTLAdmin.Configuration.Debug)
                            {
                                Logger.Instance.LogDebug(string.Format("Found inhibitor: {0}, at {1}, {2}, {3}", ent.DisplayNameText, ent.PositionComp.GetPosition().X, ent.PositionComp.GetPosition().Y, ent.PositionComp.GetPosition().Z));
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#4
0
        public void UpdateScreenSize(MyViewport currentScreenViewport)
        {
            Viewport = currentScreenViewport;

            PreviousPosition = Vector3D.Zero;
            BoundingFrustum  = new BoundingFrustumD(MatrixD.Identity);

            AspectRatio = Viewport.Width / Viewport.Height;
        }
 /// <summary>
 /// Determines which sector a vector points into.
 /// Biases towards top, front, and right (if they lie on the axis)
 /// </summary>
 /// <param name="vec"></param>
 /// <returns></returns>
 public static Sector ClassifyVector(VRageMath.Vector3D vec)
 {
     if (vec.Y >= 0.0f)
     {
         if (vec.X >= 0.0f)
         {
             if (vec.Z >= 0.0f)
             {
                 return(Sector.TOP_FRONT_RIGHT);
             }
             else
             {
                 return(Sector.TOP_FRONT_LEFT);
             }
         }
         else
         {
             if (vec.Z >= 0.0f)
             {
                 return(Sector.TOP_BACK_RIGHT);
             }
             else
             {
                 return(Sector.TOP_BACK_LEFT);
             }
         }
     }
     else
     {
         if (vec.X >= 0.0f)
         {
             if (vec.Z >= 0.0f)
             {
                 return(Sector.BOTTOM_FRONT_RIGHT);
             }
             else
             {
                 return(Sector.BOTTOM_FRONT_LEFT);
             }
         }
         else
         {
             if (vec.Z >= 0.0f)
             {
                 return(Sector.BOTTOM_BACK_RIGHT);
             }
             else
             {
                 return(Sector.BOTTOM_BACK_LEFT);
             }
         }
     }
 }
示例#6
0
        VRageMath.Vector3D Get3D_Center(List <Program.TerrainMap.Point3D> points)
        {
            if (points.Count > 0)
            {
                var lowSide  = new VRageMath.Vector3D(points.First().Position.X, points.First().Position.Y, points.First().Position.Z);
                var highSide = new VRageMath.Vector3D(points.First().Position.X, points.First().Position.Y, points.First().Position.Z);

                foreach (var point in points)
                {
                    if (point.Position.X < lowSide.X)
                    {
                        lowSide.X = point.Position.X;
                    }
                    else if (point.Position.X > highSide.X)
                    {
                        highSide.X = point.Position.X;
                    }

                    if (point.Position.Y < lowSide.Y)
                    {
                        lowSide.Y = point.Position.Y;
                    }
                    else if (point.Position.Y > highSide.Y)
                    {
                        highSide.Y = point.Position.Y;
                    }

                    if (point.Position.Z < lowSide.Z)
                    {
                        lowSide.Z = point.Position.Z;
                    }
                    else if (point.Position.Z > highSide.Z)
                    {
                        highSide.Z = point.Position.Z;
                    }
                }

                return((highSide - lowSide) / 2 + lowSide);
            }
            else
            {
                return(new VRageMath.Vector3D());
            }
        }
示例#7
0
        // Plot a course for jumping
        // This works around a game bug causing ships to be deleted if jumping to
        // a map cluster not connected to the source.
        public static HashSet <VRageMath.Vector3D> PlotJumpCourse(this IMyFunctionalBlock ftl)
        {
            var    ftld              = ftl.GetFTLData();
            var    tempList          = new HashSet <VRageMath.Vector3D>();
            var    destunit          = ftld.jumpDest - ftl.PositionComp.GetPosition();
            double remainingDistance = destunit.Length();

            destunit.Normalize();
            destunit = VRageMath.Vector3D.Negate(destunit);
            Logger.Instance.LogDebug(string.Format("Jump destination: {0:F0}, {1:F0}, {2:F0}", ftld.jumpDest.X, ftld.jumpDest.Y, ftld.jumpDest.Z));

            var clusterSize           = 10000; // VRageMath.Spatial.MyClusterTree.IdealClusterSize.Length() - 1000;
            var collisionOffsetAmount = 100;

            do
            {
                var offset = new VRageMath.Vector3D(destunit * remainingDistance);
                var pos    = ftld.jumpDest + offset;
                Logger.Instance.LogDebug(string.Format("Jump point: {0:F0}, {1:F0}, {2:F0}", pos.X, pos.Y, pos.Z));
                // Check make sure the position won't collide with anything
                var sphere = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                while (MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).Count > 0)
                {
                    pos               += (destunit * collisionOffsetAmount);
                    sphere             = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                    remainingDistance += collisionOffsetAmount;
                }
                tempList.Add(pos);
                remainingDistance -= clusterSize;
            } while (remainingDistance > clusterSize / 2);
            tempList.Add(ftld.jumpDest);

            //MyAPIGateway.Multiplayer.SendEntitiesCreated(obList.ToList());
            //return new HashSet<VRageMath.Vector3D>(tempList.Reverse());
            return(tempList);
        }
        public override void UpdateBeforeSimulation10()
        {
            if (FTLAdmin.Configuration.BlockStockJump && (Entity as IMyJumpDrive).Enabled)
            {
                try
                {
                    float distance         = (Entity as IMyJumpDrive).GetValueFloat("JumpDistance");
                    var   reference        = (Entity as IMyFunctionalBlock).GetShipReference();
                    VRageMath.Vector3D pos = reference.Translation;

                    var   smaxdist = (Entity as IMyJumpDrive).DetailedInfo.Split(' ')[(Entity as IMyJumpDrive).DetailedInfo.Split(' ').Length - 2];
                    float maxdist  = 0;
                    if (float.TryParse(smaxdist, out maxdist))
                    {
                        // Found formula in workshop script: 479442492
                        // per = (Dist - 5) * (100/(Max-5))
                        // dist = (per / (100/(max-5))) + 5
                        distance = (distance / (100 / (maxdist - 5))) + 5;
                    }

                    distance *= 1000;           // Distance from jump drive is in km, convert to m
                    pos      += (reference.Forward * distance);

                    if (FTLExtensions.IsInhibited(Entity.GetPosition()) || FTLExtensions.IsInhibited(pos))
                    {
                        (Entity as IMyJumpDrive).RequestEnable(false);
                        (Entity as IMyFunctionalBlock).ShowMessageToUsersInRange("Jump drive disabled, interference detected", 5000, true);
                    }
                }
                catch (Exception)
                {
                    // Ignore exceptions for now, they occur during load
                    //Logger.Instance.LogException(ex);
                }
            }
        }
示例#9
0
 /// <summary>
 /// Gets screen coordinates of 3d world pos in 0 - 1 distance where 1.0 is screen width(for X) or height(for Y).
 /// WARNING: Y is from bottom to top.
 /// </summary>
 /// <param name="worldPos">World position.</param>
 /// <returns>Screen coordinate in 0-1 distance.</returns>
 public Vector3D WorldToScreen(ref Vector3D worldPos)
 {
     return(Vector3D.Transform(worldPos, ViewProjectionMatrix));
 }
示例#10
0
 double IMyCamera.GetDistanceWithFOV(Vector3D position)
 {
     return(GetDistanceFromPoint(position));
 }
示例#11
0
        void Main()
        {
            // initialize
            var blocks = new List <IMyTerminalBlock>();

            if (counter == 0)
            {
                GridTerminalSystem.GetBlocksOfType <IMyShipController>(blocks, FilterShipController);

                if (blocks.Count == 0)
                {
                    throw new Exception("Did not find any cockpit.");
                }

                controller = blocks[0] as IMyShipController;
                debug.Append("use ").Append(controller.CustomName).Append(':').AppendLine();

                perpBlocks = Utils.FindPerpendicularTo(controller);

                ship       = new ShipController(controller);
                worldCoord = controller.GetPosition();
                debug.Append("POSITION = ").Append(worldCoord).AppendLine();

                Debug(debug.ToString());
                debug.Clear();
                counter++;
                return;
            }

            worldCoord = new VRageMath.Vector3D(0, 0, 0);

            bool orthogonal = perpBlocks.Count == 3;

            VRageMath.Matrix toWorld = orthogonal ? Utils.toWorld(GridTerminalSystem.Blocks) : Utils.toWorld(perpBlocks);

            blocks = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyThrust>(blocks);
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(blocks);

            debug.Append("worldCoord = ").Append(VRageMath.Vector3I.Round(worldCoord)).AppendLine();
            debug.Append("controller.GetPosition() = ").Append(VRageMath.Vector3I.Round(controller.GetPosition())).AppendLine();
            debug.Append("controller.Position = ").Append(controller.Position).AppendLine();

            debug.Append("transfrom controller.Position = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(controller.Position, toWorld))).AppendLine();
            debug.Append("transfrom controller.Position = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(controller.GetPosition(), VRageMath.Matrix.Invert(toWorld)))).AppendLine();

            VRageMath.Vector3 worldDir = worldCoord - controller.GetPosition();
            float             distance = worldDir.LengthSquared() > 0 ? worldDir.Normalize() : 0;

            debug.Append("distance = ").Append(distance).AppendLine();
            debug.Append("direction = ").Append(worldDir).AppendLine();

            VRageMath.Matrix worldController = new VRageMath.Matrix();
            controller.Orientation.GetMatrix(out worldController);
            worldController = worldController * toWorld;
            debug.Append("worldController = ").AppendLine();
            debug.Append(worldController.Right).AppendLine();
            debug.Append(worldController.Up).AppendLine();
            debug.Append(worldController.Backward).AppendLine();
            debug.Append(worldController.Translation).AppendLine();
            debug.Append("origin worldController = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(new VRageMath.Vector3(), worldController))).AppendLine();
            //VRageMath.Vector3 n = orthogonal ? worldController.Right : worldController.Up.Cross(worldController.Backward);
            //VRageMath.Vector3 projDir = worldDir - worldDir.Dot(n) / n.Dot(n) * n;
            //if (projDir.LengthSquared() > 0)
            //    projDir.Normalize();

            //VRageMath.Vector3 eY = worldController.Up;
            //eY.Normalize();
            //VRageMath.Vector3 eZ = worldController.Backward;
            //eZ.Normalize();

            //float cosinePhiY = eY.Dot(projDir);
            //float cosinePhiZ = eZ.Dot(projDir);

            //float pitch = (float)(cosinePhiY > 0 ? -Math.Acos(cosinePhiZ) : Math.Acos(cosinePhiZ));
            ////VRageMath.Matrix.AlignRotationToAxes();
            //debug.Append("pitch = ").Append(pitch).AppendLine();

            debug.Append("worldController.IsRotation() = ").Append(worldController.IsRotation());
            VRageMath.Matrix  toAlign = VRageMath.Matrix.CreateFromDir(worldDir, worldController.Up);
            VRageMath.Matrix  align   = VRageMath.Matrix.AlignRotationToAxes(ref toAlign, ref worldController);
            VRageMath.Vector3 xyz     = new VRageMath.Vector3();
            VRageMath.Matrix.GetEulerAnglesXYZ(ref align, out xyz);
            xyz = 0.1f * xyz;

            debug.Append(xyz).AppendLine();
            ship.UpdateBlocks(blocks);
            ship.Stop();
            ship.Rotate(Identity.Left, xyz.GetDim(0));
            ship.Rotate(Identity.Down, xyz.GetDim(1));
            ship.Rotate(Identity.Forward, xyz.GetDim(2));

            Debug(debug.ToString());
            debug.Clear();
        }
 void IMyEntity.SetPosition(VRageMath.Vector3D pos)
 {
     PositionComp.SetPosition(pos);
 }
示例#13
0
 bool IMyEntities.IsRaycastBlocked(VRageMath.Vector3D pos, VRageMath.Vector3D target)
 {
     return(MyEntities.IsRaycastBlocked(pos, target));
 }
示例#14
0
 VRageMath.Vector3D?IMyEntities.FindFreePlace(VRageMath.Vector3D basePos, float radius, int maxTestCount, int testsPerDistance, float stepSize)
 {
     return(MyEntities.FindFreePlace(basePos, radius, maxTestCount, testsPerDistance, stepSize));
 }
示例#15
0
 void IMySlimBlock.ComputeScaledCenter(out VRageMath.Vector3D scaledCenter)
 {
     ComputeScaledCenter(out scaledCenter);
 }
示例#16
0
 double IMyCamera.GetDistanceWithFOV(Vector3D position)
 {
     return GetDistanceFromPoint(position);
 }
示例#17
0
 Vector3D IMyCamera.WorldToScreen(ref Vector3D worldPos)
 {
     return Vector3D.Transform(worldPos, ViewProjectionMatrix);
 }
示例#18
0
 /// <summary>
 /// Gets screen coordinates of 3d world pos in 0 - 1 distance where 1.0 is screen width(for X) or height(for Y).
 /// WARNING: Y is from bottom to top.
 /// </summary>
 /// <param name="worldPos">World position.</param>
 /// <returns>Screen coordinate in 0-1 distance.</returns>
 public Vector3D WorldToScreen(ref Vector3D worldPos)
 {
     return Vector3D.Transform(worldPos, ViewProjectionMatrix);
 }
示例#19
0
 public double GetDistanceFromPoint(Vector3D position)
 {
     return Vector3D.Distance(this.Position, position);
 }
示例#20
0
 public void SetViewMatrix(MatrixD newViewMatrix)
 {
     PreviousPosition = Position;
     UpdatePropertiesInternal(newViewMatrix);
 }
示例#21
0
        public void UpdateScreenSize(MyViewport currentScreenViewport)
        {
            Viewport = currentScreenViewport; 

            PreviousPosition = Vector3D.Zero;
            BoundingFrustum = new BoundingFrustumD(MatrixD.Identity);

            AspectRatio = Viewport.Width / Viewport.Height;
        }
示例#22
0
 public double GetDistanceFromPoint(Vector3D position)
 {
     return(Vector3D.Distance(this.Position, position));
 }
示例#23
0
 public void SetViewMatrix(MatrixD newViewMatrix)
 {
     PreviousPosition = Position;
     UpdatePropertiesInternal(newViewMatrix);
 }
示例#24
0
        // This it to spawn small prefabs between the source and destination
        // This works around a game bug causing ships to be deleted if jumping to
        // a map cluster not connected to the source.
        public static HashSet <IMyEntity> SpawnTrail(this IMyFunctionalBlock ftl)
        {
            string prefabName = "NewStationPrefab";
            var    ftld       = ftl.GetFTLData();

            //looks for the definition of the ship
            var prefab = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);

            if (prefab != null && prefab.CubeGrids == null)
            {
                // If cubegrids is null, reload definitions and try again
                MyDefinitionManager.Static.ReloadPrefabsFromFile(prefab.PrefabPath);
                prefab = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);
            }

            if (prefab == null || prefab.CubeGrids == null || prefab.CubeGrids.Length == 0)
            {
                MyAPIGateway.Utilities.ShowNotification("Error loading prefab: " + prefabName, 7500);
                return(null);
            }

            //get the entity containing the ship
            var grid = prefab.CubeGrids[0];

            if (grid == null)
            {
                MyAPIGateway.Utilities.ShowNotification("Error loading prefab entity: " + prefabName, 7500);
                return(null);
            }
            //entity.CreatePhysics = false;

            var    tempList          = new HashSet <IMyEntity>();
            var    obList            = new HashSet <MyObjectBuilder_EntityBase>();
            var    destunit          = ftld.jumpDest - ftl.PositionComp.GetPosition();
            double remainingDistance = destunit.Length();

            destunit.Normalize();
            destunit = VRageMath.Vector3D.Negate(destunit);

            var clusterSize          = 10000; // VRageMath.Spatial.MyClusterTree.IdealClusterSize.Length() - 10;
            var collisionCheckAmount = 100;

            do
            {
                var offset = new VRageMath.Vector3D(destunit * remainingDistance);
                var pos    = new MyPositionAndOrientation(ftld.jumpDest + offset, ftl.WorldMatrix.Forward, ftl.WorldMatrix.Up);

                Logger.Instance.LogDebug(string.Format("Jump point: {0:F0}, {1:F0}, {2:F0}", pos.Position.X, pos.Position.Y, pos.Position.Z));

                // Check make sure the position won't collide with anything
                var sphere = new VRageMath.BoundingSphereD(pos.Position, collisionCheckAmount);
                while (MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).Count > 0)
                {
                    pos.Position      += (destunit * collisionCheckAmount);
                    sphere             = new VRageMath.BoundingSphereD(pos.Position, collisionCheckAmount);
                    remainingDistance += collisionCheckAmount;
                }

                grid.PositionAndOrientation = pos;

                //important ! every entity has a unique ID. If you try to add your prefab twice, they would have the same ID so that wont work
                //so you use RemapObjectBuilder to generate new IDs for the ship and other entities onboard.
                MyAPIGateway.Entities.RemapObjectBuilder(grid);

                //Create the object and add it to the world.
                var entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(grid);
                entity.Visible = false;
                tempList.Add(entity);
                obList.Add(grid);
                remainingDistance -= clusterSize;
            } while (remainingDistance > clusterSize / 2);
            return(tempList);
        }
示例#25
0
 void IMySlimBlock.ComputeWorldCenter(out VRageMath.Vector3D worldCenter)
 {
     ComputeWorldCenter(out worldCenter);
 }
示例#26
0
 bool IMyVoxelMap.DoOverlapSphereTest(float sphereRadius, VRageMath.Vector3D spherePos)
 {
     return(DoOverlapSphereTest(sphereRadius, spherePos));
 }
示例#27
0
 bool IMyEntities.IsInsideWorld(VRageMath.Vector3D pos)
 {
     return(MyEntities.IsInsideWorld(pos));
 }
示例#28
0
        public static bool MyProjectileDoDamage(float damage, ref VRageMath.Vector3D hitPosition, ref IMyEntity damagedEntity)
        {
            var cubeGrid = damagedEntity as IMyCubeGrid;

            if (cubeGrid == null)
            {
                return(true);
            }
            try
            {
                damage *= DamageRate;
                List <IMySlimBlock> shieldblocks = new List <IMySlimBlock>();
                cubeGrid.GetBlocks(shieldblocks, (block) =>
                {
                    if (block.FatBlock == null)
                    {
                        return(false);
                    }
                    return(block.FatBlock.BlockDefinition.SubtypeId == ShipShieldSubtypeId);
                });
                bool isdef = false;
                foreach (var shielditem in shieldblocks)
                {
                    if (shielditem.FatBlock.IsFunctional && shielditem.FatBlock.IsWorking)
                    {
                        // hitPosition = shielditem.FatBlock.WorldMatrix.Translation;
                        SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity cube = null;
                        SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity BatteryBlockEntity = null;

                        BatteryBlockEntity = (SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity)SEModAPIInternal.API.Common.GameEntityManager.GetEntity(shielditem.FatBlock.EntityId);

                        var BatteryBlock = (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock();
                        if (BatteryBlockEntity == null)
                        {
                            cube = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity((Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeGrid)cubeGrid.GetObjectBuilder(), cubeGrid);
                            BatteryBlockEntity = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity(cube, (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(), shielditem);
                        }


                        if (BatteryBlock.CurrentStoredPower > damage)
                        {
                            BatteryBlockEntity.CurrentStoredPower = BatteryBlock.CurrentStoredPower - damage;
                            isdef = true;
                            break;
                        }
                        else
                        {
                            if (BatteryBlock.CurrentStoredPower > 0)
                            {
                                BatteryBlockEntity.CurrentStoredPower = 0;
                                isdef = true;
                                break;
                            }
                        }
                    }
                }

                if (isdef == true)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                // Logging.WriteLineAndConsole(e.ToString());
            }



            //Logging.WriteLineAndConsole("DoDamage");
            return(true);
        }
示例#29
0
        void Main()
        {
            // initialize
            var blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyShipController>(blocks, FilterShipController);

            if (blocks.Count == 0)
            {
                throw new Exception("Did not find any cockpit.");
            }

            controller = blocks[0] as IMyShipController;
            debug.Append("use ").Append(controller.CustomName).Append(':').AppendLine();

            perpBlocks = Utils.FindPerpendicularTo(controller);

            for (int i = 0; i < perpBlocks.Count; ++i)
            {
                var block = perpBlocks[i];
                debug.Append(block.Position).AppendLine();
            }

            VRageMath.Vector3 cur  = perpBlocks[1].Position - perpBlocks[0].Position;
            VRageMath.Vector3 next = perpBlocks[2].Position - perpBlocks[0].Position;
            debug.Append(VRageMath.Vector3.ArePerpendicular(ref cur, ref next)).AppendLine();

            worldCoord = new VRageMath.Vector3D(0, 0, 0);

            bool orthogonal = perpBlocks.Count == 3;

            VRageMath.Matrix  toWorld = orthogonal ? Utils.toWorld(perpBlocks) : Utils.toWorld(GridTerminalSystem.Blocks);
            VRageMath.Vector3 r       = toWorld.Right;
            VRageMath.Vector3 u       = toWorld.Up;
            VRageMath.Vector3 b       = toWorld.Backward;

            debug.Append(r.Dot(u)).AppendLine();
            debug.Append(u.Dot(b)).AppendLine();
            debug.Append(b.Dot(r)).AppendLine();

            debug.Append(VRageMath.Vector3.ArePerpendicular(ref r, ref u)).AppendLine();
            debug.Append(VRageMath.Vector3.ArePerpendicular(ref u, ref b)).AppendLine();
            debug.Append(VRageMath.Vector3.ArePerpendicular(ref b, ref r)).AppendLine();

            blocks = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyThrust>(blocks);
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(blocks);

            debug.Append("worldCoord = ").Append(VRageMath.Vector3I.Round(worldCoord)).AppendLine();
            debug.Append("controller.GetPosition() = ").Append(VRageMath.Vector3I.Round(controller.GetPosition())).AppendLine();
            debug.Append("controller.Position = ").Append(controller.Position).AppendLine();

            debug.Append("transfrom controller.Position = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(controller.Position, toWorld))).AppendLine();
            debug.Append("transfrom controller.GetPosition() = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(controller.GetPosition(), VRageMath.Matrix.Invert(toWorld)))).AppendLine();
            debug.Append("transfrom zero = ").Append(VRageMath.Vector3I.Round(VRageMath.Vector3.Transform(worldCoord, VRageMath.Matrix.Invert(toWorld)))).AppendLine();

            VRageMath.Vector3 worldDir = worldCoord - controller.GetPosition();
            float             distance = worldDir.LengthSquared() > 0 ? worldDir.Normalize() : 0;

            debug.Append("distance = ").Append(distance).AppendLine();
            debug.Append("direction = ").Append(worldDir).AppendLine();

            VRageMath.Matrix worldController = new VRageMath.Matrix();
            controller.Orientation.GetMatrix(out worldController);
            worldController = worldController * VRageMath.Matrix.CreateTranslation(controller.Position) * toWorld;

            debug.Append("worldController = ").AppendLine();
            debug.Append(worldController.Right).AppendLine();
            debug.Append(worldController.Up).AppendLine();
            debug.Append(worldController.Backward).AppendLine();
            debug.Append(worldController.Translation).AppendLine();

            VRageMath.Vector3 a        = worldController.Forward;
            VRageMath.Matrix  rotation = Utils.CalculateRotation(ref worldDir, ref a);

            debug.Append((double)Math.Abs(rotation.Right.Dot(rotation.Up))).AppendLine();
            debug.Append((double)Math.Abs(rotation.Right.Dot(rotation.Backward))).AppendLine();
            debug.Append((double)Math.Abs(rotation.Up.Dot(rotation.Backward))).AppendLine();

            debug.Append("rotation transl+persp = ").Append(rotation.HasNoTranslationOrPerspective()).AppendLine();
            debug.Append("rotation rotation = ").Append(rotation.IsRotation()).AppendLine();
            debug.Append(rotation.Right).AppendLine();
            debug.Append(rotation.Up).AppendLine();
            debug.Append(rotation.Backward).AppendLine();
            debug.Append(rotation.Translation).AppendLine();

            VRageMath.Vector3 xyz = new VRageMath.Vector3();
            VRageMath.Matrix.GetEulerAnglesXYZ(ref rotation, out xyz);

            debug.Append("X = ").Append(xyz.GetDim(0)).AppendLine();
            debug.Append("Y = ").Append(xyz.GetDim(1)).AppendLine();
            debug.Append("Z = ").Append(xyz.GetDim(2)).AppendLine();

            Debug(debug.ToString());
            debug.Clear();
        }
 public void RemoveFromByteStream(VRage.ByteStream stream)
 {
     EntityId = stream.getLong();
     Type = (EntityType)stream.getUShort();
     Position = stream.getVector3D();
     Transparent = stream.getBoolean();
     IsStatic = stream.getBoolean();
     Revealability = (EntityRevealability)stream.getUShort();
     Concealability = (EntityConcealability)stream.getUShort();
     Status = (ConcealStatus)stream.getUShort();
 }
示例#31
0
 public VRageMath.Vector3D getCurrentPosition()
 {
     currentPosition = regulator.GetPosition();
     return(currentPosition);
 }
        public void LoadFromEntity(IMyEntity entity)
        {
            EntityId = entity.EntityId;
            Position = entity.GetPosition();
            Transparent = entity.Transparent;

            // DO the timer-taker updates later when we have time:
            //RefreshRevealability();
            //RefreshConcealability();
        }
 public bool GetBotSpawnPosition(string behaviorType, out VRageMath.Vector3D spawnPosition)
 {
     throw new NotImplementedException();
 }
示例#34
0
 Vector3D IMyCamera.WorldToScreen(ref Vector3D worldPos)
 {
     return(Vector3D.Transform(worldPos, ViewProjectionMatrix));
 }
示例#35
0
 VRageMath.Vector3I IMyVoxelMap.GetVoxelCoordinateFromMeters(VRageMath.Vector3D pos)
 {
     VRageMath.Vector3I result;
     MyVoxelCoordSystems.WorldPositionToVoxelCoord(this.PositionLeftBottomCorner, ref pos, out result);
     return(result);
 }
示例#36
0
 public double GetValue(ref VRageMath.Vector3D position)
 {
     return(noise.GetValue(position.X, position.Y, position.Z));
 }