/// <summary> /// eigentliche Berechnung eines neuen Punktes /// </summary> public void NewPoint() { //Neuen Punkt errechnen Random rnd1 = new Random(m_lPoints.Count); Random rnd2 = new Random(rnd1.Next()); angle = (float)rnd2.NextDouble() * 360; angle2 = (float)rnd1.NextDouble() * 360; //Neuen Punkt hinzufuegen Point3 StPoint = new Point3(0, 0, 50); Point3 Point = new Point3(0, 0, 0); Matrix Rot = new Matrix(); Matrix Rot2 = new Matrix(); Matrix Rot3 = new Matrix(); Rot.RotMatrix(angle, new Point3(1f, 0f, 0f)); Rot2.RotMatrix(angle2, new Point3(0f, 0f, 1f)); Rot3.RotMatrix(angle, new Point3(1f, 0f, 1f)); Point = MMath.MatDotPoint(Rot, StPoint); Point = MMath.MatDotPoint(Rot2, Point); m_lPoints.Add(Point); }
/// <summary> /// ein Tick im Thread /// </summary> private void ThreadTick() { // Bewegung _Pos.x += _Dir.x * _Speed; _Pos.y += _Dir.y * _Speed; _Pos.z += _Dir.z * _Speed; // Drehung um _dAngle Grad um Z Axe. Point3 ZAxis = new Point3(0, 0, 1); Matrix rot = new Matrix(); rot.RotMatrix(_dAngle, ZAxis); _Dir.assign(MM.MatDotPoint(rot, (Point3)_Dir)); // Rotation _AngleZ = (_AngleZ - 1f) % 360; _SunAngleZ = (_SunAngleZ + 0.01f) % 360; // Trace if (showTrace) { lock (trace) { PPoint newPoint = new PPoint(0, 0, 0, 2000f); if (trace.Count > 0) { newPoint.assign((Point3)_Pos - (Point3)trace.Last <PPoint>()); while (trace[0].Alpha == 0) { trace.RemoveAt(0); } } else { newPoint.assign(_Pos); } float n = (float)Math.Sqrt(Math.Pow(newPoint.x, 2) + Math.Pow(newPoint.y, 2) + Math.Pow(newPoint.z, 2)); if (n > 0.1) { trace.Add(new PPoint(_Pos.x, _Pos.y, _Pos.z, 2000f)); } } } else { trace.Clear(); } }
/// <summary> /// Eine um die Hauptsonne kreisende Sonne wird erstellt. Diese kann auch größer sein, was sie aber nicht zur Hauptsonne macht. /// </summary> private void AddSun() { if (suncount < _Light.Length - 1) { float Massfak = (float)rnd.Next(1, 3) * 5 * PlanetAdvanced2.initSunMass; float Mass = (float)rnd.NextDouble() * Massfak; Point3 Pos = RndPosToSun(Sun, true, false); // Zufällige Position bezgl der Sonne Point3 Dir = MM.MatDotPoint(RotMatrix90z(), Pos - Sun.Position); // Richtung 90Grad zum SonnenVektor Dir.Normalize(); // BewegungsRichtung normalisieren. //Dir *= (float)((rnd.NextDouble() * 3) + 2f) * 40f; // Speed zurechnen. Kosmische Gesch. schlug hier immer fehl. float distance = Point3.Distance(Sun.Position, Pos); Dir *= (float)Math.Sqrt(G * Sun.Mass / distance); // *fak(); // 1. kosmische Geschwindigkeit (Rotation auf Kreisbahn). Dir += Sun.Direction; // Bewegung der Bezugssonne draufrechnen, damit Sich Planet mitbewegt. float[] Color = { (float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble() }; suncount++; // Sonnenzähler erhöhen. (wichtig für Lichtquellen); Objects.Add(new o2Sun(Pos, Dir, Mass, Color, _Light[suncount])); } }
} // nicht nötig /// <summary> /// Tastendruck auf Maus /// </summary> /// <param name="e">Mouse Event Argument</param> public void MouseButton(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point3 pos = new Point3(-Cam.X, -Cam.Y, -Cam.Z + 0.1f); Point3 look = new Point3(1, 0, 0); Point3 zAxes = new Point3(0, 0, 1); Point3 yAxes = new Point3(0, 1, 0); Matrix rot1 = new Matrix(); Matrix rot2 = new Matrix(); rot1.RotMatrix(Cam.angleZ + 90, zAxes); rot2.RotMatrix(Cam.angleX - 90, yAxes); Matrix rotRes = MMAth.MatDotMat(rot1, rot2); look = MMAth.MatDotPoint(rotRes, look); _Shots.Add(new Shot(Cam, look, 1f, 0.0f, 0.0f, 0.5f)); } }
/// <summary> /// Fügt einem Zentralobjekt untergeordnete es umkreisende Objekte hinzu /// </summary> /// <param name="_ZentralObjekt">Dies ist das Zentralobjekt um welches die hinzugefügten kreisen sollen</param> /// <param name="cnt">Anzahl der das Zentralobjekt umkreisenden Objekte</param> private void AddPlanet(o2Object _ZentralObjekt, int cnt) { bool SunIsParent = _ZentralObjekt is o2Sun; // ist das Zentralobjekt eine Sonne? for (int i = 0; i < cnt; i++) { float Mass = 1f; if (SunIsParent) // Planet { int ps = rnd.Next(28, 30); Mass = (float)rnd.NextDouble() * (float)Math.Pow(10, ps) * PlanetAdvanced2.UniFak; // Größe Abhängig von Basisgröße der Planeten } else // Mond. { float f = rnd.Next(80, 1000); // Faktor um wie viel der Mond kleiner sein soll, als der Körper um den er kreist. Mass = _ZentralObjekt.Mass / f; // Erd-Mond ist ca. 1/81 der Erdmasse. Da er der Größte im Sonnensystem ist, nehm ich das Verhältnis als max. an. } Point3 Pos = RndPosToSun(_ZentralObjekt, false, SunIsParent); // Position soll relativ zum Zentralkörper sein float distance = Point3.Distance(_ZentralObjekt.Position, Pos); Point3 Dir = MM.MatDotPoint(RotMatrix90z(), Pos - _ZentralObjekt.Position); // Richtung 90Grad zum Sonnenwinkel Dir.Normalize(); Dir *= (float)Math.Sqrt(PlanetAdvanced2.G * _ZentralObjekt.Mass / distance); // *fak(); // 1. kosmische Geschwindigkeit (Rotation auf Kreisbahn). Dir += Dir * ((float)rnd.NextDouble() / 10f); //* fak()); // ein wenig Varianz, um es interessannt zu machen. Dir += _ZentralObjekt.Direction; // Bewegung der Bezugssonne draufrechnen, damit Sich Planet mitbewegt. float[] Color = { (float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble() }; // Farbe ist zufällig o2Object p = new o2Object(Pos, Dir, Mass, Color, null); Objects.Add(p); getList().Add(p); if (SunIsParent) { int c = rnd.Next(0, 4); AddPlanet(p, c); } } }
private void AddPlanet() { lock (Objects) { Point3 P1Pos = new Point3(0f, 0f, 0f); int fak = rnd.Next(2) - 1 < 0 ? -1 : 1; P1Pos.x = fak * (float)rnd.Next(100, 100 + (int)Sun.Size); fak = rnd.Next(2) - 1 < 0 ? -1 : 1; P1Pos.y = fak * (float)rnd.Next(100, 100 + (int)Sun.Size); Point3 P1Dir = new Point3(0f, 0f, 0f); Matrix rot = new Matrix(); Point3 ZAxis = new Point3(0f, 0f, 1f); rot.RotMatrix(90, ZAxis); P1Dir = MM.MatDotPoint(rot, P1Pos); P1Dir.Normalize(); P1Dir = P1Dir * rnd.NextDouble() * 3f; Objects.Add(new oPlanet(P1Pos, P1Dir, Sun, ((float)rnd.NextDouble() * 3f) + 2f, (float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble())); } }