public void Update(int behaviorTicks) { this.m_stuckDetection.SetCurrentTicks(behaviorTicks); if (this.m_entity != null) { this.UpdateMatrices(); this.m_gravityDirection = MyGravityProviderSystem.CalculateTotalGravityInPoint(this.m_entity.PositionComp.WorldMatrix.Translation); if (!Vector3.IsZero(this.m_gravityDirection, 0.01f)) { this.m_gravityDirection = (Vector3)Vector3D.Normalize(this.m_gravityDirection); } this.m_upVector = !MyPerGameSettings.NavmeshPresumesDownwardGravity ? -this.m_gravityDirection : Vector3.Up; if (!this.m_speed.IsValid()) { this.m_forwardVector = (Vector3)this.PositionAndOrientation.Forward; this.m_speed = 0f; this.m_rotationSpeedModifier = 1f; } using (List <MySteeringBase> .Enumerator enumerator = this.m_steerings.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.Update(); } } this.m_aiming.Update(); this.CorrectMovement(this.m_aiming.RotationHint); if (this.m_speed < 0.1f) { this.m_speed = 0f; } this.MoveCharacter(); } }
public override bool GetBotSpawnPosition(string behaviorType, out VRageMath.Vector3D spawnPosition) { if (MySession.LocalCharacter != null) { var pos = MySession.LocalCharacter.PositionComp.GetPosition(); Vector3 up; Vector3D right, forward; up = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos); if (up.LengthSquared() < 0.0001f) { up = Vector3.Up; } else { up = Vector3D.Normalize(up); } forward = Vector3.CalculatePerpendicularVector(up); right = Vector3.Cross(forward, up); spawnPosition = MyUtils.GetRandomDiscPosition(ref pos, 5.0f, ref forward, ref right); return(true); } spawnPosition = Vector3D.Zero; return(false); }
public override bool GetBotSpawnPosition(string behaviorType, out VRageMath.Vector3D spawnPosition) { // CH: TODO: Do this more generically, so that modders would be able to define their own bot types and the way they spawn if (behaviorType == "Spider") { MatrixD spawnMatrix; bool success = GetSpiderSpawnPosition(out spawnMatrix, null); spawnPosition = spawnMatrix.Translation; return(success); } else if (MySession.Static.LocalCharacter != null) { var pos = MySession.Static.LocalCharacter.PositionComp.GetPosition(); Vector3 up; Vector3D right, forward; up = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos); if (up.LengthSquared() < 0.0001f) { up = Vector3.Up; } else { up = Vector3D.Normalize(up); } forward = Vector3.CalculatePerpendicularVector(up); right = Vector3.Cross(forward, up); spawnPosition = MyUtils.GetRandomDiscPosition(ref pos, 5.0f, ref forward, ref right); return(true); } spawnPosition = Vector3D.Zero; return(false); }
public virtual void Start(MatrixD position, Vector3D initialVelocity, float scale, bool randomRotation = true) { MyDebug.AssertDebug(!m_isStarted); m_createdTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; Container.Entity.PositionComp.Scale = RandomScale * scale; Container.Entity.WorldMatrix = position; (Container.Entity.Physics as MyDebrisPhysics).ScalePhysicsShape(ref m_massProperties); Container.Entity.Physics.Clear(); Container.Entity.Physics.LinearVelocity = initialVelocity; //apply random rotation impulse if (randomRotation) { Container.Entity.Physics.AngularVelocity = new Vector3(MyUtils.GetRandomRadian(), MyUtils.GetRandomRadian(), MyUtils.GetRandomRadian()); } MyEntities.Add(m_entity); Container.Entity.Physics.Enabled = true; float simulationRatio = Sync.IsServer ? 1.0f : Sync.RelativeSimulationRatio * Sync.RelativeSimulationRatio; Vector3D gravity = simulationRatio * MyGravityProviderSystem.CalculateNaturalGravityInPoint(position.Translation); ((MyPhysicsBody)Container.Entity.Physics).RigidBody.Gravity = gravity; (Container.Entity.Physics as MyPhysicsBody).HavokWorld.ActiveRigidBodies.Add((Container.Entity.Physics as MyPhysicsBody).RigidBody); m_isStarted = true; }
private bool CheckGravity() { if (!Config.AllowInGravity) { if (!Vector3D.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(PlayerPosition))) { Chat?.Respond("Saving & Loading in gravity has been disabled!"); return(false); } } else { if (Config.MaxGravityAmount == 0) { return(true); } float Gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(PlayerPosition).Length() / 9.81f; if (Gravity > Config.MaxGravityAmount) { //Log.Warn("Players gravity amount: " + Gravity); Chat?.Respond("You are not permitted to Save/load in this gravity amount. Max amount: " + Config.MaxGravityAmount + "g"); return(false); } } return(true); }
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)); }
bool IMyShipController.TryGetPlanetElevation(MyPlanetElevation detail, out double elevation) { var blockPosition = this.PositionComp.GetPosition(); if (!MyGravityProviderSystem.IsPositionInNaturalGravity(blockPosition)) { elevation = double.PositiveInfinity; return(false); } var boundingBox = PositionComp.WorldAABB; var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox); if (nearestPlanet == null) { elevation = double.PositiveInfinity; return(false); } switch (detail) { case MyPlanetElevation.Sealevel: elevation = ((boundingBox.Center - nearestPlanet.PositionComp.GetPosition()).Length() - nearestPlanet.AverageRadius); return(true); case MyPlanetElevation.Surface: var controlledEntityPosition = CubeGrid.Physics.CenterOfMassWorld; Vector3D closestPoint = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition); elevation = Vector3D.Distance(closestPoint, controlledEntityPosition); return(true); default: throw new ArgumentOutOfRangeException("detail", detail, null); } }
public void UpdateBeforeSimulation100() { m_soundEmitters[(int)MySoundEmitterEnum.PrimaryState].Update(); if (windSystem) { float oxygen = MyOxygenProviderSystem.GetOxygenInPoint(m_character.PositionComp.GetPosition()); if (oxygen > 0f) { inAtmosphere = true;//in pressurized environment } else { Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_character.PositionComp.GetPosition()); if (gravity.LengthSquared() > 0f) { MyPlanet planet = MyGravityProviderSystem.GetNearestPlanet(m_character.PositionComp.GetPosition()); if (planet != null && planet.AtmosphereSettings.FogIntensity > 0f) { inAtmosphere = true;//in atmosphere without oxygen } else { inAtmosphere = false; } } else { inAtmosphere = false; } } windEmitter.Update(); } }
private void InitializePath(MyEnvironmentalParticle particle) { var pathData = new PathData(); if (pathData.PathPoints == null) { pathData.PathPoints = new Vector3D[PathData.PathPointCount + 2]; } var gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(particle.Position); var gravityDirection = Vector3D.Normalize(gravity); pathData.PathPoints[1] = particle.Position - gravityDirection * MyRandom.Instance.NextFloat() * 2.5f; // TODO general direction of movement for (int index = 2; index < PathData.PathPointCount + 1; ++index) { var pathLength = 5.0f; Vector3D randomNormal = Vector3D.Normalize(new Vector3D(MyRandom.Instance.NextFloat(), MyRandom.Instance.NextFloat(), MyRandom.Instance.NextFloat()) * 2.0f - Vector3D.One - 0.25 * gravityDirection); pathData.PathPoints[index] = pathData.PathPoints[index - 1] + randomNormal * (MyRandom.Instance.NextFloat() + 1.0f) * pathLength - gravityDirection / (float)index * pathLength; } pathData.PathPoints[0] = pathData.PathPoints[1] - gravityDirection; pathData.PathPoints[PathData.PathPointCount + 1] = pathData.PathPoints[PathData.PathPointCount] + Vector3D.Normalize(pathData.PathPoints[PathData.PathPointCount] - pathData.PathPoints[PathData.PathPointCount - 1]); particle.UserData = pathData; }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); Vector3 vector = MyGravityProviderSystem.CalculateNaturalGravityInPoint(base.PositionComp.GetPosition()); if (this.Physics.RigidBody.GetShape().ShapeType != HkShapeType.Sphere) { this.Physics.RigidBody.Gravity = vector; } else { this.m_smoothGravity = (this.m_smoothGravity * 0.5f) + (vector * 0.5f); this.m_smoothGravityDir = this.m_smoothGravity; this.m_smoothGravityDir.Normalize(); bool flag = false; foreach (Vector3 vector2 in this.m_supportNormals) { if (vector2.Dot(this.m_smoothGravityDir) > 0.8f) { flag = true; break; } } this.m_supportNormals.Clear(); if (!flag) { this.Physics.RigidBody.Gravity = this.m_smoothGravity; } else if (this.Physics.RigidBody.Gravity.Length() > 0.01f) { HkRigidBody rigidBody = this.Physics.RigidBody; rigidBody.Gravity *= 0.99f; } } }
private void ComputeGravityAlignedOrientation(out MatrixD resultOrientationStorage) { // Y axis bool inGravityField = true; Vector3D upVector = -MyGravityProviderSystem.CalculateTotalGravityInPoint(Position); if (upVector.LengthSquared() < MyMathConstants.EPSILON) { upVector = m_lastUpVec; m_lastOrientationWeight = 1; inGravityField = false; } else { m_lastUpVec = upVector; } upVector.Normalize(); // X axis Vector3D rightVector = m_lastRightVec - Vector3D.Dot(m_lastRightVec, upVector) * upVector; if (rightVector.LengthSquared() < MyMathConstants.EPSILON) { rightVector = m_orientation.Right - Vector3D.Dot(m_orientation.Right, upVector) * upVector; // backup behavior if singularity happens if (rightVector.LengthSquared() < MyMathConstants.EPSILON) { rightVector = m_orientation.Forward - Vector3D.Dot(m_orientation.Forward, upVector) * upVector; } // backup behavior if singularity happens } rightVector.Normalize(); m_lastRightVec = rightVector; // Z axis Vector3D forwardVector; Vector3D.Cross(ref upVector, ref rightVector, out forwardVector); resultOrientationStorage = MatrixD.Identity; resultOrientationStorage.Right = rightVector; resultOrientationStorage.Up = upVector; resultOrientationStorage.Forward = forwardVector; resultOrientationStorage = MatrixD.CreateFromAxisAngle(Vector3D.Right, m_pitch) * resultOrientationStorage * MatrixD.CreateFromAxisAngle(upVector, m_yaw); upVector = resultOrientationStorage.Up; rightVector = resultOrientationStorage.Right; resultOrientationStorage.Right = Math.Cos(m_roll) * rightVector + Math.Sin(m_roll) * upVector; resultOrientationStorage.Up = -Math.Sin(m_roll) * rightVector + Math.Cos(m_roll) * upVector; if (inGravityField && m_lastOrientationWeight > 0) { m_lastOrientationWeight = Math.Max(0, m_lastOrientationWeight - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS); resultOrientationStorage = MatrixD.Slerp(resultOrientationStorage, m_lastOrientation, MathHelper.SmoothStepStable(m_lastOrientationWeight)); } if (!inGravityField) { m_lastOrientation = resultOrientationStorage; } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); m_waitForUpdate--; if (m_waitForUpdate > 0) { return; } m_waitForUpdate = UPDATE_DELAY; Vector3D position = MySector.MainCamera.Position; MyPlanet planet = MyGravityProviderSystem.GetNearestPlanet(position); if (planet != null) { var distanceFromPlanet = Vector3D.Distance(planet.PositionComp.GetPosition(), position); if (distanceFromPlanet > planet.MaximumRadius + Math.Max(100, planet.MaximumRadius)) { ; } planet = null; //too far planet } if (m_closestPlanet != planet) { m_closestPlanet = planet; if (m_closestPlanet != null) { MyStringId category = MyStringId.GetOrCompute(m_closestPlanet.Generator.Id.SubtypeId.ToString()); MyStringId transition = MyStringId.GetOrCompute(m_closestPlanet.Generator.Id.SubtypeId.ToString()); if (!MyAudio.Static.IsValidTransitionCategory(transition, category)) { category = MyStringId.GetOrCompute("OtherPlanet"); transition = MyStringId.GetOrCompute("OtherPlanet"); } MyMusicTrack mt = new MyMusicTrack() { MusicCategory = category, TransitionCategory = transition }; MyAudio.Static.PlayMusic(mt); } else { //random MyMusicTrack mt = new MyMusicTrack() { }; MyAudio.Static.PlayMusic(mt, 1); } } }
public void Update() { ProfilerShort.Begin("MyBotNavigation.Update"); AssertIsValid(); if (m_entity == null) { return; } ProfilerShort.Begin("UpdateMatrices"); UpdateMatrices(); ProfilerShort.End(); m_gravityDirection = MyGravityProviderSystem.CalculateTotalGravityInPoint(m_entity.PositionComp.WorldMatrix.Translation); if (!Vector3.IsZero(m_gravityDirection, 0.01f)) { m_gravityDirection = Vector3D.Normalize(m_gravityDirection); } if (MyPerGameSettings.NavmeshPresumesDownwardGravity) { 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("Aiming"); m_aiming.Update(); ProfilerShort.End(); ProfilerShort.Begin("Steering accumulate correction"); CorrectMovement(m_aiming.RotationHint); ProfilerShort.End(); ProfilerShort.Begin("MoveCharacter"); MoveCharacter(); ProfilerShort.End(); AssertIsValid(); ProfilerShort.End(); }
public override void UpdateBeforeSimulation() { //if (MyFakes.ENABLE_RAGDOLL_DEBUG) Debug.WriteLine("RagdollComponent.UpdateBeforeSimulation"); base.UpdateBeforeSimulation(); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Update Ragdoll"); UpdateRagdoll(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); // TODO: This should be changed so the ragdoll gets registered in the generators, now for SE, apply gravity explictly // Apply Gravity on Ragdoll // OM: This should be called only in SE, in ME this is handled by world! if (Character.Physics != null && Character.Physics.Ragdoll != null && Character.Physics.Ragdoll.InWorld && (!Character.Physics.Ragdoll.IsKeyframed || RagdollMapper.IsPartiallySimulated) && (IsRagdollMoving || m_gravityTimer > 0)) { Vector3 gravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(Character.PositionComp.WorldAABB.Center) + Character.GetPhysicsBody().HavokWorld.Gravity *MyPerGameSettings.CharacterGravityMultiplier; Character.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * (MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(Character.Definition.Mass) : Character.Definition.Mass), null, null); m_gravityTimer = IsRagdollMoving ? GRAVITY_DELAY : m_gravityTimer - 1; } if (Character.Physics != null && Character.Physics.Ragdoll != null && IsRagdollMoving) { m_lastPosition = Character.Physics.Ragdoll.WorldMatrix.Translation; } }
public void UpdateAtmosphereStatus() { if (m_character != null && (m_localPlayer == false || (MySession.Static != null && m_character == MySession.Static.LocalCharacter))) { AtmosphereStatus original = m_atmosphereStatus; Vector3D pos = m_character.PositionComp.GetPosition(); Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos); if (gravity.LengthSquared() > 0f) { MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(pos); if (planet != null && planet.HasAtmosphere && planet.GetAirDensity(pos) > 0.5f) { m_atmosphereStatus = AtmosphereStatus.Atmosphere;//in atmosphere } else { m_atmosphereStatus = AtmosphereStatus.Space; } } else { m_atmosphereStatus = AtmosphereStatus.Space; } if (m_atmosphereStatus == AtmosphereStatus.Space) { float oxygen = 0f; if (m_character.OxygenComponent != null) { if (m_localPlayer) { if (MySession.Static.ControlledEntity is MyCharacter) { //in suit oxygen = m_character.OxygenComponent.EnvironmentOxygenLevel; } else { //in cockpit oxygen = m_character.OxygenComponent.OxygenLevelAtCharacterLocation; } } else { oxygen = m_character.OxygenComponent.EnvironmentOxygenLevel; } } if (oxygen > 0.1f) { m_atmosphereStatus = AtmosphereStatus.ShipOrStation;//in pressurized environment } } if (MyFakes.ENABLE_REALISTIC_LIMITER && MyFakes.ENABLE_NEW_SOUNDS && original != m_atmosphereStatus && MySession.Static != null && MySession.Static.Settings.RealisticSound) { MyAudio.Static.EnableMasterLimiter(!(InAtmosphere || InShipOrStation)); } } }
public SpawnInfo(MyObjectBuilder_SpaceFaunaComponent.SpawnInfo info, int currentTime) { SpawnTime = currentTime + info.SpawnTime; AbandonTime = currentTime + info.SpawnTime; Position = new Vector3D(info.X, info.Y, info.Z); Planet = MyGravityProviderSystem.GetNearestPlanet(Position); SpawnDone = false; }
private void SpawnBot(SpawnInfo spawnInfo, MyPlanet planet, MyPlanetAnimalSpawnInfo animalSpawnInfo) { PlanetAIInfo planetInfo = null; if (!m_planets.TryGetValue(planet.EntityId, out planetInfo)) { Debug.Assert(false, "Could not get planet info!"); return; } if (planetInfo.BotNumber >= MAX_BOTS_PER_PLANET) { return; } Debug.Assert(animalSpawnInfo != null); double spawnDistMin = animalSpawnInfo.SpawnDistMin; double spawnDistMax = animalSpawnInfo.SpawnDistMax; Vector3D center = spawnInfo.Position; Vector3D planetGravityVec = MyGravityProviderSystem.CalculateNaturalGravityInPoint(center); //GR: if gravity is zero provide a random Vector to normalize if (planetGravityVec == Vector3D.Zero) { planetGravityVec = Vector3D.Up; } planetGravityVec.Normalize(); Vector3D planetTangent = Vector3D.CalculatePerpendicularVector(planetGravityVec); Vector3D planetBitangent = Vector3D.Cross(planetGravityVec, planetTangent); planetTangent.Normalize(); planetBitangent.Normalize(); Vector3D spawnPos = MyUtils.GetRandomDiscPosition(ref center, spawnDistMin, spawnDistMax, ref planetTangent, ref planetBitangent); spawnPos = planet.GetClosestSurfacePointGlobal(ref spawnPos); Vector3D?spawnPosCorrected = MyEntities.FindFreePlace(spawnPos, 2.0f); if (spawnPosCorrected.HasValue) { spawnPos = spawnPosCorrected.Value; } planet.CorrectSpawnLocation(ref spawnPos, 2.0f); MyAgentDefinition botBehavior = GetAnimalDefinition(animalSpawnInfo) as MyAgentDefinition; if (botBehavior != null) { if (botBehavior.Id.SubtypeName == Wolf_SUBTYPE_ID && MySession.Static.EnableWolfs) { MyAIComponent.Static.SpawnNewBot(botBehavior, spawnPos); } else if (botBehavior.Id.SubtypeName != Wolf_SUBTYPE_ID && MySession.Static.EnableSpiders) { MyAIComponent.Static.SpawnNewBot(botBehavior, spawnPos); } } }
public override void OnRemovedFromScene(object source) { base.OnRemovedFromScene(source); MyPlanets.UnRegister(this); MyGravityProviderSystem.RemoveNaturalGravityProvider(Components.Get <MyGravityProviderComponent>()); MyOxygenProviderSystem.RemoveOxygenGenerator(this); }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPointForGrid(PositionComp.GetPosition()); Physics.AddForce(Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, Physics.Mass * gravity, Physics.CenterOfMassWorld, null); }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyPlanets.Register(this); MyGravityProviderSystem.AddNaturalGravityProvider(Components.Get <MyGravityProviderComponent>()); MyOxygenProviderSystem.AddOxygenGenerator(this); }
private unsafe void DebugDrawInternal() { if (this.m_navmeshOBBs != null) { this.m_navmeshOBBs.DebugDraw(); } if (this.DrawNavmesh) { this.DrawPersistentDebugNavmesh(false); } if (this.DrawPhysicalMesh) { this.DebugDrawPhysicalShapes(); } Vector3D position = MySession.Static.ControlledEntity.ControllerInfo.Controller.Player.GetPosition(); double * numPtr1 = (double *)ref position.Y; numPtr1[0] += 2.4000000953674316; MyRenderProxy.DebugDrawText3D(position, $"X: {Math.Round(position.X, 2)} Y: {Math.Round(position.Y, 2)} Z: {Math.Round(position.Z, 2)}", Color.Red, 1f, true, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false); if (this.m_lastGroundMeshQuery.Count > 0) { MyRenderProxy.DebugDrawSphere(this.m_lastGroundMeshQuery[0].Center, 1f, Color.Yellow, 1f, true, false, true, false); foreach (BoundingBoxD xd2 in this.m_lastGroundMeshQuery) { MyRenderProxy.DebugDrawOBB(xd2.Matrix, Color.Yellow, 0f, true, false, true, false); } if (this.m_navmeshOBBs != null) { float num; float num2; foreach (MyNavmeshOBBs.OBBCoords coords in this.m_debugDrawIntersectedOBBs) { MyRenderProxy.DebugDrawOBB(new MyOrientedBoundingBoxD(coords.OBB.Center, new Vector3(coords.OBB.HalfExtent.X, coords.OBB.HalfExtent.Y / 2.0, coords.OBB.HalfExtent.Z), coords.OBB.Orientation), Color.White, 0f, true, false, false); } MyOrientedBoundingBoxD obb = this.m_navmeshOBBs.GetOBB(0, 0).Value; MyPlanet planet = this.GetPlanet(obb.Center); Vector3 *points = (Vector3 *)stackalloc byte[(((IntPtr)4) * sizeof(Vector3))]; GetMiddleOBBPoints(obb, ref points); planet.Provider.Shape.GetBounds(points, 4, out num, out num2); if (num.IsValid() && num2.IsValid()) { Vector3D vectord2 = obb.Orientation.Up * num2; MyRenderProxy.DebugDrawSphere(obb.Orientation.Up * num, 1f, Color.Blue, 0f, true, false, true, false); MyRenderProxy.DebugDrawSphere(vectord2, 1f, Color.Blue, 0f, true, false, true, false); } DrawTerrainLimits(planet, obb); } MyRenderProxy.DebugDrawSphere(this.m_meshCenter, 2f, Color.Red, 0f, true, false, true, false); } if ((this.m_polygons != null) && (this.m_pathfindingDebugTarget != null)) { Vector3D vectord3 = -Vector3D.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(this.m_pathfindingDebugTarget.Value)); MyRenderProxy.DebugDrawSphere(this.m_pathfindingDebugTarget.Value + (1.5 * vectord3), 0.2f, Color.Red, 0f, true, false, true, false); } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. //<ib.floating> //Physics.RigidBody.Gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(PositionComp.GetPosition()); Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(PositionComp.GetPosition()); if (Physics.RigidBody.GetShape().ShapeType == HkShapeType.Sphere) { const float w = 0.5f; m_smoothGravity = m_smoothGravity * w + gravity * (1 - w); m_smoothGravityDir = m_smoothGravity; m_smoothGravityDir.Normalize(); bool anySupport = false; foreach (var supportNormal in m_supportNormals) { float cosalpha = supportNormal.Dot(m_smoothGravityDir); const float cosalphaLimit = 0.8f; // +/- 12 Degrees if (cosalpha > cosalphaLimit) { anySupport = true; break; } } m_supportNormals.Clear(); if (anySupport) { //Physics.RigidBody.Gravity = Vector3.Zero; const float limitGravity = 0.01f; if ((Physics.RigidBody.Gravity.Length() > limitGravity)) { Physics.RigidBody.Gravity *= 0.99f; // Decay gravity } } else { Physics.RigidBody.Gravity = m_smoothGravity; } } else { Physics.RigidBody.Gravity = gravity; } if (m_massChangeForCollisions < 1f) { if ((MySession.Static.ElapsedPlayTime.TotalMilliseconds - m_timeFromSpawn.TotalMilliseconds) >= 2000) { m_massChangeForCollisions = 1f; } } }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyPlanets.Register(this); MyGravityProviderSystem.AddPlanet(this); MyOxygenProviderSystem.AddOxygenGenerator(this); }
public override void OnRemovedFromScene(object source) { base.OnRemovedFromScene(source); MyPlanets.UnRegister(this); MyGravityProviderSystem.RemovePlanet(this); MyOxygenProviderSystem.RemoveOxygenGenerator(this); }
private bool IsNearPlanet() { if (ControlledEntity == null) { return(false); } return(!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(ControlledEntity.PositionComp.GetPosition()))); }
public bool UpdatePhysicalMovement() { if (!Running) { return(false); } var characterPhysics = Character.Physics; var characterProxy = characterPhysics.CharacterProxy; if (characterProxy != null) { if (characterProxy.LinearVelocity.Length() < MyCharacter.MINIMAL_SPEED) { characterProxy.LinearVelocity = Vector3.Zero; } } var rigidBody = characterPhysics.RigidBody; if (rigidBody != null) { rigidBody.Gravity = Vector3.Zero; if (MySession.Static.SurvivalMode || MyFakes.ENABLE_PLANETS_JETPACK_LIMIT_IN_CREATIVE) { Vector3 planetGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(Character.PositionComp.WorldAABB.Center); if (planetGravity != Vector3.Zero) { rigidBody.Gravity = planetGravity * MyPerGameSettings.CharacterGravityMultiplier; } } return(true); } else if (characterProxy != null) { characterProxy.Gravity = Vector3.Zero; if (MySession.Static.SurvivalMode || MyFakes.ENABLE_PLANETS_JETPACK_LIMIT_IN_CREATIVE) { Vector3 planetGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(Character.PositionComp.WorldAABB.Center); if (planetGravity != Vector3.Zero) { characterProxy.Gravity = planetGravity * MyPerGameSettings.CharacterGravityMultiplier; } } return(true); } return(false); }
public MyNavigationInputMesh(MyRDPathfinding rdPathfinding, MyPlanet planet, Vector3D center) { this.m_rdPathfinding = rdPathfinding; this.m_planet = planet; this.m_center = center; Vector3 v = (Vector3) - Vector3D.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(this.m_center)); Vector3 forward = Vector3.CalculatePerpendicularVector(v); this.rdWorldQuaternion = Quaternion.Inverse(Quaternion.CreateFromForwardUp(forward, v)); }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); if (ResourceSink != null) { ResourceSink.Update(); } if (IsWorking) { foreach (IMyEntity entityInterface in m_containedEntities) { MyEntity entity = entityInterface as MyEntity; MyCharacter character = entity as MyCharacter; IMyVirtualMass mass = entity as IMyVirtualMass; var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(entity.WorldMatrix.Translation); var gravity = GetWorldGravity(entity.WorldMatrix.Translation) * MyGravityProviderSystem.CalculateArtificialGravityStrengthMultiplier(naturalGravityMultiplier); if (mass != null && entity.Physics.RigidBody.IsActive) { if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_MISCELLANEOUS) { MyRenderProxy.DebugDrawSphere(entity.WorldMatrix.Translation, 0.2f, mass.IsWorking ? Color.Blue : Color.Red, 1.0f, false); } if (mass.IsWorking && entity.Physics.RigidBody.IsActive) { ((IMyEntity)mass.CubeGrid).Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * mass.VirtualMass, entity.WorldMatrix.Translation, null); } } else if (!entity.Physics.IsKinematic && !entity.Physics.IsStatic && entity.Physics.RigidBody2 == null && //jn: TODO this is actualy check for large grid character == null) { if (entity.Physics.RigidBody != null && entity.Physics.RigidBody.IsActive) { //<ib.change> increase gravity for floating objects //entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * entity.Physics.RigidBody.Mass, null, null); if (entity is MyFloatingObject) { var floatingEntity = entity as MyFloatingObject; float w = (floatingEntity.HasConstraints()) ? 2.0f : 1.0f; entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, w * gravity * entity.Physics.RigidBody.Mass, null, null); } else { entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * entity.Physics.RigidBody.Mass, null, null); } } } } } }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyGravityProviderSystem.AddGravityGenerator(this); UpdateEmissivity(); if (ResourceSink != null) { ResourceSink.Update(); } }
private static MyPlanet FindNearestPlanet(Vector3D worldPosition) { MyPlanet foundPlanet = MyGravityProviderSystem.GetNearestPlanet(worldPosition); if (foundPlanet != null && !((IMyGravityProvider)foundPlanet).IsPositionInRange(worldPosition)) { foundPlanet = null; } return(foundPlanet); }