// I used this method only when we didn't have real persistant sectors... for fly-through animations List <MyVoxelMapImpostor> CreateFakeImpostors() { List <MyVoxelMapImpostor> ret = new List <MyVoxelMapImpostor>(ImpostorProperties.ImpostorsCount); for (int i = 0; i < ImpostorProperties.ImpostorsCount; i++) { Vector3 sectorCenter = Vector3.Zero; float randomDistance = MyMwcUtils.GetRandomFloat(ImpostorProperties.MinDistance, ImpostorProperties.MaxDistance); Vector3 randomPositionWithinSector = MyMwcUtils.GetRandomVector3Normalized() * randomDistance; float radius = MyMwcUtils.GetRandomFloat(ImpostorProperties.MinRadius, ImpostorProperties.MaxRadius); Vector3 position = sectorCenter + randomPositionWithinSector; float angle = MyMwcUtils.GetRandomRadian(); ret.Add(new MyVoxelMapImpostor(position, radius, angle)); } // Sort by distance (back-to-front) so alpha won't make problems on overlapping quads ret.Sort(); return(ret); }
static void UpdateExplosionLines() { foreach (LinkedListNode <ExplosionLine> explosionLine in m_preallocatedExplosionLines) { explosionLine.Value.ActualTime += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS; if (explosionLine.Value.ActualTime > explosionLine.Value.TotalTime) { m_preallocatedExplosionLines.MarkForDeallocate(explosionLine); continue; } explosionLine.Value.ActualDir = Vector3.Lerp(explosionLine.Value.StartDir, explosionLine.Value.EndDir, explosionLine.Value.ActualTime / (float)explosionLine.Value.TotalTime); } m_preallocatedExplosionLines.DeallocateAllMarked(); if (m_State == NuclearState.FADE_IN && MyMwcUtils.GetRandomFloat(0, 1) > 0.75f) { ExplosionLine line = m_preallocatedExplosionLines.Allocate(true); if (line != null) { line.TotalTime = 5000; line.ActualTime = 0; line.StartDir = MyMwcUtils.GetRandomVector3Normalized(); Vector3 rotDir = MyMwcUtils.GetRandomVector3Normalized(); Matrix rotMatrix = Matrix.CreateFromAxisAngle(rotDir, 0.3f); line.EndDir = Vector3.Transform(line.StartDir, rotMatrix); } } }
public static void LoadData() { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelCacheCellRenderHelper.LoadData"); MyMwcLog.WriteLine("MyVoxelCacheCellRenderHelper.LoadData - START"); MyMwcLog.IncreaseIndent(); /* * if (m_singleMaterialHelper == null) * { * m_singleMaterialHelper = new MySingleMaterialHelper(); * m_singleMaterialHelper.LoadData(); * * m_multiMaterialHelper = new MyMultiMaterialHelper(); * m_multiMaterialHelper.LoadData(); * } */ if (m_preallocatedSingleMaterialHelpers == null) { m_preallocatedSingleMaterialHelpers = new MySingleMaterialHelper[MyMwcUtils.GetMaxValueFromEnum <MyMwcVoxelMaterialsEnum>() + 1]; m_preallocatedMultiMaterialHelpers = new Dictionary <int, MyMultiMaterialHelper>(); } MyMwcLog.DecreaseIndent(); MyMwcLog.WriteLine("MyVoxelCacheCellRenderHelper.LoadData - END"); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }
/// <summary> /// Collapses an edge defined by its two endpoint vertices. /// </summary> /// <param name="keptVertexIndex">The index of the vertex that will NOT be removed in the process. /// However, it will be moved if it's not locked.</param> /// <param name="removedVertexIndex">The index of the vertex that WILL be removed in the process.</param> private void CollapseEdge(short keptVertexIndex, short removedVertexIndex) { Debug.Assert(!IsVertexLocked(removedVertexIndex)); // if I can move the kept vertex, make its new position the average of the previous positions bool interpolate = !IsVertexLocked(keptVertexIndex); if (interpolate) { var keptVertex = m_vertices[keptVertexIndex]; keptVertex.Position = .5f * (keptVertex.Position + m_vertices[removedVertexIndex].Position); keptVertex.Normal = MyMwcUtils.Normalize( (keptVertex.Normal + m_vertices[removedVertexIndex].Normal)); m_vertices[keptVertexIndex] = keptVertex; } var removedVertexTriangles = m_adjacentTriangleIndices[removedVertexIndex]; for (int i = removedVertexTriangles.Count - 1; i >= 0; i--) { var triangleIndex = removedVertexTriangles[i]; var triangle = m_triangles[triangleIndex]; if (triangle.VertexIndex0 == removedVertexIndex) { triangle.VertexIndex0 = keptVertexIndex; Debug.Assert(keptVertexIndex < m_vertices.Count); } if (triangle.VertexIndex1 == removedVertexIndex) { triangle.VertexIndex1 = keptVertexIndex; Debug.Assert(keptVertexIndex < m_vertices.Count); } if (triangle.VertexIndex2 == removedVertexIndex) { triangle.VertexIndex2 = keptVertexIndex; Debug.Assert(keptVertexIndex < m_vertices.Count); } // todo find out why test for zero-surface does not work if (IsDegenerated(triangle) /*|| HasZeroSurface(triangle)*/) { // delete triangle RemoveTriangle(triangleIndex); } else { // update triangle m_triangles[triangleIndex] = triangle; if (!m_adjacentTriangleIndices[keptVertexIndex].Contains(triangleIndex)) { m_adjacentTriangleIndices[keptVertexIndex].Add(triangleIndex); } } } }
private void MeteorAction() { MyScriptWrapper.EnableGlobalEvent(World.Global.MyGlobalEventEnum.MeteorWind, true); MissionTimer.RegisterTimerAction(MyMwcUtils.GetRandomInt(2000, 4000), MeteorAction, false); //MyScriptWrapper.GenerateMeteor(100, MySession.PlayerShip.GetPosition() + MySession.PlayerShip.WorldMatrix.Forward * 500, MyMwcVoxelMaterialsEnum.Lava_01, MySession.PlayerShip.WorldMatrix.Forward * -1000, MyParticleEffectsIDEnum.MeteorTrail_FireAndSmoke); }
//Creates rotation matrix from direction (dir must be normalized) public static Matrix MatrixFromDir(Vector3 dir) { Vector3 right = new Vector3(0.0f, 0.0f, 1.0f); Vector3 up; float d = dir.Z; if (d > -0.99999 && d < 0.99999) { // to avoid problems with normalize in special cases right = right - dir * d; right = MyMwcUtils.Normalize(right); up = Vector3.Cross(dir, right); } else { //dir lies with z axis right = new Vector3(dir.Z, 0, -dir.X); up = new Vector3(0, 1, 0); }; Matrix m = Matrix.Identity; m.Right = right; m.Up = up; m.Forward = dir; return(m); }
public void HudDrawActualAmmo(Vector2 position, Vector2 scaleToAmmoSelection, int amount, Vector4?backgroundColor, StringBuilder ammoSpecialText) { if (backgroundColor.HasValue) { m_color = new Color(backgroundColor.Value); MyGuiManager.BeginSpriteBatch(); base.DrawSpriteBatch(position, new Vector2(m_itemWidth * scaleToAmmoSelection.X, ItemHeight * scaleToAmmoSelection.Y), m_color, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); Vector2 textPosition = position; textPosition.X += m_itemWidth / 2.6f * 2.0f; textPosition.Y += ItemHeight * scaleToAmmoSelection.Y - ItemHeight / 6.0f; m_diff.X += m_itemWidth * scaleToAmmoSelection.X * MyGuiConstants.AMMO_SELECT_ITEM_TEXT_RELATIVE_POSITION.X; m_diff.Y += ItemHeight * scaleToAmmoSelection.Y * MyGuiConstants.AMMO_SELECT_ITEM_TEXT_RELATIVE_POSITION.Y; MyMwcUtils.ClearStringBuilder(m_amount); m_amount.AppendInt32(amount); var color = new Color(MyGuiConstants.LABEL_TEXT_COLOR); MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(), m_amount, textPosition, 0.7f, color, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM); if (ammoSpecialText != null && ammoSpecialText.Length > 0) { textPosition.Y -= ItemHeight / 4.0f; MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(), ammoSpecialText, textPosition, .7f, color, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM); } MyGuiManager.EndSpriteBatch(); } }
static bool IntersectionT(float n, float d, ref float tE, ref float tL) { if (MyMwcUtils.IsZero(d)) { return(n <= 0); } float t = n / d; if (d > 0) { if (t > tL) { return(false); } if (t > tE) { tE = t; } } else { if (t < tE) { return(false); } if (t < tL) { tL = t; } } return(true); }
void SwitchToAttack(MySmallShipBot bot) { m_state = StateEnum.ATTACKING; m_attackTimer = MyMwcUtils.GetRandomFloat(2, 4); MyBotCoordinator.AddAttacker(bot, m_target); }
public override bool Draw(MyRenderObject renderObject) { base.Draw(renderObject); // Draw muzzle flash int deltaTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot; if (deltaTime <= MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN) { float FAKE_RADIUS = MyMwcUtils.GetRandomFloat(0.5f, 1.5f); float FAKE_THICKNESS = MyMwcUtils.GetRandomFloat(FAKE_RADIUS - 0.1f, FAKE_RADIUS); float FAKE_LENGTH = MyMwcUtils.GetRandomFloat(7, 8); float FAKE_ANGLE = MyMwcUtils.GetRandomFloat(0, MathHelper.PiOver2); //float colorComponent = 1; float colorComponent = 1 - (float)deltaTime / (float)MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN; colorComponent = 1 - (float)Math.Pow(colorComponent, 5); colorComponent *= 1.3f; //Vector4 color = new Vector4(1.0f, 1.0f, 1.0f, 1); Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); Vector3 muzzleInWorldSpace = m_positionMuzzleInWorldSpace + WorldMatrix.Up * 0.2f; MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunSide, color, muzzleInWorldSpace - WorldMatrix.Forward * 1.0f, WorldMatrix.Forward, FAKE_LENGTH, FAKE_THICKNESS); MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunFront, color, muzzleInWorldSpace, FAKE_RADIUS, FAKE_ANGLE); } return(true); }
static MyGuiScreenMessageBox() { m_typesConfiguration = new MyMessageBoxConfiguration[MyMwcUtils.GetMaxValueFromEnum <MyMessageBoxType>() + 1]; m_typesConfiguration[(int)MyMessageBoxType.MESSAGE] = new MyMessageBoxConfiguration( MyTextureManager.GetTexture <MyTexture2D>("Textures\\GUI\\MessageBackground_blue", flags: TextureFlags.IgnoreQuality), MyGuiConstants.MESSAGE_BOX_MESSAGE_TEXT_COLOR, MyGuiConstants.MESSAGE_BOX_MESSAGE_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_MESSAGE_BUTTON_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_MESSAGE_ROTATING_WHEEL_COLOR, MyGuiConstants.MESSAGE_BOX_MESSAGE_BACKGROUND_INTERFERENCE_VIDEO_COLOR, MyGuiManager.GetFontMinerWarsBlue(), MyGuiManager.GetConfirmButton()); m_typesConfiguration[(int)MyMessageBoxType.ERROR] = new MyMessageBoxConfiguration( MyTextureManager.GetTexture <MyTexture2D>("Textures\\GUI\\MessageBackground_red", flags: TextureFlags.IgnoreQuality), MyGuiConstants.MESSAGE_BOX_ERROR_TEXT_COLOR, MyGuiConstants.MESSAGE_BOX_ERROR_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_ERROR_BUTTON_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_ERROR_ROTATING_WHEEL_COLOR, MyGuiConstants.MESSAGE_BOX_ERROR_BACKGROUND_INTERFERENCE_VIDEO_COLOR, MyGuiManager.GetFontMinerWarsWhite(), MyGuiManager.GetMessageBoxButton()); m_typesConfiguration[(int)MyMessageBoxType.NULL] = new MyMessageBoxConfiguration( MyTextureManager.GetTexture <MyTexture2D>("Textures\\GUI\\MessageBackground_blue", flags: TextureFlags.IgnoreQuality), MyGuiConstants.MESSAGE_BOX_NULL_TEXT_COLOR, MyGuiConstants.MESSAGE_BOX_NULL_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_NULL_BUTTON_BACKGROUND_COLOR, MyGuiConstants.MESSAGE_BOX_NULL_ROTATING_WHEEL_COLOR, MyGuiConstants.MESSAGE_BOX_NULL_BACKGROUND_INTERFERENCE_VIDEO_COLOR, MyGuiManager.GetFontMinerWarsBlue(), MyGuiManager.GetConfirmButton()); }
public MyGameExtendedInfo(MyGameInfo gameInfo) { GameInfo = gameInfo; Ping = MyMwcUtils.GetRandomInt(10, 20); SectorType = MySectorType.Official; GameType = gameInfo.GameType; }
public static void Start() { Clear(); IsActive = true; startTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; ambientSound = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind, MyCamera.Position + MyCamera.ForwardVector * MaxSoundDistance, Vector3.Forward, Vector3.Up, Vector3.Zero, 0); sphereCenter = MyCamera.Position + MyCamera.ForwardVector * 400; for (int i = 0; i < SmokeCount; i++) { Vector3 pos = sphereCenter + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, SmokeSphereRadius); var smokePart = new SmokeParticle { Angle = MyMwcUtils.GetRandomRadian(), Color = Vector4.Zero, AngularVelocity = MyMwcUtils.GetRandomFloat(-0.15f, 0.15f), Pos = pos, Velocity = MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 30f) }; smokeParticles.Add(smokePart); } }
public void Start(Vector3 position, float scale, MyMwcVoxelMaterialsEnum voxelMaterial, MyGroupMask groupMask, bool explosionType) { base.Start(position, scale, groupMask, explosionType); if (explosionType) { //apply random rotation impulse base.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian()) * 0.7f; if (base.Physics.AngularVelocity.Length() == 0) { Debug.Assert(false); } if (!Physics.Enabled) { Physics.Enabled = true; } } else { if (Physics.Enabled) { Physics.Enabled = false; } } VoxelMaterial = voxelMaterial; InitDrawTechniques(); RenderObjects[0].NeedsResolveCastShadow = true; RenderObjects[0].FastCastShadowResolve = true; }
public void Start(Vector3 direction, int?trailEffectId) { this.Physics.LinearVelocity = direction; this.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomFloat(0.2f, 1.5f), MyMwcUtils.GetRandomFloat(0.2f, 1.5f), 0); if (m_size == 0) { m_size = this.WorldVolume.Radius; } if (trailEffectId != null) { m_trailEffect = MyParticlesManager.CreateParticleEffect(trailEffectId.Value); m_trailEffect.AutoDelete = true; m_trailEffect.UserScale = this.WorldVolume.Radius / 10; m_trailEffect.UserBirthMultiplier /= 2; m_trailEffect.WorldMatrix = this.WorldMatrix;// worldMatrix; } m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxMeteorFly, this.GetPosition(), this.GetForward(), Vector3.Up, direction); m_startTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; if (MyMultiplayerGameplay.IsHosting) { MyMultiplayerGameplay.Static.NewEntity(GetObjectBuilder(true), WorldMatrix); } }
public void AddShake(float shakePower) { if (MyFakes.DISABLE_CAMERA_HEADSHAKE) { return; } if (MyMwcUtils.IsZero(shakePower)) { return; } if (MyMwcUtils.IsZero(m_MaxShake)) { return; } float pow = (shakePower / m_MaxShake); //MyMwcLog.WriteLine(pow.ToString()); if (m_CurrentShakePosPower < pow) { m_CurrentShakePosPower = pow; } if (m_CurrentShakeDirPower < pow * m_DirReduction) { m_CurrentShakeDirPower = pow * m_DirReduction; } m_ShakePos = new Vector3(m_CurrentShakePosPower * m_MaxShakePos, m_CurrentShakePosPower * m_MaxShakePos, m_CurrentShakePosPower * m_MaxShakePos); m_ShakeDir = new Vector3(m_CurrentShakeDirPower * m_MaxShakeDir, 0.0f, m_CurrentShakeDirPower * m_MaxShakeDir); m_Shake = true; }
private void FollowToRoutePosition(MySmallShipBot bot) { // Fly to visible position, if too close look for new visible position if (Vector3.DistanceSquared(m_followPosition.Value, bot.GetPosition()) < 5 * 5) { m_followPosition = null; } else { bot.Move(m_followPosition.Value, m_followPosition.Value, bot.WorldMatrix.Up, false, 1, 2); if (m_stuckTimer > STUCK_TIME) { if (Vector3.DistanceSquared(bot.GetPosition(), m_stuckPosition) > STUCK_DISTANCE) { m_followPosition = null; } else { m_followPosition = m_stuckPosition + MyMwcUtils.GetRandomVector3Normalized() * 1000; } } else if (Vector3.DistanceSquared(bot.GetPosition(), m_stuckPosition) > STUCK_DISTANCE) { ResetStuck(bot); } else { m_stuckTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; } } }
private static MyEditPropertyEnum GetEditProperties(List <MyEntity> entities) { Array allEditProperties = Enum.GetValues(typeof(MyEditPropertyEnum)); int[] editPropertiesCount = new int[MyMwcUtils.GetMaxValueFromEnum <MyEditPropertyEnum>() + 1]; foreach (MyEntity entity in entities) { MyEditPropertyEnum editPropertyForEntity = GetEditProperties(entity); foreach (MyEditPropertyEnum editProperty in allEditProperties) { if ((entities.Count == 1 || m_editPropertiesForMultiEdit.Contains(editProperty)) && (editPropertyForEntity & editProperty) != 0) { editPropertiesCount[(int)editProperty]++; } } } MyEditPropertyEnum result = MyEditPropertyEnum.None; foreach (MyEditPropertyEnum editProperty in allEditProperties) { if (editPropertiesCount[(int)editProperty] == entities.Count) { result |= editProperty; } } return(result); }
public void SetTexts() { MyMwcUtils.ClearStringBuilder(m_debugText); m_debugText.AppendLine("Player friends debug info"); if (MySession.Static == null || MySession.PlayerFriends == null) { m_debugText.AppendLine("Player friends does not exists"); return; } foreach (var friend in MySession.PlayerFriends.GetDebug()) { m_debugText.Append(friend.DisplayName); m_debugText.Append(": "); if (friend.EntityId.HasValue) { m_debugText.AppendInt32((int)friend.EntityId.Value.NumericValue); m_debugText.Append(" ("); m_debugText.AppendInt32(friend.EntityId.Value.PlayerId); m_debugText.Append(")"); m_debugText.AppendLine(); m_debugText.Append(" Position: "); m_debugText.AppendDecimal(friend.GetPosition().X, 1); m_debugText.Append("; "); m_debugText.AppendDecimal(friend.GetPosition().Y, 1); m_debugText.Append("; "); m_debugText.AppendDecimal(friend.GetPosition().Z, 1); m_debugText.AppendLine(); } } }
public override void Load() { base.Load(); MissionTimer.RegisterTimerAction(MyMwcUtils.GetRandomInt(3000, 5000), m_shakeAction, true); doorDetector1 = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity(367)); doorDetector1.OnEntityEnter += DoorDetector1Open; doorDetector1.On(); doorDetector2 = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity(366)); doorDetector2.OnEntityEnter += DoorDetector2Closed; doorDetector2.On(); for (int i = 0; i < mines.GetLength(0); i++) { MyEntityDetector mineDetector = MyScriptWrapper.GetDetector(mines[i, 1]); mineDetector.OnEntityEnter += new OnEntityEnter(mineDetector_OnEntityEnter); mineDetector.OnEntityPositionChange += new OnEntityPositionChange(mineDetector_OnEntityPositionChange); mineDetector.On(); } MyScriptWrapper.OnBotReachedWaypoint += OnBotReachedWaypoint; MyScriptWrapper.OnSpawnpointBotSpawned += OnSpawnpointBotSpawned; //aliendetector MyScriptWrapper.Highlight(RadarEntity, true, this); MyScriptWrapper.EnablePhysics(RadarEntity, false); //aliendetector MyScriptWrapper.Highlight(1962, true, this); MyScriptWrapper.EnablePhysics(1962, false); }
void UpdateGoals(MySmallShipBot bot) { moveTarget = bot.GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 1000; lookTarget = bot.GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 1000; up = MyMwcUtils.GetRandomVector3Normalized() * 1000; shoot = MyMwcUtils.GetRandomBool(2); }
static string GetRandomBackgroundTexture() { int randomNumber = MyMwcUtils.GetRandomInt(MyGuiConstants.LOADING_RANDOM_SCREEN_INDEX_MIN, MyGuiConstants.LOADING_RANDOM_SCREEN_INDEX_MAX + 1); string paddedNumber = randomNumber.ToString().PadLeft(3, '0'); return("Textures\\GUI\\LoadingScreen\\Background" + paddedNumber); }
/// <summary> /// Updates velocity from external accel and gravitation /// </summary>= public void UpdateVelocity(float dt) { // apply directional gravity m_ExternalLinearAcceleration += MyPhysics.physicsSystem.Gravitation * dt; // apply point gravity Vector3 accelerationFromPoints = Vector3.Zero; foreach (var gravityPoint in MyPhysics.physicsSystem.GravitationPoints) { float distance = Vector3.Distance(Position, gravityPoint.Item1.Center); float power = MathHelper.Clamp(1 - distance / gravityPoint.Item1.Radius, 0, 1); Vector3 dirToCenter = Vector3.Normalize(gravityPoint.Item1.Center - Position); accelerationFromPoints += dirToCenter * power * gravityPoint.Item2; } m_ExternalLinearAcceleration += accelerationFromPoints * dt; m_Velocity += m_ExternalLinearAcceleration * dt; m_AngularVelocity += m_ExternalAngularAcceleration * dt; if (m_MaxAngularVelocity > 0.0f && m_AngularVelocity.Length() > m_MaxAngularVelocity) { m_AngularVelocity = MyMwcUtils.Normalize(m_AngularVelocity); m_AngularVelocity *= m_MaxAngularVelocity; } if (m_MaxLinearVelocity > 0.0f && m_Velocity.Length() > m_MaxLinearVelocity) { m_Velocity = MyMwcUtils.Normalize(m_Velocity); m_Velocity *= m_MaxLinearVelocity; } }
// Liang-Barsky line clipping. Return true if the line isn't completely clipped. static bool ClipLine(ref Vector3 start, ref Vector3 end, MyMwcVector3Int min, MyMwcVector3Int max) { Vector3 dir = end - start; if (MyMwcUtils.IsZero(dir)) { return(IsPointInside(start, min, max)); } float tE = 0, tL = 1; if (IntersectionT(min.X - start.X, dir.X, ref tE, ref tL) && IntersectionT(start.X - max.X - 1, -dir.X, ref tE, ref tL) && IntersectionT(min.Y - start.Y, dir.Y, ref tE, ref tL) && IntersectionT(start.Y - max.Y - 1, -dir.Y, ref tE, ref tL) && IntersectionT(min.Z - start.Z, dir.Z, ref tE, ref tL) && IntersectionT(start.Z - max.Z - 1, -dir.Z, ref tE, ref tL)) { if (tL < 1) { end = start + tL * dir; } if (tE > 0) { start += tE * dir; } return(true); } return(false); }
//private bool TestAABB(ref BoundingBox bbox) //{ // return (bbox.Max - bbox.Min).Length() < MyLightsConstants.MAX_SPOTLIGHT_AABB_DIAGONAL; //} private static void CalculateAABB(ref BoundingBox bbox, out float scaleZ, out float scaleXY, ref Vector3 position, ref Vector3 direction, ref Vector3 up, float reflectorConeMaxAngleCos, float reflectorRange) { float cosAngle = 1 - reflectorConeMaxAngleCos; scaleZ = reflectorRange; // Calculate cone side (hypotenuse of triangle) float side = reflectorRange / cosAngle; // Calculate cone bottom scale (Pythagoras theorem) scaleXY = (float)System.Math.Sqrt(side * side - reflectorRange * reflectorRange) * 2; up = MyMwcUtils.Normalize(up); Vector3 coneSideDirection = Vector3.Cross(up, direction); coneSideDirection = MyMwcUtils.Normalize(coneSideDirection); Vector3 coneCenter = position + direction * scaleZ; Vector3 pt1 = coneCenter + coneSideDirection * scaleXY / 2 + up * scaleXY / 2; Vector3 pt2 = coneCenter - coneSideDirection * scaleXY / 2 + up * scaleXY / 2; Vector3 pt3 = coneCenter + coneSideDirection * scaleXY / 2 - up * scaleXY / 2; Vector3 pt4 = coneCenter - coneSideDirection * scaleXY / 2 - up * scaleXY / 2; bbox = bbox.CreateInvalid(); bbox = bbox.Include(ref position); //bbox = bbox.Include(ref coneCenter); bbox = bbox.Include(ref pt1); bbox = bbox.Include(ref pt2); bbox = bbox.Include(ref pt3); bbox = bbox.Include(ref pt4); }
public MyMwcObjectBuilder_FactionEnum ChooseFaction(MyMwcObjectBuilder_FactionEnum preferredFaction = MyMwcObjectBuilder_FactionEnum.None) { if (IsStory()) { Debug.Assert(IsHost); return(MySession.Static.Player.Faction); } else { m_factions.Clear(); foreach (var k in m_respawnPoints) { m_factions[k.Key] = 0; } foreach (var p in Peers.Players) { if (m_factions.ContainsKey((int)p.Faction)) { m_factions[(int)p.Faction]++; } } if (m_factions.ContainsKey((int)MySession.Static.Player.Faction)) { m_factions[(int)MySession.Static.Player.Faction]++; } m_possibleFactionCache.Clear(); int minFactionCount = int.MaxValue; foreach (var f in m_factions) { if (f.Value < minFactionCount) { m_possibleFactionCache.Clear(); m_possibleFactionCache.Add(f.Key); minFactionCount = f.Value; } else if (f.Value == minFactionCount) { m_possibleFactionCache.Add(f.Key); } } if (m_possibleFactionCache.Contains((int)preferredFaction)) { return(preferredFaction); } else if (m_possibleFactionCache.Count > 0) { return((MyMwcObjectBuilder_FactionEnum)MyMwcUtils.GetRandomItem(m_possibleFactionCache)); } else { return(MyMwcObjectBuilder_FactionEnum.Euroamerican); // Default faction } } }
// Update an explosion objects // Explosions blinks and then wait some time // After the explosion dissapears, it will move to a nearby location and // repeat private void updateExplosion() { if (m_fading && !m_IsWaiting) { Color.W -= MyDistantObjectsImpostorsConstants.EXPLOSION_FADE * m_blinkMultiplierDown; } else if (m_exploding) { Color.W += MyDistantObjectsImpostorsConstants.EXPLOSION_FADE * m_blinkMultiplierUp; } Radius = MathHelper.Lerp(m_startingRadius / 4f, m_startingRadius, Color.W); if (Color.W <= 0) { m_IsWaiting = true; Color.W = MathHelper.Clamp(Color.W, 0, 1); Color.X = 0; Color.Y = 0; Color.Z = 0; if (m_glowTime > m_explosionDelay) { float minNewHorizontal = m_targetHorizontal - (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float maxNewHorizontal = m_targetHorizontal + (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float minNewVertical = m_targetVertical - (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float maxNewVertical = m_targetVertical + (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); Color.X = MyMwcUtils.GetRandomFloat(170.0f / 255f, 1.0f); Color.Y = MyMwcUtils.GetRandomFloat(100.0f / 255f, 1.0f); Color.Z = MyMwcUtils.GetRandomFloat(0.0f, 40.0f / 255f); m_angleHorizontal = MyMwcUtils.GetRandomFloat(minNewHorizontal, maxNewHorizontal); m_angleVertical = MyMwcUtils.GetRandomFloat(minNewVertical, maxNewVertical); m_IsWaiting = false; m_exploding = true; m_fading = false; } } if (m_IsWaiting) { m_glowTime += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS; } else { m_glowTime = 0; } if (Color.W >= 1f) { m_fading = true; m_exploding = false; Color.W = MathHelper.Clamp(Color.W, 0, 1); // We set delay time here to avoid unnecessarry logic for it m_explosionDelay = MyMwcUtils.GetRandomInt((int)(MyDistantObjectsImpostorsConstants.EXPLOSION_WAIT_MILLISECONDS / 3f), (int)(MyDistantObjectsImpostorsConstants.EXPLOSION_WAIT_MILLISECONDS * 3f)); } }
public static int GetMaterialsCount() { if (voxelMaterialCount == -1) { voxelMaterialCount = MyMwcUtils.GetMaxValueFromEnum <MyMwcVoxelMaterialsEnum>() + 1; } return(voxelMaterialCount); }
private StringBuilder GetTemplatePrefix(MyMwcObjectBuilder_SmallShip_TypesEnum shipType) { StringBuilder prefix = new StringBuilder(); MyMwcUtils.AppendStringBuilder(prefix, ((MyGuiSmallShipHelperSmallShip)MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, (int)shipType)).Name); prefix.Append(" - "); return(prefix); }
static void InitNumberOfCores() { // Get number of cores of local machine. As I don't know what values it can return, I clamp it to <1..4> (min 1 core, max 4 cores). That are tested values. I can't test eight cores... NumberOfCores = Environment.ProcessorCount; MyMwcLog.WriteLine("Found processor count: " + NumberOfCores); // What we found NumberOfCores = MyMwcUtils.GetClampInt(NumberOfCores, 1, 16); MyMwcLog.WriteLine("Using processor count: " + NumberOfCores); // What are we really going use }