mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:17:29 +02:00
Merge pull request #1142 from lordwaym/starfield-fix
Starfield fix and Milky Way
This commit is contained in:
commit
edf36f2a9e
2 changed files with 34 additions and 10 deletions
|
@ -15,26 +15,51 @@ const float Generator::STAR_COLORIZATION = 0.1;
|
||||||
void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) {
|
void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) {
|
||||||
InputVertices* vertices = & destination;
|
InputVertices* vertices = & destination;
|
||||||
//_limit = limit;
|
//_limit = limit;
|
||||||
|
|
||||||
timeval startTime;
|
timeval startTime;
|
||||||
gettimeofday(&startTime, NULL);
|
gettimeofday(&startTime, NULL);
|
||||||
|
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
vertices->clear();
|
vertices->clear();
|
||||||
vertices->reserve(limit);
|
vertices->reserve(limit);
|
||||||
|
|
||||||
|
const unsigned MILKY_WAY_WIDTH = 16.0; // width in degrees of one half of the Milky Way
|
||||||
|
const float MILKY_WAY_INCLINATION = 30.0f; // angle of Milky Way from horizontal in degrees
|
||||||
|
const float MILKY_WAY_RATIO = 0.6;
|
||||||
const unsigned NUM_DEGREES = 360;
|
const unsigned NUM_DEGREES = 360;
|
||||||
|
|
||||||
|
for(int star = 0; star < floor(limit * (1 - MILKY_WAY_RATIO)); ++star) {
|
||||||
for(int star = 0; star < limit; ++star) {
|
|
||||||
float azimuth, altitude;
|
float azimuth, altitude;
|
||||||
azimuth = ((float)rand() / (float) RAND_MAX) * NUM_DEGREES;
|
azimuth = (((float)rand() / (float) RAND_MAX) * NUM_DEGREES) - (NUM_DEGREES / 2);
|
||||||
altitude = (((float)rand() / (float) RAND_MAX) * NUM_DEGREES / 2) - NUM_DEGREES / 4;
|
altitude = (acos((2.0f * ((float)rand() / (float)RAND_MAX)) - 1.0f) / PI_OVER_180) + 90;
|
||||||
|
|
||||||
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int star = 0; star < ceil(limit * MILKY_WAY_RATIO); ++star) {
|
||||||
|
float azimuth = ((float)rand() / (float) RAND_MAX) * NUM_DEGREES;
|
||||||
|
float altitude = asin((float)rand() / (float) RAND_MAX * 2 - 1) * MILKY_WAY_WIDTH;
|
||||||
|
|
||||||
|
// we need to rotate the Milky Way band to the correct orientation in the sky
|
||||||
|
// convert from spherical coordinates to cartesian, rotate the point and then convert back.
|
||||||
|
// An improvement would be to convert all stars to cartesian at this point and not have to convert back.
|
||||||
|
|
||||||
|
float tempX = sin(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180);
|
||||||
|
float tempY = sin(altitude * PI_OVER_180);
|
||||||
|
float tempZ = -cos(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180);
|
||||||
|
|
||||||
|
float xangle = MILKY_WAY_INCLINATION * PI_OVER_180;
|
||||||
|
float newX = (tempX * cos(xangle)) - (tempY * sin(xangle));
|
||||||
|
float newY = (tempX * sin(xangle)) + (tempY * cos(xangle));
|
||||||
|
float newZ = tempZ;
|
||||||
|
|
||||||
|
azimuth = (atan2(newX,-newZ) + Radians::pi()) / PI_OVER_180;
|
||||||
|
altitude = atan2(-newY, hypotf(newX, newZ)) / PI_OVER_180;
|
||||||
|
|
||||||
|
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
||||||
|
}
|
||||||
|
|
||||||
qDebug("Took %llu msec to generate stars.\n", (usecTimestampNow() - usecTimestamp(&startTime)) / 1000);
|
qDebug("Took %llu msec to generate stars.\n", (usecTimestampNow() - usecTimestamp(&startTime)) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
#include "starfield/data/GpuVertex.h"
|
#include "starfield/data/GpuVertex.h"
|
||||||
#include "starfield/data/InputVertex.h"
|
|
||||||
|
|
||||||
using namespace starfield;
|
using namespace starfield;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue