private void setEyeBehindPlanet(Planet pl) { sp.Eye.Position.Angle = new SpatialAngle(pl.CurrentPosition.Angle); //sp.Eye.Position.Angle.Horizontal += 0.005; sp.Eye.Position.Distance = pl.CurrentPosition.Distance + pl.Radius*3; }
private Planet CreatePlanetFromData(PlanetData data, float distanceScale, float planetScale, float moonDistSc) { Sphere sphere = new Sphere(data.Radius / planetScale, data.Color, data.Name); Orbit orbit = new Orbit(data.DaysForRevolution, new Ecliptic(data.DistanceFromCenter/distanceScale, data.EclipticEccentrity), new SpatialAngle(data.EclipticAngleX * Math.PI / 180f, data.EclipticInclination * Math.PI / 180f), data.StartAngle*Math.PI/180f); Rotation rotation = new Rotation(data.HoursForRotation, 0, new SpatialAngle(data.TiltAngleX * Math.PI / 180f, data.TiltAngleUP * Math.PI / 180f)); Planet planet = new Planet(sphere, data.Reflectivity, rotation, orbit, CreateRingsFromData(data.Rings, planetScale)); if (data.Satelites != null) { foreach (PlanetData moon in data.Satelites) { planet.Satelites.Add(CreatePlanetFromData(moon, distanceScale/moonDistSc, planetScale, moonDistSc)); } } return planet; }
private void CalculateCurrentPosition(Planet pl) { pl.CurrentPosition.Angle.Horizontal += pl.Orbit.RevolutionAnglePerHour; pl.CurrentRotationAngle += pl.Rotation.RotationAnglePerHour; double ecc = (Math.Pow(Math.Sin(pl.CurrentPosition.Angle.Horizontal)+1, 3) * pl.Orbit.Ecliptic.Eccentricity * 0.5); pl.CurrentPosition.Distance = pl.Orbit.Ecliptic.MeanRadius * (1 + ecc); foreach (Planet s in pl.Satelites) { CalculateCurrentPosition(s); } }
private void DrawPlanet(Planet planet, Star star) { Gl.glPushMatrix(); rotateSphereOrbit(planet.Orbit); goToCenterOfOrbit(planet.Orbit); goToPosition(planet.CurrentPosition); if (drawCoordinates) { SetMaterialForSun(planet.Color, 1); Gl.glRasterPos3f((planet.Radius*1.5).ToFloat(), 0, 0); text(planet.Name); ReSetMaterialForSun(); } if (Eye.LookingAt == planet) { SpatialAngle planetAngle = new SpatialAngle( planet.CurrentPosition.Angle.Horizontal + planet.Orbit.Up.Horizontal, planet.CurrentPosition.Angle.Vertical + planet.Orbit.Up.Vertical); Eye.LookAt = new Position3D(planetAngle, planet.CurrentPosition.Distance); if (tracking) { Eye.LookingAt = planet; } } if (Eye.LookingFrom == planet) { SpatialAngle planetAngle = new SpatialAngle( planet.CurrentPosition.Angle.Horizontal + planet.Orbit.Up.Horizontal + star.Orbit.Up.Horizontal, planet.CurrentPosition.Angle.Vertical + planet.Orbit.Up.Vertical + star.Orbit.Up.Vertical); Eye.Position = new Position3D(planetAngle, planet.CurrentPosition.Distance + planet.Radius * 5); if (tracking) { Eye.LookingFrom = planet; } } rotatePlanetAxis(planet); foreach (Planet s in planet.Satelites) { DrawPlanet(s, star); } Gl.glRotated(planet.CurrentRotationAngle * 180 / Math.PI, 1, 0, 0); SetMaterialForPlanet(planet, star.Shinines.ToFloat()); if (drawCoordinates) { drawCoordinateSystem(planet.Radius); } drawSphere(planet); if (planet.Rings != null) { SetMaterialForPlanet(planet, (star.Shinines / 10f).ToFloat()); Gl.glRotated(90, 0, 1, 0); foreach (Projektni_zadatak.Bodies.Ring r in planet.Rings) { drawDisc(r); } } //Glut.glutWireCone(planet.Radius, planet.Radius, 30, 30); ReSetMaterialForPlanet(); Gl.glPopMatrix(); }
private static void SetMaterialForPlanet(Planet planet, float sunShinines) { float reflectivity = planet.Reflectivity.ToFloat(); SphereColor col = planet.Color; float br = reflectivity * sunShinines; float red = col.Red, green = col.Green, blue = col.Blue; Gl.glColor3d(red, green, blue); float[] mat_pla_dif = { red, green, blue, (1.0).ToFloat() }; float[] mat_pla_amb = { red / 10f, green / 10f, blue / 10f, (1.0).ToFloat() }; float[] mat_pla_spec = { red * br, green * br, blue * br, (1.0).ToFloat() }; Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, mat_pla_dif); Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR, mat_pla_spec); Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, mat_pla_amb); Gl.glMaterialf(Gl.GL_FRONT_AND_BACK, Gl.GL_REFLECTION_MAP_EXT, reflectivity); //Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_EMISSION, mat_pla_dif); }
private static void rotatePlanetAxis(Planet planet) { Gl.glRotated(planet.Rotation.AxisTilt.Vertical * 180 / Math.PI, 0, 1, 0); Gl.glRotated(planet.Rotation.AxisTilt.Horizontal * 180 / Math.PI, 1, 0, 0); }