public void Update() { ProfilerShort.Begin("MyBotNavigation.Update"); AssertIsValid(); if (m_entity == null) { return; } ProfilerShort.Begin("UpdateMatrices"); UpdateMatrices(); ProfilerShort.End(); m_gravityDirection = MyGravityProviderSystem.CalculateGravityInPoint(m_entity.PositionComp.WorldMatrix.Translation); if (!Vector3.IsZero(m_gravityDirection, 0.01f)) { m_gravityDirection.Normalize(); } if (MyFakes.NAVMESH_PRESUMES_DOWNWARD_GRAVITY) { m_upVector = Vector3.Up; } else { m_upVector = -m_gravityDirection; } if (!m_speed.IsValid()) { m_forwardVector = PositionAndOrientation.Forward; m_speed = 0.0f; m_rotationSpeedModifier = 1; } ProfilerShort.Begin("Steering update"); foreach (var steering in m_steerings) { ProfilerShort.Begin(steering.GetName()); steering.Update(); ProfilerShort.End(); } ProfilerShort.End(); ProfilerShort.Begin("Steering accumulate correction"); CorrectMovement(); ProfilerShort.End(); ProfilerShort.Begin("Aiming"); m_aiming.Update(); ProfilerShort.End(); ProfilerShort.Begin("MoveCharacter"); MoveCharacter(); ProfilerShort.End(); AssertIsValid(); ProfilerShort.End(); }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); // TODO: This should be changed so the ragdoll gets registered in the generators, now for SE, apply gravity explictly // Apply Gravity on Ragdoll if (Character.Physics.Ragdoll != null && Character.Physics.Ragdoll.IsAddedToWorld && (!Character.Physics.Ragdoll.IsKeyframed || RagdollMapper.IsPartiallySimulated)) { Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(Character.PositionComp.WorldAABB.Center) + Character.Physics.HavokWorld.Gravity * MyCharacter.CHARACTER_GRAVITY_MULTIPLIER; Character.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * Character.Definition.Mass, null, null); } VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Update Ragdoll"); UpdateRagdoll(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo) { if (indicator.Entity == null) { return; } Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position); //gravity += MyPhysics.HavokWorld.Gravity; bool anyGravity = !MyUtils.IsZero(gravity.Length()); // Background and text drawing MyFontEnum font; StringBuilder text; m_hudIndicatorText.Clear(); m_hudIndicatorText.AppendFormatedDecimal("", gravity.Length() / 9.81f, 1, " g"); MyGuiPaddedTexture bg; if (anyGravity) { font = MyFontEnum.Blue; text = MyTexts.Get(MySpaceTexts.HudInfoGravity); bg = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT; } else { font = MyFontEnum.Red; text = MyTexts.Get(MySpaceTexts.HudInfoNoGravity); bg = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED; } bool drawOxygen = MySession.Static.Settings.EnableOxygen; Vector2 bgSizeDelta = new Vector2(0.015f, 0f); float oxygenLevel = 0f; Vector2 bgSize = bg.SizeGui + bgSizeDelta; Vector2 bgPos, textPos, gTextPos, position; MyGuiDrawAlignEnum align; if (indicator.Entity is MyCharacter) { bgPos = new Vector2(0.99f, 0.99f); bgPos = ConvertHudToNormalizedGuiPosition(ref bgPos); textPos = bgPos - bgSize * new Vector2(0.94f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f; gTextPos = bgPos - bgSize * new Vector2(0.56f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f; align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM; position = bgPos - bgSize * new Vector2(0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f; oxygenLevel = (indicator.Entity as MyCharacter).EnvironmentOxygenLevel; } else { bgPos = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f)); bgPos = ConvertHudToNormalizedGuiPosition(ref bgPos); textPos = bgPos + bgSize * new Vector2(1 - 0.94f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f; gTextPos = bgPos + bgSize * new Vector2(1 - 0.56f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f; align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM; position = bgPos - bgSize * new Vector2(-0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f; var cockpit = indicator.Entity as MyCockpit; if (cockpit != null && cockpit.Pilot != null) { oxygenLevel = cockpit.Pilot.EnvironmentOxygenLevel; } else { drawOxygen = false; } } if (drawOxygen) { bgSizeDelta += new Vector2(0f, 0.025f); } MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui + bgSizeDelta, Color.White, align); MyGuiManager.DrawString(font, text, textPos, m_textScale); if (drawOxygen) { var oxygenFont = MyFontEnum.Blue; var oxygenText = new StringBuilder("Oxygen: "); if (oxygenLevel == 0f) { oxygenText.Append("None"); oxygenFont = MyFontEnum.Red; } else if (oxygenLevel < 0.5f) { oxygenText.Append("Low"); oxygenFont = MyFontEnum.Red; } else { oxygenText.Append("High"); } MyGuiManager.DrawString(oxygenFont, oxygenText, textPos - new Vector2(0f, 0.025f), m_textScale); } if (anyGravity) { MyGuiManager.DrawString(MyFontEnum.White, m_hudIndicatorText, gTextPos, m_textScale); } position = MyGuiManager.GetHudSize() * ConvertNormalizedGuiToHud(ref position); if (MyVideoSettingsManager.IsTripleHead()) { position.X += 1.0f; } // Draw each of gravity indicators. foreach (var generatorGravity in MyGravityProviderSystem.GravityVectors) { DrawGravityVectorIndicator(position, generatorGravity, MyHudTexturesEnum.gravity_arrow, Color.Gray); } //if (MyPhysics.HavokWorld.Gravity != Vector3.Zero) // DrawGravityVectorIndicator(position, MyPhysics.HavokWorld.Gravity, MyHudTexturesEnum.gravity_arrow, Color.Gray); if (anyGravity) { DrawGravityVectorIndicator(position, gravity, MyHudTexturesEnum.gravity_arrow, Color.White); } // Draw center MyAtlasTextureCoordinate centerTextCoord; if (anyGravity) { centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_white); } else { centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_red); } float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X; float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y; Vector2 rightVector = Vector2.UnitX; MyRenderProxy.DrawSpriteAtlas( m_atlas, position, centerTextCoord.Offset, centerTextCoord.Size, rightVector, new Vector2(hudSizeX, hudSizeY), MyHudConstants.HUD_COLOR_LIGHT, Vector2.One * 0.005f); }