mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 06:29:50 +02:00
Starfield now generates stars at startup rather than load them from the server - approx. 50msec to load 50,000 stars. STAR_COLORIZATION const in Generator.cpp is used to defined how colorful the stars should be. STARFIELD_NUM_STARS and STARFIELD_SEED sets the number of stars and the random number seed used to generate the starfield.
53 lines
No EOL
1.6 KiB
C++
53 lines
No EOL
1.6 KiB
C++
//
|
|
// starfield/Generator.cpp
|
|
// interface
|
|
//
|
|
// Created by Chris Barnard on 10/13/13.
|
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#include "starfield/Generator.h"
|
|
|
|
using namespace starfield;
|
|
|
|
const float Generator::STAR_COLORIZATION = 0.1;
|
|
|
|
void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) {
|
|
InputVertices* vertices = & destination;
|
|
//_limit = limit;
|
|
|
|
timeval startTime;
|
|
gettimeofday(&startTime, NULL);
|
|
|
|
srand(seed);
|
|
|
|
vertices->clear();
|
|
vertices->reserve(limit);
|
|
|
|
const unsigned NUM_DEGREES = 360;
|
|
|
|
|
|
for(int star = 0; star < limit; ++star) {
|
|
float azimuth, altitude;
|
|
azimuth = ((float)rand() / (float) RAND_MAX) * NUM_DEGREES;
|
|
altitude = (((float)rand() / (float) RAND_MAX) * NUM_DEGREES / 2) - NUM_DEGREES / 4;
|
|
|
|
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
|
}
|
|
|
|
qDebug("Took %llu msec to generate stars.\n", (usecTimestampNow() - usecTimestamp(&startTime)) / 1000);
|
|
}
|
|
|
|
// computeStarColor
|
|
// - Generate a star color.
|
|
//
|
|
// colorization can be a value between 0 and 1 specifying how colorful the resulting star color is.
|
|
//
|
|
// 0 = completely black & white
|
|
// 1 = very colorful
|
|
unsigned Generator::computeStarColor(float colorization) {
|
|
unsigned char red = rand() % 256;
|
|
unsigned char green = round((red * (1 - colorization)) + ((rand() % 256) * colorization));
|
|
unsigned char blue = round((red * (1 - colorization)) + ((rand() % 256) * colorization));
|
|
return red | green << 8 | blue << 16;
|
|
} |