From b4dd6b57aaf9dda78b2cf1949f1c513181824c12 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 6 May 2013 13:30:07 -0700 Subject: [PATCH] Starting on environment bits. --- interface/src/Environment.cpp | 12 +++++ interface/src/Environment.h | 24 +++++++++ interface/src/main.cpp | 6 +++ libraries/shared/src/PacketHeaders.h | 1 + libraries/voxels/src/EnvironmentData.cpp | 69 ++++++++++++++++++++++++ libraries/voxels/src/EnvironmentData.h | 43 +++++++++++++++ 6 files changed, 155 insertions(+) create mode 100644 interface/src/Environment.cpp create mode 100644 interface/src/Environment.h create mode 100644 libraries/voxels/src/EnvironmentData.cpp create mode 100644 libraries/voxels/src/EnvironmentData.h diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp new file mode 100644 index 0000000000..3bff8961df --- /dev/null +++ b/interface/src/Environment.cpp @@ -0,0 +1,12 @@ +// +// Environment.cpp +// interface +// +// Created by Andrzej Kapolka on 5/6/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. + +#include "Environment.h" + +void Environment::render() { + +} diff --git a/interface/src/Environment.h b/interface/src/Environment.h new file mode 100644 index 0000000000..e028d86e32 --- /dev/null +++ b/interface/src/Environment.h @@ -0,0 +1,24 @@ +// +// Environment.h +// interface +// +// Created by Andrzej Kapolka on 5/16/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__Environment__ +#define __interface__Environment__ + +#include "EnvironmentData.h" + +class Environment : public EnvironmentData { +public: + + void render(); + +private: + + +}; + +#endif /* defined(__interface__Environment__) */ diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 424e4113bc..3a2e3a9acd 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -74,6 +74,7 @@ #include #include #include "VoxelSystem.h" +#include "Environment.h" #include "Oscilloscope.h" #include "UDPSocket.h" #include "SerialInterface.h" @@ -136,6 +137,8 @@ VoxelSystem voxels; bool wantToKillLocalVoxels = false; +Environment environment; + #ifndef _WIN32 Audio audio(&audioScope, &myAvatar); @@ -1645,6 +1648,9 @@ void* networkReceive(void* args) { case PACKET_HEADER_ERASE_VOXEL: voxels.parseData(incomingPacket, bytesReceived); break; + case PACKET_HEADER_ENVIRONMENT_DATA: + environment.parseData(incomingPacket, bytesReceived); + break; case PACKET_HEADER_BULK_AVATAR_DATA: AgentList::getInstance()->processBulkAgentData(&senderAddress, incomingPacket, diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index ed2e5d5638..4fd6aa105d 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -23,5 +23,6 @@ const char PACKET_HEADER_ERASE_VOXEL = 'E'; const char PACKET_HEADER_VOXEL_DATA = 'V'; const char PACKET_HEADER_BULK_AVATAR_DATA = 'X'; const char PACKET_HEADER_TRANSMITTER_DATA = 't'; +const char PACKET_HEADER_ENVIRONMENT_DATA = 'e'; #endif diff --git a/libraries/voxels/src/EnvironmentData.cpp b/libraries/voxels/src/EnvironmentData.cpp new file mode 100644 index 0000000000..9fff790810 --- /dev/null +++ b/libraries/voxels/src/EnvironmentData.cpp @@ -0,0 +1,69 @@ +// +// EnvironmentData.cpp +// interface +// +// Created by Andrzej Kapolka on 5/6/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. + +#include + +#include "EnvironmentData.h" +#include "PacketHeaders.h" + +int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const { + unsigned char* bufferStart = destinationBuffer; + + memcpy(destinationBuffer, &_atmosphereCenter, sizeof(_atmosphereCenter)); + destinationBuffer += sizeof(_atmosphereCenter); + + memcpy(destinationBuffer, &_atmosphereInnerRadius, sizeof(_atmosphereInnerRadius)); + destinationBuffer += sizeof(_atmosphereInnerRadius); + + memcpy(destinationBuffer, &_atmosphereOuterRadius, sizeof(_atmosphereOuterRadius)); + destinationBuffer += sizeof(_atmosphereOuterRadius); + + memcpy(destinationBuffer, &_rayleighScattering, sizeof(_rayleighScattering)); + destinationBuffer += sizeof(_rayleighScattering); + + memcpy(destinationBuffer, &_mieScattering, sizeof(_mieScattering)); + destinationBuffer += sizeof(_mieScattering); + + memcpy(destinationBuffer, &_sunLocation, sizeof(_sunLocation)); + destinationBuffer += sizeof(_sunLocation); + + memcpy(destinationBuffer, &_sunBrightness, sizeof(_sunBrightness)); + destinationBuffer += sizeof(_sunBrightness); + + return destinationBuffer - bufferStart; +} + +int EnvironmentData::parseData(unsigned char* sourceBuffer, int numBytes) { + // increment to push past the packet header + sourceBuffer++; + + unsigned char* startPosition = sourceBuffer; + + memcpy(&_atmosphereCenter, sourceBuffer, sizeof(_atmosphereCenter)); + sourceBuffer += sizeof(_atmosphereCenter); + + memcpy(&_atmosphereInnerRadius, sourceBuffer, sizeof(_atmosphereInnerRadius)); + sourceBuffer += sizeof(_atmosphereInnerRadius); + + memcpy(&_atmosphereOuterRadius, sourceBuffer, sizeof(_atmosphereOuterRadius)); + sourceBuffer += sizeof(_atmosphereOuterRadius); + + memcpy(&_rayleighScattering, sourceBuffer, sizeof(_rayleighScattering)); + sourceBuffer += sizeof(_rayleighScattering); + + memcpy(&_mieScattering, sourceBuffer, sizeof(_mieScattering)); + sourceBuffer += sizeof(_mieScattering); + + memcpy(&_sunLocation, sourceBuffer, sizeof(_sunLocation)); + sourceBuffer += sizeof(_sunLocation); + + memcpy(&_sunBrightness, sourceBuffer, sizeof(_sunBrightness)); + sourceBuffer += sizeof(_sunBrightness); + + return sourceBuffer - startPosition; +} + diff --git a/libraries/voxels/src/EnvironmentData.h b/libraries/voxels/src/EnvironmentData.h new file mode 100644 index 0000000000..12ebcd4a94 --- /dev/null +++ b/libraries/voxels/src/EnvironmentData.h @@ -0,0 +1,43 @@ +// +// EnvironmentData.h +// interface +// +// Created by Andrzej Kapolka on 5/16/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__EnvironmentData__ +#define __interface__EnvironmentData__ + +#include + +class EnvironmentData { +public: + + void setAtmosphereCenter(const glm::vec3& center); + void setAtmosphereInnerRadius(float radius); + void setAtmosphereOuterRadius(float radius); + + void setRayleighScattering(float scattering); + void setMieScattering(float scattering); + + void setSunLocation(const glm::vec3 location); + void setSunBrightness(float brightness); + + int getBroadcastData(unsigned char* destinationBuffer) const; + int parseData(unsigned char* sourceBuffer, int numBytes); + +private: + + glm::vec3 _atmosphereCenter; + float _atmosphereInnerRadius; + float _atmosphereOuterRadius; + + float _rayleighScattering; + float _mieScattering; + + glm::vec3 _sunLocation; + float _sunBrightness; +}; + +#endif /* defined(__interface__EnvironmentData__) */