Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philip Rosedale 2013-04-16 13:26:49 -07:00
commit f4f8a4e41b
48 changed files with 406 additions and 508 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME audio-mixer) set(TARGET_NAME audio-mixer)

View file

@ -309,7 +309,7 @@ int main(int argc, const char * argv[])
agentList->increaseAgentId(); agentList->increaseAgentId();
} }
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes); agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
} else { } else {
memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024); memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024);
agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024); agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024);

View file

@ -2,17 +2,21 @@ cmake_minimum_required(VERSION 2.8)
set(TARGET_NAME "avatar-mixer") set(TARGET_NAME "avatar-mixer")
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
# setup the project # setup the project
include(${MACRO_DIR}/SetupHifiProject.cmake) include(${MACRO_DIR}/SetupHifiProject.cmake)
setup_hifi_project(${TARGET_NAME}) setup_hifi_project(${TARGET_NAME})
# link the shared hifi library # include glm
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})
# link required hifi libraries
include(${MACRO_DIR}/LinkHifiLibrary.cmake) include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
# link the threads library
find_package(Threads REQUIRED)
target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})

View file

@ -1,118 +0,0 @@
//
// AvatarAgentData.cpp
// hifi
//
// Created by Stephen Birarda on 4/9/13.
//
//
#include <cstdio>
#include "AvatarAgentData.h"
AvatarAgentData::AvatarAgentData() {
}
AvatarAgentData::~AvatarAgentData() {
}
AvatarAgentData* AvatarAgentData::clone() const {
return new AvatarAgentData(*this);
}
void AvatarAgentData::parseData(void *data, int size) {
char* packetData = (char *)data + 1;
// Extract data from packet
sscanf(packetData,
PACKET_FORMAT,
&_pitch,
&_yaw,
&_roll,
&_headPositionX,
&_headPositionY,
&_headPositionZ,
&_loudness,
&_averageLoudness,
&_handPositionX,
&_handPositionY,
&_handPositionZ);
}
float AvatarAgentData::getPitch() {
return _pitch;
}
float AvatarAgentData::getYaw() {
return _yaw;
}
float AvatarAgentData::getRoll() {
return _roll;
}
float AvatarAgentData::getHeadPositionX() {
return _headPositionX;
}
float AvatarAgentData::getHeadPositionY() {
return _headPositionY;
}
float AvatarAgentData::getHeadPositionZ() {
return _headPositionZ;
}
float AvatarAgentData::getLoudness() {
return _loudness;
}
float AvatarAgentData::getAverageLoudness() {
return _averageLoudness;
}
float AvatarAgentData::getHandPositionX() {
return _handPositionX;
}
float AvatarAgentData::getHandPositionY() {
return _handPositionY;
}
float AvatarAgentData::getHandPositionZ() {
return _handPositionZ;
}
void AvatarAgentData::setPitch(float pitch) {
_pitch = pitch;
}
void AvatarAgentData::setYaw(float yaw) {
_yaw = yaw;
}
void AvatarAgentData::setRoll(float roll) {
_roll = roll;
}
void AvatarAgentData::setHeadPosition(float x, float y, float z) {
_headPositionX = x;
_headPositionY = y;
_headPositionZ = z;
}
void AvatarAgentData::setLoudness(float loudness) {
_loudness = loudness;
}
void AvatarAgentData::setAverageLoudness(float averageLoudness) {
_averageLoudness = averageLoudness;
}
void AvatarAgentData::setHandPosition(float x, float y, float z) {
_handPositionX = x;
_handPositionY = y;
_handPositionZ = z;
}

View file

@ -1,58 +0,0 @@
//
// AvatarAgentData.h
// hifi
//
// Created by Stephen Birarda on 4/9/13.
//
//
#ifndef __hifi__AvatarAgentData__
#define __hifi__AvatarAgentData__
#include <iostream>
#include <AgentData.h>
const char PACKET_FORMAT[] = "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f";
class AvatarAgentData : public AgentData {
public:
AvatarAgentData();
~AvatarAgentData();
void parseData(void *data, int size);
AvatarAgentData* clone() const;
float getPitch();
void setPitch(float pitch);
float getYaw();
void setYaw(float yaw);
float getRoll();
void setRoll(float roll);
float getHeadPositionX();
float getHeadPositionY();
float getHeadPositionZ();
void setHeadPosition(float x, float y, float z);
float getLoudness();
void setLoudness(float loudness);
float getAverageLoudness();
void setAverageLoudness(float averageLoudness);
float getHandPositionX();
float getHandPositionY();
float getHandPositionZ();
void setHandPosition(float x, float y, float z);
private:
float _pitch;
float _yaw;
float _roll;
float _headPositionX;
float _headPositionY;
float _headPositionZ;
float _loudness;
float _averageLoudness;
float _handPositionX;
float _handPositionY;
float _handPositionZ;
};
#endif /* defined(__hifi__AvatarAgentData__) */

View file

@ -32,37 +32,22 @@
#include <StdDev.h> #include <StdDev.h>
#include <UDPSocket.h> #include <UDPSocket.h>
#include "AvatarAgentData.h" #include "AvatarData.h"
const int AVATAR_LISTEN_PORT = 55444; const int AVATAR_LISTEN_PORT = 55444;
const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000;
unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId());
AvatarAgentData *agentData = (AvatarAgentData *)agentToAdd->getLinkedData(); AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData();
currentPosition += agentData->getBroadcastData(currentPosition);
int bytesWritten = sprintf((char *)currentPosition,
PACKET_FORMAT,
agentData->getPitch(),
agentData->getYaw(),
agentData->getRoll(),
agentData->getHeadPositionX(),
agentData->getHeadPositionY(),
agentData->getHeadPositionZ(),
agentData->getLoudness(),
agentData->getAverageLoudness(),
agentData->getHandPositionX(),
agentData->getHandPositionY(),
agentData->getHandPositionZ());
currentPosition += bytesWritten;
return currentPosition; return currentPosition;
} }
void attachAvatarDataToAgent(Agent *newAgent) { void attachAvatarDataToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new AvatarAgentData()); newAgent->setLinkedData(new AvatarData());
} }
} }
@ -78,7 +63,7 @@ int main(int argc, char* argv[])
agentList->startPingUnknownAgentsThread(); agentList->startPingUnknownAgentsThread();
sockaddr *agentAddress = new sockaddr; sockaddr *agentAddress = new sockaddr;
char *packetData = new char[MAX_PACKET_SIZE]; unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
ssize_t receivedBytes = 0; ssize_t receivedBytes = 0;
unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE];
@ -92,7 +77,7 @@ int main(int argc, char* argv[])
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_HEADER_HEAD_DATA: case PACKET_HEADER_HEAD_DATA:
// this is positional data from an agent // this is positional data from an agent
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes); agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
currentBufferPosition = broadcastPacket + 1; currentBufferPosition = broadcastPacket + 1;
agentIndex = 0; agentIndex = 0;
@ -116,7 +101,7 @@ int main(int argc, char* argv[])
break; break;
default: default:
// hand this off to the AgentList // hand this off to the AgentList
agentList->processAgentData(agentAddress, (void *)packetData, receivedBytes); agentList->processAgentData(agentAddress, packetData, receivedBytes);
break; break;
} }
} }

View file

@ -1,5 +1,5 @@
MACRO(INCLUDE_GLM TARGET MACRO_DIR) MACRO(INCLUDE_GLM TARGET ROOT_DIR)
set(GLM_ROOT_DIR ${MACRO_DIR}/../../externals) set(GLM_ROOT_DIR ${ROOT_DIR}/externals)
find_package(GLM REQUIRED) find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS}) include_directories(${GLM_INCLUDE_DIRS})
ENDMACRO(INCLUDE_GLM _target _macro_dir) ENDMACRO(INCLUDE_GLM _target _root_dir)

View file

@ -3,12 +3,6 @@ MACRO(LINK_HIFI_LIBRARY LIBRARY TARGET ROOT_DIR)
add_subdirectory(${ROOT_DIR}/libraries/${LIBRARY} ${ROOT_DIR}/libraries/${LIBRARY}) add_subdirectory(${ROOT_DIR}/libraries/${LIBRARY} ${ROOT_DIR}/libraries/${LIBRARY})
endif (NOT TARGET ${LIBRARY}) endif (NOT TARGET ${LIBRARY})
string(TOUPPER ${LIBRARY} UPPERCASED_LIBRARY_NAME)
set(HIFI_LIBRARY_PROPERTY "HIFI_${UPPERCASED_LIBRARY_NAME}_LIBRARY")
get_directory_property(HIFI_LIBRARY
DIRECTORY ${ROOT_DIR}/libraries/${LIBRARY}
DEFINITION ${HIFI_LIBRARY_PROPERTY})
include_directories(${ROOT_DIR}/libraries/${LIBRARY}/src) include_directories(${ROOT_DIR}/libraries/${LIBRARY}/src)
add_dependencies(${TARGET} ${LIBRARY}) add_dependencies(${TARGET} ${LIBRARY})

View file

@ -0,0 +1,9 @@
MACRO(SETUP_HIFI_LIBRARY TARGET)
project(${TARGET_NAME})
# grab the implemenation and header files
file(GLOB LIB_SRCS src/*.h src/*.cpp)
# create a library and set the property so it can be referenced later
add_library(${TARGET_NAME} ${LIB_SRCS})
ENDMACRO(SETUP_HIFI_LIBRARY _target)

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME domain-server) set(TARGET_NAME domain-server)

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME injector) set(TARGET_NAME injector)

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME interface) set(TARGET_NAME interface)
@ -26,7 +26,7 @@ endif (WIN32)
# set up the external glm library # set up the external glm library
include(${MACRO_DIR}/IncludeGLM.cmake) include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${MACRO_DIR}) include_glm(${TARGET_NAME} ${ROOT_DIR})
# create the InterfaceConfig.h file based on GL_HEADERS above # create the InterfaceConfig.h file based on GL_HEADERS above
configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h) configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h)
@ -56,10 +56,11 @@ add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS})
# link in the hifi shared library # link in the hifi shared library
include(${MACRO_DIR}/LinkHifiLibrary.cmake) include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
# link in the hifi voxels library # link required hifi libraries
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
# find required libraries # find required libraries
find_package(GLM REQUIRED) find_package(GLM REQUIRED)

View file

@ -156,7 +156,7 @@ int audioCallback (const void *inputBuffer,
// memcpy the three float positions // memcpy the three float positions
for (int p = 0; p < 3; p++) { for (int p = 0; p < 3; p++) {
memcpy(currentPacketPtr, &data->linkedHead->getPos()[p], sizeof(float)); memcpy(currentPacketPtr, &data->linkedHead->getBodyPosition()[p], sizeof(float));
currentPacketPtr += sizeof(float); currentPacketPtr += sizeof(float);
} }
@ -411,7 +411,7 @@ void *receiveAudioViaUDP(void *args) {
} }
if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL); if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL);
ringBuffer->parseData(receivedData, PACKET_LENGTH_BYTES); ringBuffer->parseData((unsigned char *)receivedData, PACKET_LENGTH_BYTES);
previousReceiveTime = currentReceiveTime; previousReceiveTime = currentReceiveTime;
} }

3
interface/src/Camera.cpp Executable file → Normal file
View file

@ -5,8 +5,9 @@
// //
//--------------------------------------------------------------------- //---------------------------------------------------------------------
#include <SharedUtil.h>
#include "Camera.h" #include "Camera.h"
#include "Util.h"

0
interface/src/Camera.h Executable file → Normal file
View file

View file

@ -17,6 +17,7 @@
#include "Head.h" #include "Head.h"
#include <AgentList.h> #include <AgentList.h>
#include <AgentTypes.h> #include <AgentTypes.h>
#include <PacketHeaders.h>
using namespace std; using namespace std;
@ -44,9 +45,6 @@ vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512; unsigned int iris_texture_width = 512;
unsigned int iris_texture_height = 256; unsigned int iris_texture_height = 256;
Head::Head() { Head::Head() {
initializeAvatar(); initializeAvatar();
@ -124,8 +122,6 @@ Head::Head() {
Head::Head(const Head &otherHead) { Head::Head(const Head &otherHead) {
initializeAvatar(); initializeAvatar();
bodyPosition = otherHead.bodyPosition;
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i];
PupilSize = otherHead.PupilSize; PupilSize = otherHead.PupilSize;
@ -380,12 +376,12 @@ void Head::simulate(float deltaTime) {
//---------------------------------------------------------- //----------------------------------------------------------
// update body yaw by body yaw delta // update body yaw by body yaw delta
//---------------------------------------------------------- //----------------------------------------------------------
bodyYaw += bodyYawDelta * deltaTime; _bodyYaw += bodyYawDelta * deltaTime;
//---------------------------------------------------------- //----------------------------------------------------------
// (for now) set head yaw to body yaw // (for now) set head yaw to body yaw
//---------------------------------------------------------- //----------------------------------------------------------
Yaw = bodyYaw; Yaw = _bodyYaw;
//---------------------------------------------------------- //----------------------------------------------------------
// decay body yaw delta // decay body yaw delta
@ -401,7 +397,7 @@ void Head::simulate(float deltaTime) {
//---------------------------------------------------------- //----------------------------------------------------------
// update position by velocity // update position by velocity
//---------------------------------------------------------- //----------------------------------------------------------
bodyPosition += (glm::vec3)avatar.velocity * deltaTime; _bodyPosition += (glm::vec3)avatar.velocity * deltaTime;
//---------------------------------------------------------- //----------------------------------------------------------
// decay velocity // decay velocity
@ -514,7 +510,7 @@ void Head::render(int faceToFace, int isMine) {
// show avatar position // show avatar position
//--------------------------------------------------- //---------------------------------------------------
glPushMatrix(); glPushMatrix();
glTranslatef( bodyPosition.x, bodyPosition.y, bodyPosition.z ); glTranslatef(_bodyPosition.x, _bodyPosition.y, _bodyPosition.z);
glScalef( 0.03, 0.03, 0.03 ); glScalef( 0.03, 0.03, 0.03 );
glutSolidSphere( 1, 10, 10 ); glutSolidSphere( 1, 10, 10 );
glPopMatrix(); glPopMatrix();
@ -618,7 +614,7 @@ void Head::renderHead( int faceToFace, int isMine ) {
glScalef( 0.03, 0.03, 0.03 ); glScalef( 0.03, 0.03, 0.03 );
glRotatef( bodyYaw, 0, 1, 0); glRotatef(_bodyYaw, 0, 1, 0);
// Don't render a head if it is really close to your location, because that is your own head! // Don't render a head if it is really close to your location, because that is your own head!
@ -776,9 +772,9 @@ void Head::initializeAvatar() {
closestOtherAvatar = 0; closestOtherAvatar = 0;
bodyYaw = -90.0; _bodyYaw = -90.0;
bodyPitch = 0.0; _bodyPitch = 0.0;
bodyRoll = 0.0; _bodyRoll = 0.0;
bodyYawDelta = 0.0; bodyYawDelta = 0.0;
@ -899,24 +895,20 @@ void Head::updateAvatarSkeleton() {
// rotate body... // rotate body...
//---------------------------------- //----------------------------------
avatar.orientation.setToIdentity(); avatar.orientation.setToIdentity();
avatar.orientation.yaw( bodyYaw ); avatar.orientation.yaw( _bodyYaw );
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// calculate positions of all bones by traversing the skeleton tree: // calculate positions of all bones by traversing the skeleton tree:
//------------------------------------------------------------------------ //------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
if ( bone[b].parent == AVATAR_BONE_NULL ) { if ( bone[b].parent == AVATAR_BONE_NULL ) {
bone[b].orientation.set( avatar.orientation ); bone[b].orientation.set(avatar.orientation);
//printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z );
//printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z ); glm::vec3 ppp = _bodyPosition;
glm::vec3 ppp = bodyPosition;
// ppp.y += 0.2; // ppp.y += 0.2;
bone[b].position = ppp;// + glm::vec3( 0.0f, 1.0f, 0.0f ) * 1.0f; bone[b].position = ppp;// + glm::vec3( 0.0f, 1.0f, 0.0f ) * 1.0f;
} }
else { else {
bone[b].orientation.set( bone[ bone[b].parent ].orientation ); bone[b].orientation.set( bone[ bone[b].parent ].orientation );
@ -946,7 +938,7 @@ void Head::updateAvatarSprings( float deltaTime ) {
glm::vec3 springVector( bone[b].springyPosition ); glm::vec3 springVector( bone[b].springyPosition );
if ( bone[b].parent == AVATAR_BONE_NULL ) { if ( bone[b].parent == AVATAR_BONE_NULL ) {
springVector -= bodyPosition; springVector -= _bodyPosition;
} }
else { else {
springVector -= bone[ bone[b].parent ].springyPosition; springVector -= bone[ bone[b].parent ].springyPosition;
@ -1014,17 +1006,6 @@ glm::vec3 Head::getHeadPosition() {
); );
} }
glm::vec3 Head::getBodyPosition() {
return glm::vec3
(
bone[ AVATAR_BONE_PELVIS_SPINE ].position.x,
bone[ AVATAR_BONE_PELVIS_SPINE ].position.y,
bone[ AVATAR_BONE_PELVIS_SPINE ].position.z
);
}
void Head::updateHandMovement() { void Head::updateHandMovement() {
glm::vec3 transformedHandMovement; glm::vec3 transformedHandMovement;
@ -1183,48 +1164,12 @@ void Head::renderBody() {
} }
// Transmit data to agents requesting it
// called on me just prior to sending data to others (continuasly called)
int Head::getBroadcastData(char* data) {
// Copy data for transmission to the buffer, return length of data
sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
//avatar.yaw, avatar.pitch, avatar.roll,
bodyPosition.x + leanSideways, bodyPosition.y, bodyPosition.z + leanForward,
loudness, averageLoudness,
//hand->getPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change
bone[ AVATAR_BONE_RIGHT_HAND ].position.x,
bone[ AVATAR_BONE_RIGHT_HAND ].position.y,
bone[ AVATAR_BONE_RIGHT_HAND ].position.z );
return strlen(data);
}
//called on the other agents - assigns it to my views of the others
void Head::parseData(void *data, int size) {
sscanf
(
(char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
&Pitch, &Yaw, &Roll,
//&avatar.yaw, &avatar.pitch, &avatar.roll,
&bodyPosition.x, &bodyPosition.y, &bodyPosition.z,
&loudness, &averageLoudness,
&bone[ AVATAR_BONE_RIGHT_HAND ].position.x,
&bone[ AVATAR_BONE_RIGHT_HAND ].position.y,
&bone[ AVATAR_BONE_RIGHT_HAND ].position.z
);
handBeingMoved = true;
}
void Head::SetNewHeadTarget(float pitch, float yaw) { void Head::SetNewHeadTarget(float pitch, float yaw) {
PitchTarget = pitch; PitchTarget = pitch;
YawTarget = yaw; YawTarget = yaw;
} }
void Head::processTransmitterData(char *packetData, int numBytes) { void Head::processTransmitterData(unsigned char* packetData, int numBytes) {
// Read a packet from a transmitter app, process the data // Read a packet from a transmitter app, process the data
float accX, accY, accZ, float accX, accY, accZ,
graX, graY, graZ, graX, graY, graZ,

View file

@ -10,10 +10,13 @@
#define __interface__head__ #define __interface__head__
#include <iostream> #include <iostream>
#include "AgentData.h"
#include <AvatarData.h>
#include <Orientation.h> // added by Ventrella as a utility
#include "Field.h" #include "Field.h"
#include "world.h" #include "world.h"
#include "Orientation.h" // added by Ventrella as a utility
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include "SerialInterface.h" #include "SerialInterface.h"
@ -39,48 +42,6 @@ enum AvatarMode
NUM_AVATAR_MODES NUM_AVATAR_MODES
}; };
/*
enum AvatarJoints
{
AVATAR_JOINT_NULL = -1,
AVATAR_JOINT_PELVIS,
AVATAR_JOINT_TORSO,
AVATAR_JOINT_CHEST,
AVATAR_JOINT_NECK_BASE,
AVATAR_JOINT_HEAD_BASE,
AVATAR_JOINT_HEAD_TOP,
AVATAR_JOINT_LEFT_CLAVICLE,
AVATAR_JOINT_LEFT_SHOULDER,
AVATAR_JOINT_LEFT_ELBOW,
AVATAR_JOINT_LEFT_WRIST,
AVATAR_JOINT_LEFT_FINGERTIPS,
AVATAR_JOINT_RIGHT_CLAVICLE,
AVATAR_JOINT_RIGHT_SHOULDER,
AVATAR_JOINT_RIGHT_ELBOW,
AVATAR_JOINT_RIGHT_WRIST,
AVATAR_JOINT_RIGHT_FINGERTIPS,
AVATAR_JOINT_LEFT_HIP,
AVATAR_JOINT_LEFT_KNEE,
AVATAR_JOINT_LEFT_HEEL,
AVATAR_JOINT_LEFT_TOES,
AVATAR_JOINT_RIGHT_HIP,
AVATAR_JOINT_RIGHT_KNEE,
AVATAR_JOINT_RIGHT_HEEL,
AVATAR_JOINT_RIGHT_TOES,
NUM_AVATAR_JOINTS
};
*/
enum AvatarBones enum AvatarBones
{ {
AVATAR_BONE_NULL = -1, AVATAR_BONE_NULL = -1,
@ -134,7 +95,7 @@ struct Avatar
Orientation orientation; Orientation orientation;
}; };
class Head : public AgentData { class Head : public AvatarData {
public: public:
Head(); Head();
~Head(); ~Head();
@ -171,8 +132,6 @@ class Head : public AgentData {
glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadLookatDirectionRight();
glm::vec3 getHeadPosition(); glm::vec3 getHeadPosition();
glm::vec3 getBonePosition( AvatarBones b ); glm::vec3 getBonePosition( AvatarBones b );
glm::vec3 getBodyPosition();
AvatarMode getMode(); AvatarMode getMode();
@ -189,18 +148,12 @@ class Head : public AgentData {
void setHandMovement( glm::vec3 movement ); void setHandMovement( glm::vec3 movement );
void updateHandMovement(); void updateHandMovement();
// Send and receive network data
int getBroadcastData(char * data);
void parseData(void *data, int size);
float getLoudness() {return loudness;}; float getLoudness() {return loudness;};
float getAverageLoudness() {return averageLoudness;}; float getAverageLoudness() {return averageLoudness;};
void setAverageLoudness(float al) {averageLoudness = al;}; void setAverageLoudness(float al) {averageLoudness = al;};
void setLoudness(float l) {loudness = l;}; void setLoudness(float l) {loudness = l;};
void SetNewHeadTarget(float, float); void SetNewHeadTarget(float, float);
glm::vec3 getPos() { return bodyPosition; };
void setPos(glm::vec3 newpos) { bodyPosition = newpos; };
// Set what driving keys are being pressed to control thrust levels // Set what driving keys are being pressed to control thrust levels
void setDriveKeys(int key, bool val) { driveKeys[key] = val; }; void setDriveKeys(int key, bool val) { driveKeys[key] = val; };
@ -215,7 +168,7 @@ class Head : public AgentData {
// Related to getting transmitter UDP data used to animate the avatar hand // Related to getting transmitter UDP data used to animate the avatar hand
// //
void processTransmitterData(char * packetData, int numBytes); void processTransmitterData(unsigned char * packetData, int numBytes);
float getTransmitterHz() { return transmitterHz; }; float getTransmitterHz() { return transmitterHz; };
private: private:
@ -253,13 +206,8 @@ class Head : public AgentData {
float audioAttack; float audioAttack;
float browAudioLift; float browAudioLift;
glm::vec3 bodyPosition;
bool triggeringAction; bool triggeringAction;
float bodyYaw;
float bodyPitch;
float bodyRoll;
float bodyYawDelta; float bodyYawDelta;
float closeEnoughToInteract; float closeEnoughToInteract;

View file

@ -60,9 +60,11 @@ public:
*/ */
void activate() const { void activate() const {
if (_hndProg != 0u) if (_hndProg != 0u) {
oGlLog( glUseProgram(_hndProg) ); oGlLog( glUseProgram(_hndProg) );
} }
}
/** /**
* Adds a shader to the program. * Adds a shader to the program.
@ -77,16 +79,20 @@ public:
*/ */
bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) { bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) {
if (! _hndProg) { _hndProg = glCreateProgram(); } if (! _hndProg && !! glCreateProgram) {
_hndProg = glCreateProgram();
}
if (! _hndProg) { return false; }
GLuint s = glCreateShader(type); GLuint s = glCreateShader(type);
glShaderSource(s, nStrings, strings, 0l); glShaderSource(s, nStrings, strings, 0l);
glCompileShader(s); glCompileShader(s);
GLint status; GLint status;
glGetShaderiv(s, GL_COMPILE_STATUS, & status); glGetShaderiv(s, GL_COMPILE_STATUS, & status);
if (!! status) if (status != 0)
glAttachShader(_hndProg, s); glAttachShader(_hndProg, s);
#ifdef NDEBUG #ifdef NDEBUG // always fetch log in debug mode
else else
#endif #endif
fetchLog(s, glGetShaderiv, glGetShaderInfoLog); fetchLog(s, glGetShaderiv, glGetShaderInfoLog);
@ -104,12 +110,21 @@ public:
glLinkProgram(_hndProg); glLinkProgram(_hndProg);
GLint status; GLint status;
glGetProgramiv(_hndProg, GL_LINK_STATUS, & status); glGetProgramiv(_hndProg, GL_LINK_STATUS, & status);
#ifdef NDEBUG #ifndef NDEBUG // always fetch log in debug mode
if (status == 0)
#endif
fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog); fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog);
#endif
if (status == 0) {
#ifdef NDEBUG // only on error in release mode
fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog);
#endif
glDeleteProgram(_hndProg);
_hndProg = 0u;
return false;
return status != 0; } else {
return true;
}
} }
private: private:

View file

@ -8,8 +8,11 @@
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include <iostream> #include <iostream>
#include <glm/glm.hpp>
#include <cstring> #include <cstring>
#include <glm/glm.hpp>
#include <SharedUtil.h>
#include "world.h" #include "world.h"
#include "Util.h" #include "Util.h"

View file

@ -17,21 +17,6 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
static const float ZERO = 0.0;
static const float ONE = 1.0;
static const float ONE_HALF = 0.5;
static const double ONE_THIRD = 0.3333333;
static const double PIE = 3.14159265359;
static const double PI_TIMES_TWO = 3.14159265359 * 2.0;
static const double PI_OVER_180 = 3.14159265359 / 180.0;
static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations
static const double SQUARE_ROOT_OF_2 = sqrt(2);
static const double SQUARE_ROOT_OF_3 = sqrt(3);
static const float METER = 1.0;
static const float DECIMETER = 0.1;
static const float CENTIMETER = 0.01;
static const float MILLIIMETER = 0.001;
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos); float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos);
float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw); float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw);

View file

@ -112,33 +112,33 @@ long int VoxelSystem::getVoxelsBytesReadRunningAverage() {
} }
void VoxelSystem::parseData(void *data, int size) { void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char command = *(unsigned char*)data; unsigned char command = *sourceBuffer;
unsigned char *voxelData = (unsigned char *) data + 1; unsigned char *voxelData = sourceBuffer + 1;
switch(command) { switch(command) {
case PACKET_HEADER_VOXEL_DATA: case PACKET_HEADER_VOXEL_DATA:
// ask the VoxelTree to read the bitstream into the tree // ask the VoxelTree to read the bitstream into the tree
tree->readBitstreamToTree(voxelData, size - 1); tree->readBitstreamToTree(voxelData, numBytes - 1);
break; break;
case PACKET_HEADER_ERASE_VOXEL: case PACKET_HEADER_ERASE_VOXEL:
// ask the tree to read the "remove" bitstream // ask the tree to read the "remove" bitstream
tree->processRemoveVoxelBitstream((unsigned char*)data,size); tree->processRemoveVoxelBitstream(sourceBuffer, numBytes);
break; break;
case PACKET_HEADER_Z_COMMAND: case PACKET_HEADER_Z_COMMAND:
// the Z command is a special command that allows the sender to send high level semantic // the Z command is a special command that allows the sender to send high level semantic
// requests, like erase all, or add sphere scene, different receivers may handle these // requests, like erase all, or add sphere scene, different receivers may handle these
// messages differently // messages differently
char* packetData =(char*)data; char* packetData = (char *)sourceBuffer;
char* command = &packetData[1]; // start of the command char* command = &packetData[1]; // start of the command
int commandLength = strlen(command); // commands are null terminated strings int commandLength = strlen(command); // commands are null terminated strings
int totalLength = 1+commandLength+1; int totalLength = 1+commandLength+1;
printf("got Z message len(%d)= %s\n",size,command); printf("got Z message len(%d)= %s\n", numBytes, command);
while (totalLength <= size) { while (totalLength <= numBytes) {
if (0==strcmp(command,(char*)"erase all")) { if (0==strcmp(command,(char*)"erase all")) {
printf("got Z message == erase all\n"); printf("got Z message == erase all\n");
tree->eraseAllVoxels(); tree->eraseAllVoxels();
@ -184,7 +184,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
int voxelsAdded = 0; int voxelsAdded = 0;
float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE);
glm::vec3 viewerPosition = viewerHead->getPos(); glm::vec3 viewerPosition = viewerHead->getBodyPosition();
// XXXBHG - Note: It appears as if the X and Z coordinates of Head or Agent are flip-flopped relative to the // XXXBHG - Note: It appears as if the X and Z coordinates of Head or Agent are flip-flopped relative to the
// coords of the voxel space. This flip flop causes LOD behavior to be extremely odd. This is my temporary hack // coords of the voxel space. This flip flop causes LOD behavior to be extremely odd. This is my temporary hack

View file

@ -26,7 +26,7 @@ public:
VoxelSystem(); VoxelSystem();
~VoxelSystem(); ~VoxelSystem();
void parseData(void *data, int size); void parseData(unsigned char* sourceBuffer, int numBytes);
VoxelSystem* clone() const; VoxelSystem* clone() const;
void init(); void init();

View file

@ -228,7 +228,7 @@ void displayStats(void)
char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene";
drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2);
glm::vec3 avatarPos = myAvatar.getPos(); glm::vec3 avatarPos = myAvatar.getBodyPosition();
char stats[200]; char stats[200];
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ",
@ -309,7 +309,7 @@ void init(void)
if (noiseOn) { if (noiseOn) {
myAvatar.setNoise(noise); myAvatar.setNoise(noise);
} }
myAvatar.setPos(start_location ); myAvatar.setBodyPosition(start_location);
myCamera.setPosition( start_location ); myCamera.setPosition( start_location );
@ -351,7 +351,7 @@ void reset_sensors()
renderYawRate = 0; renderYawRate = 0;
renderPitchRate = 0; renderPitchRate = 0;
myAvatar.setPos(start_location); myAvatar.setBodyPosition(start_location);
headMouseX = WIDTH/2; headMouseX = WIDTH/2;
headMouseY = HEIGHT/2; headMouseY = HEIGHT/2;
@ -449,8 +449,10 @@ void updateAvatar(float frametime)
#endif #endif
// Send my stream of head/hand data to the avatar mixer and voxel server // Send my stream of head/hand data to the avatar mixer and voxel server
char broadcastString[200]; unsigned char broadcastString[200];
int broadcastBytes = myAvatar.getBroadcastData(broadcastString); *broadcastString = PACKET_HEADER_HEAD_DATA;
int broadcastBytes = myAvatar.getBroadcastData(broadcastString + 1);
const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER};
AgentList::getInstance()->broadcastToAgents(broadcastString, broadcastBytes, broadcastReceivers, 2); AgentList::getInstance()->broadcastToAgents(broadcastString, broadcastBytes, broadcastReceivers, 2);
@ -458,7 +460,7 @@ void updateAvatar(float frametime)
// If I'm in paint mode, send a voxel out to VOXEL server agents. // If I'm in paint mode, send a voxel out to VOXEL server agents.
if (::paintOn) { if (::paintOn) {
glm::vec3 avatarPos = myAvatar.getPos(); glm::vec3 avatarPos = myAvatar.getBodyPosition();
// For some reason, we don't want to flip X and Z here. // For some reason, we don't want to flip X and Z here.
::paintingVoxel.x = avatarPos.x/10.0; ::paintingVoxel.x = avatarPos.x/10.0;
@ -473,7 +475,7 @@ void updateAvatar(float frametime)
::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) { ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) {
if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){ if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){
AgentList::getInstance()->broadcastToAgents((char*)bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
delete bufferOut; delete bufferOut;
} }
} }
@ -700,11 +702,13 @@ void display(void)
//-------------------------------------------------------- //--------------------------------------------------------
// camera settings // camera settings
//-------------------------------------------------------- //--------------------------------------------------------
myCamera.setTargetPosition( myAvatar.getBodyPosition() );
if ( displayHead ) { if ( displayHead ) {
//----------------------------------------------- //-----------------------------------------------
// set the camera to looking at my own face // set the camera to looking at my own face
//----------------------------------------------- //-----------------------------------------------
myCamera.setTargetPosition ( myAvatar.getPos() ); myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
myCamera.setYaw ( - myAvatar.getBodyYaw() ); myCamera.setYaw ( - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 ); myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 ); myCamera.setRoll ( 0.0 );
@ -716,7 +720,7 @@ void display(void)
//---------------------------------------------------- //----------------------------------------------------
// set the camera to third-person view behind my av // set the camera to third-person view behind my av
//---------------------------------------------------- //----------------------------------------------------
myCamera.setTargetPosition ( myAvatar.getPos() ); myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
myCamera.setRoll ( 0.0 ); myCamera.setRoll ( 0.0 );
@ -815,7 +819,7 @@ void display(void)
if (agent->getLinkedData() != NULL) { if (agent->getLinkedData() != NULL) {
Head *agentHead = (Head *)agent->getLinkedData(); Head *agentHead = (Head *)agent->getLinkedData();
glPushMatrix(); glPushMatrix();
glm::vec3 pos = agentHead->getPos(); glm::vec3 pos = agentHead->getBodyPosition();
glTranslatef(-pos.x, -pos.y, -pos.z); glTranslatef(-pos.x, -pos.y, -pos.z);
agentHead->render(0, 0); agentHead->render(0, 0);
glPopMatrix(); glPopMatrix();
@ -905,9 +909,11 @@ void display(void)
// If application has just started, report time from startup to now (first frame display) // If application has just started, report time from startup to now (first frame display)
if (justStarted) { if (justStarted) {
printf("Startup Time: %4.2f\n", float startupTime = (usecTimestampNow() - usecTimestamp(&applicationStartupTime))/1000000.0;
(usecTimestampNow() - usecTimestamp(&applicationStartupTime))/1000000.0);
justStarted = false; justStarted = false;
char title[30];
snprintf(title, 30, "Interface: %4.2f seconds", startupTime);
glutSetWindowTitle(title);
} }
} }
@ -1087,14 +1093,14 @@ void sendVoxelServerEraseAll() {
char message[100]; char message[100];
sprintf(message,"%c%s",'Z',"erase all"); sprintf(message,"%c%s",'Z',"erase all");
int messageSize = strlen(message) + 1; int messageSize = strlen(message) + 1;
AgentList::getInstance()->broadcastToAgents(message, messageSize, &AGENT_TYPE_VOXEL, 1); AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
} }\
void sendVoxelServerAddScene() { void sendVoxelServerAddScene() {
char message[100]; char message[100];
sprintf(message,"%c%s",'Z',"add scene"); sprintf(message,"%c%s",'Z',"add scene");
int messageSize = strlen(message) + 1; int messageSize = strlen(message) + 1;
AgentList::getInstance()->broadcastToAgents(message, messageSize, &AGENT_TYPE_VOXEL, 1); AgentList::getInstance()->broadcastToAgents((unsigned char*)message, messageSize, &AGENT_TYPE_VOXEL, 1);
} }
void shiftPaintingColor() void shiftPaintingColor()
@ -1107,7 +1113,7 @@ void shiftPaintingColor()
} }
void setupPaintingVoxel() { void setupPaintingVoxel() {
glm::vec3 avatarPos = myAvatar.getPos(); glm::vec3 avatarPos = myAvatar.getBodyPosition();
::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space
::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space
@ -1280,7 +1286,7 @@ void *networkReceive(void *args)
{ {
sockaddr senderAddress; sockaddr senderAddress;
ssize_t bytesReceived; ssize_t bytesReceived;
char *incomingPacket = new char[MAX_PACKET_SIZE]; unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE];
while (!stopNetworkReceiveThread) { while (!stopNetworkReceiveThread) {
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
@ -1525,6 +1531,9 @@ int main(int argc, const char * argv[])
AgentList::getInstance()->startPingUnknownAgentsThread(); AgentList::getInstance()->startPingUnknownAgentsThread();
glutInit(&argc, (char**)argv); glutInit(&argc, (char**)argv);
WIDTH = glutGet(GLUT_SCREEN_WIDTH);
HEIGHT = glutGet(GLUT_SCREEN_HEIGHT);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT); glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Interface"); glutCreateWindow("Interface");

View file

@ -67,7 +67,7 @@
#include <glm/gtc/swizzle.hpp> #include <glm/gtc/swizzle.hpp>
#include "UrlReader.h" #include "UrlReader.h"
#include "AngleUtils.h" #include "AngleUtil.h"
#include "Radix2InplaceSort.h" #include "Radix2InplaceSort.h"
#include "Radix2IntegerScanner.h" #include "Radix2IntegerScanner.h"
#include "FloodFill.h" #include "FloodFill.h"

View file

@ -72,16 +72,17 @@ namespace starfield {
size_t _valLodNalloc; size_t _valLodNalloc;
size_t _valLodNrender; size_t _valLodNrender;
BrightnessLevels _seqLodBrightness; BrightnessLevels _seqLodBrightness;
BrightnessLevel _valLodAllocBrightness;
#if STARFIELD_MULTITHREADING #if STARFIELD_MULTITHREADING
atomic<BrightnessLevel> _valLodBrightness; atomic<BrightnessLevel> _valLodBrightness;
BrightnessLevel _valLodAllocBrightness;
atomic<Renderer*> _ptrRenderer; atomic<Renderer*> _ptrRenderer;
typedef lock_guard<mutex> lock; typedef lock_guard<mutex> lock;
#else #else
BrightnessLevel _valLodBrightness; BrightnessLevel _valLodBrightness;
BrightnessLevel _valLodAllocBrightness;
Renderer* _ptrRenderer; Renderer* _ptrRenderer;
@ -89,6 +90,10 @@ namespace starfield {
#define _(x) #define _(x)
#endif #endif
static inline size_t toBufSize(double f) {
return size_t(floor(f + 0.5f));
}
public: public:
Controller() : Controller() :
@ -99,8 +104,8 @@ namespace starfield {
_valLodOveralloc(1.2), _valLodOveralloc(1.2),
_valLodNalloc(0), _valLodNalloc(0),
_valLodNrender(0), _valLodNrender(0),
_valLodAllocBrightness(0),
_valLodBrightness(0), _valLodBrightness(0),
_valLodAllocBrightness(0),
_ptrRenderer(0l) { _ptrRenderer(0l) {
} }
@ -144,8 +149,8 @@ namespace starfield {
rcpChange = 1.0; rcpChange = 1.0;
nRender = lrint(_valLodFraction * newLast); nRender = toBufSize(_valLodFraction * newLast);
n = min(newLast, size_t(lrint(_valLodOveralloc * nRender))); n = min(newLast, toBufSize(_valLodOveralloc * nRender));
} else { } else {
@ -282,7 +287,7 @@ namespace starfield {
// calculate allocation size and corresponding brightness // calculate allocation size and corresponding brightness
// threshold // threshold
double oaFract = std::min(fraction * (1.0 + overalloc), 1.0); double oaFract = std::min(fraction * (1.0 + overalloc), 1.0);
n = lrint(oaFract * last); n = toBufSize(oaFract * last);
bMin = _seqLodBrightness[n]; bMin = _seqLodBrightness[n];
n = std::upper_bound( n = std::upper_bound(
_seqLodBrightness.begin() + n - 1, _seqLodBrightness.begin() + n - 1,
@ -290,7 +295,7 @@ namespace starfield {
bMin, GreaterBrightness() ) - _seqLodBrightness.begin(); bMin, GreaterBrightness() ) - _seqLodBrightness.begin();
// also determine number of vertices to render and brightness // also determine number of vertices to render and brightness
nRender = lrint(fraction * last); nRender = toBufSize(fraction * last);
// Note: nRender does not have to be accurate // Note: nRender does not have to be accurate
b = _seqLodBrightness[nRender]; b = _seqLodBrightness[nRender];
// this setting controls the renderer, also keep b as the // this setting controls the renderer, also keep b as the
@ -304,7 +309,7 @@ namespace starfield {
// fprintf(stderr, "Stars.cpp: " // fprintf(stderr, "Stars.cpp: "
// "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n", // "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n",
// fraction, oaFract, lrint(oaFract * last)), n, bMin, b); // fraction, oaFract, toBufSize(oaFract * last)), n, bMin, b);
// will not have to reallocate? set new fraction right away // will not have to reallocate? set new fraction right away
// (it is consistent with the rest of the state in this case) // (it is consistent with the rest of the state in this case)

View file

@ -50,7 +50,7 @@ namespace starfield {
return false; return false;
} }
fprintf(stderr, "Stars.cpp: read %d stars, rendering %ld\n", fprintf(stderr, "Stars.cpp: read %u vertices, using %lu\n",
_valRecordsRead, _ptrVertices->size()); _valRecordsRead, _ptrVertices->size());
return true; return true;

View file

@ -26,8 +26,8 @@ namespace starfield {
InputVertex(float azimuth, float altitude, unsigned color) { InputVertex(float azimuth, float altitude, unsigned color) {
_valColor = (color >> 16 & 0xffu) | (color & 0xff00u) | _valColor = ((color >> 16) & 0xffu) | (color & 0xff00u) |
(color << 16 & 0xff0000u) | 0xff000000u; ((color << 16) & 0xff0000u) | 0xff000000u;
azimuth = angleConvert<Degrees,Radians>(azimuth); azimuth = angleConvert<Degrees,Radians>(azimuth);
altitude = angleConvert<Degrees,Radians>(altitude); altitude = angleConvert<Degrees,Radians>(altitude);

View file

@ -13,15 +13,8 @@
#error "This is an implementation file - not intended for direct inclusion." #error "This is an implementation file - not intended for direct inclusion."
#endif #endif
#ifdef _WIN32
#include "../Config.h"
#define lrint(x) (floor(x + (x > 0) ? 0.5 : -0.5))
inline float remainder(float x, float y) { return std::fmod(x, y); }
inline int round(float x) { return (floor(x + 0.5)); }
double log2( double n ) { return log( n ) / log( 2 ); }
#else
#include "starfield/Config.h" #include "starfield/Config.h"
#endif
namespace starfield { namespace starfield {
class Tiling { class Tiling {
@ -35,7 +28,7 @@ namespace starfield {
Tiling(unsigned k) : Tiling(unsigned k) :
_valK(k), _valK(k),
_valRcpSlice(k / Radians::twicePi()) { _valRcpSlice(k / Radians::twicePi()) {
_valBits = ceil(log2(getTileCount())); _valBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2
} }
unsigned getAzimuthalTiles() const { return _valK; } unsigned getAzimuthalTiles() const { return _valK; }
@ -58,7 +51,7 @@ namespace starfield {
private: private:
unsigned discreteAngle(float unsigned_angle) const { unsigned discreteAngle(float unsigned_angle) const {
return unsigned(round(unsigned_angle * _valRcpSlice)); return unsigned(floor(unsigned_angle * _valRcpSlice + 0.5f));
} }
unsigned discreteAzimuth(float a) const { unsigned discreteAzimuth(float a) const {

View file

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/")
set(TARGET_NAME avatars)
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
setup_hifi_library(${TARGET_NAME})
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})

View file

@ -0,0 +1,112 @@
//
// AvatarData.cpp
// hifi
//
// Created by Stephen Birarda on 4/9/13.
//
//
#include <cstdio>
#include <cstring>
#include <stdint.h>
#include <PacketHeaders.h>
#include "AvatarData.h"
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO);
memcpy(buffer, &angleHolder, sizeof(uint16_t));
return sizeof(uint16_t);
}
int unpackFloatAngleFromTwoByte(uint16_t *byteAnglePointer, float *destinationPointer) {
*destinationPointer = (*byteAnglePointer / std::numeric_limits<uint16_t>::max()) * 360.0 - 180;
return sizeof(uint16_t);
}
AvatarData::AvatarData() :
_bodyYaw(-90.0),
_bodyPitch(0.0),
_bodyRoll(0.0) {
}
AvatarData::~AvatarData() {
}
AvatarData* AvatarData::clone() const {
return new AvatarData(*this);
}
// transmit data to agents requesting it
// called on me just prior to sending data to others (continuasly called)
int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
unsigned char* bufferStart = destinationBuffer;
// TODO: DRY this up to a shared method
// that can pack any type given the number of bytes
// and return the number of bytes to push the pointer
memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3);
destinationBuffer += sizeof(float) * 3;
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
return destinationBuffer - bufferStart;
}
// called on the other agents - assigns it to my views of the others
void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
// increment to push past the packet header
sourceBuffer++;
memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3;
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll);
}
glm::vec3 AvatarData::getBodyPosition() {
return glm::vec3(_bodyPosition.x,
_bodyPosition.y,
_bodyPosition.z);
}
void AvatarData::setBodyPosition(glm::vec3 bodyPosition) {
_bodyPosition = bodyPosition;
}
float AvatarData::getBodyYaw() {
return _bodyYaw;
}
void AvatarData::setBodyYaw(float bodyYaw) {
_bodyYaw = bodyYaw;
}
float AvatarData::getBodyPitch() {
return _bodyPitch;
}
void AvatarData::setBodyPitch(float bodyPitch) {
_bodyPitch = bodyPitch;
}
float AvatarData::getBodyRoll() {
return _bodyRoll;
}
void AvatarData::setBodyRoll(float bodyRoll) {
_bodyRoll = bodyRoll;
}

View file

@ -0,0 +1,48 @@
//
// AvatarData.h
// hifi
//
// Created by Stephen Birarda on 4/9/13.
//
//
#ifndef __hifi__AvatarData__
#define __hifi__AvatarData__
#include <iostream>
#include <glm/glm.hpp>
#include <AgentData.h>
class AvatarData : public AgentData {
public:
AvatarData();
~AvatarData();
AvatarData* clone() const;
glm::vec3 getBodyPosition();
void setBodyPosition(glm::vec3 bodyPosition);
int getBroadcastData(unsigned char* destinationBuffer);
void parseData(unsigned char* sourceBuffer, int numBytes);
float getBodyYaw();
void setBodyYaw(float bodyYaw);
float getBodyPitch();
void setBodyPitch(float bodyPitch);
float getBodyRoll();
void setBodyRoll(float bodyRoll);
protected:
glm::vec3 _bodyPosition;
float _bodyYaw;
float _bodyPitch;
float _bodyRoll;
};
#endif /* defined(__hifi__AvatarData__) */

View file

@ -6,8 +6,7 @@
//----------------------------------------------------------- //-----------------------------------------------------------
#include "Orientation.h" #include "Orientation.h"
#include "Util.h" #include <SharedUtil.h>
Orientation::Orientation() { Orientation::Orientation() {
right = glm::vec3( 1.0, 0.0, 0.0 ); right = glm::vec3( 1.0, 0.0, 0.0 );

View file

@ -12,7 +12,7 @@
class AgentData { class AgentData {
public: public:
virtual ~AgentData() = 0; virtual ~AgentData() = 0;
virtual void parseData(void * data, int size) = 0; virtual void parseData(unsigned char* sourceBuffer, int numBytes) = 0;
virtual AgentData* clone() const = 0; virtual AgentData* clone() const = 0;
}; };

View file

@ -81,10 +81,10 @@ unsigned int AgentList::getSocketListenPort() {
return socketListenPort; return socketListenPort;
} }
void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
switch (((char *)packetData)[0]) { switch (((char *)packetData)[0]) {
case PACKET_HEADER_DOMAIN: { case PACKET_HEADER_DOMAIN: {
updateList((unsigned char *)packetData, dataBytes); updateList(packetData, dataBytes);
break; break;
} }
case PACKET_HEADER_PING: { case PACKET_HEADER_PING: {
@ -98,7 +98,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size
} }
} }
void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent) { void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) {
// find the avatar mixer in our agent list and update the lastRecvTime from it // find the avatar mixer in our agent list and update the lastRecvTime from it
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress); int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
@ -120,6 +120,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
memcpy(packetHolder + 1, currentPosition, numBytesPerAgent); memcpy(packetHolder + 1, currentPosition, numBytesPerAgent);
int matchingAgentIndex = indexOfMatchingAgent(agentID); int matchingAgentIndex = indexOfMatchingAgent(agentID);
if (matchingAgentIndex >= 0) { if (matchingAgentIndex >= 0) {
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1); updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
} }
@ -130,7 +131,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
delete[] packetHolder; delete[] packetHolder;
} }
void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
// find the agent by the sockaddr // find the agent by the sockaddr
int agentIndex = indexOfMatchingAgent(senderAddress); int agentIndex = indexOfMatchingAgent(senderAddress);
@ -139,7 +140,7 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, s
} }
} }
void AgentList::updateAgentWithData(Agent *agent, void *packetData, int dataBytes) { void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
agent->setLastRecvTimeUsecs(usecTimestampNow()); agent->setLastRecvTimeUsecs(usecTimestampNow());
if (agent->getLinkedData() == NULL) { if (agent->getLinkedData() == NULL) {
@ -257,7 +258,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
} }
} }
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) {
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) { for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
// only send to the AgentTypes we are asked to send to. // only send to the AgentTypes we are asked to send to.
if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) { if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) {

View file

@ -49,13 +49,13 @@ public:
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId); bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes); void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent); void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes); void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void updateAgentWithData(Agent *agent, void *packetData, int dataBytes); void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes); void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
char getOwnerType(); char getOwnerType();
unsigned int getSocketListenPort(); unsigned int getSocketListenPort();

View file

@ -32,9 +32,9 @@ struct Rotations {
static float halfPi() { return 0.25f; } static float halfPi() { return 0.25f; }
}; };
/** //
* Converts an angle from one unit to another. // Converts an angle from one unit to another.
*/ //
template< class UnitFrom, class UnitTo > template< class UnitFrom, class UnitTo >
float angleConvert(float a) { float angleConvert(float a) {
@ -42,21 +42,28 @@ float angleConvert(float a) {
} }
/** //
* Clamps an angle to the range of [-180; 180) degrees. // Clamps an angle to the range of [-180; 180) degrees.
*/ //
template< class Unit > template< class Unit >
float angleSignedNormal(float a) { float angleSignedNormal(float a) {
float result = remainder(a, Unit::twicePi()); // result is remainder(a, Unit::twicePi());
if (result == Unit::pi()) float result = fmod(a, Unit::twicePi());
result = -Unit::pi(); if (result >= Unit::pi()) {
result -= Unit::twicePi();
} else if (result < -Unit::pi()) {
result += Unit::twicePi();
}
return result; return result;
} }
/** //
* Clamps an angle to the range of [0; 360) degrees. // Clamps an angle to the range of [0; 360) degrees.
*/ //
template< class Unit > template< class Unit >
float angleUnsignedNormal(float a) { float angleUnsignedNormal(float a) {
@ -64,13 +71,13 @@ float angleUnsignedNormal(float a) {
} }
/** //
* Clamps a polar direction so that azimuth is in the range of [0; 360) // Clamps a polar direction so that azimuth is in the range of [0; 360)
* degrees and altitude is in the range of [-90; 90] degrees. // degrees and altitude is in the range of [-90; 90] degrees.
* //
* The so normalized angle still contains ambiguity due to gimbal lock: // The so normalized angle still contains ambiguity due to gimbal lock:
* Both poles can be reached from any azimuthal direction. // Both poles can be reached from any azimuthal direction.
*/ //
template< class Unit > template< class Unit >
void angleHorizontalPolar(float& azimuth, float& altitude) { void angleHorizontalPolar(float& azimuth, float& altitude) {

View file

@ -105,12 +105,10 @@ void AudioRingBuffer::setBearing(float newBearing) {
bearing = newBearing; bearing = newBearing;
} }
void AudioRingBuffer::parseData(void *data, int size) { void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char *audioDataStart = (unsigned char *) data; if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
if (size > (bufferLengthSamples * sizeof(int16_t))) { unsigned char *dataPtr = sourceBuffer + 1;
unsigned char *dataPtr = audioDataStart + 1;
for (int p = 0; p < 3; p ++) { for (int p = 0; p < 3; p ++) {
memcpy(&position[p], dataPtr, sizeof(float)); memcpy(&position[p], dataPtr, sizeof(float));
@ -123,7 +121,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
memcpy(&bearing, dataPtr, sizeof(float)); memcpy(&bearing, dataPtr, sizeof(float));
dataPtr += sizeof(float); dataPtr += sizeof(float);
audioDataStart = dataPtr; sourceBuffer = dataPtr;
} }
if (endOfLastWrite == NULL) { if (endOfLastWrite == NULL) {
@ -134,7 +132,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
started = false; started = false;
} }
memcpy(endOfLastWrite, audioDataStart, bufferLengthSamples * sizeof(int16_t)); memcpy(endOfLastWrite, sourceBuffer, bufferLengthSamples * sizeof(int16_t));
endOfLastWrite += bufferLengthSamples; endOfLastWrite += bufferLengthSamples;

View file

@ -19,7 +19,7 @@ class AudioRingBuffer : public AgentData {
~AudioRingBuffer(); ~AudioRingBuffer();
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer); AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
void parseData(void *data, int size); void parseData(unsigned char* sourceBuffer, int numBytes);
AudioRingBuffer* clone() const; AudioRingBuffer* clone() const;
int16_t* getNextOutput(); int16_t* getNextOutput();

View file

@ -10,6 +10,7 @@
#define __hifi__SharedUtil__ #define __hifi__SharedUtil__
#include <stdint.h> #include <stdint.h>
#include <math.h>
#ifdef _WIN32 #ifdef _WIN32
#include "Systime.h" #include "Systime.h"
@ -17,6 +18,21 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
static const float ZERO = 0.0;
static const float ONE = 1.0;
static const float ONE_HALF = 0.5;
static const double ONE_THIRD = 0.3333333;
static const double PIE = 3.14159265359;
static const double PI_TIMES_TWO = 3.14159265359 * 2.0;
static const double PI_OVER_180 = 3.14159265359 / 180.0;
static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations
static const double SQUARE_ROOT_OF_2 = sqrt(2);
static const double SQUARE_ROOT_OF_3 = sqrt(3);
static const float METER = 1.0;
static const float DECIMETER = 0.1;
static const float CENTIMETER = 0.01;
static const float MILLIIMETER = 0.001;
double usecTimestamp(timeval *time); double usecTimestamp(timeval *time);
double usecTimestampNow(); double usecTimestampNow();

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../../) set(ROOT_DIR ../..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
# setup for find modules # setup for find modules
@ -8,19 +8,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm
set(TARGET_NAME voxels) set(TARGET_NAME voxels)
project(${TARGET_NAME}) include(${MACRO_DIR}/SetupHifiLibrary.cmake)
setup_hifi_library(${TARGET_NAME})
# set up the external glm library
include(${MACRO_DIR}/IncludeGLM.cmake) include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${MACRO_DIR}) include_glm(${TARGET_NAME} ${ROOT_DIR})
# grab the implemenation and header files
file(GLOB HIFI_VOXELS_SRCS src/*.h src/*.cpp)
# create a library and set the property so it can be referenced later
add_library(${TARGET_NAME} ${HIFI_VOXELS_SRCS})
include(${MACRO_DIR}/LinkHifiLibrary.cmake) include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
set(HIFI_VOXELS_LIBRARY ${TARGET_NAME})

View file

@ -8,7 +8,6 @@
// //
// //
#include "Util.h"
#include "ViewFrustum.h" #include "ViewFrustum.h"
ViewFrustum::ViewFrustum() : ViewFrustum::ViewFrustum() :

View file

@ -192,37 +192,23 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) {
VoxelNode* parentNode = NULL; VoxelNode* parentNode = NULL;
VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode); VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode);
printf("deleteVoxelCodeFromTree() looking [codeBuffer] for:\n");
printOctalCode(codeBuffer);
printf("deleteVoxelCodeFromTree() found [nodeToDelete->octalCode] for:\n");
printOctalCode(nodeToDelete->octalCode);
// If the node exists... // If the node exists...
int lengthInBytes = bytesRequiredForCodeLength(*codeBuffer); // includes octet count, not color! int lengthInBytes = bytesRequiredForCodeLength(*codeBuffer); // includes octet count, not color!
printf("compare octal codes of length %d\n",lengthInBytes);
if (0==memcmp(nodeToDelete->octalCode,codeBuffer,lengthInBytes)) { if (0 == memcmp(nodeToDelete->octalCode,codeBuffer,lengthInBytes)) {
printf("found node to delete...\n");
float* vertices = firstVertexForCode(nodeToDelete->octalCode); float* vertices = firstVertexForCode(nodeToDelete->octalCode);
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
delete []vertices; delete []vertices;
if (parentNode) { if (parentNode) {
float* vertices = firstVertexForCode(parentNode->octalCode); float* vertices = firstVertexForCode(parentNode->octalCode);
printf("parent of deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
delete []vertices; delete []vertices;
int childNDX = branchIndexWithDescendant(parentNode->octalCode, codeBuffer); int childNDX = branchIndexWithDescendant(parentNode->octalCode, codeBuffer);
printf("child INDEX=%d\n",childNDX);
printf("deleting Node at parentNode->children[%d]\n",childNDX);
delete parentNode->children[childNDX]; // delete the child nodes delete parentNode->children[childNDX]; // delete the child nodes
printf("setting parentNode->children[%d] to NULL\n",childNDX);
parentNode->children[childNDX]=NULL; // set it to NULL parentNode->children[childNDX]=NULL; // set it to NULL
printf("reaverageVoxelColors()\n");
reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode
} }
} }

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME space-server) set(TARGET_NAME space-server)

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
set(TARGET_NAME voxel-server) set(TARGET_NAME voxel-server)
set(ROOT_DIR ../) set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
include(${MACRO_DIR}/SetupHifiProject.cmake) include(${MACRO_DIR}/SetupHifiProject.cmake)

View file

@ -27,9 +27,10 @@ VoxelAgentData* VoxelAgentData::clone() const {
return new VoxelAgentData(*this); return new VoxelAgentData(*this);
} }
void VoxelAgentData::parseData(void *data, int size) { void VoxelAgentData::parseData(unsigned char* sourceBuffer, int numBytes) {
// push past the packet header
sourceBuffer++;
// pull the position from the interface agent data packet // pull the position from the interface agent data packet
sscanf((char *)data, memcpy(&position, sourceBuffer, sizeof(float) * 3);
"H%*f,%*f,%*f,%f,%f,%f",
&position[0], &position[1], &position[2]);
} }

View file

@ -22,7 +22,7 @@ public:
~VoxelAgentData(); ~VoxelAgentData();
VoxelAgentData(const VoxelAgentData &otherAgentData); VoxelAgentData(const VoxelAgentData &otherAgentData);
void parseData(void *data, int size); void parseData(unsigned char* sourceBuffer, int numBytes);
VoxelAgentData* clone() const; VoxelAgentData* clone() const;
}; };

View file

@ -289,7 +289,7 @@ int main(int argc, const char * argv[])
sockaddr agentPublicAddress; sockaddr agentPublicAddress;
char *packetData = new char[MAX_PACKET_SIZE]; unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
ssize_t receivedBytes; ssize_t receivedBytes;
// loop to send to agents requesting data // loop to send to agents requesting data
@ -352,7 +352,7 @@ int main(int argc, const char * argv[])
// the Z command is a special command that allows the sender to send the voxel server high level semantic // the Z command is a special command that allows the sender to send the voxel server high level semantic
// requests, like erase all, or add sphere scene // requests, like erase all, or add sphere scene
char* command = &packetData[1]; // start of the command char* command = (char*) &packetData[1]; // start of the command
int commandLength = strlen(command); // commands are null terminated strings int commandLength = strlen(command); // commands are null terminated strings
int totalLength = 1+commandLength+1; int totalLength = 1+commandLength+1;
@ -385,7 +385,7 @@ int main(int argc, const char * argv[])
agentList->increaseAgentId(); agentList->increaseAgentId();
} }
agentList->updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes); agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes);
} }
} }
} }