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; }
private Vector3D GetInterpolatedPosition(MyEnvironmentalParticle particle) { Vector3D newPosition = particle.Position; Debug.Assert(particle.UserData != null); if (particle.UserData == null) { return(newPosition); } double globalRatio = MathHelper.Clamp((double)(MySandboxGame.TotalGamePlayTimeInMilliseconds - particle.BirthTime) / (double)particle.LifeTime, 0.0, 1.0); var pointCount = PathData.PathPointCount - 2; int pathIndex = 1 + (int)(globalRatio * pointCount); float localRatio = (float)(globalRatio * pointCount - Math.Truncate(globalRatio * pointCount)); PathData pathData = (particle.UserData as PathData?).Value; newPosition = Vector3D.CatmullRom(pathData.PathPoints[pathIndex - 1], pathData.PathPoints[pathIndex], pathData.PathPoints[pathIndex + 1], pathData.PathPoints[pathIndex + 2], localRatio); if (!newPosition.IsValid()) { newPosition = particle.Position; } return(newPosition); }
protected bool Despawn(MyEnvironmentalParticle particle) { if (particle == null) { return(false); } foreach (var activeParticle in m_activeParticles) { if (particle != activeParticle) { continue; } m_activeParticles.Remove(particle); particle.Deactivate(); m_nonActiveParticles.Add(particle); return(true); } return(false); }
private Vector3D GetInterpolatedPosition(MyEnvironmentalParticle particle) { Vector3D newPosition = particle.Position; Debug.Assert(particle.UserData != null); if (particle.UserData == null) return newPosition; double globalRatio = MathHelper.Clamp((double)(MySandboxGame.TotalGamePlayTimeInMilliseconds - particle.BirthTime) / (double)particle.LifeTime, 0.0, 1.0); var pointCount = PathData.PathPointCount - 2; int pathIndex = 1 + (int)(globalRatio * pointCount); float localRatio = (float)(globalRatio * pointCount - Math.Truncate(globalRatio * pointCount)); PathData pathData = (particle.UserData as PathData?).Value; newPosition = Vector3D.CatmullRom(pathData.PathPoints[pathIndex - 1], pathData.PathPoints[pathIndex], pathData.PathPoints[pathIndex + 1], pathData.PathPoints[pathIndex + 2], localRatio); if (!newPosition.IsValid()) newPosition = particle.Position; return newPosition; }
private void InitializePath(MyEnvironmentalParticle particle) { var pathData = new PathData(); if(pathData.PathPoints == null) pathData.PathPoints = new Vector3D[PathData.PathPointCount+2]; var gravityDirection = Vector3D.Normalize(MyGravityProviderSystem.CalculateNaturalGravityInPoint(particle.Position)); pathData.PathPoints[1] = particle.Position - Vector3D.Normalize(MyGravityProviderSystem.CalculateNaturalGravityInPoint(particle.Position)) * MyRandom.Instance.NextFloat()*2.5f; 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); 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; // TODO: Boxing }
protected bool Despawn(MyEnvironmentalParticle particle) { if (particle == null) return false; foreach(var activeParticle in m_activeParticles) { if (particle != activeParticle) continue; m_activeParticles.Remove(particle); particle.Deactivate(); m_nonActiveParticles.Add(particle); return true; } return false; }