3
0
Fork 0
mirror of https://github.com/JulianGro/overte.git synced 2025-04-30 06:42:52 +02:00

Added a "flat" mode for environments that makes them follow you around on the

X/Z axes.  The default environment is flat.  Closes .
This commit is contained in:
Andrzej Kapolka 2014-03-20 12:09:20 -07:00
parent 735f563f5e
commit 20ae5c15f7
6 changed files with 45 additions and 14 deletions

View file

@ -14,12 +14,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Application.cpp" line="3575"/>
<location filename="src/Application.cpp" line="3577"/>
<source>Open Script</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Application.cpp" line="3576"/>
<location filename="src/Application.cpp" line="3578"/>
<source>JavaScript Files (*.js)</source>
<translation type="unfinished"></translation>
</message>
@ -113,18 +113,18 @@
<context>
<name>Menu</name>
<message>
<location filename="src/Menu.cpp" line="437"/>
<location filename="src/Menu.cpp" line="439"/>
<source>Open .ini config file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Menu.cpp" line="439"/>
<location filename="src/Menu.cpp" line="451"/>
<location filename="src/Menu.cpp" line="441"/>
<location filename="src/Menu.cpp" line="453"/>
<source>Text files (*.ini)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Menu.cpp" line="449"/>
<location filename="src/Menu.cpp" line="451"/>
<source>Save .ini config file</source>
<translation type="unfinished"></translation>
</message>

View file

@ -2150,7 +2150,8 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
}
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() {
@ -2312,7 +2313,8 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
float alpha = 1.0f;
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
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()) {
alpha = 0.0f;

View file

@ -92,7 +92,7 @@ glm::vec3 Environment::getGravity (const glm::vec3& position) {
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
glm::vec3 vector = environmentData.getAtmosphereCenter() - position;
glm::vec3 vector = environmentData.getAtmosphereCenter(position) - position;
float surfaceRadius = environmentData.getAtmosphereInnerRadius();
if (glm::length(vector) <= surfaceRadius) {
// 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;
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
float distance = glm::distance(position, environmentData.getAtmosphereCenter()) -
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
environmentData.getAtmosphereOuterRadius();
if (distance < closestDistance) {
closest = environmentData;
@ -132,6 +132,8 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
// collide with the "floor"
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
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
}
glm::vec3 environmentPenetration;
if (findCapsuleSpherePenetration(start, end, radius, environmentData.getAtmosphereCenter(),
if (findCapsuleSpherePenetration(start, end, radius, environmentData.getAtmosphereCenter(middle),
environmentData.getAtmosphereInnerRadius(), environmentPenetration)) {
penetration = addPenetrations(penetration, environmentPenetration);
found = true;
@ -203,10 +205,12 @@ ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
}
void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) {
glm::vec3 center = data.getAtmosphereCenter(camera.getPosition());
glPushMatrix();
glTranslatef(data.getAtmosphereCenter().x, data.getAtmosphereCenter().y, data.getAtmosphereCenter().z);
glm::vec3 relativeCameraPos = camera.getPosition() - data.getAtmosphereCenter();
glTranslatef(center.x, center.y, center.z);
glm::vec3 relativeCameraPos = camera.getPosition() - center;
float height = glm::length(relativeCameraPos);
// use the appropriate shader depending on whether we're inside or outside

View file

@ -46,6 +46,8 @@ PacketVersion versionForPacketType(PacketType type) {
switch (type) {
case PacketTypeAvatarData:
return 3;
case PacketTypeEnvironmentData:
return 1;
case PacketTypeParticleData:
return 1;
case PacketTypeDomainList:

View file

@ -14,6 +14,7 @@
// GameEngine.cpp
EnvironmentData::EnvironmentData(int id) :
_id(id),
_flat(true),
_gravity(0.0f),
_atmosphereCenter(0, -1000, 0),
_atmosphereInnerRadius(1000),
@ -25,12 +26,23 @@ EnvironmentData::EnvironmentData(int id) :
_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 {
unsigned char* bufferStart = destinationBuffer;
memcpy(destinationBuffer, &_id, sizeof(_id));
destinationBuffer += sizeof(_id);
memcpy(destinationBuffer, &_flat, sizeof(_flat));
destinationBuffer += sizeof(_flat);
memcpy(destinationBuffer, &_gravity, sizeof(_gravity));
destinationBuffer += sizeof(_gravity);
@ -67,6 +79,9 @@ int EnvironmentData::parseData(const unsigned char* sourceBuffer, int numBytes)
memcpy(&_id, sourceBuffer, sizeof(_id));
sourceBuffer += sizeof(_id);
memcpy(&_flat, sourceBuffer, sizeof(_flat));
sourceBuffer += sizeof(_flat);
memcpy(&_gravity, sourceBuffer, sizeof(_gravity));
sourceBuffer += sizeof(_gravity);

View file

@ -19,6 +19,9 @@ public:
void setID(int id) { _id = id; }
int getID() const { return _id; }
void setFlat(bool flat) { _flat = flat; }
bool isFlat() const { return _flat; }
void setGravity(float gravity) { _gravity = gravity; }
float getGravity() const { return _gravity; }
@ -42,6 +45,9 @@ public:
const glm::vec3& getSunLocation() const { return _sunLocation; }
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 parseData(const unsigned char* sourceBuffer, int numBytes);
@ -49,6 +55,8 @@ private:
int _id;
bool _flat;
float _gravity;
glm::vec3 _atmosphereCenter;