Fixed bugs for planets in multiple star systems:
- Moons of planets that orbited barycenters were not getting rendered - Picking was broken in solar systems with moving originsver1_5_1
parent
9d1e4db55f
commit
55b070d1a4
|
@ -403,13 +403,20 @@ void Body::getLifespan(double& begin, double& end) const
|
|||
|
||||
|
||||
#define SOLAR_IRRADIANCE 1367.6
|
||||
#define SOLAR_POWER 3.8462e26
|
||||
#define SOLAR_POWER 3.8462e26 // Watts
|
||||
|
||||
float Body::getLuminosity(const Star& sun,
|
||||
float distanceFromSun) const
|
||||
{
|
||||
return getLuminosity(sun.getLuminosity(), distanceFromSun);
|
||||
}
|
||||
|
||||
|
||||
float Body::getLuminosity(float sunLuminosity,
|
||||
float distanceFromSun) const
|
||||
{
|
||||
// Compute the total power of the star in Watts
|
||||
double power = SOLAR_POWER * sun.getLuminosity();
|
||||
double power = SOLAR_POWER * sunLuminosity;
|
||||
|
||||
// Compute the irradiance at a distance of 1au from the star in W/m^2
|
||||
// double irradiance = power / sphereArea(astro::AUtoKilometers(1.0) * 1000);
|
||||
|
@ -440,13 +447,23 @@ float Body::getApparentMagnitude(const Star& sun,
|
|||
float Body::getApparentMagnitude(const Star& sun,
|
||||
const Vec3d& sunPosition,
|
||||
const Vec3d& viewerPosition) const
|
||||
{
|
||||
return getApparentMagnitude(sun.getLuminosity(),
|
||||
sunPosition,
|
||||
viewerPosition);
|
||||
}
|
||||
|
||||
|
||||
float Body::getApparentMagnitude(float sunLuminosity,
|
||||
const Vec3d& sunPosition,
|
||||
const Vec3d& viewerPosition) const
|
||||
{
|
||||
double distanceToViewer = viewerPosition.length();
|
||||
double distanceToSun = sunPosition.length();
|
||||
float illuminatedFraction = (float) (1.0 + (viewerPosition / distanceToViewer) *
|
||||
(sunPosition / distanceToSun)) / 2.0f;
|
||||
|
||||
return astro::lumToAppMag(getLuminosity(sun, (float) distanceToSun) * illuminatedFraction, (float) astro::kilometersToLightYears(distanceToViewer));
|
||||
return astro::lumToAppMag(getLuminosity(sunLuminosity, (float) distanceToSun) * illuminatedFraction, (float) astro::kilometersToLightYears(distanceToViewer));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -137,12 +137,17 @@ class Body
|
|||
|
||||
float getLuminosity(const Star& sun,
|
||||
float distanceFromSun) const;
|
||||
float getLuminosity(float sunLuminosity,
|
||||
float distanceFromSun) const;
|
||||
float getApparentMagnitude(const Star& sun,
|
||||
float distanceFromSun,
|
||||
float distanceFromViewer) const;
|
||||
float getApparentMagnitude(const Star& sun,
|
||||
const Vec3d& sunPosition,
|
||||
const Vec3d& viewerPosition) const;
|
||||
float getApparentMagnitude(float sunLuminosity,
|
||||
const Vec3d& sunPosition,
|
||||
const Vec3d& viewerPosition) const;
|
||||
|
||||
Mat4d getLocalToHeliocentric(double) const;
|
||||
Point3d getHeliocentricPosition(double) const;
|
||||
|
|
|
@ -5790,13 +5790,20 @@ void Renderer::renderPlanetarySystem(const Star& sun,
|
|||
// relative to the observer.
|
||||
Vec3d posd = bodyPos - observerPos;
|
||||
|
||||
double distanceFromObserver = posd.length();
|
||||
float appMag = body->getApparentMagnitude(sun,
|
||||
bodyPos - Point3d(0, 0, 0),
|
||||
posd);
|
||||
// Compute the apparent magnitude; instead of summing the reflected
|
||||
// light from all nearby stars, we just consider the one with the
|
||||
// highest apparent brightness.
|
||||
float appMag = 100.0f;
|
||||
for (unsigned int li = 0; li < lightSources.size(); li++)
|
||||
{
|
||||
Vec3d sunPos = bodyPos - lightSources[li].position;
|
||||
appMag = min(appMag, body->getApparentMagnitude(lightSources[li].luminosity, sunPos, posd));
|
||||
}
|
||||
|
||||
Vec3f pos((float) posd.x, (float) posd.y, (float) posd.z);
|
||||
|
||||
// Compute the size of the planet/moon disc in pixels
|
||||
double distanceFromObserver = posd.length();
|
||||
float discSize = (body->getRadius() / (float) distanceFromObserver) / pixelSize;
|
||||
|
||||
// if (discSize > 1 || appMag < 1.0f / brightnessScale)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <celmath/vecmath.h>
|
||||
#include <celmath/intersect.h>
|
||||
#include <celutil/utf8.h>
|
||||
#include <cassert>
|
||||
#include "astro.h"
|
||||
#include "3dsmesh.h"
|
||||
#include "meshmanager.h"
|
||||
|
@ -428,9 +429,18 @@ Selection Universe::pickPlanet(SolarSystem& solarSystem,
|
|||
sin(tolerance/2.0) : ANGULAR_RES);
|
||||
PlanetPickInfo pickInfo;
|
||||
|
||||
// Transform the pick direction
|
||||
pickInfo.pickRay = Ray3d(astro::heliocentricPosition(origin,
|
||||
solarSystem.getCenter()), Vec3d(direction.x, direction.y, direction.z));
|
||||
Star* star = solarSystem.getStar();
|
||||
assert(star != NULL);
|
||||
|
||||
// Transform the pick ray origin into astrocentric coordinates
|
||||
UniversalCoord starPos = star->getPosition(when);
|
||||
Vec3d v = origin - starPos;
|
||||
Point3d astrocentricOrigin(astro::microLightYearsToKilometers(v.x),
|
||||
astro::microLightYearsToKilometers(v.y),
|
||||
astro::microLightYearsToKilometers(v.z));
|
||||
|
||||
pickInfo.pickRay = Ray3d(astrocentricOrigin,
|
||||
Vec3d(direction.x, direction.y, direction.z));
|
||||
|
||||
pickInfo.sinAngle2Closest = 1.0;
|
||||
pickInfo.closestDistance = 1.0e50;
|
||||
|
@ -746,6 +756,25 @@ Selection Universe::pick(const UniversalCoord& origin,
|
|||
{
|
||||
Selection sel;
|
||||
|
||||
closeStars.clear();
|
||||
getNearStars(origin, 1.0f, closeStars);
|
||||
for (vector<const Star*>::const_iterator iter = closeStars.begin();
|
||||
iter != closeStars.end(); iter++)
|
||||
{
|
||||
SolarSystem* solarSystem = getSolarSystem(*iter);
|
||||
if (solarSystem != NULL)
|
||||
{
|
||||
sel = pickPlanet(*solarSystem,
|
||||
origin, direction,
|
||||
when,
|
||||
faintestMag,
|
||||
tolerance);
|
||||
if (!sel.empty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
SolarSystem* closestSolarSystem = getNearestSolarSystem(origin);
|
||||
if (closestSolarSystem != NULL)
|
||||
{
|
||||
|
@ -755,6 +784,7 @@ Selection Universe::pick(const UniversalCoord& origin,
|
|||
faintestMag,
|
||||
tolerance);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sel.empty())
|
||||
sel = pickStar(origin, direction, when, faintestMag, tolerance);
|
||||
|
|
|
@ -107,6 +107,8 @@ class Universe
|
|||
AsterismList* asterisms;
|
||||
ConstellationBoundaries* boundaries;
|
||||
MarkerList* markers;
|
||||
|
||||
std::vector<const Star*> closeStars;
|
||||
};
|
||||
|
||||
#endif // UNIVERSE_H_
|
||||
|
|
Loading…
Reference in New Issue