public static List <AstronomicalObject> GetSolarSystem() { return(new List <AstronomicalObject> { new AstronomicalObject(new Point3D(0, 0, 0), 109 * 2) { BodyName = "Słońce", Mass = 332_950 * AstronomicalObject.Me, Velocity = new Vector3D(0, 0, 0), Material = new DiffuseMaterial { DiffuseMap = SunTexture } },
public Helix.Material CreateMaterial(IGeometryMaterial mat, out bool isTransparent) { var diffuseTexture = ReadTexture(mat); if (diffuseTexture == null) { isTransparent = false; return(ErrorMaterial); } var material = new Helix.DiffuseMaterial { DiffuseMap = diffuseTexture }; material.Freeze(); isTransparent = mat.Flags.HasFlag(MaterialFlags.Transparent); return(material); }
public MainWindow() { DataContext = this; InitializeComponent(); #region Create planes var builder = new MeshBuilder(true, false, false); builder.AddRectangularMesh(BoxFaces.Front, 10, 10, 100, 100); PlaneGeometry = builder.ToMesh(); RedDiffuseMaterial = new hx.DiffuseMaterial() { DiffuseColor = new Color4(1f, 0f, 0f, 0.5f), }; BlueDiffuseMaterial = new hx.DiffuseMaterial() { DiffuseColor = new Color4(0f, 0f, 1f, 0.5f), }; RedPhongMaterial = new PhongMaterial() { AmbientColor = new Color4(1f, 0f, 0f, 0.5f), }; BluePhongMaterial = new PhongMaterial() { AmbientColor = new Color4(0f, 0f, 1f, 0.5f), }; var matrix = new Matrix3D(); matrix.Translate(new Vector3D(-125, -50, 0)); RedDiffusePlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(-125, -50, 50)); BlueDiffusePlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(25, -50, 0)); RedPhongPlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(25, -50, 50)); BluePhongPlaneTransform = new MatrixTransform3D(matrix); #endregion #region Create points PointsGeometry = new PointGeometry3D() { Positions = new Vector3Collection(new Vector3[] { new Vector3(0, 0, 5), }), }; PointsInstances = new List <Matrix>(); for (var x = -50; x <= 50; x += 10) { var matrix2 = Matrix.Translation(x, x / 5f, x / 5f); PointsInstances.Add(matrix2); } matrix = new Matrix3D(); matrix.Translate(new Vector3D(-75, 0, 0)); DiffusePointsTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(75, 0, 0)); PhongPointsTransform = new MatrixTransform3D(matrix); #endregion if (viewport.Camera is hx.OrthographicCamera camera) { camera.NearPlaneDistance = -5000; camera.FarPlaneDistance = 5000; camera.LookDirection = new Vector3D(0, 0, -10); camera.Position = new Point3D(0, 0, 11); camera.UpDirection = new Vector3D(0, 1, 0); camera.Width = 300; } }
public SolarSystem(int stars, int planets) { const double au = AstronomicalObject.Au; const double me = AstronomicalObject.Me; Bodies = new List <AstronomicalObject> { new AstronomicalObject(new Point3D(0, 0, 0), 10.9 * 2) /* sun */ { BodyName = stars == 1 ? "Gwiazda" : "Gwiazda A", Mass = 333_000 * me * Utils.GetNormalRandom(10, 2), Velocity = new Vector3D(0, 0, 0), Material = new DiffuseMaterial { DiffuseMap = SunTexture } } }; if (stars > 1) { var mass = 333_000 * AstronomicalObject.Me * Utils.GetNormalRandom(1, 0.2); var position = -AstronomicalObject.Au * 0.3; Bodies.Add(new AstronomicalObject(new Point3D(position, 0, 0), 10.9) /* sun */ { BodyName = "Gwiazda B", Mass = mass, Velocity = new Vector3D(0, 0, -GetVelocity(Math.Abs(position), Bodies[0].Mass + mass)) * 1.15, Material = new DiffuseMaterial { DiffuseMap = SunTexture } }); Bodies[0].Velocity = -Bodies[1].Velocity * mass / Bodies[0].Mass; } var centerMass = Bodies.Sum(body => body.Mass); for (var i = 1; i <= planets; i++) { var mass = Utils.GetNormalRandom(me * 2, me * 0.8); var position = new Point3D(Utils.GetNormalRandom(au * i * 0.7, au * 0.1), 0, 0); var velocity = GetVelocity(position.X, centerMass) * Utils.GetNormalRandom(1.1, 0.1); var a = Utils.GetNormalRandom(0, Math.PI * 0.05); Bodies.Add(new AstronomicalObject(position, mass / me * 5) { BodyName = $"Planeta {(char) (64 + i)}", Mass = mass, Velocity = new Vector3D(0, Math.Sin(a) * velocity, -Math.Cos(a) * velocity), Material = new DiffuseMaterial { DiffuseColor = Utils.GetRandomColor4() } }); } OrbitPrevPoints = new List <Point3D>(); OrbitBuilders = new List <LineBuilder>(); OrbitModels = new List <LineGeometryModel3D>(); foreach (var body in Bodies) { OrbitBuilders.Add(new LineBuilder()); OrbitModels.Add(new LineGeometryModel3D { Thickness = 0.5, Color = Colors.Yellow }); OrbitPrevPoints.Add(body.Position); } }