mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Added a "flat" mode for environments that makes them follow you around on the
X/Z axes. The default environment is flat. Closes #2378.
This commit is contained in:
parent
735f563f5e
commit
20ae5c15f7
6 changed files with 45 additions and 14 deletions
|
@ -14,12 +14,12 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="src/Application.cpp" line="3575"/>
|
<location filename="src/Application.cpp" line="3577"/>
|
||||||
<source>Open Script</source>
|
<source>Open Script</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="src/Application.cpp" line="3576"/>
|
<location filename="src/Application.cpp" line="3578"/>
|
||||||
<source>JavaScript Files (*.js)</source>
|
<source>JavaScript Files (*.js)</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -113,18 +113,18 @@
|
||||||
<context>
|
<context>
|
||||||
<name>Menu</name>
|
<name>Menu</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="src/Menu.cpp" line="437"/>
|
<location filename="src/Menu.cpp" line="439"/>
|
||||||
<source>Open .ini config file</source>
|
<source>Open .ini config file</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="src/Menu.cpp" line="439"/>
|
<location filename="src/Menu.cpp" line="441"/>
|
||||||
<location filename="src/Menu.cpp" line="451"/>
|
<location filename="src/Menu.cpp" line="453"/>
|
||||||
<source>Text files (*.ini)</source>
|
<source>Text files (*.ini)</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="src/Menu.cpp" line="449"/>
|
<location filename="src/Menu.cpp" line="451"/>
|
||||||
<source>Save .ini config file</source>
|
<source>Save .ini config file</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -2150,7 +2150,8 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Application::getSunDirection() {
|
glm::vec3 Application::getSunDirection() {
|
||||||
return glm::normalize(_environment.getClosestData(_myCamera.getPosition()).getSunLocation() - _myCamera.getPosition());
|
return glm::normalize(_environment.getClosestData(_myCamera.getPosition()).getSunLocation(_myCamera.getPosition()) -
|
||||||
|
_myCamera.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::updateShadowMap() {
|
void Application::updateShadowMap() {
|
||||||
|
@ -2312,7 +2313,8 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
||||||
float alpha = 1.0f;
|
float alpha = 1.0f;
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
||||||
const EnvironmentData& closestData = _environment.getClosestData(whichCamera.getPosition());
|
const EnvironmentData& closestData = _environment.getClosestData(whichCamera.getPosition());
|
||||||
float height = glm::distance(whichCamera.getPosition(), closestData.getAtmosphereCenter());
|
float height = glm::distance(whichCamera.getPosition(),
|
||||||
|
closestData.getAtmosphereCenter(whichCamera.getPosition()));
|
||||||
if (height < closestData.getAtmosphereInnerRadius()) {
|
if (height < closestData.getAtmosphereInnerRadius()) {
|
||||||
alpha = 0.0f;
|
alpha = 0.0f;
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ glm::vec3 Environment::getGravity (const glm::vec3& position) {
|
||||||
|
|
||||||
foreach (const ServerData& serverData, _data) {
|
foreach (const ServerData& serverData, _data) {
|
||||||
foreach (const EnvironmentData& environmentData, serverData) {
|
foreach (const EnvironmentData& environmentData, serverData) {
|
||||||
glm::vec3 vector = environmentData.getAtmosphereCenter() - position;
|
glm::vec3 vector = environmentData.getAtmosphereCenter(position) - position;
|
||||||
float surfaceRadius = environmentData.getAtmosphereInnerRadius();
|
float surfaceRadius = environmentData.getAtmosphereInnerRadius();
|
||||||
if (glm::length(vector) <= surfaceRadius) {
|
if (glm::length(vector) <= surfaceRadius) {
|
||||||
// At or inside a planet, gravity is as set for the planet
|
// At or inside a planet, gravity is as set for the planet
|
||||||
|
@ -116,7 +116,7 @@ const EnvironmentData Environment::getClosestData(const glm::vec3& position) {
|
||||||
float closestDistance = FLT_MAX;
|
float closestDistance = FLT_MAX;
|
||||||
foreach (const ServerData& serverData, _data) {
|
foreach (const ServerData& serverData, _data) {
|
||||||
foreach (const EnvironmentData& environmentData, serverData) {
|
foreach (const EnvironmentData& environmentData, serverData) {
|
||||||
float distance = glm::distance(position, environmentData.getAtmosphereCenter()) -
|
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
|
||||||
environmentData.getAtmosphereOuterRadius();
|
environmentData.getAtmosphereOuterRadius();
|
||||||
if (distance < closestDistance) {
|
if (distance < closestDistance) {
|
||||||
closest = environmentData;
|
closest = environmentData;
|
||||||
|
@ -132,6 +132,8 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
|
||||||
// collide with the "floor"
|
// collide with the "floor"
|
||||||
bool found = findCapsulePlanePenetration(start, end, radius, glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), penetration);
|
bool found = findCapsulePlanePenetration(start, end, radius, glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), penetration);
|
||||||
|
|
||||||
|
glm::vec3 middle = (start + end) * 0.5f;
|
||||||
|
|
||||||
// get the lock for the duration of the call
|
// get the lock for the duration of the call
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
|
||||||
continue; // don't bother colliding with gravity-less environments
|
continue; // don't bother colliding with gravity-less environments
|
||||||
}
|
}
|
||||||
glm::vec3 environmentPenetration;
|
glm::vec3 environmentPenetration;
|
||||||
if (findCapsuleSpherePenetration(start, end, radius, environmentData.getAtmosphereCenter(),
|
if (findCapsuleSpherePenetration(start, end, radius, environmentData.getAtmosphereCenter(middle),
|
||||||
environmentData.getAtmosphereInnerRadius(), environmentPenetration)) {
|
environmentData.getAtmosphereInnerRadius(), environmentPenetration)) {
|
||||||
penetration = addPenetrations(penetration, environmentPenetration);
|
penetration = addPenetrations(penetration, environmentPenetration);
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -203,10 +205,12 @@ ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) {
|
void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) {
|
||||||
|
glm::vec3 center = data.getAtmosphereCenter(camera.getPosition());
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(data.getAtmosphereCenter().x, data.getAtmosphereCenter().y, data.getAtmosphereCenter().z);
|
glTranslatef(center.x, center.y, center.z);
|
||||||
|
|
||||||
glm::vec3 relativeCameraPos = camera.getPosition() - data.getAtmosphereCenter();
|
glm::vec3 relativeCameraPos = camera.getPosition() - center;
|
||||||
float height = glm::length(relativeCameraPos);
|
float height = glm::length(relativeCameraPos);
|
||||||
|
|
||||||
// use the appropriate shader depending on whether we're inside or outside
|
// use the appropriate shader depending on whether we're inside or outside
|
||||||
|
|
|
@ -46,6 +46,8 @@ PacketVersion versionForPacketType(PacketType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PacketTypeAvatarData:
|
case PacketTypeAvatarData:
|
||||||
return 3;
|
return 3;
|
||||||
|
case PacketTypeEnvironmentData:
|
||||||
|
return 1;
|
||||||
case PacketTypeParticleData:
|
case PacketTypeParticleData:
|
||||||
return 1;
|
return 1;
|
||||||
case PacketTypeDomainList:
|
case PacketTypeDomainList:
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// GameEngine.cpp
|
// GameEngine.cpp
|
||||||
EnvironmentData::EnvironmentData(int id) :
|
EnvironmentData::EnvironmentData(int id) :
|
||||||
_id(id),
|
_id(id),
|
||||||
|
_flat(true),
|
||||||
_gravity(0.0f),
|
_gravity(0.0f),
|
||||||
_atmosphereCenter(0, -1000, 0),
|
_atmosphereCenter(0, -1000, 0),
|
||||||
_atmosphereInnerRadius(1000),
|
_atmosphereInnerRadius(1000),
|
||||||
|
@ -25,12 +26,23 @@ EnvironmentData::EnvironmentData(int id) :
|
||||||
_sunBrightness(20.0f) {
|
_sunBrightness(20.0f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 EnvironmentData::getAtmosphereCenter(const glm::vec3& cameraPosition) const {
|
||||||
|
return _atmosphereCenter + (_flat ? glm::vec3(cameraPosition.x, 0.0f, cameraPosition.z) : glm::vec3());
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 EnvironmentData::getSunLocation(const glm::vec3& cameraPosition) const {
|
||||||
|
return _sunLocation + (_flat ? glm::vec3(cameraPosition.x, 0.0f, cameraPosition.z) : glm::vec3());
|
||||||
|
}
|
||||||
|
|
||||||
int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
||||||
unsigned char* bufferStart = destinationBuffer;
|
unsigned char* bufferStart = destinationBuffer;
|
||||||
|
|
||||||
memcpy(destinationBuffer, &_id, sizeof(_id));
|
memcpy(destinationBuffer, &_id, sizeof(_id));
|
||||||
destinationBuffer += sizeof(_id);
|
destinationBuffer += sizeof(_id);
|
||||||
|
|
||||||
|
memcpy(destinationBuffer, &_flat, sizeof(_flat));
|
||||||
|
destinationBuffer += sizeof(_flat);
|
||||||
|
|
||||||
memcpy(destinationBuffer, &_gravity, sizeof(_gravity));
|
memcpy(destinationBuffer, &_gravity, sizeof(_gravity));
|
||||||
destinationBuffer += sizeof(_gravity);
|
destinationBuffer += sizeof(_gravity);
|
||||||
|
|
||||||
|
@ -67,6 +79,9 @@ int EnvironmentData::parseData(const unsigned char* sourceBuffer, int numBytes)
|
||||||
memcpy(&_id, sourceBuffer, sizeof(_id));
|
memcpy(&_id, sourceBuffer, sizeof(_id));
|
||||||
sourceBuffer += sizeof(_id);
|
sourceBuffer += sizeof(_id);
|
||||||
|
|
||||||
|
memcpy(&_flat, sourceBuffer, sizeof(_flat));
|
||||||
|
sourceBuffer += sizeof(_flat);
|
||||||
|
|
||||||
memcpy(&_gravity, sourceBuffer, sizeof(_gravity));
|
memcpy(&_gravity, sourceBuffer, sizeof(_gravity));
|
||||||
sourceBuffer += sizeof(_gravity);
|
sourceBuffer += sizeof(_gravity);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ public:
|
||||||
void setID(int id) { _id = id; }
|
void setID(int id) { _id = id; }
|
||||||
int getID() const { return _id; }
|
int getID() const { return _id; }
|
||||||
|
|
||||||
|
void setFlat(bool flat) { _flat = flat; }
|
||||||
|
bool isFlat() const { return _flat; }
|
||||||
|
|
||||||
void setGravity(float gravity) { _gravity = gravity; }
|
void setGravity(float gravity) { _gravity = gravity; }
|
||||||
float getGravity() const { return _gravity; }
|
float getGravity() const { return _gravity; }
|
||||||
|
|
||||||
|
@ -42,6 +45,9 @@ public:
|
||||||
const glm::vec3& getSunLocation() const { return _sunLocation; }
|
const glm::vec3& getSunLocation() const { return _sunLocation; }
|
||||||
float getSunBrightness() const { return _sunBrightness; }
|
float getSunBrightness() const { return _sunBrightness; }
|
||||||
|
|
||||||
|
glm::vec3 getAtmosphereCenter(const glm::vec3& cameraPosition) const;
|
||||||
|
glm::vec3 getSunLocation(const glm::vec3& cameraPosition) const;
|
||||||
|
|
||||||
int getBroadcastData(unsigned char* destinationBuffer) const;
|
int getBroadcastData(unsigned char* destinationBuffer) const;
|
||||||
int parseData(const unsigned char* sourceBuffer, int numBytes);
|
int parseData(const unsigned char* sourceBuffer, int numBytes);
|
||||||
|
|
||||||
|
@ -49,6 +55,8 @@ private:
|
||||||
|
|
||||||
int _id;
|
int _id;
|
||||||
|
|
||||||
|
bool _flat;
|
||||||
|
|
||||||
float _gravity;
|
float _gravity;
|
||||||
|
|
||||||
glm::vec3 _atmosphereCenter;
|
glm::vec3 _atmosphereCenter;
|
||||||
|
|
Loading…
Reference in a new issue