public unsafe void CreateExplosionDebris(ref BoundingSphereD explosionSphere, float voxelsCountInPercent, MyVoxelMaterialDefinition voxelMaterial, MyVoxelBase voxelMap) { MatrixD matrix = MatrixD.CreateRotationX((double)MyUtils.GetRandomRadian()) * MatrixD.CreateRotationY((double)MyUtils.GetRandomRadian()); int count = this.m_voxelDebrisOffsets.Count; int num = this.m_voxelDebrisOffsets.Count; int num2 = 0; while (true) { if (num2 < num) { MyDebrisVoxel voxel = this.CreateVoxelDebris(((float)explosionSphere.Radius) * 100f, ((float)explosionSphere.Radius) * 1000f); if (voxel != null) { Vector3D result = (this.m_voxelDebrisOffsets[num2] * ((float)explosionSphere.Radius)) * 0.5780347f; Vector3D *vectordPtr1 = (Vector3D *)ref result; Vector3D.Transform(ref (Vector3D) ref vectordPtr1, ref matrix, out result); result += explosionSphere.Center; Vector3 vector = MyUtils.GetRandomVector3Normalized(); if (vector != Vector3.Zero) { (voxel.Debris as MyDebrisVoxel.MyDebrisVoxelLogic).Start(result, vector * MyUtils.GetRandomFloat(4f, 8f), voxelMaterial); } num2++; continue; } } return; } }
private MyDebrisVoxel CreateVoxelDebris(float minAmount, float maxAmount) { this.m_desc.Model = GetAnyAmountLessDebrisVoxel(minAmount, maxAmount); MyDebrisVoxel voxel1 = new MyDebrisVoxel(); voxel1.Debris.Init(this.m_desc); Interlocked.Increment(ref this.m_debrisCount); return(voxel1); }
public void CreateExplosionDebris(ref BoundingSphereD explosionSphere, float voxelsCountInPercent, MyVoxelMaterialDefinition voxelMaterial, MyVoxelBase voxelMap) { MyDebug.AssertDebug((voxelsCountInPercent >= 0.0f) && (voxelsCountInPercent <= 1.0f)); MyDebug.AssertDebug(explosionSphere.Radius > 0); ProfilerShort.Begin("CreateExplosionDebris"); ProfilerShort.Begin("Matrices"); // This matrix will rotate all newly created debrises, so they won't apper as alligned with coordinate system MatrixD randomRotationMatrix = MatrixD.CreateRotationX(MyUtils.GetRandomRadian()) * MatrixD.CreateRotationY(MyUtils.GetRandomRadian()); float highScale = MathHelper.Clamp((float)explosionSphere.Radius * m_debrisScaleUpper, 0, m_debrisScaleClamp); float lowScale = highScale * (m_debrisScaleLower / m_debrisScaleUpper); int objectsToGenerate = (int)(m_voxelDebrisOffsets.Count * voxelsCountInPercent); ProfilerShort.End(); ProfilerShort.Begin("m_positionOffsets"); const float SPHERE_FIT_CUBE_SCALE = 1 / 1.73f; // Resize sphere to fit inside cube int debrisCount = m_voxelDebrisOffsets.Count; //float debrisScale = Math.Max(explosionSphere.Radius / debrisCount, 0.2f); float debrisScale = Math.Max((float)explosionSphere.Radius, 0.2f); for (int i = 0; i < debrisCount; i++) { MyDebrisVoxel newObj = CreateVoxelDebris(); if (newObj == null) { break; // no point in continuing } Vector3D position = m_voxelDebrisOffsets[i] * (float)explosionSphere.Radius * SPHERE_FIT_CUBE_SCALE; Vector3D.Transform(ref position, ref randomRotationMatrix, out position); position += explosionSphere.Center; var initialVelocity = MyUtils.GetRandomVector3Normalized(); if (initialVelocity == Vector3.Zero) { continue; } initialVelocity *= MyUtils.GetRandomFloat(MyDebrisConstants.EXPLOSION_DEBRIS_INITIAL_SPEED_MIN, MyDebrisConstants.EXPLOSION_DEBRIS_INITIAL_SPEED_MAX); (newObj.Debris as MyDebrisVoxel.MyDebrisVoxelLogic).Start(position, initialVelocity, debrisScale, voxelMaterial); } ProfilerShort.End(); ProfilerShort.End(); }
private MyDebrisVoxel CreateVoxelDebris() { m_desc.ScaleMin = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MIN; m_desc.ScaleMax = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MAX; var newObj = new MyDebrisVoxel(); m_desc.Model = m_debrisVoxels[m_voxelDebrisModelIndex]; m_voxelDebrisModelIndex++; if (m_voxelDebrisModelIndex >= m_debrisVoxels.Count()) { m_voxelDebrisModelIndex = 0; } newObj.Debris.Init(m_desc); return(newObj); }
private MyDebrisVoxel CreateVoxelDebris() { if (m_debrisCount > MaxDebrisCount) { return(null); } m_desc.ScaleMin = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MIN; m_desc.ScaleMax = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MAX; var newObj = new MyDebrisVoxel(); m_desc.Model = m_debrisVoxels[m_voxelDebrisModelIndex]; m_voxelDebrisModelIndex++; m_voxelDebrisModelIndex %= m_debrisVoxels.Length; newObj.Debris.Init(m_desc); m_debrisCount++; return(newObj); }
private MyDebrisVoxel CreateVoxelDebris() { m_desc.ScaleMin = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MIN; m_desc.ScaleMax = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MAX; var newObj = new MyDebrisVoxel(); m_desc.Model = m_debrisVoxels[m_voxelDebrisModelIndex]; m_voxelDebrisModelIndex++; if (m_voxelDebrisModelIndex >= m_debrisVoxels.Count()) { m_voxelDebrisModelIndex = 0; } newObj.Debris.Init(m_desc); return newObj; }
private MyDebrisVoxel CreateVoxelDebris() { if (m_debrisCount > MaxDebrisCount) return null; m_desc.ScaleMin = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MIN; m_desc.ScaleMax = MyDebrisConstants.EXPLOSION_VOXEL_DEBRIS_INITIAL_SCALE_MAX; var newObj = new MyDebrisVoxel(); m_desc.Model = m_debrisVoxels[m_voxelDebrisModelIndex]; m_voxelDebrisModelIndex++; m_voxelDebrisModelIndex %= m_debrisVoxels.Length; newObj.Debris.Init(m_desc); m_debrisCount++; return newObj; }