mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge branch 'master' of git://github.com/worklist/hifi into 19262
This commit is contained in:
commit
ba4f6bc92c
59 changed files with 1683 additions and 1112 deletions
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
set(TARGET_NAME audio-mixer)
|
||||
|
|
|
@ -309,7 +309,7 @@ int main(int argc, const char * argv[])
|
|||
agentList->increaseAgentId();
|
||||
}
|
||||
|
||||
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes);
|
||||
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
|
||||
} else {
|
||||
memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024);
|
||||
agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024);
|
||||
|
|
|
@ -2,17 +2,21 @@ cmake_minimum_required(VERSION 2.8)
|
|||
|
||||
set(TARGET_NAME "avatar-mixer")
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
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/")
|
||||
|
||||
# setup the project
|
||||
include(${MACRO_DIR}/SetupHifiProject.cmake)
|
||||
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)
|
||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||
|
||||
# link the threads library
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
|
||||
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
|
|
@ -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;
|
||||
}
|
|
@ -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__) */
|
|
@ -32,37 +32,22 @@
|
|||
#include <StdDev.h>
|
||||
#include <UDPSocket.h>
|
||||
|
||||
#include "AvatarAgentData.h"
|
||||
#include "AvatarData.h"
|
||||
|
||||
const int AVATAR_LISTEN_PORT = 55444;
|
||||
const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000;
|
||||
|
||||
unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
|
||||
currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket());
|
||||
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;
|
||||
}
|
||||
|
||||
void attachAvatarDataToAgent(Agent *newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new AvatarAgentData());
|
||||
newAgent->setLinkedData(new AvatarData());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +63,7 @@ int main(int argc, char* argv[])
|
|||
agentList->startPingUnknownAgentsThread();
|
||||
|
||||
sockaddr *agentAddress = new sockaddr;
|
||||
char *packetData = new char[MAX_PACKET_SIZE];
|
||||
unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE];
|
||||
|
@ -92,7 +77,7 @@ int main(int argc, char* argv[])
|
|||
switch (packetData[0]) {
|
||||
case PACKET_HEADER_HEAD_DATA:
|
||||
// this is positional data from an agent
|
||||
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes);
|
||||
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
|
||||
|
||||
currentBufferPosition = broadcastPacket + 1;
|
||||
agentIndex = 0;
|
||||
|
@ -116,7 +101,7 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
default:
|
||||
// hand this off to the AgentList
|
||||
agentList->processAgentData(agentAddress, (void *)packetData, receivedBytes);
|
||||
agentList->processAgentData(agentAddress, packetData, receivedBytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MACRO(INCLUDE_GLM TARGET MACRO_DIR)
|
||||
set(GLM_ROOT_DIR ${MACRO_DIR}/../../externals)
|
||||
MACRO(INCLUDE_GLM TARGET ROOT_DIR)
|
||||
set(GLM_ROOT_DIR ${ROOT_DIR}/externals)
|
||||
find_package(GLM REQUIRED)
|
||||
include_directories(${GLM_INCLUDE_DIRS})
|
||||
ENDMACRO(INCLUDE_GLM _target _macro_dir)
|
||||
ENDMACRO(INCLUDE_GLM _target _root_dir)
|
|
@ -3,12 +3,6 @@ MACRO(LINK_HIFI_LIBRARY LIBRARY TARGET ROOT_DIR)
|
|||
add_subdirectory(${ROOT_DIR}/libraries/${LIBRARY} ${ROOT_DIR}/libraries/${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)
|
||||
|
||||
add_dependencies(${TARGET} ${LIBRARY})
|
||||
|
|
9
cmake/macros/SetupHifiLibrary.cmake
Normal file
9
cmake/macros/SetupHifiLibrary.cmake
Normal 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)
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
set(TARGET_NAME domain-server)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
set(TARGET_NAME injector)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
set(TARGET_NAME interface)
|
||||
|
@ -26,7 +26,7 @@ endif (WIN32)
|
|||
|
||||
# set up the external glm library
|
||||
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
|
||||
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
|
||||
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(avatars ${TARGET_NAME} ${ROOT_DIR})
|
||||
|
||||
# find required libraries
|
||||
find_package(GLM REQUIRED)
|
||||
|
|
|
@ -156,7 +156,7 @@ int audioCallback (const void *inputBuffer,
|
|||
|
||||
// memcpy the three float positions
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ void *receiveAudioViaUDP(void *args) {
|
|||
}
|
||||
if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL);
|
||||
|
||||
ringBuffer->parseData(receivedData, PACKET_LENGTH_BYTES);
|
||||
ringBuffer->parseData((unsigned char *)receivedData, PACKET_LENGTH_BYTES);
|
||||
|
||||
previousReceiveTime = currentReceiveTime;
|
||||
}
|
||||
|
|
68
interface/src/Camera.cpp
Executable file → Normal file
68
interface/src/Camera.cpp
Executable file → Normal file
|
@ -5,44 +5,52 @@
|
|||
//
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#include "Camera.h"
|
||||
#include "Util.h"
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Camera.h"
|
||||
|
||||
//------------------------
|
||||
Camera::Camera()
|
||||
{
|
||||
mode = CAMERA_MODE_THIRD_PERSON;
|
||||
fieldOfView = 60.0; // default
|
||||
yaw = 0.0;
|
||||
pitch = 0.0;
|
||||
roll = 0.0;
|
||||
up = 0.0;
|
||||
distance = 0.0;
|
||||
targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
orientation.setToIdentity();
|
||||
_mode = CAMERA_MODE_THIRD_PERSON;
|
||||
_tightness = DEFAULT_CAMERA_TIGHTNESS;
|
||||
_fieldOfView = 60.0; // default
|
||||
_nearClip = 0.01; // default
|
||||
_farClip = 50.0; // default
|
||||
_yaw = 0.0;
|
||||
_pitch = 0.0;
|
||||
_roll = 0.0;
|
||||
_up = 0.0;
|
||||
_distance = 0.0;
|
||||
_idealYaw = 0.0;
|
||||
_targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_idealPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_orientation.setToIdentity();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------
|
||||
void Camera::update()
|
||||
void Camera::update( float deltaTime )
|
||||
{
|
||||
double radian = ( yaw / 180.0 ) * PIE;
|
||||
float radian = ( _yaw / 180.0 ) * PIE;
|
||||
|
||||
//these need to be checked to make sure they correspond to the cordinate system.
|
||||
double x = distance * -sin( radian );
|
||||
double z = distance * cos( radian );
|
||||
double y = up;
|
||||
//these need to be checked to make sure they correspond to the coordinate system.
|
||||
double x = _distance * -sin( radian );
|
||||
double z = _distance * cos( radian );
|
||||
double y = _up;
|
||||
|
||||
_idealPosition = _targetPosition + glm::vec3( x, y, z );
|
||||
float t = _tightness * deltaTime;
|
||||
|
||||
position = targetPosition + glm::vec3( x, y, z );
|
||||
if ( t > 1.0 ){
|
||||
t = 1.0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//geterate the ortho-normals for the orientation based on the Euler angles
|
||||
//------------------------------------------------------------------------
|
||||
orientation.setToIdentity();
|
||||
orientation.yaw ( yaw );
|
||||
orientation.pitch ( pitch );
|
||||
orientation.roll ( roll );
|
||||
_position += ( _idealPosition - _position ) * t;
|
||||
_yaw += ( _idealYaw - _yaw ) * t;
|
||||
|
||||
// generate the ortho-normals for the orientation based on the Euler angles
|
||||
_orientation.setToIdentity();
|
||||
_orientation.yaw ( _yaw );
|
||||
_orientation.pitch ( _pitch );
|
||||
_orientation.roll ( _roll );
|
||||
}
|
||||
|
||||
|
|
84
interface/src/Camera.h
Executable file → Normal file
84
interface/src/Camera.h
Executable file → Normal file
|
@ -13,50 +13,66 @@
|
|||
|
||||
enum CameraMode
|
||||
{
|
||||
CAMERA_MODE_NULL = -1,
|
||||
CAMERA_MODE_FIRST_PERSON,
|
||||
CAMERA_MODE_THIRD_PERSON,
|
||||
CAMERA_MODE_MY_OWN_FACE,
|
||||
NUM_CAMERA_MODES
|
||||
CAMERA_MODE_NULL = -1,
|
||||
CAMERA_MODE_FIRST_PERSON,
|
||||
CAMERA_MODE_THIRD_PERSON,
|
||||
CAMERA_MODE_MY_OWN_FACE,
|
||||
NUM_CAMERA_MODES
|
||||
};
|
||||
|
||||
static const float DEFAULT_CAMERA_TIGHTNESS = 10.0f;
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
Camera();
|
||||
|
||||
void update();
|
||||
|
||||
void setMode ( CameraMode m ) { mode = m; }
|
||||
void setYaw ( float y ) { yaw = y; }
|
||||
void setPitch ( float p ) { pitch = p; }
|
||||
void setRoll ( float r ) { roll = r; }
|
||||
void setUp ( float u ) { up = u; }
|
||||
void setDistance ( float d ) { distance = d; }
|
||||
void setTargetPosition ( glm::vec3 t ) { targetPosition = t; };
|
||||
void setPosition ( glm::vec3 p ) { position = p; };
|
||||
void setOrientation ( Orientation o ) { orientation.set(o); }
|
||||
Camera();
|
||||
|
||||
float getYaw () { return yaw; }
|
||||
float getPitch () { return pitch; }
|
||||
float getRoll () { return roll; }
|
||||
glm::vec3 getPosition () { return position; }
|
||||
Orientation getOrientation () { return orientation; }
|
||||
CameraMode getMode () { return mode; }
|
||||
void update( float deltaTime );
|
||||
|
||||
void setMode ( CameraMode m ) { _mode = m; }
|
||||
void setYaw ( float y ) { _idealYaw = y; }
|
||||
void setPitch ( float p ) { _pitch = p; }
|
||||
void setRoll ( float r ) { _roll = r; }
|
||||
void setUp ( float u ) { _up = u; }
|
||||
void setDistance ( float d ) { _distance = d; }
|
||||
void setTargetPosition ( glm::vec3 t ) { _targetPosition = t; };
|
||||
void setPosition ( glm::vec3 p ) { _position = p; };
|
||||
void setOrientation ( Orientation o ) { _orientation.set(o); }
|
||||
void setTightness ( float t ) { _tightness = t; }
|
||||
void setFieldOfView ( float f ) { _fieldOfView = f; }
|
||||
void setAspectRatio ( float a ) { _aspectRatio = a; }
|
||||
void setNearClip ( float n ) { _nearClip = n; }
|
||||
void setFarClip ( float f ) { _farClip = f; }
|
||||
|
||||
float getYaw () { return _yaw; }
|
||||
float getPitch () { return _pitch; }
|
||||
float getRoll () { return _roll; }
|
||||
glm::vec3 getPosition () { return _position; }
|
||||
Orientation getOrientation () { return _orientation; }
|
||||
CameraMode getMode () { return _mode; }
|
||||
float getFieldOfView () { return _fieldOfView; }
|
||||
float getAspectRatio () { return _aspectRatio; }
|
||||
float getNearClip () { return _nearClip; }
|
||||
float getFarClip () { return _farClip; }
|
||||
|
||||
private:
|
||||
|
||||
CameraMode mode;
|
||||
glm::vec3 position;
|
||||
glm::vec3 targetPosition;
|
||||
float fieldOfView;
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
float up;
|
||||
float distance;
|
||||
Orientation orientation;
|
||||
CameraMode _mode;
|
||||
glm::vec3 _position;
|
||||
glm::vec3 _idealPosition;
|
||||
glm::vec3 _targetPosition;
|
||||
float _fieldOfView;
|
||||
float _aspectRatio;
|
||||
float _nearClip;
|
||||
float _farClip;
|
||||
float _yaw;
|
||||
float _pitch;
|
||||
float _roll;
|
||||
float _up;
|
||||
float _idealYaw;
|
||||
float _distance;
|
||||
float _tightness;
|
||||
Orientation _orientation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// interface
|
||||
//
|
||||
// Created by Philip Rosedale on 9/11/12.
|
||||
// adapted by Jeffrey Ventrella, starting on April 2, 2013
|
||||
// adapted by Jeffrey Ventrella
|
||||
// Copyright (c) 2012 Physical, Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
|||
#include "Head.h"
|
||||
#include <AgentList.h>
|
||||
#include <AgentTypes.h>
|
||||
#include <PacketHeaders.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -35,6 +36,8 @@ float browWidth = 0.8;
|
|||
float browThickness = 0.16;
|
||||
|
||||
const float DECAY = 0.1;
|
||||
const float THRUST_MAG = 10.0;
|
||||
const float YAW_MAG = 300.0;
|
||||
|
||||
char iris_texture_file[] = "resources/images/green_eye.png";
|
||||
|
||||
|
@ -42,15 +45,8 @@ vector<unsigned char> iris_texture;
|
|||
unsigned int iris_texture_width = 512;
|
||||
unsigned int iris_texture_height = 256;
|
||||
|
||||
|
||||
|
||||
|
||||
Head::Head() {
|
||||
initializeAvatar();
|
||||
|
||||
//position = glm::vec3(0,0,0);
|
||||
//velocity = glm::vec3(0,0,0);
|
||||
//thrust = glm::vec3(0,0,0);
|
||||
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false;
|
||||
|
||||
|
@ -95,7 +91,6 @@ Head::Head() {
|
|||
usingSprings = false;
|
||||
|
||||
springForce = 6.0f;
|
||||
springToBodyTightness = 4.0f;
|
||||
springVelocityDecay = 16.0f;
|
||||
|
||||
if (iris_texture.size() == 0) {
|
||||
|
@ -106,8 +101,7 @@ Head::Head() {
|
|||
}
|
||||
}
|
||||
|
||||
for (int o=0; o<NUM_OTHER_AVATARS; o++)
|
||||
{
|
||||
for (int o=0; o<NUM_OTHER_AVATARS; o++) {
|
||||
DEBUG_otherAvatarListTimer[o] = 0.0f;
|
||||
DEBUG_otherAvatarListPosition[o] = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
@ -115,11 +109,11 @@ Head::Head() {
|
|||
//--------------------------------------------------
|
||||
// test... just slam them into random positions...
|
||||
//--------------------------------------------------
|
||||
DEBUG_otherAvatarListPosition[ 0 ] = glm::vec3( 0.0, 0.1, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 1 ] = glm::vec3( 4.0, 0.1, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 2 ] = glm::vec3( 2.0, 0.1, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 3 ] = glm::vec3( 1.0, 0.1, -4.0 );
|
||||
DEBUG_otherAvatarListPosition[ 4 ] = glm::vec3( -2.0, 0.1, -2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 0 ] = glm::vec3( 0.0, 0.3, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 1 ] = glm::vec3( 4.0, 0.3, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 2 ] = glm::vec3( 2.0, 0.3, 2.0 );
|
||||
DEBUG_otherAvatarListPosition[ 3 ] = glm::vec3( 1.0, 0.3, -4.0 );
|
||||
DEBUG_otherAvatarListPosition[ 4 ] = glm::vec3( -2.0, 0.3, -2.0 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,9 +122,6 @@ Head::Head() {
|
|||
Head::Head(const Head &otherHead) {
|
||||
initializeAvatar();
|
||||
|
||||
position = otherHead.position;
|
||||
//velocity = otherHead.velocity;
|
||||
//thrust = otherHead.thrust;
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i];
|
||||
|
||||
PupilSize = otherHead.PupilSize;
|
||||
|
@ -223,6 +214,7 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
|
|||
|
||||
if ((Pitch < MAX_PITCH) && (Pitch > MIN_PITCH))
|
||||
addPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime);
|
||||
|
||||
addRoll(-measured_roll_rate * HEAD_ROLL_SCALE * frametime);
|
||||
|
||||
if (head_mirror) {
|
||||
|
@ -251,13 +243,18 @@ void Head::setLeanSideways(float dist){
|
|||
leanSideways = dist;
|
||||
}
|
||||
|
||||
void Head::setTriggeringAction( bool d ) {
|
||||
triggeringAction = d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Head::simulate(float deltaTime) {
|
||||
|
||||
//-------------------------------------
|
||||
// DEBUG - other avatars...
|
||||
//-------------------------------------
|
||||
closeEnoughToInteract = 0.5f;
|
||||
//closeEnoughToInteract = 0.3f;
|
||||
closestOtherAvatar = -1;
|
||||
float closestDistance = 10000.0f;
|
||||
|
||||
|
@ -279,26 +276,15 @@ void Head::simulate(float deltaTime) {
|
|||
*/
|
||||
|
||||
for (int o=0; o<NUM_OTHER_AVATARS; o++) {
|
||||
|
||||
/*
|
||||
//-------------------------------------
|
||||
// move the debug other avatars around...
|
||||
//-------------------------------------
|
||||
DEBUG_otherAvatarListTimer[o] += deltaTime;
|
||||
float x = 6.0f * sin( DEBUG_otherAvatarListTimer[o] * 0.07 + o * 129.0 );
|
||||
float z = 6.0f * sin( DEBUG_otherAvatarListTimer[o] * 0.10 + o * 12.0 );
|
||||
float y = 0.0f;
|
||||
*/
|
||||
|
||||
//-------------------------------------
|
||||
// test other avs for proximity...
|
||||
//-------------------------------------
|
||||
glm::vec3 v( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
glm::vec3 v( bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
|
||||
v -= DEBUG_otherAvatarListPosition[o];
|
||||
|
||||
float distance = glm::length( v );
|
||||
|
||||
if ( distance < closeEnoughToInteract ) {
|
||||
if ( distance < avatar.maxArmLength ) {
|
||||
if ( distance < closestDistance ) {
|
||||
closestDistance = distance;
|
||||
closestOtherAvatar = o;
|
||||
|
@ -324,7 +310,7 @@ void Head::simulate(float deltaTime) {
|
|||
//printf( "just started moving hand\n" );
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
if ( previousHandBeingMoved ){
|
||||
usingSprings = false;
|
||||
//printf( "just stopped moving hand\n" );
|
||||
|
@ -339,14 +325,11 @@ void Head::simulate(float deltaTime) {
|
|||
previousHandBeingMoved = handBeingMoved;
|
||||
handBeingMoved = false;
|
||||
|
||||
|
||||
|
||||
const float THRUST_MAG = 10.0;
|
||||
const float YAW_MAG = 300.0;
|
||||
|
||||
//-------------------------------------------------
|
||||
// this handles the avatar being driven around...
|
||||
//-------------------------------------------------
|
||||
avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
|
||||
//notice that the z values from avatar.orientation are flipped to accommodate different coordinate system
|
||||
if (driveKeys[FWD]) {
|
||||
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z );
|
||||
avatar.thrust += front * THRUST_MAG;
|
||||
|
@ -378,40 +361,51 @@ void Head::simulate(float deltaTime) {
|
|||
bodyYawDelta += YAW_MAG * deltaTime;
|
||||
}
|
||||
|
||||
bodyYaw += bodyYawDelta * deltaTime;
|
||||
//----------------------------------------------------------
|
||||
float translationalSpeed = glm::length( avatar.velocity );
|
||||
float rotationalSpeed = fabs( bodyYawDelta );
|
||||
if ( translationalSpeed + rotationalSpeed > 0.2 )
|
||||
{
|
||||
mode = AVATAR_MODE_WALKING;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = AVATAR_MODE_COMMUNICATING;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// update body yaw by body yaw delta
|
||||
//----------------------------------------------------------
|
||||
_bodyYaw += bodyYawDelta * deltaTime;
|
||||
|
||||
Yaw = bodyYaw;
|
||||
//----------------------------------------------------------
|
||||
// (for now) set head yaw to body yaw
|
||||
//----------------------------------------------------------
|
||||
Yaw = _bodyYaw;
|
||||
|
||||
//----------------------------------------------------------
|
||||
// decay body yaw delta
|
||||
//----------------------------------------------------------
|
||||
const float TEST_YAW_DECAY = 5.0;
|
||||
bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
|
||||
|
||||
//----------------------------------------------------------
|
||||
// add thrust to velocity
|
||||
//----------------------------------------------------------
|
||||
avatar.velocity += glm::dvec3( avatar.thrust * deltaTime );
|
||||
|
||||
position += (glm::vec3)avatar.velocity * deltaTime;
|
||||
//avatar.position += (glm::vec3)avatar.velocity * deltaTime;
|
||||
//position = avatar.position;
|
||||
|
||||
//avatar.velocity *= 0.9;
|
||||
//----------------------------------------------------------
|
||||
// update position by velocity
|
||||
//----------------------------------------------------------
|
||||
_bodyPosition += (glm::vec3)avatar.velocity * deltaTime;
|
||||
|
||||
//----------------------------------------------------------
|
||||
// decay velocity
|
||||
//----------------------------------------------------------
|
||||
const float LIN_VEL_DECAY = 5.0;
|
||||
avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
|
||||
|
||||
|
||||
/*
|
||||
// Increment velocity as time
|
||||
velocity += thrust * deltaTime;
|
||||
|
||||
// Increment position as a function of velocity
|
||||
position += velocity * deltaTime;
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
// Decay velocity
|
||||
const float LIN_VEL_DECAY = 5.0;
|
||||
velocity *= (1.0 - LIN_VEL_DECAY*deltaTime);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
if (!noise) {
|
||||
// Decay back toward center
|
||||
|
@ -518,7 +512,7 @@ void Head::render(int faceToFace, int isMine) {
|
|||
// show avatar position
|
||||
//---------------------------------------------------
|
||||
glPushMatrix();
|
||||
glTranslatef( position.x, position.y, position.z );
|
||||
glTranslatef(_bodyPosition.x, _bodyPosition.y, _bodyPosition.z);
|
||||
glScalef( 0.03, 0.03, 0.03 );
|
||||
glutSolidSphere( 1, 10, 10 );
|
||||
glPopMatrix();
|
||||
|
@ -526,7 +520,7 @@ void Head::render(int faceToFace, int isMine) {
|
|||
//---------------------------------------------------
|
||||
// show avatar orientation
|
||||
//---------------------------------------------------
|
||||
renderOrientationDirections(avatar.bone[ AVATAR_BONE_HEAD ].position, avatar.bone[ AVATAR_BONE_HEAD ].orientation, 0.2f );
|
||||
renderOrientationDirections(bone[ AVATAR_BONE_HEAD ].position, bone[ AVATAR_BONE_HEAD ].orientation, 0.2f );
|
||||
|
||||
//---------------------------------------------------
|
||||
// render body
|
||||
|
@ -552,7 +546,7 @@ void Head::render(int faceToFace, int isMine) {
|
|||
if ( usingSprings ) {
|
||||
if ( closestOtherAvatar != -1 ) {
|
||||
|
||||
glm::vec3 v1( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
glm::vec3 v1( bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
glm::vec3 v2( DEBUG_otherAvatarListPosition[ closestOtherAvatar ] );
|
||||
|
||||
glLineWidth( 5.0 );
|
||||
|
@ -568,25 +562,25 @@ void Head::render(int faceToFace, int isMine) {
|
|||
|
||||
|
||||
void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) {
|
||||
glm::vec3 pRight = position + orientation.getRight () * size;
|
||||
glm::vec3 pUp = position + orientation.getUp () * size;
|
||||
glm::vec3 pFront = position + orientation.getFront () * size;
|
||||
glm::vec3 pRight = position + orientation.right * size;
|
||||
glm::vec3 pUp = position + orientation.up * size;
|
||||
glm::vec3 pFront = position + orientation.front * size;
|
||||
|
||||
glColor3f( 1.0f, 0.0f, 0.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pRight.x, pRight.y, pRight.z );
|
||||
glEnd();
|
||||
|
||||
glColor3f( 0.0f, 1.0f, 0.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pUp.x, pUp.y, pUp.z );
|
||||
glEnd();
|
||||
|
||||
glColor3f( 0.0f, 0.0f, 1.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( bone[ AVATAR_BONE_HEAD ].position.x, bone[ AVATAR_BONE_HEAD ].position.y, bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pFront.x, pFront.y, pFront.z );
|
||||
glEnd();
|
||||
}
|
||||
|
@ -605,33 +599,27 @@ void Head::renderHead( int faceToFace, int isMine ) {
|
|||
if ( usingSprings ) {
|
||||
glTranslatef
|
||||
(
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].springyPosition.x,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].springyPosition.y,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].springyPosition.z
|
||||
bone[ AVATAR_BONE_HEAD ].springyPosition.x,
|
||||
bone[ AVATAR_BONE_HEAD ].springyPosition.y,
|
||||
bone[ AVATAR_BONE_HEAD ].springyPosition.z
|
||||
);
|
||||
}
|
||||
else {
|
||||
glTranslatef
|
||||
(
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.x,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.y,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.z
|
||||
bone[ AVATAR_BONE_HEAD ].position.x,
|
||||
bone[ AVATAR_BONE_HEAD ].position.y,
|
||||
bone[ AVATAR_BONE_HEAD ].position.z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
glScalef( 0.03, 0.03, 0.03 );
|
||||
|
||||
|
||||
//glTranslatef(leanSideways, 0.f, leanForward);
|
||||
glRotatef(_bodyYaw, 0, 1, 0);
|
||||
|
||||
//glRotatef(Yaw, 0, 1, 0);
|
||||
|
||||
glRotatef( bodyYaw, 0, 1, 0);
|
||||
|
||||
//hand->render(1);
|
||||
|
||||
// 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!
|
||||
//if (!isMine || faceToFace)
|
||||
{
|
||||
|
||||
|
@ -774,26 +762,34 @@ void Head::setHandMovement( glm::vec3 movement ) {
|
|||
movedHandOffset = movement;
|
||||
}
|
||||
|
||||
AvatarMode Head::getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
void Head::initializeAvatar() {
|
||||
//avatar.position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.orientation.setToIdentity();
|
||||
|
||||
closestOtherAvatar = 0;
|
||||
|
||||
bodyYaw = -90.0;
|
||||
bodyPitch = 0.0;
|
||||
bodyRoll = 0.0;
|
||||
_bodyYaw = -90.0;
|
||||
_bodyPitch = 0.0;
|
||||
_bodyRoll = 0.0;
|
||||
|
||||
bodyYawDelta = 0.0;
|
||||
|
||||
triggeringAction = false;
|
||||
|
||||
mode = AVATAR_MODE_STANDING;
|
||||
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
avatar.bone[b].position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.bone[b].springyVelocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.bone[b].orientation.setToIdentity();
|
||||
bone[b].position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
bone[b].springyVelocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
bone[b].springBodyTightness = 4.0;
|
||||
bone[b].orientation.setToIdentity();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -803,73 +799,73 @@ void Head::initializeAvatar() {
|
|||
//----------------------------------------------------------------------------
|
||||
// spine and head
|
||||
//----------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].parent = AVATAR_BONE_NULL;
|
||||
avatar.bone[ AVATAR_BONE_MID_SPINE ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].parent = AVATAR_BONE_MID_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_NECK ].parent = AVATAR_BONE_CHEST_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].parent = AVATAR_BONE_NECK;
|
||||
bone[ AVATAR_BONE_PELVIS_SPINE ].parent = AVATAR_BONE_NULL;
|
||||
bone[ AVATAR_BONE_MID_SPINE ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
bone[ AVATAR_BONE_CHEST_SPINE ].parent = AVATAR_BONE_MID_SPINE;
|
||||
bone[ AVATAR_BONE_NECK ].parent = AVATAR_BONE_CHEST_SPINE;
|
||||
bone[ AVATAR_BONE_HEAD ].parent = AVATAR_BONE_NECK;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// left chest and arm
|
||||
//----------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].parent = AVATAR_BONE_LEFT_CHEST;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].parent = AVATAR_BONE_LEFT_SHOULDER;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].parent = AVATAR_BONE_LEFT_UPPER_ARM;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_HAND ].parent = AVATAR_BONE_LEFT_FOREARM;
|
||||
bone[ AVATAR_BONE_LEFT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
|
||||
bone[ AVATAR_BONE_LEFT_SHOULDER ].parent = AVATAR_BONE_LEFT_CHEST;
|
||||
bone[ AVATAR_BONE_LEFT_UPPER_ARM ].parent = AVATAR_BONE_LEFT_SHOULDER;
|
||||
bone[ AVATAR_BONE_LEFT_FOREARM ].parent = AVATAR_BONE_LEFT_UPPER_ARM;
|
||||
bone[ AVATAR_BONE_LEFT_HAND ].parent = AVATAR_BONE_LEFT_FOREARM;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// right chest and arm
|
||||
//----------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].parent = AVATAR_BONE_RIGHT_CHEST;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].parent = AVATAR_BONE_RIGHT_SHOULDER;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].parent = AVATAR_BONE_RIGHT_UPPER_ARM;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].parent = AVATAR_BONE_RIGHT_FOREARM;
|
||||
bone[ AVATAR_BONE_RIGHT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
|
||||
bone[ AVATAR_BONE_RIGHT_SHOULDER ].parent = AVATAR_BONE_RIGHT_CHEST;
|
||||
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].parent = AVATAR_BONE_RIGHT_SHOULDER;
|
||||
bone[ AVATAR_BONE_RIGHT_FOREARM ].parent = AVATAR_BONE_RIGHT_UPPER_ARM;
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].parent = AVATAR_BONE_RIGHT_FOREARM;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// left pelvis and leg
|
||||
//----------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH;
|
||||
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN;
|
||||
bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS;
|
||||
bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH;
|
||||
bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// right pelvis and leg
|
||||
//----------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
|
||||
bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
|
||||
bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS;
|
||||
bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH;
|
||||
bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
|
||||
|
||||
|
||||
//----------------------------------------------------------
|
||||
// specify the default pose position
|
||||
//----------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition = glm::vec3( -0.06, 0.06, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.06, 0.06, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
|
||||
bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 );
|
||||
bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
|
||||
bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
|
||||
bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
|
||||
bone[ AVATAR_BONE_HEAD ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition = glm::vec3( -0.06, 0.06, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.06, 0.06, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
|
||||
bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
|
||||
bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// calculate bone length
|
||||
|
@ -883,67 +879,71 @@ void Head::initializeAvatar() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
void Head::calculateBoneLengths() {
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
avatar.bone[b].length = glm::length( avatar.bone[b].defaultPosePosition );
|
||||
bone[b].length = glm::length( bone[b].defaultPosePosition );
|
||||
}
|
||||
|
||||
avatar.maxArmLength
|
||||
= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length
|
||||
+ avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].length
|
||||
+ avatar.bone[ AVATAR_BONE_RIGHT_HAND ].length;
|
||||
= bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length
|
||||
+ bone[ AVATAR_BONE_RIGHT_FOREARM ].length
|
||||
+ bone[ AVATAR_BONE_RIGHT_HAND ].length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Head::updateAvatarSkeleton() {
|
||||
//----------------------------------
|
||||
// rotate...
|
||||
// rotate body...
|
||||
//----------------------------------
|
||||
avatar.orientation.setToIdentity();
|
||||
avatar.orientation.yaw( bodyYaw );
|
||||
avatar.orientation.yaw( _bodyYaw );
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// calculate positions of all bones by traversing the skeleton tree:
|
||||
//------------------------------------------------------------------------
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL ) {
|
||||
avatar.bone[b].orientation.set( avatar.orientation );
|
||||
avatar.bone[b].position = position;
|
||||
if ( bone[b].parent == AVATAR_BONE_NULL ) {
|
||||
bone[b].orientation.set(avatar.orientation);
|
||||
//printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z );
|
||||
glm::vec3 ppp = _bodyPosition;
|
||||
|
||||
// ppp.y += 0.2;
|
||||
|
||||
bone[b].position = ppp;// + glm::vec3( 0.0f, 1.0f, 0.0f ) * 1.0f;
|
||||
}
|
||||
else {
|
||||
avatar.bone[b].orientation.set( avatar.bone[ avatar.bone[b].parent ].orientation );
|
||||
avatar.bone[b].position = avatar.bone[ avatar.bone[b].parent ].position;
|
||||
bone[b].orientation.set( bone[ bone[b].parent ].orientation );
|
||||
bone[b].position = bone[ bone[b].parent ].position;
|
||||
}
|
||||
|
||||
float xx = glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getRight () );
|
||||
float yy = glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getUp () );
|
||||
float zz = -glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getFront () );
|
||||
float xx = glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getRight () );
|
||||
float yy = glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getUp () );
|
||||
float zz = -glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getFront () );
|
||||
|
||||
glm::vec3 rotatedBoneVector( xx, yy, zz );
|
||||
avatar.bone[b].position += rotatedBoneVector;
|
||||
bone[b].position += rotatedBoneVector;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Head::initializeAvatarSprings() {
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
avatar.bone[b].springyPosition = avatar.bone[b].position;
|
||||
avatar.bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
bone[b].springyPosition = bone[b].position;
|
||||
bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Head::updateAvatarSprings( float deltaTime ) {
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
glm::vec3 springVector( avatar.bone[b].springyPosition );
|
||||
glm::vec3 springVector( bone[b].springyPosition );
|
||||
|
||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL ) {
|
||||
springVector -= position;
|
||||
if ( bone[b].parent == AVATAR_BONE_NULL ) {
|
||||
springVector -= _bodyPosition;
|
||||
}
|
||||
else {
|
||||
springVector -= avatar.bone[ avatar.bone[b].parent ].springyPosition;
|
||||
springVector -= bone[ bone[b].parent ].springyPosition;
|
||||
}
|
||||
|
||||
float length = glm::length( springVector );
|
||||
|
@ -951,29 +951,29 @@ void Head::updateAvatarSprings( float deltaTime ) {
|
|||
if ( length > 0.0f ) {
|
||||
glm::vec3 springDirection = springVector / length;
|
||||
|
||||
float force = ( length - avatar.bone[b].length ) * springForce * deltaTime;
|
||||
float force = ( length - bone[b].length ) * springForce * deltaTime;
|
||||
|
||||
avatar.bone[ b ].springyVelocity -= springDirection * force;
|
||||
avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force;
|
||||
bone[ b ].springyVelocity -= springDirection * force;
|
||||
bone[ bone[b].parent ].springyVelocity += springDirection * force;
|
||||
}
|
||||
|
||||
avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime;
|
||||
bone[b].springyVelocity += ( bone[b].position - bone[b].springyPosition ) * bone[b].springBodyTightness * deltaTime;
|
||||
|
||||
float decay = 1.0 - springVelocityDecay * deltaTime;
|
||||
|
||||
if ( decay > 0.0 ) {
|
||||
avatar.bone[b].springyVelocity *= decay;
|
||||
bone[b].springyVelocity *= decay;
|
||||
}
|
||||
else {
|
||||
avatar.bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity;
|
||||
bone[b].springyPosition += bone[b].springyVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
float Head::getBodyYaw() {
|
||||
return bodyYaw;
|
||||
return _bodyYaw;
|
||||
}
|
||||
|
||||
glm::vec3 Head::getHeadLookatDirection() {
|
||||
|
@ -1006,46 +1006,48 @@ glm::vec3 Head::getHeadLookatDirectionRight() {
|
|||
glm::vec3 Head::getHeadPosition() {
|
||||
return glm::vec3
|
||||
(
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.x,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.y,
|
||||
avatar.bone[ AVATAR_BONE_HEAD ].position.z
|
||||
bone[ AVATAR_BONE_HEAD ].position.x,
|
||||
bone[ AVATAR_BONE_HEAD ].position.y,
|
||||
bone[ AVATAR_BONE_HEAD ].position.z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Head::getBodyPosition() {
|
||||
return glm::vec3
|
||||
(
|
||||
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.x,
|
||||
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.y,
|
||||
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void Head::updateHandMovement() {
|
||||
glm::vec3 transformedHandMovement;
|
||||
|
||||
transformedHandMovement
|
||||
= avatar.orientation.getRight() * -movedHandOffset.x
|
||||
+ avatar.orientation.getUp() * -movedHandOffset.y
|
||||
+ avatar.orientation.getFront() * -movedHandOffset.y * 0.4f;
|
||||
+ avatar.orientation.getUp() * -movedHandOffset.y * 0.5f
|
||||
+ avatar.orientation.getFront() * -movedHandOffset.y;
|
||||
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||
|
||||
//if holding hands, add a pull to the hand...
|
||||
if ( usingSprings ) {
|
||||
if ( closestOtherAvatar != -1 ) {
|
||||
glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]);
|
||||
handShakePull -= avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
|
||||
handShakePull *= 0.3;
|
||||
|
||||
transformedHandMovement += handShakePull;
|
||||
if ( closestOtherAvatar != -1 ) {
|
||||
if ( triggeringAction ) {
|
||||
|
||||
/*
|
||||
glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]);
|
||||
handShakePull -= bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
|
||||
handShakePull *= 1.0;
|
||||
|
||||
transformedHandMovement += handShakePull;
|
||||
*/
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].position = DEBUG_otherAvatarListPosition[ closestOtherAvatar ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||
glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// determine the arm vector
|
||||
//-------------------------------------------------------------------------------
|
||||
glm::vec3 armVector = bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
armVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// test to see if right hand is being dragged beyond maximum arm length
|
||||
|
@ -1059,40 +1061,53 @@ void Head::updateHandMovement() {
|
|||
//-------------------------------------------------------------------------------
|
||||
// reset right hand to be constrained to maximum arm length
|
||||
//-------------------------------------------------------------------------------
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].position = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
glm::vec3 armNormal = armVector / distance;
|
||||
armVector = armNormal * avatar.maxArmLength;
|
||||
distance = avatar.maxArmLength;
|
||||
glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
glm::vec3 constrainedPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
constrainedPosition += armVector;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition;
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition;
|
||||
}
|
||||
|
||||
/*
|
||||
//-------------------------------------------------------------------------------
|
||||
// keep arm from going through av body...
|
||||
//-------------------------------------------------------------------------------
|
||||
glm::vec3 adjustedArmVector = bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
adjustedArmVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
|
||||
float rightComponent = glm::dot( adjustedArmVector, avatar.orientation.getRight() );
|
||||
|
||||
if ( rightComponent < 0.0 )
|
||||
{
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].position -= avatar.orientation.getRight() * rightComponent;
|
||||
}
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// set elbow position
|
||||
//-----------------------------------------------------------------------------
|
||||
glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
newElbowPosition += armVector * (float)ONE_HALF;
|
||||
glm::vec3 newElbowPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||
newElbowPosition += armVector * ONE_HALF;
|
||||
glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector );
|
||||
|
||||
// XXXBHG - Jeffery, you should clean this up. You can't multiple glm::vec3's by doubles, only floats
|
||||
newElbowPosition += perpendicular * (float)(( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF);
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
|
||||
newElbowPosition += perpendicular * ( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF;
|
||||
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// set wrist position
|
||||
//-----------------------------------------------------------------------------
|
||||
glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
glm::vec3 vv( bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
vv -= bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
glm::vec3 newWristPosition = bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
newWristPosition += vv * 0.7f;
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition;
|
||||
bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Head::renderBody()
|
||||
{
|
||||
void Head::renderBody() {
|
||||
//-----------------------------------------
|
||||
// Render bone positions as spheres
|
||||
//-----------------------------------------
|
||||
|
@ -1100,14 +1115,14 @@ void Head::renderBody()
|
|||
if ( usingSprings ) {
|
||||
glColor3fv( lightBlue );
|
||||
glPushMatrix();
|
||||
glTranslatef( avatar.bone[b].springyPosition.x, avatar.bone[b].springyPosition.y, avatar.bone[b].springyPosition.z );
|
||||
glTranslatef( bone[b].springyPosition.x, bone[b].springyPosition.y, bone[b].springyPosition.z );
|
||||
glutSolidSphere( 0.02f, 10.0f, 5.0f );
|
||||
glPopMatrix();
|
||||
}
|
||||
else {
|
||||
glColor3fv( skinColor );
|
||||
glPushMatrix();
|
||||
glTranslatef( avatar.bone[b].position.x, avatar.bone[b].position.y, avatar.bone[b].position.z );
|
||||
glTranslatef( bone[b].position.x, bone[b].position.y, bone[b].position.z );
|
||||
glutSolidSphere( 0.02f, 10.0f, 5.0f );
|
||||
glPopMatrix();
|
||||
}
|
||||
|
@ -1117,13 +1132,13 @@ void Head::renderBody()
|
|||
// Render lines connecting the bone positions
|
||||
//-----------------------------------------------------
|
||||
if ( usingSprings ) {
|
||||
glColor3f( 0.2f, 0.3f, 0.4f );
|
||||
glColor3f( 0.4f, 0.5f, 0.6f );
|
||||
glLineWidth(3.0);
|
||||
|
||||
for (int b=1; b<NUM_AVATAR_BONES; b++) {
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].springyPosition.x );
|
||||
glVertex3fv( &avatar.bone[ b ].springyPosition.x );
|
||||
glVertex3fv( &bone[ bone[ b ].parent ].springyPosition.x );
|
||||
glVertex3fv( &bone[ b ].springyPosition.x );
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
@ -1133,47 +1148,26 @@ void Head::renderBody()
|
|||
|
||||
for (int b=1; b<NUM_AVATAR_BONES; b++) {
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].position.x );
|
||||
glVertex3fv( &avatar.bone[ b ].position.x);
|
||||
glVertex3fv( &bone[ bone[ b ].parent ].position.x );
|
||||
glVertex3fv( &bone[ b ].position.x);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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,
|
||||
position.x + leanSideways, position.y, position.z + leanForward,
|
||||
loudness, averageLoudness,
|
||||
//hand->getPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x,
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y,
|
||||
avatar.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,
|
||||
&position.x, &position.y, &position.z,
|
||||
&loudness, &averageLoudness,
|
||||
&avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x,
|
||||
&avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y,
|
||||
&avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z
|
||||
);
|
||||
|
||||
handBeingMoved = true;
|
||||
|
||||
if (( usingSprings ) && ( triggeringAction )) {
|
||||
glColor4f( 1.0, 1.0, 0.5, 0.5 );
|
||||
glPushMatrix();
|
||||
glTranslatef
|
||||
(
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.x,
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y,
|
||||
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z
|
||||
);
|
||||
glutSolidSphere( 0.03f, 10.0f, 5.0f );
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Head::SetNewHeadTarget(float pitch, float yaw) {
|
||||
|
@ -1181,7 +1175,7 @@ void Head::SetNewHeadTarget(float pitch, float 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
|
||||
float accX, accY, accZ,
|
||||
graX, graY, graZ,
|
||||
|
|
|
@ -10,10 +10,13 @@
|
|||
#define __interface__head__
|
||||
|
||||
#include <iostream>
|
||||
#include "AgentData.h"
|
||||
|
||||
#include <AvatarData.h>
|
||||
#include <Orientation.h> // added by Ventrella as a utility
|
||||
|
||||
#include "Field.h"
|
||||
#include "world.h"
|
||||
#include "Orientation.h" // added by Ventrella as a utility
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
#include "SerialInterface.h"
|
||||
|
||||
|
@ -29,47 +32,15 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
|||
#define ROT_RIGHT 7
|
||||
#define MAX_DRIVE_KEYS 8
|
||||
|
||||
#define NUM_OTHER_AVATARS 5
|
||||
#define NUM_OTHER_AVATARS 5 // temporary - for testing purposes!
|
||||
|
||||
/*
|
||||
enum AvatarJoints
|
||||
enum AvatarMode
|
||||
{
|
||||
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
|
||||
AVATAR_MODE_STANDING = 0,
|
||||
AVATAR_MODE_WALKING,
|
||||
AVATAR_MODE_COMMUNICATING,
|
||||
NUM_AVATAR_MODES
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
enum AvatarBones
|
||||
{
|
||||
|
@ -97,7 +68,7 @@ enum AvatarBones
|
|||
AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint
|
||||
AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint
|
||||
AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint
|
||||
|
||||
|
||||
NUM_AVATAR_BONES
|
||||
};
|
||||
|
||||
|
@ -108,7 +79,7 @@ struct AvatarBone
|
|||
glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose"
|
||||
glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position)
|
||||
glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position)
|
||||
float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position
|
||||
float springBodyTightness; // how tightly the springy position tries to stay on the position
|
||||
float yaw; // the yaw Euler angle of the bone rotation off the parent
|
||||
float pitch; // the pitch Euler angle of the bone rotation off the parent
|
||||
float roll; // the roll Euler angle of the bone rotation off the parent
|
||||
|
@ -122,10 +93,9 @@ struct Avatar
|
|||
glm::vec3 thrust;
|
||||
float maxArmLength;
|
||||
Orientation orientation;
|
||||
AvatarBone bone[ NUM_AVATAR_BONES ];
|
||||
};
|
||||
|
||||
class Head : public AgentData {
|
||||
class Head : public AvatarData {
|
||||
public:
|
||||
Head();
|
||||
~Head();
|
||||
|
@ -159,8 +129,11 @@ class Head : public AgentData {
|
|||
glm::vec3 getHeadLookatDirectionUp();
|
||||
glm::vec3 getHeadLookatDirectionRight();
|
||||
glm::vec3 getHeadPosition();
|
||||
glm::vec3 getBonePosition( AvatarBones b );
|
||||
glm::vec3 getBodyPosition();
|
||||
glm::vec3 getBonePosition( AvatarBones b );
|
||||
|
||||
AvatarMode getMode();
|
||||
|
||||
void setTriggeringAction( bool trigger );
|
||||
|
||||
void render(int faceToFace, int isMine);
|
||||
|
||||
|
@ -173,18 +146,12 @@ class Head : public AgentData {
|
|||
void setHandMovement( glm::vec3 movement );
|
||||
void updateHandMovement();
|
||||
|
||||
// Send and receive network data
|
||||
int getBroadcastData(char * data);
|
||||
void parseData(void *data, int size);
|
||||
|
||||
float getLoudness() {return loudness;};
|
||||
float getAverageLoudness() {return averageLoudness;};
|
||||
void setAverageLoudness(float al) {averageLoudness = al;};
|
||||
void setLoudness(float l) {loudness = l;};
|
||||
|
||||
void SetNewHeadTarget(float, float);
|
||||
glm::vec3 getPos() { return position; };
|
||||
void setPos(glm::vec3 newpos) { position = newpos; };
|
||||
|
||||
// Set what driving keys are being pressed to control thrust levels
|
||||
void setDriveKeys(int key, bool val) { driveKeys[key] = val; };
|
||||
|
@ -199,7 +166,7 @@ class Head : public AgentData {
|
|||
// 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; };
|
||||
|
||||
private:
|
||||
|
@ -236,12 +203,9 @@ class Head : public AgentData {
|
|||
float averageLoudness;
|
||||
float audioAttack;
|
||||
float browAudioLift;
|
||||
|
||||
glm::vec3 position;
|
||||
|
||||
float bodyYaw;
|
||||
float bodyPitch;
|
||||
float bodyRoll;
|
||||
bool triggeringAction;
|
||||
|
||||
float bodyYawDelta;
|
||||
|
||||
float closeEnoughToInteract;
|
||||
|
@ -254,13 +218,11 @@ class Head : public AgentData {
|
|||
bool handBeingMoved;
|
||||
bool previousHandBeingMoved;
|
||||
glm::vec3 movedHandOffset;
|
||||
//glm::vec3 movedHandPosition;
|
||||
|
||||
int driveKeys[MAX_DRIVE_KEYS];
|
||||
|
||||
float springVelocityDecay;
|
||||
float springForce;
|
||||
float springToBodyTightness; // XXXBHG - this had been commented out, but build breaks without it.
|
||||
|
||||
int eyeContact;
|
||||
eyeContactTargets eyeContactTarget;
|
||||
|
@ -268,6 +230,10 @@ class Head : public AgentData {
|
|||
GLUquadric *sphere;
|
||||
Avatar avatar;
|
||||
|
||||
AvatarBone bone[ NUM_AVATAR_BONES ];
|
||||
|
||||
AvatarMode mode;
|
||||
|
||||
void initializeAvatar();
|
||||
void updateAvatarSkeleton();
|
||||
void initializeAvatarSprings();
|
||||
|
|
|
@ -41,7 +41,7 @@ void MenuColumn::mouseClickRow(int numberOfRowsIndex) {
|
|||
}
|
||||
|
||||
bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
|
||||
int rightPosition = leftPosition + 200;
|
||||
int rightPosition = leftPosition + 200; // XXXBHG - this looks like a hack?
|
||||
int topPosition = menuHeight;
|
||||
int bottomPosition = menuHeight;
|
||||
int columnWidth = 0;
|
||||
|
@ -67,13 +67,14 @@ void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPositi
|
|||
}
|
||||
|
||||
bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
|
||||
int rightPosition = leftPosition + 100;
|
||||
|
||||
int maxColumnWidth = this->getMaxRowWidth();
|
||||
|
||||
int rightPosition = leftPosition + maxColumnWidth;
|
||||
int topPosition = menuHeight;
|
||||
int bottomPosition = menuHeight;
|
||||
int columnWidth = 0;
|
||||
bool overMenu = false;
|
||||
for (unsigned int i = 0; i < rows.size(); ++i) {
|
||||
columnWidth = rows[i].getWidth();
|
||||
topPosition = bottomPosition + lineHeight ;
|
||||
if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) {
|
||||
setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition);
|
||||
|
@ -116,26 +117,47 @@ int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int MenuColumn::addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) {
|
||||
MenuRow* row;
|
||||
row = new MenuRow(rowName, callback, stateNameCallback);
|
||||
rows.push_back(*row);
|
||||
delete row;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MenuColumn::getMaxRowWidth() {
|
||||
float scale = 0.09;
|
||||
int mono = 0;
|
||||
int maxColumnWidth = 100 - (SPACE_BEFORE_ROW_NAME*2); // the minimum size we want
|
||||
for (unsigned int i = 0; i < rows.size(); ++i) {
|
||||
maxColumnWidth = std::max(maxColumnWidth,rows[i].getWidth(scale, mono, 0));
|
||||
}
|
||||
|
||||
maxColumnWidth += SPACE_BEFORE_ROW_NAME*2; // space before and after!!
|
||||
return maxColumnWidth;
|
||||
}
|
||||
|
||||
void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
|
||||
float scale = 0.09;
|
||||
int mono = 0;
|
||||
int numberOfRows = rows.size();
|
||||
if (numberOfRows > 0) {
|
||||
|
||||
int maxColumnWidth = this->getMaxRowWidth();
|
||||
|
||||
glColor3f(0.9,0.9,0.9);
|
||||
glBegin(GL_QUADS); {
|
||||
glVertex2f(leftPosition, yOffset + menuHeight);
|
||||
glVertex2f(leftPosition+100, yOffset + menuHeight);
|
||||
glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight);
|
||||
glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight);
|
||||
glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight + numberOfRows*lineHeight);
|
||||
glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
float scale = 0.09;
|
||||
int mono = 0;
|
||||
int y = menuHeight + lineHeight / 2 ;
|
||||
char* rowName;
|
||||
int columnWidth = 0;
|
||||
for (unsigned int i = 0; i < rows.size(); ++i) {
|
||||
rowName = rows[i].getName();
|
||||
columnWidth = rows[i].getWidth(scale, mono, 0);
|
||||
drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0);
|
||||
y += lineHeight;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
void render(int yOffset, int menuHeight, int lineHeight);
|
||||
void renderMouseOver(int yOffset);
|
||||
int addRow(const char* rowName, MenuRowCallback callback);
|
||||
int addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback);
|
||||
int getMaxRowWidth();
|
||||
private:
|
||||
char columnName[MAX_COLUMN_NAME];
|
||||
int columnWidth;
|
||||
|
|
|
@ -16,14 +16,26 @@
|
|||
#include "MenuColumn.h"
|
||||
#include "Menu.h"
|
||||
|
||||
MenuRow::MenuRow() {
|
||||
MenuRow::MenuRow() :
|
||||
callback(NULL),
|
||||
stateNameCallback(NULL) {
|
||||
}
|
||||
|
||||
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) {
|
||||
int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName));
|
||||
strncpy(this->rowName, columnName, length);
|
||||
memcpy(this->rowName + length, " \0", 5);
|
||||
this->callback = callback;
|
||||
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) :
|
||||
callback(callback),
|
||||
stateNameCallback(NULL) {
|
||||
this->nameLength = strlen(columnName);
|
||||
strncpy(this->rowName, columnName, MAX_COLUMN_NAME); // copy the base name
|
||||
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
|
||||
rowWidth = 0;
|
||||
}
|
||||
|
||||
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) :
|
||||
callback(callback),
|
||||
stateNameCallback(stateNameCallback) {
|
||||
this->nameLength = strlen(columnName);
|
||||
strncpy(this->rowName, columnName, MAX_COLUMN_NAME);
|
||||
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
|
||||
rowWidth = 0;
|
||||
}
|
||||
|
||||
|
@ -31,19 +43,30 @@ MenuRow::~MenuRow() {
|
|||
}
|
||||
|
||||
void MenuRow::call() {
|
||||
callback(-2);
|
||||
callback(MENU_ROW_PICKED);
|
||||
}
|
||||
|
||||
const char* MenuRow::getStateName() {
|
||||
int currentValue = callback(MENU_ROW_GET_VALUE);
|
||||
const char* stateName;
|
||||
// If the MenuRow has a custom stateNameCallback function, then call it to get a string
|
||||
// to display in the menu. Otherwise, use the default implementation.
|
||||
if (stateNameCallback != NULL) {
|
||||
stateName = stateNameCallback(currentValue);
|
||||
} else {
|
||||
if (currentValue == 0) {
|
||||
stateName = " OFF ";
|
||||
} else if (currentValue == 1) {
|
||||
stateName = " ON ";
|
||||
} else {
|
||||
stateName = " ";
|
||||
}
|
||||
}
|
||||
return stateName;
|
||||
}
|
||||
|
||||
char* MenuRow::getName() {
|
||||
int length = (int) strlen(this->rowName) - 4;
|
||||
int currentValue = callback(-1);
|
||||
if (currentValue == 0) {
|
||||
memcpy(this->rowName + length, " OFF\0", 5);
|
||||
} else if (currentValue == 1) {
|
||||
memcpy(this->rowName + length, " ON \0", 5);
|
||||
} else {
|
||||
memcpy(this->rowName + length, " \0", 5);
|
||||
}
|
||||
strcpy(this->rowName + nameLength, getStateName());
|
||||
return this->rowName;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,22 +12,29 @@
|
|||
const int MAX_COLUMN_NAME = 50;
|
||||
const int SPACE_BETWEEN_COLUMNS = 20;
|
||||
const int SPACE_BEFORE_ROW_NAME = 10;
|
||||
const int MENU_ROW_PICKED = -2;
|
||||
const int MENU_ROW_GET_VALUE = -1;
|
||||
|
||||
typedef int(*MenuRowCallback)(int);
|
||||
typedef const char*(*MenuStateNameCallback)(int);
|
||||
|
||||
class MenuRow {
|
||||
public:
|
||||
MenuRow();
|
||||
MenuRow(const char* rowName, MenuRowCallback callback);
|
||||
MenuRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback);
|
||||
~MenuRow();
|
||||
void call();
|
||||
char * getName();
|
||||
const char* getStateName();
|
||||
int getWidth(float scale, int mono, int leftPosition);
|
||||
int getWidth();
|
||||
private:
|
||||
int nameLength;
|
||||
char rowName[MAX_COLUMN_NAME];
|
||||
int rowWidth;
|
||||
MenuRowCallback callback;
|
||||
MenuStateNameCallback stateNameCallback;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__MenuRow__) */
|
||||
|
|
|
@ -60,8 +60,10 @@ public:
|
|||
*/
|
||||
void activate() const {
|
||||
|
||||
if (_hndProg != 0u)
|
||||
if (_hndProg != 0u) {
|
||||
|
||||
oGlLog( glUseProgram(_hndProg) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,16 +79,20 @@ public:
|
|||
*/
|
||||
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);
|
||||
glShaderSource(s, nStrings, strings, 0l);
|
||||
glCompileShader(s);
|
||||
GLint status;
|
||||
glGetShaderiv(s, GL_COMPILE_STATUS, & status);
|
||||
if (!! status)
|
||||
if (status != 0)
|
||||
glAttachShader(_hndProg, s);
|
||||
#ifdef NDEBUG
|
||||
#ifdef NDEBUG // always fetch log in debug mode
|
||||
else
|
||||
#endif
|
||||
fetchLog(s, glGetShaderiv, glGetShaderInfoLog);
|
||||
|
@ -104,12 +110,21 @@ public:
|
|||
glLinkProgram(_hndProg);
|
||||
GLint status;
|
||||
glGetProgramiv(_hndProg, GL_LINK_STATUS, & status);
|
||||
#ifdef NDEBUG
|
||||
if (status == 0)
|
||||
#ifndef NDEBUG // always fetch log in debug mode
|
||||
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:
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
//
|
||||
// Channels are received in the following order (integer 0-4096 based on voltage 0-3.3v)
|
||||
//
|
||||
// AIN 15: Pitch Gyro (nodding your head 'yes')
|
||||
// AIN 16: Yaw Gyro (shaking your head 'no')
|
||||
// AIN 17: Roll Gyro (looking quizzical, tilting your head)
|
||||
// AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor)
|
||||
// AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor)
|
||||
// AIN 20: Forward/Back acceleration (Toward or away from your monitor)
|
||||
// 0 - AIN 15: Pitch Gyro (nodding your head 'yes')
|
||||
// 1 - AIN 16: Yaw Gyro (shaking your head 'no')
|
||||
// 2 - AIN 17: Roll Gyro (looking quizzical, tilting your head)
|
||||
// 3 - AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor)
|
||||
// 4 - AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor)
|
||||
// 5 - AIN 20: Forward/Back acceleration (Toward or away from your monitor)
|
||||
//
|
||||
|
||||
#include "SerialInterface.h"
|
||||
|
@ -21,14 +21,15 @@
|
|||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
int serial_fd;
|
||||
int serialFd;
|
||||
const int MAX_BUFFER = 255;
|
||||
char serial_buffer[MAX_BUFFER];
|
||||
int serial_buffer_pos = 0;
|
||||
char serialBuffer[MAX_BUFFER];
|
||||
int serialBufferPos = 0;
|
||||
|
||||
const int ZERO_OFFSET = 2048;
|
||||
const short NO_READ_MAXIMUM_MSECS = 3000;
|
||||
const short SAMPLES_TO_DISCARD = 100;
|
||||
const short SAMPLES_TO_DISCARD = 100; // Throw out the first few samples
|
||||
const int GRAVITY_SAMPLES = 200; // Use the first samples to compute gravity vector
|
||||
|
||||
void SerialInterface::pair() {
|
||||
|
||||
|
@ -48,7 +49,7 @@ void SerialInterface::pair() {
|
|||
char *serialPortname = new char[100];
|
||||
sprintf(serialPortname, "/dev/%s", entry->d_name);
|
||||
|
||||
init(serialPortname, 115200);
|
||||
initializePort(serialPortname, 115200);
|
||||
|
||||
delete [] serialPortname;
|
||||
}
|
||||
|
@ -60,18 +61,20 @@ void SerialInterface::pair() {
|
|||
|
||||
}
|
||||
|
||||
// Init the serial port to the specified values
|
||||
int SerialInterface::init(char* portname, int baud)
|
||||
// Connect to the serial port
|
||||
int SerialInterface::initializePort(char* portname, int baud)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
serial_fd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
|
||||
printf("Attemping to open serial interface: %s\n", portname);
|
||||
|
||||
if (serial_fd == -1) return -1; // Failed to open port
|
||||
printf("Opening SerialUSB %s: ", portname);
|
||||
|
||||
if (serialFd == -1) {
|
||||
printf("Failed.\n");
|
||||
return -1; // Failed to open port
|
||||
}
|
||||
struct termios options;
|
||||
tcgetattr(serial_fd,&options);
|
||||
tcgetattr(serialFd,&options);
|
||||
switch(baud)
|
||||
{
|
||||
case 9600: cfsetispeed(&options,B9600);
|
||||
|
@ -95,10 +98,10 @@ int SerialInterface::init(char* portname, int baud)
|
|||
options.c_cflag &= ~CSTOPB;
|
||||
options.c_cflag &= ~CSIZE;
|
||||
options.c_cflag |= CS8;
|
||||
tcsetattr(serial_fd,TCSANOW,&options);
|
||||
tcsetattr(serialFd,TCSANOW,&options);
|
||||
|
||||
|
||||
printf("Serial interface opened!\n");
|
||||
printf("Connected.\n");
|
||||
resetSerial();
|
||||
active = true;
|
||||
#endif
|
||||
|
@ -126,22 +129,17 @@ void SerialInterface::renderLevels(int width, int height) {
|
|||
glBegin(GL_LINES);
|
||||
glVertex2f(disp_x, height*0.95);
|
||||
glVertex2f(disp_x, height*(0.25 + 0.75f*getValue(i)/4096));
|
||||
glColor4f(1, 0, 0, 1);
|
||||
glVertex2f(disp_x - 3, height*(0.25 + 0.75f*getValue(i)/4096));
|
||||
glVertex2f(disp_x, height*(0.25 + 0.75f*getValue(i)/4096));
|
||||
glEnd();
|
||||
// Trailing Average value
|
||||
glColor4f(1, 1, 0, 1);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(disp_x + 2, height*0.95);
|
||||
glVertex2f(disp_x + 2, height*(0.25 + 0.75f*getTrailingValue(i)/4096));
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glVertex2f(disp_x, height*(0.25 + 0.75f*getTrailingValue(i)/4096));
|
||||
glVertex2f(disp_x + 4, height*(0.25 + 0.75f*getTrailingValue(i)/4096));
|
||||
glEnd();
|
||||
|
||||
/*
|
||||
glColor3f(1,0,0);
|
||||
glBegin(GL_LINES);
|
||||
glLineWidth(4.0);
|
||||
glVertex2f(disp_x - 10, height*0.5 - getValue(i)/4096);
|
||||
glVertex2f(disp_x + 10, height*0.5 - getValue(i)/4096);
|
||||
glEnd();
|
||||
*/
|
||||
sprintf(val, "%d", getValue(i));
|
||||
drawtext(disp_x-GAP/2, (height*0.95)+2, 0.08, 90, 1.0, 0, val, 0, 1, 0);
|
||||
|
||||
|
@ -162,20 +160,20 @@ void SerialInterface::renderLevels(int width, int height) {
|
|||
}
|
||||
void SerialInterface::readData() {
|
||||
#ifdef __APPLE__
|
||||
// This array sets the rate of trailing averaging for each channel.
|
||||
// This array sets the rate of trailing averaging for each channel:
|
||||
// If the sensor rate is 100Hz, 0.001 will make the long term average a 10-second average
|
||||
const float AVG_RATE[] = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01};
|
||||
const float AVG_RATE[] = {0.002, 0.002, 0.002, 0.002, 0.002, 0.002};
|
||||
char bufchar[1];
|
||||
|
||||
int initialSamples = totalSamples;
|
||||
|
||||
while (read(serial_fd, &bufchar, 1) > 0) {
|
||||
while (read(serialFd, &bufchar, 1) > 0) {
|
||||
//std::cout << bufchar[0];
|
||||
serial_buffer[serial_buffer_pos] = bufchar[0];
|
||||
serial_buffer_pos++;
|
||||
serialBuffer[serialBufferPos] = bufchar[0];
|
||||
serialBufferPos++;
|
||||
// Have we reached end of a line of input?
|
||||
if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER)) {
|
||||
std::string serialLine(serial_buffer, serial_buffer_pos-1);
|
||||
if ((bufchar[0] == '\n') || (serialBufferPos >= MAX_BUFFER)) {
|
||||
std::string serialLine(serialBuffer, serialBufferPos-1);
|
||||
//std::cout << serialLine << "\n";
|
||||
int spot;
|
||||
//int channel = 0;
|
||||
|
@ -191,6 +189,7 @@ void SerialInterface::readData() {
|
|||
serialLine = serialLine.substr(spot+1, serialLine.length() - spot - 1);
|
||||
}
|
||||
|
||||
// Update Trailing Averages
|
||||
for (int i = 0; i < NUM_CHANNELS; i++) {
|
||||
if (totalSamples > SAMPLES_TO_DISCARD) {
|
||||
trailingAverage[i] = (1.f - AVG_RATE[i])*trailingAverage[i] +
|
||||
|
@ -200,8 +199,21 @@ void SerialInterface::readData() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Use a set of initial samples to compute gravity
|
||||
if (totalSamples < GRAVITY_SAMPLES) {
|
||||
gravity.x += lastMeasured[ACCEL_X];
|
||||
gravity.y += lastMeasured[ACCEL_Y];
|
||||
gravity.z += lastMeasured[ACCEL_Z];
|
||||
}
|
||||
if (totalSamples == GRAVITY_SAMPLES) {
|
||||
gravity = glm::normalize(gravity);
|
||||
std::cout << "gravity: " << gravity.x << "," <<
|
||||
gravity.y << "," << gravity.z << "\n";
|
||||
}
|
||||
|
||||
totalSamples++;
|
||||
serial_buffer_pos = 0;
|
||||
serialBufferPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +222,7 @@ void SerialInterface::readData() {
|
|||
gettimeofday(&now, NULL);
|
||||
|
||||
if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) {
|
||||
std::cout << "No data coming over serial. Shutting down SerialInterface.\n";
|
||||
std::cout << "No data - Shutting down SerialInterface.\n";
|
||||
resetSerial();
|
||||
}
|
||||
} else {
|
||||
|
@ -223,6 +235,7 @@ void SerialInterface::resetSerial() {
|
|||
#ifdef __APPLE__
|
||||
active = false;
|
||||
totalSamples = 0;
|
||||
gravity = glm::vec3(0,-1,0);
|
||||
|
||||
gettimeofday(&lastGoodRead, NULL);
|
||||
|
||||
|
@ -233,7 +246,7 @@ void SerialInterface::resetSerial() {
|
|||
}
|
||||
// Clear serial input buffer
|
||||
for (int i = 1; i < MAX_BUFFER; i++) {
|
||||
serial_buffer[i] = ' ';
|
||||
serialBuffer[i] = ' ';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -45,8 +45,10 @@ public:
|
|||
void resetTrailingAverages();
|
||||
void renderLevels(int width, int height);
|
||||
bool active;
|
||||
glm::vec3 getGravity() {return gravity;};
|
||||
|
||||
private:
|
||||
int init(char * portname, int baud);
|
||||
int initializePort(char * portname, int baud);
|
||||
void resetSerial();
|
||||
int lastMeasured[NUM_CHANNELS];
|
||||
float trailingAverage[NUM_CHANNELS];
|
||||
|
@ -54,6 +56,7 @@ private:
|
|||
int LED;
|
||||
int totalSamples;
|
||||
timeval lastGoodRead;
|
||||
glm::vec3 gravity;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,8 +8,11 @@
|
|||
|
||||
#include "InterfaceConfig.h"
|
||||
#include <iostream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <cstring>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "world.h"
|
||||
#include "Util.h"
|
||||
|
||||
|
|
|
@ -17,21 +17,6 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
static const double ZERO = 0.0;
|
||||
static const double ONE = 1.0;
|
||||
static const double 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 double METER = 1.0;
|
||||
static const double DECIMETER = 0.1;
|
||||
static const double CENTIMETER = 0.01;
|
||||
static const double MILLIIMETER = 0.001;
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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 *voxelData = (unsigned char *) data + 1;
|
||||
unsigned char command = *sourceBuffer;
|
||||
unsigned char *voxelData = sourceBuffer + 1;
|
||||
|
||||
switch(command) {
|
||||
case PACKET_HEADER_VOXEL_DATA:
|
||||
// ask the VoxelTree to read the bitstream into the tree
|
||||
tree->readBitstreamToTree(voxelData, size - 1);
|
||||
tree->readBitstreamToTree(voxelData, numBytes - 1);
|
||||
break;
|
||||
case PACKET_HEADER_ERASE_VOXEL:
|
||||
// ask the tree to read the "remove" bitstream
|
||||
tree->processRemoveVoxelBitstream((unsigned char*)data,size);
|
||||
tree->processRemoveVoxelBitstream(sourceBuffer, numBytes);
|
||||
break;
|
||||
case PACKET_HEADER_Z_COMMAND:
|
||||
|
||||
// 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
|
||||
// messages differently
|
||||
char* packetData =(char*)data;
|
||||
char* packetData = (char *)sourceBuffer;
|
||||
char* command = &packetData[1]; // start of the command
|
||||
int commandLength = strlen(command); // commands are null terminated strings
|
||||
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")) {
|
||||
printf("got Z message == erase all\n");
|
||||
tree->eraseAllVoxels();
|
||||
|
@ -184,7 +184,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
|
|||
int voxelsAdded = 0;
|
||||
|
||||
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
|
||||
// coords of the voxel space. This flip flop causes LOD behavior to be extremely odd. This is my temporary hack
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
VoxelSystem();
|
||||
~VoxelSystem();
|
||||
|
||||
void parseData(void *data, int size);
|
||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||
VoxelSystem* clone() const;
|
||||
|
||||
void init();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -67,7 +67,7 @@
|
|||
#include <glm/gtc/swizzle.hpp>
|
||||
|
||||
#include "UrlReader.h"
|
||||
#include "AngleUtils.h"
|
||||
#include "AngleUtil.h"
|
||||
#include "Radix2InplaceSort.h"
|
||||
#include "Radix2IntegerScanner.h"
|
||||
#include "FloodFill.h"
|
||||
|
|
|
@ -72,16 +72,17 @@ namespace starfield {
|
|||
size_t _valLodNalloc;
|
||||
size_t _valLodNrender;
|
||||
BrightnessLevels _seqLodBrightness;
|
||||
BrightnessLevel _valLodAllocBrightness;
|
||||
|
||||
#if STARFIELD_MULTITHREADING
|
||||
atomic<BrightnessLevel> _valLodBrightness;
|
||||
BrightnessLevel _valLodAllocBrightness;
|
||||
|
||||
atomic<Renderer*> _ptrRenderer;
|
||||
|
||||
typedef lock_guard<mutex> lock;
|
||||
#else
|
||||
BrightnessLevel _valLodBrightness;
|
||||
BrightnessLevel _valLodAllocBrightness;
|
||||
|
||||
Renderer* _ptrRenderer;
|
||||
|
||||
|
@ -89,6 +90,10 @@ namespace starfield {
|
|||
#define _(x)
|
||||
#endif
|
||||
|
||||
static inline size_t toBufSize(double f) {
|
||||
return size_t(floor(f + 0.5f));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Controller() :
|
||||
|
@ -99,8 +104,8 @@ namespace starfield {
|
|||
_valLodOveralloc(1.2),
|
||||
_valLodNalloc(0),
|
||||
_valLodNrender(0),
|
||||
_valLodAllocBrightness(0),
|
||||
_valLodBrightness(0),
|
||||
_valLodAllocBrightness(0),
|
||||
_ptrRenderer(0l) {
|
||||
}
|
||||
|
||||
|
@ -144,8 +149,8 @@ namespace starfield {
|
|||
|
||||
rcpChange = 1.0;
|
||||
|
||||
nRender = lrint(_valLodFraction * newLast);
|
||||
n = min(newLast, size_t(lrint(_valLodOveralloc * nRender)));
|
||||
nRender = toBufSize(_valLodFraction * newLast);
|
||||
n = min(newLast, toBufSize(_valLodOveralloc * nRender));
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -282,7 +287,7 @@ namespace starfield {
|
|||
// calculate allocation size and corresponding brightness
|
||||
// threshold
|
||||
double oaFract = std::min(fraction * (1.0 + overalloc), 1.0);
|
||||
n = lrint(oaFract * last);
|
||||
n = toBufSize(oaFract * last);
|
||||
bMin = _seqLodBrightness[n];
|
||||
n = std::upper_bound(
|
||||
_seqLodBrightness.begin() + n - 1,
|
||||
|
@ -290,7 +295,7 @@ namespace starfield {
|
|||
bMin, GreaterBrightness() ) - _seqLodBrightness.begin();
|
||||
|
||||
// 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
|
||||
b = _seqLodBrightness[nRender];
|
||||
// this setting controls the renderer, also keep b as the
|
||||
|
@ -304,7 +309,7 @@ namespace starfield {
|
|||
|
||||
// fprintf(stderr, "Stars.cpp: "
|
||||
// "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
|
||||
// (it is consistent with the rest of the state in this case)
|
||||
|
|
|
@ -50,8 +50,8 @@ namespace starfield {
|
|||
|
||||
return false;
|
||||
}
|
||||
fprintf(stderr, "Stars.cpp: read %d stars, rendering %ld\n",
|
||||
_valRecordsRead, _ptrVertices->size());
|
||||
fprintf(stderr, "Stars.cpp: read %u vertices, using %lu\n",
|
||||
_valRecordsRead, _ptrVertices->size());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace starfield {
|
|||
|
||||
InputVertex(float azimuth, float altitude, unsigned color) {
|
||||
|
||||
_valColor = (color >> 16 & 0xffu) | (color & 0xff00u) |
|
||||
(color << 16 & 0xff0000u) | 0xff000000u;
|
||||
_valColor = ((color >> 16) & 0xffu) | (color & 0xff00u) |
|
||||
((color << 16) & 0xff0000u) | 0xff000000u;
|
||||
|
||||
azimuth = angleConvert<Degrees,Radians>(azimuth);
|
||||
altitude = angleConvert<Degrees,Radians>(altitude);
|
||||
|
|
|
@ -13,15 +13,8 @@
|
|||
#error "This is an implementation file - not intended for direct inclusion."
|
||||
#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"
|
||||
#endif
|
||||
|
||||
namespace starfield {
|
||||
|
||||
class Tiling {
|
||||
|
@ -35,7 +28,7 @@ namespace starfield {
|
|||
Tiling(unsigned k) :
|
||||
_valK(k),
|
||||
_valRcpSlice(k / Radians::twicePi()) {
|
||||
_valBits = ceil(log2(getTileCount()));
|
||||
_valBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2
|
||||
}
|
||||
|
||||
unsigned getAzimuthalTiles() const { return _valK; }
|
||||
|
@ -58,7 +51,7 @@ namespace starfield {
|
|||
private:
|
||||
|
||||
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 {
|
||||
|
|
18
libraries/avatars/CMakeLists.txt
Normal file
18
libraries/avatars/CMakeLists.txt
Normal 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})
|
112
libraries/avatars/src/AvatarData.cpp
Normal file
112
libraries/avatars/src/AvatarData.cpp
Normal 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;
|
||||
}
|
||||
|
||||
|
48
libraries/avatars/src/AvatarData.h
Normal file
48
libraries/avatars/src/AvatarData.h
Normal 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__) */
|
|
@ -6,8 +6,7 @@
|
|||
//-----------------------------------------------------------
|
||||
|
||||
#include "Orientation.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
Orientation::Orientation() {
|
||||
right = glm::vec3( 1.0, 0.0, 0.0 );
|
|
@ -12,7 +12,7 @@
|
|||
class AgentData {
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -81,10 +81,10 @@ unsigned int AgentList::getSocketListenPort() {
|
|||
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]) {
|
||||
case PACKET_HEADER_DOMAIN: {
|
||||
updateList((unsigned char *)packetData, dataBytes);
|
||||
updateList(packetData, dataBytes);
|
||||
break;
|
||||
}
|
||||
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
|
||||
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
|
||||
|
||||
|
@ -120,6 +120,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
|
|||
memcpy(packetHolder + 1, currentPosition, numBytesPerAgent);
|
||||
|
||||
int matchingAgentIndex = indexOfMatchingAgent(agentID);
|
||||
|
||||
if (matchingAgentIndex >= 0) {
|
||||
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
|
||||
}
|
||||
|
@ -130,7 +131,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
|
|||
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
|
||||
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());
|
||||
|
||||
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++) {
|
||||
// only send to the AgentTypes we are asked to send to.
|
||||
if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) {
|
||||
|
@ -427,11 +428,11 @@ void AgentList::stopDomainServerCheckInThread() {
|
|||
}
|
||||
|
||||
int unpackAgentId(unsigned char *packedData, uint16_t *agentId) {
|
||||
memcpy(packedData, agentId, sizeof(uint16_t));
|
||||
memcpy(agentId, packedData, sizeof(uint16_t));
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
int packAgentId(unsigned char *packStore, uint16_t agentId) {
|
||||
memcpy(&agentId, packStore, sizeof(uint16_t));
|
||||
memcpy(packStore, &agentId, sizeof(uint16_t));
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ public:
|
|||
|
||||
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
|
||||
|
||||
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
||||
void processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent);
|
||||
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
|
||||
|
||||
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
||||
void updateAgentWithData(Agent *agent, void *packetData, int dataBytes);
|
||||
void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t 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();
|
||||
unsigned int getSocketListenPort();
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ struct Rotations {
|
|||
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 >
|
||||
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 >
|
||||
float angleSignedNormal(float a) {
|
||||
|
||||
float result = remainder(a, Unit::twicePi());
|
||||
if (result == Unit::pi())
|
||||
result = -Unit::pi();
|
||||
// result is remainder(a, Unit::twicePi());
|
||||
float result = fmod(a, Unit::twicePi());
|
||||
if (result >= Unit::pi()) {
|
||||
|
||||
result -= Unit::twicePi();
|
||||
|
||||
} else if (result < -Unit::pi()) {
|
||||
|
||||
result += Unit::twicePi();
|
||||
}
|
||||
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 >
|
||||
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)
|
||||
* degrees and altitude is in the range of [-90; 90] degrees.
|
||||
*
|
||||
* The so normalized angle still contains ambiguity due to gimbal lock:
|
||||
* Both poles can be reached from any azimuthal direction.
|
||||
*/
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// The so normalized angle still contains ambiguity due to gimbal lock:
|
||||
// Both poles can be reached from any azimuthal direction.
|
||||
//
|
||||
template< class Unit >
|
||||
void angleHorizontalPolar(float& azimuth, float& altitude) {
|
||||
|
|
@ -105,12 +105,10 @@ void AudioRingBuffer::setBearing(float newBearing) {
|
|||
bearing = newBearing;
|
||||
}
|
||||
|
||||
void AudioRingBuffer::parseData(void *data, int size) {
|
||||
unsigned char *audioDataStart = (unsigned char *) data;
|
||||
|
||||
if (size > (bufferLengthSamples * sizeof(int16_t))) {
|
||||
void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
|
||||
|
||||
unsigned char *dataPtr = audioDataStart + 1;
|
||||
unsigned char *dataPtr = sourceBuffer + 1;
|
||||
|
||||
for (int p = 0; p < 3; p ++) {
|
||||
memcpy(&position[p], dataPtr, sizeof(float));
|
||||
|
@ -123,7 +121,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
|
|||
memcpy(&bearing, dataPtr, sizeof(float));
|
||||
dataPtr += sizeof(float);
|
||||
|
||||
audioDataStart = dataPtr;
|
||||
sourceBuffer = dataPtr;
|
||||
}
|
||||
|
||||
if (endOfLastWrite == NULL) {
|
||||
|
@ -134,7 +132,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
|
|||
started = false;
|
||||
}
|
||||
|
||||
memcpy(endOfLastWrite, audioDataStart, bufferLengthSamples * sizeof(int16_t));
|
||||
memcpy(endOfLastWrite, sourceBuffer, bufferLengthSamples * sizeof(int16_t));
|
||||
|
||||
endOfLastWrite += bufferLengthSamples;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class AudioRingBuffer : public AgentData {
|
|||
~AudioRingBuffer();
|
||||
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
||||
|
||||
void parseData(void *data, int size);
|
||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||
AudioRingBuffer* clone() const;
|
||||
|
||||
int16_t* getNextOutput();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __hifi__SharedUtil__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
|
@ -17,6 +18,21 @@
|
|||
#include <sys/time.h>
|
||||
#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 usecTimestampNow();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../../)
|
||||
set(ROOT_DIR ../..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
# setup for find modules
|
||||
|
@ -8,19 +8,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm
|
|||
|
||||
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_glm(${TARGET_NAME} ${MACRO_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_glm(${TARGET_NAME} ${ROOT_DIR})
|
||||
|
||||
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||
|
||||
set(HIFI_VOXELS_LIBRARY ${TARGET_NAME})
|
||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
76
libraries/voxels/src/AABox.cpp
Executable file
76
libraries/voxels/src/AABox.cpp
Executable file
|
@ -0,0 +1,76 @@
|
|||
/* ------------------------------------------------------
|
||||
|
||||
Axis Aligned Boxes - Lighthouse3D
|
||||
|
||||
-----------------------------------------------------*/
|
||||
|
||||
#include "AABox.h"
|
||||
|
||||
|
||||
AABox::AABox(const glm::vec3& corner, float x, float y, float z) {
|
||||
setBox(corner,x,y,z);
|
||||
}
|
||||
|
||||
AABox::AABox(void) {
|
||||
corner.x = 0; corner.y = 0; corner.z = 0;
|
||||
x = 1.0f;
|
||||
y = 1.0f;
|
||||
z = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
AABox::~AABox() {}
|
||||
|
||||
|
||||
|
||||
void AABox::setBox(const glm::vec3& corner, float x, float y, float z) {
|
||||
this->corner = corner;
|
||||
if (x < 0.0) {
|
||||
x = -x;
|
||||
this->corner.x -= x;
|
||||
}
|
||||
if (y < 0.0) {
|
||||
y = -y;
|
||||
this->corner.y -= y;
|
||||
}
|
||||
if (z < 0.0) {
|
||||
z = -z;
|
||||
this->corner.z -= z;
|
||||
}
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glm::vec3 AABox::getVertexP(const glm::vec3 &normal) {
|
||||
glm::vec3 res = corner;
|
||||
if (normal.x > 0)
|
||||
res.x += x;
|
||||
|
||||
if (normal.y > 0)
|
||||
res.y += y;
|
||||
|
||||
if (normal.z > 0)
|
||||
res.z += z;
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
glm::vec3 AABox::getVertexN(const glm::vec3 &normal) {
|
||||
glm::vec3 res = corner;
|
||||
|
||||
if (normal.x < 0)
|
||||
res.x += x;
|
||||
|
||||
if (normal.y < 0)
|
||||
res.y += y;
|
||||
|
||||
if (normal.z < 0)
|
||||
res.z += z;
|
||||
|
||||
return(res);
|
||||
}
|
33
libraries/voxels/src/AABox.h
Executable file
33
libraries/voxels/src/AABox.h
Executable file
|
@ -0,0 +1,33 @@
|
|||
/* ------------------------------------------------------
|
||||
|
||||
Axis Aligned Boxes - Lighthouse3D
|
||||
|
||||
-----------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _AABOX_
|
||||
#define _AABOX_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class AABox
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
glm::vec3 corner;
|
||||
float x,y,z;
|
||||
|
||||
AABox(const glm::vec3 &corner, float x, float y, float z);
|
||||
AABox(void);
|
||||
~AABox();
|
||||
|
||||
void setBox(const glm::vec3& corner, float x, float y, float z);
|
||||
|
||||
// for use in frustum computations
|
||||
glm::vec3 getVertexP(const glm::vec3& normal);
|
||||
glm::vec3 getVertexN(const glm::vec3& normal);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
83
libraries/voxels/src/Plane.cpp
Executable file
83
libraries/voxels/src/Plane.cpp
Executable file
|
@ -0,0 +1,83 @@
|
|||
// Plane.cpp
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Plane.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// These are some useful utilities that vec3 is missing
|
||||
float vec3_length(const glm::vec3& v) {
|
||||
return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
|
||||
}
|
||||
|
||||
void vec3_normalize(glm::vec3& v) {
|
||||
|
||||
float len;
|
||||
|
||||
len = vec3_length(v);
|
||||
if (len) {
|
||||
v.x /= len;;
|
||||
v.y /= len;
|
||||
v.z /= len;
|
||||
}
|
||||
}
|
||||
|
||||
float vec3_innerProduct(const glm::vec3& v1,const glm::vec3& v2) {
|
||||
|
||||
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Plane::Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) {
|
||||
|
||||
set3Points(v1,v2,v3);
|
||||
}
|
||||
|
||||
|
||||
Plane::Plane() {}
|
||||
|
||||
Plane::~Plane() {}
|
||||
|
||||
|
||||
void Plane::set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) {
|
||||
|
||||
|
||||
glm::vec3 aux1, aux2;
|
||||
|
||||
aux1 = v1 - v2;
|
||||
aux2 = v3 - v2;
|
||||
|
||||
normal = aux2 * aux1;
|
||||
|
||||
vec3_normalize(normal);
|
||||
point = v2;
|
||||
d = -(vec3_innerProduct(normal,point));
|
||||
}
|
||||
|
||||
void Plane::setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point) {
|
||||
|
||||
this->normal = normal;
|
||||
vec3_normalize(this->normal);
|
||||
d = -(vec3_innerProduct(this->normal,point));
|
||||
}
|
||||
|
||||
void Plane::setCoefficients(float a, float b, float c, float d) {
|
||||
|
||||
// set the normal vector
|
||||
normal = glm::vec3(a,b,c);
|
||||
//compute the lenght of the vector
|
||||
float l = normal.length();
|
||||
// normalize the vector
|
||||
normal = glm::vec3(a/l,b/l,c/l);
|
||||
// and divide d by th length as well
|
||||
this->d = d/l;
|
||||
}
|
||||
|
||||
float Plane::distance(const glm::vec3 &p) {
|
||||
return (d + vec3_innerProduct(normal,p));
|
||||
}
|
||||
|
||||
void Plane::print() {
|
||||
//printf("Plane(");normal.print();printf("# %f)",d);
|
||||
}
|
35
libraries/voxels/src/Plane.h
Executable file
35
libraries/voxels/src/Plane.h
Executable file
|
@ -0,0 +1,35 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// Plane.h - inspired and modified from lighthouse3d.com
|
||||
//
|
||||
|
||||
|
||||
#ifndef _PLANE_
|
||||
#define _PLANE_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
||||
class Plane
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
glm::vec3 normal,point;
|
||||
float d;
|
||||
|
||||
|
||||
Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3);
|
||||
Plane(void);
|
||||
~Plane();
|
||||
|
||||
void set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3);
|
||||
void setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point);
|
||||
void setCoefficients(float a, float b, float c, float d);
|
||||
float distance(const glm::vec3 &p);
|
||||
|
||||
void print();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -10,10 +10,29 @@
|
|||
|
||||
#include "ViewFrustum.h"
|
||||
|
||||
ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction,
|
||||
glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) {
|
||||
this->calculateViewFrustum(position, direction, up, right, screenWidth, screenHeight);
|
||||
}
|
||||
ViewFrustum::ViewFrustum() :
|
||||
_position(glm::vec3(0,0,0)),
|
||||
_direction(glm::vec3(0,0,0)),
|
||||
_up(glm::vec3(0,0,0)),
|
||||
_right(glm::vec3(0,0,0)),
|
||||
_fieldOfView(0.0),
|
||||
_aspectRatio(1.0),
|
||||
_nearClip(0.1),
|
||||
_farClip(500.0),
|
||||
_nearHeight(0.0),
|
||||
_nearWidth(0.0),
|
||||
_farHeight(0.0),
|
||||
_farWidth(0.0),
|
||||
_farCenter(glm::vec3(0,0,0)),
|
||||
_farTopLeft(glm::vec3(0,0,0)),
|
||||
_farTopRight(glm::vec3(0,0,0)),
|
||||
_farBottomLeft(glm::vec3(0,0,0)),
|
||||
_farBottomRight(glm::vec3(0,0,0)),
|
||||
_nearCenter(glm::vec3(0,0,0)),
|
||||
_nearTopLeft(glm::vec3(0,0,0)),
|
||||
_nearTopRight(glm::vec3(0,0,0)),
|
||||
_nearBottomLeft(glm::vec3(0,0,0)),
|
||||
_nearBottomRight(glm::vec3(0,0,0)) { }
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// ViewFrustum::calculateViewFrustum()
|
||||
|
@ -24,44 +43,54 @@ ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction,
|
|||
// Notes on how/why this works:
|
||||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/
|
||||
//
|
||||
void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction,
|
||||
glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) {
|
||||
|
||||
// Save the values we were passed...
|
||||
this->_position=position;
|
||||
this->_direction=direction;
|
||||
this->_up=up;
|
||||
this->_right=right;
|
||||
this->_screenWidth=screenWidth;
|
||||
this->_screenHeight=screenHeight;
|
||||
|
||||
glm::vec3 front = direction;
|
||||
float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg
|
||||
float ratio = screenWidth/screenHeight;
|
||||
|
||||
this->_nearDist = 0.1;
|
||||
this->_farDist = 10.0;
|
||||
|
||||
this->_nearHeight = 2 * tan(fovHalfAngle) * this->_nearDist;
|
||||
this->_nearWidth = this->_nearHeight * ratio;
|
||||
this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist;
|
||||
this->_farWidth = this->_farHeight * ratio;
|
||||
void ViewFrustum::calculate() {
|
||||
|
||||
float farHalfHeight = this->_farHeight * 0.5f;
|
||||
float farHalfWidth = this->_farWidth * 0.5f;
|
||||
this->_farCenter = this->_position+front * this->_farDist;
|
||||
static const double PI_OVER_180 = 3.14159265359 / 180.0; // would be better if this was in a shared location
|
||||
|
||||
glm::vec3 front = _direction;
|
||||
|
||||
// Calculating field of view.
|
||||
float fovInRadians = this->_fieldOfView * PI_OVER_180;
|
||||
|
||||
float twoTimesTanHalfFOV = 2.0f * tan(fovInRadians/2.0f);
|
||||
|
||||
// Do we need this?
|
||||
//tang = (float)tan(ANG2RAD * angle * 0.5) ;
|
||||
|
||||
float nearClip = this->_nearClip;
|
||||
float farClip = this->_farClip;
|
||||
|
||||
this->_nearHeight = (twoTimesTanHalfFOV * nearClip);
|
||||
this->_nearWidth = this->_nearHeight * this->_aspectRatio;
|
||||
this->_farHeight = (twoTimesTanHalfFOV * farClip);
|
||||
this->_farWidth = this->_farHeight * this->_aspectRatio;
|
||||
|
||||
float farHalfHeight = (this->_farHeight * 0.5f);
|
||||
float farHalfWidth = (this->_farWidth * 0.5f);
|
||||
this->_farCenter = this->_position+front * farClip;
|
||||
this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth);
|
||||
this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth);
|
||||
this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth);
|
||||
this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth);
|
||||
|
||||
float nearHalfHeight = this->_nearHeight * 0.5f;
|
||||
float nearHalfWidth = this->_nearWidth * 0.5f;
|
||||
this->_nearCenter = this->_position+front * this->_nearDist;
|
||||
float nearHalfHeight = (this->_nearHeight * 0.5f);
|
||||
float nearHalfWidth = (this->_nearWidth * 0.5f);
|
||||
this->_nearCenter = this->_position+front * nearClip;
|
||||
this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth);
|
||||
this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth);
|
||||
this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth);
|
||||
this->_nearBottomRight = this->_nearCenter - (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth);
|
||||
|
||||
// compute the six planes
|
||||
// the function set3Points assumes that the points
|
||||
// are given in counter clockwise order
|
||||
this->_planes[TOPP].set3Points(this->_nearTopRight,this->_nearTopLeft,this->_farTopLeft);
|
||||
this->_planes[BOTTOMP].set3Points(this->_nearBottomLeft,this->_nearBottomRight,this->_farBottomRight);
|
||||
this->_planes[LEFTP].set3Points(this->_nearTopLeft,this->_nearBottomLeft,this->_farBottomLeft);
|
||||
this->_planes[RIGHTP].set3Points(this->_nearBottomRight,this->_nearTopRight,this->_farBottomRight);
|
||||
this->_planes[NEARP].set3Points(this->_nearTopLeft,this->_nearTopRight,this->_nearBottomRight);
|
||||
this->_planes[FARP].set3Points(this->_farTopRight,this->_farTopLeft,this->_farBottomLeft);
|
||||
|
||||
}
|
||||
|
||||
void ViewFrustum::dump() {
|
||||
|
@ -71,11 +100,11 @@ void ViewFrustum::dump() {
|
|||
printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z);
|
||||
printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z);
|
||||
|
||||
printf("farDist=%f\n", this->_farDist);
|
||||
printf("farDist=%f\n", this->_farClip);
|
||||
printf("farHeight=%f\n", this->_farHeight);
|
||||
printf("farWidth=%f\n", this->_farWidth);
|
||||
|
||||
printf("nearDist=%f\n", this->_nearDist);
|
||||
printf("nearDist=%f\n", this->_nearClip);
|
||||
printf("nearHeight=%f\n", this->_nearHeight);
|
||||
printf("nearWidth=%f\n", this->_nearWidth);
|
||||
|
||||
|
@ -103,3 +132,37 @@ void ViewFrustum::dump() {
|
|||
}
|
||||
|
||||
|
||||
int ViewFrustum::pointInFrustum(glm::vec3 &p) {
|
||||
int result = INSIDE;
|
||||
for(int i=0; i < 6; i++) {
|
||||
if (this->_planes[i].distance(p) < 0)
|
||||
return OUTSIDE;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
int ViewFrustum::sphereInFrustum(glm::vec3 ¢er, float radius) {
|
||||
int result = INSIDE;
|
||||
float distance;
|
||||
for(int i=0; i < 6; i++) {
|
||||
distance = this->_planes[i].distance(center);
|
||||
if (distance < -radius)
|
||||
return OUTSIDE;
|
||||
else if (distance < radius)
|
||||
result = INTERSECT;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
int ViewFrustum::boxInFrustum(AABox &b) {
|
||||
int result = INSIDE;
|
||||
for(int i=0; i < 6; i++) {
|
||||
if (this->_planes[i].distance(b.getVertexP(this->_planes[i].normal)) < 0)
|
||||
return OUTSIDE;
|
||||
else if (this->_planes[i].distance(b.getVertexN(this->_planes[i].normal)) < 0)
|
||||
result = INTERSECT;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,55 +12,84 @@
|
|||
#define __hifi__ViewFrustum__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "Plane.h"
|
||||
#include "AABox.h"
|
||||
|
||||
class ViewFrustum {
|
||||
private:
|
||||
glm::vec3 _position;
|
||||
glm::vec3 _direction;
|
||||
glm::vec3 _up;
|
||||
glm::vec3 _right;
|
||||
float _screenWidth;
|
||||
float _screenHeight;
|
||||
|
||||
float _nearDist;
|
||||
float _farDist;
|
||||
|
||||
float _nearHeight;
|
||||
float _nearWidth;
|
||||
float _farHeight;
|
||||
float _farWidth;
|
||||
// camera location/orientation attributes
|
||||
glm::vec3 _position;
|
||||
glm::vec3 _direction;
|
||||
glm::vec3 _up;
|
||||
glm::vec3 _right;
|
||||
|
||||
glm::vec3 _farCenter;
|
||||
glm::vec3 _farTopLeft;
|
||||
glm::vec3 _farTopRight;
|
||||
glm::vec3 _farBottomLeft;
|
||||
glm::vec3 _farBottomRight;
|
||||
// Lens attributes
|
||||
float _fieldOfView;
|
||||
float _aspectRatio;
|
||||
float _nearClip;
|
||||
float _farClip;
|
||||
|
||||
glm::vec3 _nearCenter;
|
||||
glm::vec3 _nearTopLeft;
|
||||
glm::vec3 _nearTopRight;
|
||||
glm::vec3 _nearBottomLeft;
|
||||
glm::vec3 _nearBottomRight;
|
||||
// Calculated values
|
||||
float _nearHeight;
|
||||
float _nearWidth;
|
||||
float _farHeight;
|
||||
float _farWidth;
|
||||
glm::vec3 _farCenter;
|
||||
glm::vec3 _farTopLeft;
|
||||
glm::vec3 _farTopRight;
|
||||
glm::vec3 _farBottomLeft;
|
||||
glm::vec3 _farBottomRight;
|
||||
glm::vec3 _nearCenter;
|
||||
glm::vec3 _nearTopLeft;
|
||||
glm::vec3 _nearTopRight;
|
||||
glm::vec3 _nearBottomLeft;
|
||||
glm::vec3 _nearBottomRight;
|
||||
enum { TOPP = 0, BOTTOMP, LEFTP, RIGHTP, NEARP, FARP };
|
||||
Plane _planes[6]; // How will this be used?
|
||||
|
||||
public:
|
||||
const glm::vec3& getFarCenter() const { return _farCenter; };
|
||||
const glm::vec3& getFarTopLeft() const { return _farTopLeft; };
|
||||
const glm::vec3& getFarTopRight() const { return _farTopRight; };
|
||||
const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; };
|
||||
const glm::vec3& getFarBottomRight() const { return _farBottomRight; };
|
||||
// setters for camera attributes
|
||||
void setPosition (const glm::vec3& p) { _position = p; }
|
||||
void setOrientation (const glm::vec3& d, const glm::vec3& u, const glm::vec3& r )
|
||||
{ _direction = d; _up = u; _right = r; }
|
||||
|
||||
const glm::vec3& getNearCenter() const { return _nearCenter; };
|
||||
const glm::vec3& getNearTopLeft() const { return _nearTopLeft; };
|
||||
const glm::vec3& getNearTopRight() const { return _nearTopRight; };
|
||||
const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; };
|
||||
const glm::vec3& getNearBottomRight() const { return _nearBottomRight; };
|
||||
// setters for lens attributes
|
||||
void setFieldOfView ( float f ) { _fieldOfView = f; }
|
||||
void setAspectRatio ( float a ) { _aspectRatio = a; }
|
||||
void setNearClip ( float n ) { _nearClip = n; }
|
||||
void setFarClip ( float f ) { _farClip = f; }
|
||||
|
||||
void calculateViewFrustum(glm::vec3 position, glm::vec3 direction,
|
||||
glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight);
|
||||
// getters for lens attributes
|
||||
float getFieldOfView() const { return _fieldOfView; };
|
||||
float getAspectRatio() const { return _aspectRatio; };
|
||||
float getNearClip() const { return _nearClip; };
|
||||
float getFarClip() const { return _farClip; };
|
||||
|
||||
ViewFrustum(glm::vec3 position, glm::vec3 direction,
|
||||
glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight);
|
||||
|
||||
void dump();
|
||||
const glm::vec3& getFarCenter() const { return _farCenter; };
|
||||
const glm::vec3& getFarTopLeft() const { return _farTopLeft; };
|
||||
const glm::vec3& getFarTopRight() const { return _farTopRight; };
|
||||
const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; };
|
||||
const glm::vec3& getFarBottomRight() const { return _farBottomRight; };
|
||||
|
||||
const glm::vec3& getNearCenter() const { return _nearCenter; };
|
||||
const glm::vec3& getNearTopLeft() const { return _nearTopLeft; };
|
||||
const glm::vec3& getNearTopRight() const { return _nearTopRight; };
|
||||
const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; };
|
||||
const glm::vec3& getNearBottomRight() const { return _nearBottomRight;};
|
||||
|
||||
void calculate();
|
||||
|
||||
ViewFrustum();
|
||||
|
||||
void dump();
|
||||
|
||||
enum {OUTSIDE, INTERSECT, INSIDE};
|
||||
|
||||
int pointInFrustum(glm::vec3 &p);
|
||||
int sphereInFrustum(glm::vec3 ¢er, float radius);
|
||||
int boxInFrustum(AABox &b);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -192,37 +192,23 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) {
|
|||
VoxelNode* parentNode = NULL;
|
||||
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...
|
||||
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)) {
|
||||
printf("found node to delete...\n");
|
||||
if (0 == memcmp(nodeToDelete->octalCode,codeBuffer,lengthInBytes)) {
|
||||
|
||||
float* vertices = firstVertexForCode(nodeToDelete->octalCode);
|
||||
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
||||
delete []vertices;
|
||||
|
||||
if (parentNode) {
|
||||
float* vertices = firstVertexForCode(parentNode->octalCode);
|
||||
printf("parent of deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
||||
delete []vertices;
|
||||
|
||||
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
|
||||
printf("setting parentNode->children[%d] to NULL\n",childNDX);
|
||||
parentNode->children[childNDX]=NULL; // set it to NULL
|
||||
|
||||
printf("reaverageVoxelColors()\n");
|
||||
reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
set(TARGET_NAME space-server)
|
||||
|
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
|
|||
|
||||
set(TARGET_NAME voxel-server)
|
||||
|
||||
set(ROOT_DIR ../)
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
include(${MACRO_DIR}/SetupHifiProject.cmake)
|
||||
|
|
|
@ -27,9 +27,10 @@ VoxelAgentData* VoxelAgentData::clone() const {
|
|||
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
|
||||
sscanf((char *)data,
|
||||
"H%*f,%*f,%*f,%f,%f,%f",
|
||||
&position[0], &position[1], &position[2]);
|
||||
memcpy(&position, sourceBuffer, sizeof(float) * 3);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
~VoxelAgentData();
|
||||
VoxelAgentData(const VoxelAgentData &otherAgentData);
|
||||
|
||||
void parseData(void *data, int size);
|
||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||
VoxelAgentData* clone() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ int main(int argc, const char * argv[])
|
|||
|
||||
sockaddr agentPublicAddress;
|
||||
|
||||
char *packetData = new char[MAX_PACKET_SIZE];
|
||||
unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes;
|
||||
|
||||
// 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
|
||||
// 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 totalLength = 1+commandLength+1;
|
||||
|
||||
|
@ -385,7 +385,7 @@ int main(int argc, const char * argv[])
|
|||
agentList->increaseAgentId();
|
||||
}
|
||||
|
||||
agentList->updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes);
|
||||
agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue