public void SetGroupMask(MyGroupMask grMask) { for (int i = 0; i < m_RBElementList.Count; i++) { m_RBElementList[i].GroupMask = grMask; } }
// IMPORTANT: This class isn't realy inicialized by constructor, but by Start() // So don't initialize members here, do it in Start() protected virtual void Start(Vector3 position, float scale, MyGroupMask groupMask, bool explosionType) { Save = false; m_explosionType = explosionType; m_createdTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; Matrix worldMat = Matrix.Identity;//; Matrix.CreateScale(scale); Scale = scale; worldMat.Translation = position; SetWorldMatrix(worldMat); // This is here because we are restarting the object after it was sleeping in object pool this.Physics.Clear(); if (m_explosionType) { NeedsUpdate = true; this.Physics.PlayCollisionCueEnabled = true; //reset the physical radius of object! if ((this.Physics as MyPhysicsBody).GetRBElementList().Count > 0) { MyRBElement element = (this.Physics as MyPhysicsBody).GetRBElementList()[0]; (element as MyRBSphereElement).Radius = this.ModelLod0.BoundingSphere.Radius * scale; } //this.Physics.Enabled = true; this.Physics.GroupMask = groupMask; this.Physics.AngularDamping = MySession.Is25DSector ? 0.5f : 0.1f; //this.Physics.Update(); } else NeedsUpdate = false; }
static public bool AcceptCollision(MyRBElement el0, MyRBElement el1) { if (!MyPhysics.physicsSystem.GetRigidBodyModule().IsEnabledCollisionInLayers(el0.CollisionLayer, el1.CollisionLayer)) { return(false); } MyGroupMask mask0 = el0.GroupMask; MyGroupMask mask1 = el1.GroupMask; if ((mask0.m_Mask0 & mask1.m_Mask0) > 0) { return(false); } if ((mask0.m_Mask1 & mask1.m_Mask1) > 0) { return(false); } if ((mask0.m_Mask2 & mask1.m_Mask2) > 0) { return(false); } if ((mask0.m_Mask3 & mask1.m_Mask3) > 0) { return(false); } return(true); }
public void PushBackGroupMask(MyGroupMask mask) { System.UInt32 fullMask = 0xffffffff; if ((mask.m_Mask0 & fullMask) != 0) { // here we go m_BaseMask.m_Mask0 &= ~mask.m_Mask0; } else { if ((mask.m_Mask1 & fullMask) != 0) { // here we go m_BaseMask.m_Mask1 &= ~mask.m_Mask1; } else { if ((mask.m_Mask2 & fullMask) != 0) { // here we go m_BaseMask.m_Mask2 &= ~mask.m_Mask2; } else { if ((mask.m_Mask3 & fullMask) != 0) { // here we go m_BaseMask.m_Mask3 &= ~mask.m_Mask3; } } } } }
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 static MyGroupMask operator ~(MyGroupMask groupMask0) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = ~groupMask0.m_Mask0; groupMask.m_Mask1 = ~groupMask0.m_Mask1; groupMask.m_Mask2 = ~groupMask0.m_Mask2; groupMask.m_Mask3 = ~groupMask0.m_Mask3; return groupMask; }
public MyRBElement() { m_RBMaterial = new MyRBMaterial(0.5f, 0.5f, 0.7f, 0); m_RigidBody = null; m_ElementInteractions = new List <MyRBElementInteraction>(2); Flags = MyElementFlag.EF_RB_ELEMENT | MyElementFlag.EF_AABB_DIRTY; m_GroupMask = new MyGroupMask(); }
public static MyGroupMask operator |(MyGroupMask groupMask0, MyGroupMask groupMask1) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = groupMask0.m_Mask0 | groupMask1.m_Mask0; groupMask.m_Mask1 = groupMask0.m_Mask1 | groupMask1.m_Mask1; groupMask.m_Mask2 = groupMask0.m_Mask2 | groupMask1.m_Mask2; groupMask.m_Mask3 = groupMask0.m_Mask3 | groupMask1.m_Mask3; return groupMask; }
public static MyGroupMask operator &(MyGroupMask groupMask0, MyGroupMask groupMask1) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = groupMask0.m_Mask0 & groupMask1.m_Mask0; groupMask.m_Mask1 = groupMask0.m_Mask1 & groupMask1.m_Mask1; groupMask.m_Mask2 = groupMask0.m_Mask2 & groupMask1.m_Mask2; groupMask.m_Mask3 = groupMask0.m_Mask3 & groupMask1.m_Mask3; return groupMask; }
public MyRBElement() { m_RBMaterial = new MyRBMaterial(0.5f, 0.5f, 0.7f, 0); m_RigidBody = null; m_ElementInteractions = new List<MyRBElementInteraction>(2); Flags = MyElementFlag.EF_RB_ELEMENT | MyElementFlag.EF_AABB_DIRTY; m_GroupMask = new MyGroupMask(); }
public static MyGroupMask operator ~(MyGroupMask groupMask0) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = ~groupMask0.m_Mask0; groupMask.m_Mask1 = ~groupMask0.m_Mask1; groupMask.m_Mask2 = ~groupMask0.m_Mask2; groupMask.m_Mask3 = ~groupMask0.m_Mask3; return(groupMask); }
public static MyGroupMask operator &(MyGroupMask groupMask0, MyGroupMask groupMask1) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = groupMask0.m_Mask0 & groupMask1.m_Mask0; groupMask.m_Mask1 = groupMask0.m_Mask1 & groupMask1.m_Mask1; groupMask.m_Mask2 = groupMask0.m_Mask2 & groupMask1.m_Mask2; groupMask.m_Mask3 = groupMask0.m_Mask3 & groupMask1.m_Mask3; return(groupMask); }
public static MyGroupMask operator |(MyGroupMask groupMask0, MyGroupMask groupMask1) { MyGroupMask groupMask = new MyGroupMask(); groupMask.m_Mask0 = groupMask0.m_Mask0 | groupMask1.m_Mask0; groupMask.m_Mask1 = groupMask0.m_Mask1 | groupMask1.m_Mask1; groupMask.m_Mask2 = groupMask0.m_Mask2 | groupMask1.m_Mask2; groupMask.m_Mask3 = groupMask0.m_Mask3 | groupMask1.m_Mask3; return(groupMask); }
public bool Equals(MyGroupMask other) { return(other.m_Mask0 == m_Mask0 && other.m_Mask1 == m_Mask1 && other.m_Mask2 == m_Mask2 && other.m_Mask3 == m_Mask3); }
public bool Equals(MyGroupMask other) { return other.m_Mask0 == m_Mask0 && other.m_Mask1 == m_Mask1 && other.m_Mask2 == m_Mask2 && other.m_Mask3 == m_Mask3; }
public static void CreateExplosionDebris(ref BoundingSphere explosionSphere, float voxelsCountInPercent, MyMwcVoxelMaterialsEnum voxelMaterial, MyGroupMask groupMask, MyVoxelMap voxelMap) { MyCommonDebugUtils.AssertDebug((voxelsCountInPercent >= 0.0f) && (voxelsCountInPercent <= 1.0f)); MyCommonDebugUtils.AssertDebug(explosionSphere.Radius > 0); Render.MyRender.GetRenderProfiler().StartProfilingBlock("CreateExplosionDebris"); Render.MyRender.GetRenderProfiler().StartProfilingBlock("Matrices"); // This matrix will rotate all newly created debrises, so they won't apper as alligned with coordinate system Matrix randomRotationMatrix = Matrix.CreateRotationX(MyMwcUtils.GetRandomRadian()) * Matrix.CreateRotationY(MyMwcUtils.GetRandomRadian()); float highScale = MathHelper.Clamp(explosionSphere.Radius * DebrisScaleUpper, 0, DebrisScaleClamp); float lowScale = highScale * (DebrisScaleLower / DebrisScaleUpper); int objectsToGenerate = (int)(m_positionOffsets.Count * voxelsCountInPercent * MyRenderConstants.RenderQualityProfile.ExplosionDebrisCountMultiplier); long dbgObjectsGenerated = 0; Render.MyRender.GetRenderProfiler().EndProfilingBlock(); Render.MyRender.GetRenderProfiler().StartProfilingBlock("m_positionOffsets"); for (int i = 0; i < m_positionOffsets.Count; i++) { // IMPORTANT: If you place explosion debris exactly in the center of an explosion, JLX will fail or end in endless loop // Probably it's because it can't handle external force acting from inside the object. if (dbgObjectsGenerated >= objectsToGenerate) break; const float cubeInsideSphereMod = 1 / 1.73f; // Resize sphere to fit inside cube Vector3 position = m_positionOffsets[i] * explosionSphere.Radius * cubeInsideSphereMod; Vector3.Transform(ref position, ref randomRotationMatrix, out position); position += explosionSphere.Center; MyExplosionDebrisVoxel newObj = Allocate(); if (newObj != null) { // Check if new object won't intersect any existing triangle - because if yes, then it will decrease JLX performace a lot float randomNewScale = MyMwcUtils.GetRandomFloat(lowScale, highScale); BoundingSphere sphere = new BoundingSphere(position, newObj.m_modelLod0.BoundingSphere.Radius * randomNewScale); Render.MyRender.GetRenderProfiler().StartProfilingBlock("GetIntersectionWithSphere"); //This takes 4-5ms, is it necessary? // if (MyEntities.GetIntersectionWithSphere(ref sphere) == null) //if (false) { Render.MyRender.GetRenderProfiler().StartProfilingBlock("newObj.Start"); newObj.Start(position, randomNewScale, voxelMaterial, groupMask, true); MyEntities.Add(newObj); Render.MyRender.GetRenderProfiler().EndProfilingBlock(); /* Vector3 imp = position - explosionSphere.Center; imp.Normalize(); imp *= MyExplosionsConstants.EXPLOSION_STRENGTH_IMPULSE; newObj.Physics.AddForce(PhysicsManager.Physics.MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, imp, explosionSphere.Center, Vector3.Zero); */ if (MinerWars.AppCode.Game.Explosions.MyExplosion.DEBUG_EXPLOSIONS) m_debugVoxelSpheres.Add(sphere); dbgObjectsGenerated++; } //else { // Put back to object pool //newObj.Close(); } Render.MyRender.GetRenderProfiler().EndProfilingBlock(); //if (newObj.Physics.Enabled) // newObj.Physics.Enabled = false; // newObj.Physics.CollisionLayer = MyConstants.COLLISION_LAYER_UNCOLLIDABLE; } } Render.MyRender.GetRenderProfiler().EndProfilingBlock(); Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }
public void Start(float playerDamage, float damage, float empDamage, MyExplosionTypeEnum type, BoundingSphere explosionSphere, int lifespanInMiliseconds, MyExplosionForceDirection explosionForceDirection, MyGroupMask groupMask, bool createExplosionDebris, int cascadeLevel = 0, MyEntity hitEntity = null, float particleScale = 1.0f, MyEntity ownerEntity = null, bool affectVoxels = true, bool applyForceAndDamage = true, bool createDecals = true, Vector3? direction = null, bool forceDebris = false, bool playSound = false) { MyExplosionInfo info = new MyExplosionInfo(playerDamage, damage, empDamage, explosionSphere, type, playSound) { LifespanMiliseconds = lifespanInMiliseconds, ExplosionForceDirection = explosionForceDirection, GroupMask = groupMask, ExplosionFlags = MyExplosionFlags.CREATE_PARTICLE_EFFECT, CascadeLevel = cascadeLevel, HitEntity = hitEntity, ParticleScale = particleScale, OwnerEntity = ownerEntity, Direction = direction, VoxelCutoutScale = 1.0f, }; info.AffectVoxels = affectVoxels; info.ApplyForceAndDamage = applyForceAndDamage; info.CreateDebris = createExplosionDebris; info.CreateDecals = createDecals; info.ForceDebris = forceDebris; info.VoxelExplosionCenter = explosionSphere.Center; Start(ref info); }
public bool GetGroupMask(ref MyGroupMask mask) { System.UInt32 fullMask = 0xffffffff; System.UInt32 halfMask = 0x0000ffff; System.UInt32 lowMask = 0x000000ff; System.UInt32 lowestMask = 0x0000000f; System.UInt32 ulowestMask = 0x00000003; System.UInt32 uulowestMask = 0x00000001; mask.m_Mask0 = 0; mask.m_Mask1 = 0; mask.m_Mask2 = 0; mask.m_Mask3 = 0; System.UInt32 bits = 0; System.UInt32 index = 0; int offset = 0; if ((m_BaseMask.m_Mask0 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask0; index = 0; } else { if ((m_BaseMask.m_Mask1 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask1; index = 1; } else { if ((m_BaseMask.m_Mask2 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask2; index = 2; } else { if ((m_BaseMask.m_Mask3 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask3; index = 3; } else { return(false); } } } } if ((bits & halfMask) == halfMask) { bits = bits >> 16; offset += 16; } if ((bits & lowMask) == lowMask) { bits = bits >> 8; offset += 8; } if ((bits & lowestMask) == lowestMask) { bits = bits >> 4; offset += 4; } if ((bits & ulowestMask) == ulowestMask) { bits = bits >> 2; offset += 2; } if ((bits & uulowestMask) == uulowestMask) { bits = bits >> 1; offset += 1; } switch (index) { case 0: mask.m_Mask0 = ((uint)1 << offset); m_BaseMask.m_Mask0 |= mask.m_Mask0; break; case 1: mask.m_Mask1 = ((uint)1 << offset); m_BaseMask.m_Mask1 |= mask.m_Mask1; break; case 2: mask.m_Mask2 = ((uint)1 << offset); m_BaseMask.m_Mask2 |= mask.m_Mask2; break; case 3: mask.m_Mask3 = ((uint)1 << offset); m_BaseMask.m_Mask3 |= mask.m_Mask3; break; } return(true); }
public bool GetGroupMask(ref MyGroupMask mask) { System.UInt32 fullMask = 0xffffffff; System.UInt32 halfMask = 0x0000ffff; System.UInt32 lowMask = 0x000000ff; System.UInt32 lowestMask = 0x0000000f; System.UInt32 ulowestMask = 0x00000003; System.UInt32 uulowestMask = 0x00000001; mask.m_Mask0 = 0; mask.m_Mask1 = 0; mask.m_Mask2 = 0; mask.m_Mask3 = 0; System.UInt32 bits = 0; System.UInt32 index = 0; int offset = 0; if ((m_BaseMask.m_Mask0 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask0; index = 0; } else { if ((m_BaseMask.m_Mask1 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask1; index = 1; } else { if ((m_BaseMask.m_Mask2 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask2; index = 2; } else { if ((m_BaseMask.m_Mask3 & fullMask) != fullMask) { bits = m_BaseMask.m_Mask3; index = 3; } else { return false; } } } } if ((bits & halfMask) == halfMask) { bits = bits >> 16; offset += 16; } if ((bits & lowMask) == lowMask) { bits = bits >> 8; offset += 8; } if ((bits & lowestMask) == lowestMask) { bits = bits >> 4; offset += 4; } if ((bits & ulowestMask) == ulowestMask) { bits = bits >> 2; offset += 2; } if ((bits & uulowestMask) == uulowestMask) { bits = bits >> 1; offset += 1; } switch (index) { case 0: mask.m_Mask0 = ((uint)1 << offset); m_BaseMask.m_Mask0 |= mask.m_Mask0; break; case 1: mask.m_Mask1 = ((uint)1 << offset); m_BaseMask.m_Mask1 |= mask.m_Mask1; break; case 2: mask.m_Mask2 = ((uint)1 << offset); m_BaseMask.m_Mask2 |= mask.m_Mask2; break; case 3: mask.m_Mask3 = ((uint)1 << offset); m_BaseMask.m_Mask3 |= mask.m_Mask3; break; } return true; }