public void UpdateEntity(MyEntity entity) { Vector3 position; Quaternion rotation; GetValues(m_time, out position, out rotation); entity.MoveAndRotate(position, Matrix.CreateFromQuaternion(rotation)); }
public void UpdateTangent(MyEntity entity, Vector3 up) { Vector3 position0, position1; Quaternion rotation0, rotation1; GetValues(m_time - 0.05f, out position0, out rotation0); GetValues(m_time + 0.05f, out position1, out rotation1); Vector3 forward = position1 - position0; if (!MyUtils.IsValid(forward)) { forward = entity.WorldMatrix.Forward; } entity.MoveAndRotate((position0 + position1) / 2, Matrix.CreateWorld(Vector3.Zero, forward, up)); }
/// <summary> /// Moves and Rotates entity /// </summary> /// <param name="newPosition"></param> /// <param name="newOrientation"></param> /// <param name="entity"></param> public static void MoveAndRotateObject(Vector3 newPosition, Matrix newOrientation, MyEntity entity) { BoundingSphere sphere = new BoundingSphere(newPosition + entity.LocalVolumeOffset, entity.WorldVolume.Radius); if (MyMwcSectorConstants.SECTOR_SIZE_FOR_PHYS_OBJECTS_BOUNDING_BOX.Contains(sphere) == MinerWarsMath.ContainmentType.Contains) { Matrix entityBeforeMoveOrientation = entity.GetWorldRotation(); Vector3 entityBeforeMovePosition = entity.GetPosition(); if (entityBeforeMovePosition != newPosition || entityBeforeMoveOrientation != newOrientation) { // Move object bool moveSuccesfull = entity.MoveAndRotate(newPosition, newOrientation); Vector3 currentPosition = entity.GetPosition(); Matrix currentOrientation = entity.GetWorldRotation(); if (moveSuccesfull) { //entity.UpdateWorldMatrix(); // Play movement or rotation sounds if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_delayMovementSoundInMillis) { if (entityBeforeMovePosition != currentPosition) { MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveStep); } if (entityBeforeMoveOrientation != currentOrientation) { MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectRotateStep); } m_delayMovementSoundInMillis = MyMinerGame.TotalGamePlayTimeInMilliseconds + MyEditorConstants.DELAY_OBJECT_MOVEMENT_SOUND_IN_MILLIS; } MyEditor.Static.RecheckAllColidingEntitesAndClearNonColiding();//check all coliding entites to see if any went out of collision state //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("CheckAllCollidingObjectsForEntity"); // This was taking up to 170ms for 800 prefabs, so its replaced by void CheckCollisions(IEnumerable<MyEntity> entities) in HandleInput(). //MyEditor.Static.CheckAllCollidingObjectsForEntity(entity);//check all colliding state of entity after move //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else { if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_delayMovementSoundInMillis) { if ((entityBeforeMovePosition != currentPosition) || (entityBeforeMoveOrientation != currentOrientation)) { MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveInvalid); m_delayMovementSoundInMillis = MyMinerGame.TotalGamePlayTimeInMilliseconds + 1000; } } } } } }