Esempio n. 1
0
        private void CreateConstraint(MyCubeGrid other, MyShipMergeBlock block)
        {
            var data = new HkPrismaticConstraintData();

            data.MaximumLinearLimit = 0;
            data.MinimumLinearLimit = 0;
            var posA      = ConstraintPositionInGridSpace();
            var posB      = block.ConstraintPositionInGridSpace();
            var axisA     = PositionComp.LocalMatrix.GetDirectionVector(m_forward);
            var axisAPerp = PositionComp.LocalMatrix.GetDirectionVector(m_right);
            var axisB     = -block.PositionComp.LocalMatrix.GetDirectionVector(m_forward);

            Base6Directions.Direction thisRightForOther = block.WorldMatrix.GetClosestDirection(WorldMatrix.GetDirectionVector(m_right));
            Base6Directions.Direction otherRight        = WorldMatrix.GetClosestDirection(block.WorldMatrix.GetDirectionVector(block.m_right));

            var axisBPerp = block.PositionComp.LocalMatrix.GetDirectionVector(thisRightForOther);

            data.SetInBodySpace(posA, posB, axisA, axisB, axisAPerp, axisBPerp, CubeGrid.Physics, other.Physics);
            var data2 = new HkMalleableConstraintData();

            data2.SetData(data);
            data.ClearHandle();
            data           = null;
            data2.Strength = 0.00001f;

            var constraint = new HkConstraint(CubeGrid.Physics.RigidBody, other.Physics.RigidBody, data2);

            AddConstraint(constraint);

            SetConstraint(block, constraint, otherRight);
            m_other.SetConstraint(this, constraint, thisRightForOther);
        }
Esempio n. 2
0
        public SceneManager(Game game)
            : base(game)
        {
            this.game = game;

            floorEffect = Game.Content.Load <Effect>("effects");
            player      = Game.Content.Load <PlayerData>("Configuration/PlayerData");
            tankmode    = Game.Content.Load <Mode[]>(@"Configuration/TankMode");
            world       = Game.Content.Load <WorldMatrix>("Configuration/WorldData");
            tankStatus  = new TankStatusMode(tankmode[0]);


            city             = new City();
            background       = new BackGround(game);
            inputHandler     = new InputHandler();
            textHandler      = new TextHandler();
            levelHander      = new GameLevelHandler(Game.Content);
            explosionHandler = new ExplosionHandler(game);
            gameMenu         = new GameMenuScreen(game, levelHander);
            worldData        = new GameWorldData(world);
            camera           = new FirstPersonCamera(game);
            background.InitializeModel(floorEffect);

            camera.prepareCamera();
            camera.setWeapon(Game.Content.Load <Model>(@"Models\weapon"));
        }
Esempio n. 3
0
        public GameMap(GameModelDTO data)
            : base(data)
        {
            Camera = new GameCamera();

            worldMatrix = new WorldMatrix(this);
        }
        public override void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            base.Save(saveContext);

            utility.Write(Unknown1);
            utility.Write(BranchVisible);

            // FIXME according to SPICA this is an arbitrary list of child "GfxObjects" (AKA ChunkDICTObject in my world)
            // Dunno if it's freeform (unlikely) or has context to specific types (in which case we'll need some clever implementation)
            utility.Write(ChildCount);  // ???
            utility.Write(ChildOffset); // Offset to pointer list (?) of children I assume
            if (ChildCount != 0 && ChildOffset != 0)
            {
                throw new NotImplementedException("Child objects not implemented");
            }

            saveContext.WriteDICTPointerPlaceholder(AnimGroup);

            TransformScale.Write(utility);
            TransformRotate.Write(utility);
            TransformTranslate.Write(utility);
            LocalMatrix.Write(utility);
            WorldMatrix.Write(utility);
        }
Esempio n. 5
0
        private void CalculateMergeData(ref MergeData data)
        {
            var   mergeBlockDefinition = this.BlockDefinition as MyMergeBlockDefinition;
            float maxStrength          = mergeBlockDefinition != null ? mergeBlockDefinition.Strength : 0.1f;

            data.Distance = (float)(WorldMatrix.Translation - m_other.WorldMatrix.Translation).Length() - CubeGrid.GridSize;

            data.StrengthFactor = (float)Math.Exp(-data.Distance / CubeGrid.GridSize);
            // Debug.Assert(x <= 1.0f); // This is not so important, but testers kept reporting it, so let's leave it commented out :-)
            float strength = MathHelper.Lerp(0.0f, maxStrength * (CubeGrid.GridSizeEnum == MyCubeSize.Large ? 0.005f : 0.1f), data.StrengthFactor); // 0.005 for large grid, 0.1 for small grid!?

            Vector3 thisVelocity  = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition());
            Vector3 otherVelocity = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition());

            data.RelativeVelocity = otherVelocity - thisVelocity;
            float velocityFactor = 1.0f;

            // The quicker the ships move towards each other, the weaker the constraint strength
            float rvLength = data.RelativeVelocity.Length();

            velocityFactor          = Math.Max(3.6f / (rvLength > 0.1f ? rvLength : 0.1f), 1.0f);
            data.ConstraintStrength = strength / velocityFactor;

            Vector3 toOther = m_other.PositionComp.GetPosition() - PositionComp.GetPosition();
            Vector3 forward = WorldMatrix.GetDirectionVector(m_forward);

            data.Distance   = (toOther).Length();
            data.PositionOk = data.Distance < CubeGrid.GridSize + 0.17f; // 17 cm is tested working value. 15 cm was too few

            data.AxisDelta = (float)(forward + m_other.WorldMatrix.GetDirectionVector(m_forward)).Length();
            data.AxisOk    = data.AxisDelta < 0.1f;

            data.RotationDelta = (float)(WorldMatrix.GetDirectionVector(m_right) - m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight)).Length();
            data.RotationOk    = data.RotationDelta < 0.08f;
        }
 protected override void Arrange()
 {
     _rndMock = new Mock<IRnd>();
     _rndMock.Setup(r => r.NextX()).Returns(-50);
     _rndMock.Setup(r => r.NextY()).Returns(-50);
     _worldMatrix = new WorldMatrix();
     _worldMatrix.Notify(new GameTime(new DateTime(2014, 2, 23, 20, 0, 0, 0), 100));
     _monster = new LargeMonster(_worldMatrix, _rndMock.Object);
     _worldMatrix.Add(_oldLocation, _monster);
 }
Esempio n. 7
0
 public GameWorldData(WorldMatrix matrix)
 {
     this.boundryLeft         = matrix.boundryLeft;
     this.boundryRight        = matrix.boundryRight;
     this.boundryNear         = matrix.boundryNear;
     this.boundryFar          = matrix.boundryFar;
     this.FLYING_OUT_ZONE     = matrix.FLYING_OUT_ZONE;
     this.PLAYER_BULLET_SPEED = matrix.PLAYER_BULLET_SPEED;
     this.OCTREE_WORLD_CENTER = new Vector3(matrix.OCTREE_WORLD_CENTER_X, 0, matrix.OCTREE_WORLD_CENTER_Z);
     this.OCTREE_WORLD_SIZE   = matrix.OCTREE_WORLD_SIZE;
 }
 protected override void Arrange()
 {
     _rndMock = new Mock<IRnd>();
     _rndMock.Setup(r => r.NextX()).Returns(50);
     _rndMock.Setup(r => r.NextY()).Returns(50);
     _worldMatrix = new WorldMatrix();
     _worldMatrix.Notify(new GameTime(new DateTime(2014, 2, 23, 20, 0, 0, 0), 100));
     _monster = new Monster1x1(_worldMatrix, _rndMock.Object);
     _worldMatrix.Add(_oldLocation, _monster);
     var locationOfMonster = _worldMatrix.GetLocationOf(_monster);
     Assert.IsNotNull(locationOfMonster);
     _oldDistance = Calculator.CalculateDistance(locationOfMonster.Value, _monster.NextDestination);
 }
        protected override void Arrange()
        {
            _rndMock = new Mock<IRnd>();
            _rndMock.Setup(r => r.NextX()).Returns(0);
            _rndMock.Setup(r => r.NextY()).Returns(0);
            _worldMatrix = new WorldMatrix();
            _worldMatrix.Notify(new GameTime(new DateTime(2014, 2, 23, 20, 0, 0, 0), 100));

            _monster1 = new Monster1x1(_worldMatrix, _rndMock.Object);
            _monster2 = new Monster1x1(_worldMatrix, _rndMock.Object);
            _worldMatrix.Add(_oldLocation1, _monster1);
            _worldMatrix.Add(_oldLocation2, _monster2);

            //we need a first notify in order to have a baseline
            _worldMatrix.Notify(new GameTime(new DateTime(2014, 2, 23, 20, 0, 0, 100), 100));
        }
Esempio n. 10
0
        public void OnCameraUpdate(object sender, CameraEventArgs e)
        {
            scale = ((Camera)sender).CreateScale(WorldMatrix.ExtractTranslation(), 0.5f, PixelSize);

            Model.AssignUniform("WorldMatrixUniform", WorldMatrix);

            var shape = new SphereShape(scale * 0.15f);

            _rightCollisionObject.CollisionShape   = shape;
            _upCollisionObject.CollisionShape      = shape;
            _forwardCollisionObject.CollisionShape = shape;

            var collisionMatrix = WorldMatrix.ClearScale();

            _rightCollisionObject.WorldTransform   = Matrix4.CreateTranslation(Vector3.UnitX * scale) * collisionMatrix;
            _upCollisionObject.WorldTransform      = Matrix4.CreateTranslation(Vector3.UnitY * scale) * collisionMatrix;
            _forwardCollisionObject.WorldTransform = Matrix4.CreateTranslation(Vector3.UnitZ * scale) *
                                                     collisionMatrix;
        }
Esempio n. 11
0
 public FastMonster(WorldMatrix worldMatrix, IRnd rnd)
     : base(worldMatrix, rnd)
 {
 }
Esempio n. 12
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking || !PowerReceiver.IsPowered)
            {
                return;
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                PowerReceiver.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetAllTopMostEntitiesInBox <MyEntity>(ref boundingBox, m_potentialPenetrations);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            if (IsActive)
            {
                bool empty = true;
                foreach (var entity in m_potentialPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        if (entity.Physics == null || !entity.Physics.Enabled)
                        {
                            continue;
                        }

                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;

                        if (entity.Physics.RigidBody != null)
                        {
                            shape2 = entity.Physics.RigidBody.GetShape();

                            var worldMatrix = entity.WorldMatrix;
                            rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                            posDiff   = entity.PositionComp.GetPosition() - position1;
                            if (entity is MyVoxelMap)
                            {
                                var voxel = entity as MyVoxelMap;
                                posDiff -= voxel.Storage.Size / 2;
                            }
                        }
                        else if (entity.Physics.CharacterProxy != null)
                        {
                            shape2 = entity.Physics.CharacterProxy.GetShape();
                            var worldMatrix = entity.WorldMatrix;
                            rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                            posDiff   = entity.PositionComp.GetPosition() - position1;
                        }
                        else
                        {
                            continue;
                        }

                        if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            empty = false;
                            break;
                        }
                    }
                }

                if (empty)
                {
                    IsActive = false;
                }
            }
            else
            {
                foreach (var entity in m_potentialPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        if (entity.Physics == null || !entity.Physics.Enabled)
                        {
                            continue;
                        }

                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;

                        if (entity.Physics.RigidBody != null)
                        {
                            shape2 = entity.Physics.RigidBody.GetShape();

                            var worldMatrix = entity.WorldMatrix;
                            rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                            posDiff   = entity.PositionComp.GetPosition() - position1;
                            if (entity is MyVoxelMap)
                            {
                                var voxel = entity as MyVoxelMap;
                                posDiff -= voxel.Storage.Size / 2;
                            }
                        }
                        else if (entity.Physics.CharacterProxy != null)
                        {
                            shape2 = entity.Physics.CharacterProxy.GetShape();
                            var worldMatrix = entity.WorldMatrix;
                            rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);
                            posDiff   = entity.PositionComp.GetPosition() - position1;
                        }
                        else
                        {
                            continue;
                        }

                        if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            IsActive           = true;
                            break;
                        }
                    }
                }
            }
            m_potentialPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Esempio n. 13
0
 void Awake()
 {
     m_GameManager = GameObject.Find("Services").GetComponentInChildren<GameManager>();
     m_WorldMatrix = m_GameManager.Matrix;
     m_InstanciationTime = Time.time;
 }
Esempio n. 14
0
 public GoodGuy(WorldMatrix worldMatrix)
 {
     _worldMatrix = worldMatrix;
 }
Esempio n. 15
0
 private Vector3 GetMergeNormalWorld()
 {
     return(WorldMatrix.GetDirectionVector(m_forward));
 }
 protected override void Arrange()
 {
     _worldMatrix = new WorldMatrix();
     _theMonster = new MediumSizedMonster(_worldMatrix);
 }
Esempio n. 17
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (SafeConstraint != null)
            {
                if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_CONNECTORS_AND_MERGE_BLOCKS && CustomName.ToString() == "DEBUG")
                {
                    DebugDrawInfo(new Vector2(0.0f, 0.0f));
                    m_other.DebugDrawInfo(new Vector2(0.0f, 120.0f));

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_right) * 10.0f, Color.Red, Color.Red, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight) * 10.0f, Color.Red, Color.Red, false);

                    MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_otherRight) * 5.0f, Color.Yellow, Color.Yellow, false);
                    MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_right) * 5.0f, Color.Yellow, Color.Yellow, false);
                }

                Vector3 thisVelocity     = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition());
                Vector3 otherVelocity    = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition());
                Vector3 relativeVelocity = otherVelocity - thisVelocity;

                // Damping to avoid too quick approach
                if (relativeVelocity.Length() > 0.5f)
                {
                    CubeGrid.Physics.LinearVelocity         += relativeVelocity * 0.05f;
                    m_other.CubeGrid.Physics.LinearVelocity -= relativeVelocity * 0.05f;
                }
            }
        }
Esempio n. 18
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking)
            {
                return;
            }

            if (!ResourceSink.IsPowered)
            {
                if (ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, BlockDefinition.RequiredPowerInput))
                {
                    float origInput = ResourceSink.RequiredInput;
                    ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, 0);
                    ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, origInput);
                }
                else
                {
                    return;
                }
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).TransformFast(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            bool empty = true;

            foreach (var entity in m_potentialPenetrations)
            {
                if (entity is MyVoxelBase)
                {
                    //voxels are handled in different loop (becaose of planets)
                    continue;
                }
                if (ShouldDetect(entity))
                {
                    Quaternion rotation2;
                    Vector3    posDiff;
                    HkShape?   shape2;
                    if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                    {
                        if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            empty = false;
                            break;
                        }
                    }
                }
            }

            if (DetectAsteroids)
            {
                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    var voxel = entity as MyVoxelPhysics;
                    if (voxel != null)
                    {
                        Vector3D localPositionMin, localPositionMax;

                        MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin);
                        MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax);
                        var aabb = new BoundingBox(localPositionMin, localPositionMax);
                        aabb.Translate(voxel.StorageMin);
                        if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint)
                        {
                            LastDetectedEntity = voxel;
                            empty = false;
                            break;
                        }
                    }
                    else
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }
            }
            IsActive = !empty;
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Esempio n. 19
0
        public override void FixConnections()
        {
            var rootEntity = GetRootEntity();

            if (rootEntity != null)
            {
                foreach (var triangle in Triangles)
                {
                    if (triangle.AttachedIndices == null)
                    {
                        continue;
                    }
                    for (var i = 0; i < 3; i++)
                    {
                        var attachedIndex = triangle.AttachedIndices[i];
                        if (attachedIndex != uint.MaxValue)
                        {
                            foreach (ModelEntity subModel in rootEntity.ChildEntities)
                            {
                                if (subModel == this)
                                {
                                    continue;
                                }
                                foreach (var subTriangle in subModel.Triangles)
                                {
                                    for (var j = 0; j < subTriangle.Vertices.Length; j++)
                                    {
                                        if (subTriangle.AttachableIndices[j] == attachedIndex)
                                        {
                                            var newVertex = Vector3.TransformPosition(subTriangle.Vertices[j], subModel.WorldMatrix);
                                            newVertex            = Vector3.TransformPosition(newVertex, WorldMatrix.Inverted());
                                            triangle.Vertices[i] = newVertex;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 20
0
 public MediumSizedMonster(WorldMatrix worldMatrix)
     : base(worldMatrix, new Rnd(200, 200))
 {
 }
Esempio n. 21
0
 public void RenderTriangleStrip(int vertexPoolIdx, int first, int count, int textureIdx, int lightmapIdx)
 {
     _renderer.RenderTriangleStrip(WorldMatrix.ToFloatArray(), vertexPoolIdx, first, count, textureIdx, lightmapIdx);
 }
Esempio n. 22
0
 public LargeMonster(WorldMatrix worldMatrix, IRnd rnd)
     : base(worldMatrix, rnd)
 {
 }
 protected override void Arrange()
 {
     _worldMatrix = new WorldMatrix();
     _theMonster = new Monster1x1(_worldMatrix, new Rnd(200, 200));
     _anotherMonster = new Monster1x1(_worldMatrix, new Rnd(200, 200));
 }
 protected override void Arrange()
 {
     _worldMatrix = new WorldMatrix();
     _theStone = new Stone1x1();
 }
Esempio n. 25
0
 public Vector3 GetPosition()
 {
     return(WorldMatrix.xna().Translation.dx());
 }
Esempio n. 26
0
 void Awake()
 {
     m_GameManager       = GameObject.Find("Services").GetComponentInChildren <GameManager>();
     m_WorldMatrix       = m_GameManager.Matrix;
     m_InstanciationTime = Time.time;
 }
Esempio n. 27
0
 public void SetWorldMatrix(WorldMatrix worldMatrix)
 {
 }
 protected override void Arrange()
 {
     _worldMatrix = new WorldMatrix();
     _theMonster = new LargeMonster(_worldMatrix, new Rnd(200,200));
 }
Esempio n. 29
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking || !ResourceSink.IsPowered)
            {
                return;
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetAllTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            if (IsActive)
            {
                bool empty = true;
                foreach (var entity in m_potentialPenetrations)
                {
                    if (entity is MyVoxelBase)
                    {
                        continue;
                    }
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }

                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }

                if (empty)
                {
                    IsActive = false;
                }
            }
            else
            {
                foreach (var entity in m_potentialPenetrations)
                {
                    if (entity is MyVoxelBase)
                    {
                        continue;
                    }
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                IsActive           = true;
                                break;
                            }
                        }
                    }
                }

                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                IsActive           = true;
                                break;
                            }
                        }
                    }
                }
            }
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }