mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 13:53:38 +02:00
merge branch assignee with upstream/master
This commit is contained in:
commit
6844490dbe
27 changed files with 572 additions and 281 deletions
|
@ -434,7 +434,7 @@ void sendDanceFloor() {
|
|||
for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) {
|
||||
for (int j = 0; j < DANCE_FLOOR_LENGTH; j++) {
|
||||
|
||||
int randomColorIndex = randIntInRange( -(DANCE_FLOOR_COLORS), (DANCE_FLOOR_COLORS + 1));
|
||||
int randomColorIndex = randIntInRange(-DANCE_FLOOR_COLORS, DANCE_FLOOR_COLORS);
|
||||
::danceFloorColors[i][j] = randomColorIndex;
|
||||
::danceFloorLights[i][j] = ::danceFloorPosition +
|
||||
glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE);
|
||||
|
@ -697,8 +697,7 @@ int main(int argc, const char * argv[])
|
|||
::wantLocalDomain = cmdOptionExists(argc, argv,local);
|
||||
if (::wantLocalDomain) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
nodeList->setDomainIPToLocalhost();
|
||||
}
|
||||
|
||||
nodeList->linkedDataCreateCallback = NULL; // do we need a callback?
|
||||
|
|
|
@ -70,16 +70,15 @@ bool wantLocalDomain = false;
|
|||
int main(int argc, const char* argv[]) {
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT);
|
||||
|
||||
// Handle Local Domain testing with the --local command line
|
||||
const char* local = "--local";
|
||||
::wantLocalDomain = cmdOptionExists(argc, argv,local);
|
||||
if (::wantLocalDomain) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
}
|
||||
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT);
|
||||
nodeList->setDomainIPToLocalhost();
|
||||
}
|
||||
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
|
|
|
@ -60,8 +60,7 @@ int main(int argc, const char* argv[]) {
|
|||
const char* local = "--local";
|
||||
if (cmdOptionExists(argc, argv, local)) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
nodeList->setDomainIPToLocalhost();
|
||||
}
|
||||
|
||||
nodeList->linkedDataCreateCallback = attachAvatarDataToNode;
|
||||
|
@ -97,7 +96,7 @@ int main(int argc, const char* argv[]) {
|
|||
switch (packetData[0]) {
|
||||
case PACKET_TYPE_HEAD_DATA:
|
||||
// grab the node ID from the packet
|
||||
unpackNodeId(packetData + 1, &nodeID);
|
||||
unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID);
|
||||
|
||||
// add or update the node in our list
|
||||
avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID);
|
||||
|
|
|
@ -82,6 +82,7 @@ const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins
|
|||
|
||||
const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
|
||||
// in the idle loop? (60 FPS is default)
|
||||
static QTimer* idleTimer = NULL;
|
||||
|
||||
const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
|
||||
// Startup optimistically with small jitter buffer that
|
||||
|
@ -227,14 +228,14 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
|
||||
const char* domainIP = getCmdOption(argc, constArgv, "--domain");
|
||||
if (domainIP) {
|
||||
strcpy(DOMAIN_IP, domainIP);
|
||||
NodeList::getInstance()->setDomainIP(domainIP);
|
||||
}
|
||||
|
||||
// Handle Local Domain testing with the --local command line
|
||||
if (cmdOptionExists(argc, constArgv, "--local")) {
|
||||
printLog("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
|
||||
NodeList::getInstance()->setDomainIPToLocalhost();
|
||||
}
|
||||
|
||||
// Check to see if the user passed in a command line option for loading a local
|
||||
|
@ -341,7 +342,7 @@ void Application::initializeGL() {
|
|||
timer->start(1000);
|
||||
|
||||
// call our idle function whenever we can
|
||||
QTimer* idleTimer = new QTimer(this);
|
||||
idleTimer = new QTimer(this);
|
||||
connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
|
||||
idleTimer->start(0);
|
||||
_idleLoopStdev.reset();
|
||||
|
@ -973,19 +974,9 @@ void Application::idle() {
|
|||
gettimeofday(&check, NULL);
|
||||
|
||||
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
|
||||
sendPostedEvents(NULL, QEvent::TouchBegin);
|
||||
sendPostedEvents(NULL, QEvent::TouchUpdate);
|
||||
sendPostedEvents(NULL, QEvent::TouchEnd);
|
||||
|
||||
double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
|
||||
if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
|
||||
|
||||
// If we're using multi-touch look, immediately process any
|
||||
// touch events, and no other events.
|
||||
// This is necessary because id the idle() call takes longer than the
|
||||
// interval between idle() calls, the event loop never gets to run,
|
||||
// and touch events get delayed.
|
||||
|
||||
const float BIGGEST_DELTA_TIME_SECS = 0.25f;
|
||||
update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
|
||||
_glWidget->updateGL();
|
||||
|
@ -998,6 +989,9 @@ void Application::idle() {
|
|||
_idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
|
||||
_idleLoopStdev.reset();
|
||||
}
|
||||
|
||||
// After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
|
||||
idleTimer->start(2);
|
||||
}
|
||||
}
|
||||
void Application::terminate() {
|
||||
|
@ -1101,8 +1095,14 @@ void Application::editPreferences() {
|
|||
QFormLayout* form = new QFormLayout();
|
||||
layout->addLayout(form, 1);
|
||||
|
||||
const int QLINE_MINIMUM_WIDTH = 400;
|
||||
|
||||
QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname()));
|
||||
domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||
form->addRow("Domain server:", domainServerHostname);
|
||||
|
||||
QLineEdit* avatarURL = new QLineEdit(_myAvatar.getVoxels()->getVoxelURL().toString());
|
||||
avatarURL->setMinimumWidth(400);
|
||||
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
|
||||
form->addRow("Avatar URL:", avatarURL);
|
||||
|
||||
QSpinBox* horizontalFieldOfView = new QSpinBox();
|
||||
|
@ -1133,9 +1133,33 @@ void Application::editPreferences() {
|
|||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const char* newHostname = domainServerHostname->text().toLocal8Bit().data();
|
||||
|
||||
// check if the domain server hostname is new
|
||||
if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, sizeof(&newHostname)) != 0) {
|
||||
// if so we need to clear the nodelist and delete the local voxels
|
||||
Node *voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
|
||||
|
||||
if (voxelServer) {
|
||||
voxelServer->lock();
|
||||
}
|
||||
|
||||
_voxels.killLocalVoxels();
|
||||
|
||||
if (voxelServer) {
|
||||
voxelServer->unlock();
|
||||
}
|
||||
|
||||
NodeList::getInstance()->clear();
|
||||
NodeList::getInstance()->setDomainHostname(newHostname);
|
||||
}
|
||||
|
||||
QUrl url(avatarURL->text());
|
||||
_myAvatar.getVoxels()->setVoxelURL(url);
|
||||
sendAvatarVoxelURLMessage(url);
|
||||
|
||||
_headCameraPitchYawScale = headCameraPitchYawScale->value();
|
||||
_myAvatar.setLeanScale(leanScale->value());
|
||||
_audioJitterBufferSamples = audioJitterBufferSamples->value();
|
||||
|
@ -1182,6 +1206,24 @@ void Application::setRenderThirdPerson(bool thirdPerson) {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::increaseAvatarSize() {
|
||||
if (5.0f < _myAvatar.getScale() + 0.05f) {
|
||||
return;
|
||||
}
|
||||
|
||||
_myAvatar.setScale(_myAvatar.getScale() + 0.05f);
|
||||
_myCamera.setScale(_myAvatar.getScale() + 0.05f);
|
||||
}
|
||||
|
||||
void Application::decreaseAvatarSize() {
|
||||
if (_myAvatar.getScale() - 0.05f < 0.15f) {
|
||||
return;
|
||||
}
|
||||
|
||||
_myAvatar.setScale(_myAvatar.getScale() - 0.05f);
|
||||
_myCamera.setScale(_myAvatar.getScale() - 0.05f);
|
||||
}
|
||||
|
||||
void Application::setFrustumOffset(bool frustumOffset) {
|
||||
// reshape so that OpenGL will get the right lens details for the camera of choice
|
||||
resizeGL(_glWidget->width(), _glWidget->height());
|
||||
|
@ -1196,6 +1238,12 @@ void Application::setRenderWarnings(bool renderWarnings) {
|
|||
_voxels.setRenderPipelineWarnings(renderWarnings);
|
||||
}
|
||||
|
||||
void Application::setRenderVoxels(bool voxelRender) {
|
||||
if (!voxelRender) {
|
||||
doKillLocalVoxels();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::doKillLocalVoxels() {
|
||||
_wantToKillLocalVoxels = true;
|
||||
}
|
||||
|
@ -1392,10 +1440,9 @@ void Application::importVoxels() {
|
|||
_glWidget, tr("Import Voxels"), desktopLocation,
|
||||
tr("Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)"));
|
||||
|
||||
QByteArray fileNameAscii = fileNameString.toAscii();
|
||||
const char* fileName = fileNameAscii.data();
|
||||
|
||||
VoxelTree importVoxels;
|
||||
const char* fileName = fileNameString.toAscii().data();
|
||||
|
||||
_clipboardTree.eraseAllVoxels();
|
||||
if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
|
||||
QImage pngImage = QImage(fileName);
|
||||
if (pngImage.height() != pngImage.width()) {
|
||||
|
@ -1411,43 +1458,11 @@ void Application::importVoxels() {
|
|||
pixels = reinterpret_cast<const uint32_t*>(tmp.constBits());
|
||||
}
|
||||
|
||||
importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height());
|
||||
_clipboardTree.readFromSquareARGB32Pixels(pixels, pngImage.height());
|
||||
} else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
|
||||
importVoxels.readFromSVOFile(fileName);
|
||||
} else {
|
||||
importVoxels.readFromSchematicFile(fileName);
|
||||
}
|
||||
|
||||
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
|
||||
|
||||
// Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to
|
||||
// the server as an set voxel message, this will also rebase the voxels to the new location
|
||||
unsigned char* calculatedOctCode = NULL;
|
||||
SendVoxelsOperationArgs args;
|
||||
|
||||
int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
|
||||
|
||||
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
|
||||
*sequenceAt = 0;
|
||||
args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
|
||||
|
||||
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
|
||||
// voxel size/position details.
|
||||
if (selectedNode) {
|
||||
args.newBaseOctCode = selectedNode->getOctalCode();
|
||||
} else {
|
||||
args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
|
||||
}
|
||||
|
||||
importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
|
||||
|
||||
// If we have voxels left in the packet, then send the packet
|
||||
if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
|
||||
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
||||
}
|
||||
|
||||
if (calculatedOctCode) {
|
||||
delete[] calculatedOctCode;
|
||||
_clipboardTree.readFromSVOFile(fileName);
|
||||
} else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
|
||||
_clipboardTree.readFromSchematicFile(fileName);
|
||||
}
|
||||
|
||||
// restore the main window's active state
|
||||
|
@ -1539,9 +1554,8 @@ void Application::initMenu() {
|
|||
optionsMenu->addAction("Go Home", this, SLOT(goHome()));
|
||||
|
||||
QMenu* renderMenu = menuBar->addMenu("Render");
|
||||
(_renderVoxels = renderMenu->addAction("Voxels"))->setCheckable(true);
|
||||
(_renderVoxels = renderMenu->addAction("Voxels", this, SLOT(setRenderVoxels(bool)), Qt::SHIFT | Qt::Key_V))->setCheckable(true);
|
||||
_renderVoxels->setChecked(true);
|
||||
_renderVoxels->setShortcut(Qt::SHIFT | Qt::Key_V);
|
||||
(_renderVoxelTextures = renderMenu->addAction("Voxel Textures"))->setCheckable(true);
|
||||
(_renderStarsOn = renderMenu->addAction("Stars"))->setCheckable(true);
|
||||
_renderStarsOn->setChecked(true);
|
||||
|
@ -1555,7 +1569,7 @@ void Application::initMenu() {
|
|||
_renderAvatarsOn->setChecked(true);
|
||||
(_renderAvatarBalls = renderMenu->addAction("Avatar as Balls"))->setCheckable(true);
|
||||
_renderAvatarBalls->setChecked(false);
|
||||
renderMenu->addAction("Cycle Voxeltar Mode", _myAvatar.getVoxels(), SLOT(cycleMode()));
|
||||
renderMenu->addAction("Cycle Voxel Mode", _myAvatar.getVoxels(), SLOT(cycleMode()));
|
||||
(_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true);
|
||||
_renderFrameTimerOn->setChecked(false);
|
||||
(_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true);
|
||||
|
@ -1564,6 +1578,9 @@ void Application::initMenu() {
|
|||
"First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
|
||||
(_manualThirdPerson = renderMenu->addAction(
|
||||
"Third Person", this, SLOT(setRenderThirdPerson(bool))))->setCheckable(true);
|
||||
renderMenu->addAction("Increase Avatar Size", this, SLOT(increaseAvatarSize()), Qt::SHIFT | Qt::Key_Plus);
|
||||
renderMenu->addAction("Decrease Avatar Size", this, SLOT(decreaseAvatarSize()), Qt::SHIFT | Qt::Key_Minus);
|
||||
|
||||
|
||||
QMenu* toolsMenu = menuBar->addMenu("Tools");
|
||||
(_renderStatsOn = toolsMenu->addAction("Stats"))->setCheckable(true);
|
||||
|
@ -1656,6 +1673,8 @@ void Application::initMenu() {
|
|||
(_renderCoverageMapV2 = debugMenu->addAction("Render Coverage Map V2"))->setCheckable(true);
|
||||
_renderCoverageMapV2->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::Key_P);
|
||||
|
||||
(_simulateLeapHand = debugMenu->addAction("Simulate Leap Hand"))->setCheckable(true);
|
||||
(_testRaveGlove = debugMenu->addAction("Test RaveGlove"))->setCheckable(true);
|
||||
|
||||
QMenu* settingsMenu = menuBar->addMenu("Settings");
|
||||
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
|
||||
|
@ -1914,6 +1933,7 @@ void Application::update(float deltaTime) {
|
|||
}
|
||||
|
||||
// Leap finger-sensing device
|
||||
LeapManager::enableFakeFingers(_simulateLeapHand->isChecked() || _testRaveGlove->isChecked());
|
||||
LeapManager::nextFrame();
|
||||
_myAvatar.getHand().setLeapFingers(LeapManager::getFingerTips(), LeapManager::getFingerRoots());
|
||||
_myAvatar.getHand().setLeapHands(LeapManager::getHandPositions(), LeapManager::getHandNormals());
|
||||
|
@ -1935,8 +1955,8 @@ void Application::update(float deltaTime) {
|
|||
|
||||
//loop through all the other avatars and simulate them...
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
nodeList->lock();
|
||||
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
node->lock();
|
||||
if (node->getLinkedData() != NULL) {
|
||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||
if (!avatar->isInitialized()) {
|
||||
|
@ -1945,8 +1965,8 @@ void Application::update(float deltaTime) {
|
|||
avatar->simulate(deltaTime, NULL);
|
||||
avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
|
||||
}
|
||||
node->unlock();
|
||||
}
|
||||
nodeList->unlock();
|
||||
|
||||
// Simulate myself
|
||||
if (_gravityUse->isChecked()) {
|
||||
|
@ -2435,8 +2455,10 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
if (_renderAvatarsOn->isChecked()) {
|
||||
// Render avatars of other nodes
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
nodeList->lock();
|
||||
|
||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
node->lock();
|
||||
|
||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||
if (!avatar->isInitialized()) {
|
||||
|
@ -2445,8 +2467,9 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
avatar->render(false, _renderAvatarBalls->isChecked());
|
||||
avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked());
|
||||
}
|
||||
|
||||
node->unlock();
|
||||
}
|
||||
nodeList->unlock();
|
||||
|
||||
// Render my own Avatar
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
|
@ -3195,7 +3218,7 @@ void* Application::networkReceive(void* args) {
|
|||
if (app->_wantToKillLocalVoxels) {
|
||||
app->_voxels.killLocalVoxels();
|
||||
app->_wantToKillLocalVoxels = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) {
|
||||
app->_packetCount++;
|
||||
|
@ -3216,11 +3239,23 @@ void* Application::networkReceive(void* args) {
|
|||
case PACKET_TYPE_VOXEL_DATA_MONOCHROME:
|
||||
case PACKET_TYPE_Z_COMMAND:
|
||||
case PACKET_TYPE_ERASE_VOXEL:
|
||||
app->_voxels.parseData(app->_incomingPacket, bytesReceived);
|
||||
break;
|
||||
case PACKET_TYPE_ENVIRONMENT_DATA:
|
||||
app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived);
|
||||
case PACKET_TYPE_ENVIRONMENT_DATA: {
|
||||
if (app->_renderVoxels->isChecked()) {
|
||||
Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
|
||||
if (voxelServer) {
|
||||
voxelServer->lock();
|
||||
|
||||
if (app->_incomingPacket[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
|
||||
app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived);
|
||||
} else {
|
||||
app->_voxels.parseData(app->_incomingPacket, bytesReceived);
|
||||
}
|
||||
|
||||
voxelServer->unlock();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PACKET_TYPE_BULK_AVATAR_DATA:
|
||||
NodeList::getInstance()->processBulkNodeData(&senderAddress,
|
||||
app->_incomingPacket,
|
||||
|
|
|
@ -118,6 +118,8 @@ private slots:
|
|||
|
||||
void setRenderFirstPerson(bool firstPerson);
|
||||
void setRenderThirdPerson(bool thirdPerson);
|
||||
void increaseAvatarSize();
|
||||
void decreaseAvatarSize();
|
||||
|
||||
void renderThrustAtVoxel(const glm::vec3& thrust);
|
||||
void renderLineToTouchedVoxel();
|
||||
|
@ -126,6 +128,7 @@ private slots:
|
|||
void cycleFrustumRenderMode();
|
||||
|
||||
void setRenderWarnings(bool renderWarnings);
|
||||
void setRenderVoxels(bool renderVoxels);
|
||||
void doKillLocalVoxels();
|
||||
void doRandomizeVoxelColors();
|
||||
void doFalseRandomizeVoxelColors();
|
||||
|
@ -260,6 +263,9 @@ private:
|
|||
|
||||
QAction* _renderCoverageMapV2;
|
||||
QAction* _renderCoverageMap;
|
||||
|
||||
QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data
|
||||
QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode
|
||||
|
||||
BandwidthMeter _bandwidthMeter;
|
||||
BandwidthDialog* _bandwidthDialog;
|
||||
|
|
|
@ -96,6 +96,10 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
Node* audioMixer = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
|
||||
|
||||
if (audioMixer) {
|
||||
audioMixer->lock();
|
||||
sockaddr_in audioSocket = *(sockaddr_in*) audioMixer->getActiveSocket();
|
||||
audioMixer->unlock();
|
||||
|
||||
glm::vec3 headPosition = interfaceAvatar->getHeadJointPosition();
|
||||
glm::quat headOrientation = interfaceAvatar->getHead().getOrientation();
|
||||
|
||||
|
@ -122,12 +126,13 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
|
||||
// copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet
|
||||
memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES_PER_CHANNEL);
|
||||
nodeList->getNodeSocket()->send(audioMixer->getActiveSocket(),
|
||||
dataPacket,
|
||||
BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
|
||||
nodeList->getNodeSocket()->send((sockaddr*) &audioSocket,
|
||||
dataPacket,
|
||||
BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
|
||||
|
||||
interface->getBandwidthMeter()->outputStream(BandwidthMeter::AUDIO)
|
||||
.updateValue(BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
|
||||
interface->getBandwidthMeter()->outputStream(BandwidthMeter::AUDIO).updateValue(BUFFER_LENGTH_BYTES_PER_CHANNEL
|
||||
+ leadingBytes);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_leanScale(0.5f),
|
||||
_pelvisStandingHeight(0.0f),
|
||||
_pelvisFloatingHeight(0.0f),
|
||||
_scale(1.0f),
|
||||
_distanceToNearestAvatar(std::numeric_limits<float>::max()),
|
||||
_gravity(0.0f, -1.0f, 0.0f),
|
||||
_worldUpDirection(DEFAULT_UP_DIRECTION),
|
||||
|
@ -111,9 +112,9 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_skeleton.initialize();
|
||||
|
||||
initializeBodyBalls();
|
||||
|
||||
|
||||
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
|
||||
|
||||
|
||||
_maxArmLength = _skeleton.getArmLength();
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
|
||||
|
@ -145,32 +146,32 @@ void Avatar::initializeBodyBalls() {
|
|||
}
|
||||
|
||||
// specify the radius of each ball
|
||||
_bodyBall[ BODY_BALL_PELVIS ].radius = 0.07;
|
||||
_bodyBall[ BODY_BALL_TORSO ].radius = 0.065;
|
||||
_bodyBall[ BODY_BALL_CHEST ].radius = 0.08;
|
||||
_bodyBall[ BODY_BALL_NECK_BASE ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = 0.07;
|
||||
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = 0.01;
|
||||
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = 0.01;
|
||||
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_PELVIS ].radius = BODY_BALL_RADIUS_PELVIS;
|
||||
_bodyBall[ BODY_BALL_TORSO ].radius = BODY_BALL_RADIUS_TORSO;
|
||||
_bodyBall[ BODY_BALL_CHEST ].radius = BODY_BALL_RADIUS_CHEST;
|
||||
_bodyBall[ BODY_BALL_NECK_BASE ].radius = BODY_BALL_RADIUS_NECK_BASE;
|
||||
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = BODY_BALL_RADIUS_HEAD_BASE;
|
||||
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = BODY_BALL_RADIUS_LEFT_COLLAR;
|
||||
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = BODY_BALL_RADIUS_LEFT_SHOULDER;
|
||||
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = BODY_BALL_RADIUS_LEFT_ELBOW;
|
||||
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = BODY_BALL_RADIUS_LEFT_WRIST;
|
||||
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = BODY_BALL_RADIUS_LEFT_FINGERTIPS;
|
||||
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = BODY_BALL_RADIUS_RIGHT_COLLAR;
|
||||
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = BODY_BALL_RADIUS_RIGHT_SHOULDER;
|
||||
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = BODY_BALL_RADIUS_RIGHT_ELBOW;
|
||||
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = BODY_BALL_RADIUS_RIGHT_WRIST;
|
||||
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
|
||||
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = BODY_BALL_RADIUS_LEFT_HIP;
|
||||
|
||||
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = 0.03;
|
||||
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = BODY_BALL_RADIUS_LEFT_MID_THIGH;
|
||||
|
||||
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = BODY_BALL_RADIUS_LEFT_KNEE;
|
||||
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = BODY_BALL_RADIUS_LEFT_HEEL;
|
||||
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = BODY_BALL_RADIUS_LEFT_TOES;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = BODY_BALL_RADIUS_RIGHT_HIP;
|
||||
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = BODY_BALL_RADIUS_RIGHT_KNEE;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = BODY_BALL_RADIUS_RIGHT_HEEL;
|
||||
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = BODY_BALL_RADIUS_RIGHT_TOES;
|
||||
|
||||
|
||||
// specify the parent joint for each ball
|
||||
|
@ -331,7 +332,7 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
|
|||
_head.setCameraFollowsHead(gyroLook);
|
||||
|
||||
// Update torso lean distance based on accelerometer data
|
||||
const float TORSO_LENGTH = 0.5f;
|
||||
const float TORSO_LENGTH = _scale * 0.5f;
|
||||
const float MAX_LEAN = 45.0f;
|
||||
_head.setLeanSideways(glm::clamp(glm::degrees(atanf(estimatedPosition.x * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
|
@ -378,18 +379,18 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
const float THRUST_JUMP = 120.f;
|
||||
|
||||
// Add Thrusts from keyboard
|
||||
if (_driveKeys[FWD ]) {_thrust += THRUST_MAG_FWD * deltaTime * front;}
|
||||
if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG_BACK * deltaTime * front;}
|
||||
if (_driveKeys[RIGHT ]) {_thrust += THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[LEFT ]) {_thrust -= THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[UP ]) {_thrust += THRUST_MAG_UP * deltaTime * up;}
|
||||
if (_driveKeys[DOWN ]) {_thrust -= THRUST_MAG_DOWN * deltaTime * up;}
|
||||
if (_driveKeys[FWD ]) {_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;}
|
||||
if (_driveKeys[BACK ]) {_thrust -= _scale * THRUST_MAG_BACK * deltaTime * front;}
|
||||
if (_driveKeys[RIGHT ]) {_thrust += _scale * THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[LEFT ]) {_thrust -= _scale * THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[UP ]) {_thrust += _scale * THRUST_MAG_UP * deltaTime * up;}
|
||||
if (_driveKeys[DOWN ]) {_thrust -= _scale * THRUST_MAG_DOWN * deltaTime * up;}
|
||||
if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;}
|
||||
if (_driveKeys[ROT_LEFT ]) {_bodyYawDelta += YAW_MAG * deltaTime;}
|
||||
|
||||
// Add one time jumping force if requested
|
||||
if (_shouldJump) {
|
||||
_thrust += THRUST_JUMP * up;
|
||||
_thrust += _scale * THRUST_JUMP * up;
|
||||
_shouldJump = false;
|
||||
}
|
||||
|
||||
|
@ -424,8 +425,7 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
}
|
||||
|
||||
// Update speed brake status
|
||||
|
||||
const float MIN_SPEED_BRAKE_VELOCITY = 0.4f;
|
||||
const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f;
|
||||
if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) {
|
||||
_speedBrakes = true;
|
||||
}
|
||||
|
@ -434,7 +434,6 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
_speedBrakes = false;
|
||||
}
|
||||
_isThrustOn = (glm::length(_thrust) > EPSILON);
|
||||
|
||||
}
|
||||
|
||||
void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||
|
@ -443,6 +442,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||
|
||||
//
|
||||
if (!isMyAvatar() && _scale != _newScale) {
|
||||
setScale(_newScale);
|
||||
}
|
||||
|
||||
// Update movement timers
|
||||
if (isMyAvatar()) {
|
||||
_elapsedTimeSinceCollision += deltaTime;
|
||||
|
@ -528,16 +532,17 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
//update the movement of the hand and process handshaking with other avatars...
|
||||
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
||||
_avatarTouch.simulate(deltaTime);
|
||||
|
||||
|
||||
if (isMyAvatar()) {
|
||||
|
||||
// apply gravity
|
||||
if (USING_AVATAR_GRAVITY) {
|
||||
// For gravity, always move the avatar by the amount driven by gravity, so that the collision
|
||||
// routines will detect it and collide every frame when pulled by gravity to a surface
|
||||
//
|
||||
_velocity += _gravity * (GRAVITY_EARTH * deltaTime);
|
||||
_position += _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||
//
|
||||
|
||||
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
|
||||
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||
}
|
||||
|
||||
updateCollisionWithEnvironment();
|
||||
|
@ -571,11 +576,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
_bodyRollDelta *= bodySpinMomentum;
|
||||
|
||||
const float MAX_STATIC_FRICTION_VELOCITY = 0.5f;
|
||||
const float STATIC_FRICTION_STRENGTH = 20.f;
|
||||
const float STATIC_FRICTION_STRENGTH = _scale * 20.f;
|
||||
applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH);
|
||||
|
||||
const float LINEAR_DAMPING_STRENGTH = 1.0f;
|
||||
const float SPEED_BRAKE_POWER = 10.0f;
|
||||
const float SPEED_BRAKE_POWER = _scale * 10.0f;
|
||||
const float SQUARED_DAMPING_STRENGTH = 0.2f;
|
||||
if (_speedBrakes) {
|
||||
applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH * SPEED_BRAKE_POWER, SQUARED_DAMPING_STRENGTH * SPEED_BRAKE_POWER);
|
||||
|
@ -592,7 +597,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
|
||||
|
||||
// these forces keep the body upright...
|
||||
const float BODY_UPRIGHT_FORCE = 10.0;
|
||||
const float BODY_UPRIGHT_FORCE = _scale * 10.0;
|
||||
float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime;
|
||||
if (tiltDecay > 1.0f) {tiltDecay = 1.0f;}
|
||||
|
||||
|
@ -662,7 +667,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
|
||||
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||
_head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position);
|
||||
_head.setScale (_bodyBall[ BODY_BALL_HEAD_BASE ].radius);
|
||||
_head.setScale(_scale);
|
||||
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
|
||||
_head.simulate(deltaTime, isMyAvatar());
|
||||
|
||||
|
@ -748,7 +753,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem
|
|||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
|
||||
if (distance < PERIPERSONAL_RADIUS) {
|
||||
if (distance < _scale * PERIPERSONAL_RADIUS) {
|
||||
_interactingOther = otherAvatar;
|
||||
}
|
||||
}
|
||||
|
@ -1017,7 +1022,7 @@ void Avatar::render(bool lookingInMirror, bool renderAvatarBalls) {
|
|||
}
|
||||
|
||||
// render a simple round on the ground projected down from the avatar's position
|
||||
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f);
|
||||
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), _scale * 0.1f, 0.2f);
|
||||
|
||||
// render body
|
||||
renderBody(lookingInMirror, renderAvatarBalls);
|
||||
|
@ -1091,7 +1096,7 @@ void Avatar::resetBodyBalls() {
|
|||
|
||||
void Avatar::updateBodyBalls(float deltaTime) {
|
||||
// Check for a large repositioning, and re-initialize balls if this has happened
|
||||
const float BEYOND_BODY_SPRING_RANGE = 2.f;
|
||||
const float BEYOND_BODY_SPRING_RANGE = _scale * 2.f;
|
||||
if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) {
|
||||
resetBodyBalls();
|
||||
}
|
||||
|
@ -1222,8 +1227,8 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
|||
}
|
||||
|
||||
float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const {
|
||||
const float RENDER_OPAQUE_OUTSIDE = 0.25f; // render opaque if greater than this distance
|
||||
const float DO_NOT_RENDER_INSIDE = 0.25f; // do not render if less than this distance
|
||||
const float RENDER_OPAQUE_OUTSIDE = _scale * 0.25f; // render opaque if greater than this distance
|
||||
const float DO_NOT_RENDER_INSIDE = _scale * 0.25f; // do not render if less than this distance
|
||||
float distanceToCamera = glm::length(Application::getInstance()->getCamera()->getPosition() - _bodyBall[ball].position);
|
||||
return (lookingInMirror || !isMyAvatar()) ? 1.0f : glm::clamp(
|
||||
(distanceToCamera - DO_NOT_RENDER_INSIDE) / (RENDER_OPAQUE_OUTSIDE - DO_NOT_RENDER_INSIDE), 0.f, 1.f);
|
||||
|
@ -1390,3 +1395,47 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2,
|
|||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Avatar::setScale(const float scale) {
|
||||
_scale = scale;
|
||||
_newScale = _scale;
|
||||
|
||||
_skeleton.setScale(_scale);
|
||||
|
||||
// specify the new radius of each ball
|
||||
_bodyBall[ BODY_BALL_PELVIS ].radius = _scale * BODY_BALL_RADIUS_PELVIS;
|
||||
_bodyBall[ BODY_BALL_TORSO ].radius = _scale * BODY_BALL_RADIUS_TORSO;
|
||||
_bodyBall[ BODY_BALL_CHEST ].radius = _scale * BODY_BALL_RADIUS_CHEST;
|
||||
_bodyBall[ BODY_BALL_NECK_BASE ].radius = _scale * BODY_BALL_RADIUS_NECK_BASE;
|
||||
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = _scale * BODY_BALL_RADIUS_HEAD_BASE;
|
||||
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_LEFT_COLLAR;
|
||||
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_LEFT_SHOULDER;
|
||||
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_LEFT_ELBOW;
|
||||
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = _scale * BODY_BALL_RADIUS_LEFT_WRIST;
|
||||
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_LEFT_FINGERTIPS;
|
||||
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_RIGHT_COLLAR;
|
||||
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_RIGHT_SHOULDER;
|
||||
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_RIGHT_ELBOW;
|
||||
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = _scale * BODY_BALL_RADIUS_RIGHT_WRIST;
|
||||
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
|
||||
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = _scale * BODY_BALL_RADIUS_LEFT_HIP;
|
||||
|
||||
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = _scale * BODY_BALL_RADIUS_LEFT_MID_THIGH;
|
||||
|
||||
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = _scale * BODY_BALL_RADIUS_LEFT_KNEE;
|
||||
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = _scale * BODY_BALL_RADIUS_LEFT_HEEL;
|
||||
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = _scale * BODY_BALL_RADIUS_LEFT_TOES;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HIP;
|
||||
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = _scale * BODY_BALL_RADIUS_RIGHT_KNEE;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HEEL;
|
||||
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = _scale * BODY_BALL_RADIUS_RIGHT_TOES;
|
||||
|
||||
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
|
||||
|
||||
_maxArmLength = _skeleton.getArmLength();
|
||||
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
|
||||
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
|
||||
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
|
||||
_avatarTouch.setReachableRadius(_scale * PERIPERSONAL_RADIUS);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,30 @@
|
|||
#include "Skeleton.h"
|
||||
#include "Transmitter.h"
|
||||
|
||||
const float BODY_BALL_RADIUS_PELVIS = 0.07;
|
||||
const float BODY_BALL_RADIUS_TORSO = 0.065;
|
||||
const float BODY_BALL_RADIUS_CHEST = 0.08;
|
||||
const float BODY_BALL_RADIUS_NECK_BASE = 0.03;
|
||||
const float BODY_BALL_RADIUS_HEAD_BASE = 0.07;
|
||||
const float BODY_BALL_RADIUS_LEFT_COLLAR = 0.04;
|
||||
const float BODY_BALL_RADIUS_LEFT_SHOULDER = 0.03;
|
||||
const float BODY_BALL_RADIUS_LEFT_ELBOW = 0.02;
|
||||
const float BODY_BALL_RADIUS_LEFT_WRIST = 0.02;
|
||||
const float BODY_BALL_RADIUS_LEFT_FINGERTIPS = 0.01;
|
||||
const float BODY_BALL_RADIUS_RIGHT_COLLAR = 0.04;
|
||||
const float BODY_BALL_RADIUS_RIGHT_SHOULDER = 0.03;
|
||||
const float BODY_BALL_RADIUS_RIGHT_ELBOW = 0.02;
|
||||
const float BODY_BALL_RADIUS_RIGHT_WRIST = 0.02;
|
||||
const float BODY_BALL_RADIUS_RIGHT_FINGERTIPS = 0.01;
|
||||
const float BODY_BALL_RADIUS_LEFT_HIP = 0.04;
|
||||
const float BODY_BALL_RADIUS_LEFT_MID_THIGH = 0.03;
|
||||
const float BODY_BALL_RADIUS_LEFT_KNEE = 0.025;
|
||||
const float BODY_BALL_RADIUS_LEFT_HEEL = 0.025;
|
||||
const float BODY_BALL_RADIUS_LEFT_TOES = 0.025;
|
||||
const float BODY_BALL_RADIUS_RIGHT_HIP = 0.04;
|
||||
const float BODY_BALL_RADIUS_RIGHT_KNEE = 0.025;
|
||||
const float BODY_BALL_RADIUS_RIGHT_HEEL = 0.025;
|
||||
const float BODY_BALL_RADIUS_RIGHT_TOES = 0.025;
|
||||
|
||||
enum AvatarBodyBallID
|
||||
{
|
||||
|
@ -105,6 +129,7 @@ public:
|
|||
void setGravity (glm::vec3 gravity);
|
||||
void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction);
|
||||
void setOrientation (const glm::quat& orientation);
|
||||
void setScale (const float scale);
|
||||
|
||||
//getters
|
||||
bool isInitialized () const { return _initialized;}
|
||||
|
@ -118,6 +143,7 @@ public:
|
|||
glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; }
|
||||
glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; }
|
||||
glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; }
|
||||
float getScale () const { return _scale;}
|
||||
const glm::vec3& getVelocity () const { return _velocity;}
|
||||
float getSpeed () const { return _speed;}
|
||||
float getHeight () const { return _height;}
|
||||
|
@ -200,6 +226,7 @@ private:
|
|||
float _pelvisStandingHeight;
|
||||
float _pelvisFloatingHeight;
|
||||
float _pelvisToHeadLength;
|
||||
float _scale;
|
||||
float _height;
|
||||
Balls* _balls;
|
||||
AvatarTouch _avatarTouch;
|
||||
|
|
|
@ -50,6 +50,7 @@ Camera::Camera() {
|
|||
_targetPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_idealPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_scale = 1.0f;
|
||||
}
|
||||
|
||||
void Camera::update(float deltaTime) {
|
||||
|
@ -91,14 +92,14 @@ void Camera::updateFollowMode(float deltaTime) {
|
|||
|
||||
if (_needsToInitialize || (_tightness == 0.0f)) {
|
||||
_rotation = _targetRotation;
|
||||
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance);
|
||||
_idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
|
||||
_position = _idealPosition;
|
||||
_needsToInitialize = false;
|
||||
|
||||
} else {
|
||||
// pull rotation towards ideal
|
||||
_rotation = safeMix(_rotation, _targetRotation, t);
|
||||
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance);
|
||||
_idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
|
||||
_position += (_idealPosition - _position) * t;
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +175,12 @@ void Camera::setEyeOffsetOrientation (const glm::quat& o) {
|
|||
_frustumNeedsReshape = true;
|
||||
}
|
||||
|
||||
void Camera::setScale(float s) {
|
||||
_scale = s;
|
||||
_needsToInitialize = true;
|
||||
_frustumNeedsReshape = true;
|
||||
}
|
||||
|
||||
void Camera::initialize() {
|
||||
_needsToInitialize = true;
|
||||
_modeShift = 0.0;
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void setFarClip ( float f );
|
||||
void setEyeOffsetPosition ( const glm::vec3& p );
|
||||
void setEyeOffsetOrientation( const glm::quat& o );
|
||||
void setScale ( const float s );
|
||||
|
||||
const glm::vec3& getTargetPosition () { return _targetPosition; }
|
||||
const glm::vec3& getPosition () { return _position; }
|
||||
|
@ -54,10 +55,11 @@ public:
|
|||
CameraMode getMode () { return _mode; }
|
||||
float getFieldOfView () { return _fieldOfView; }
|
||||
float getAspectRatio () { return _aspectRatio; }
|
||||
float getNearClip () { return _nearClip; }
|
||||
float getFarClip () { return _farClip; }
|
||||
float getNearClip () { return _scale * _nearClip; }
|
||||
float getFarClip () { return _scale * _farClip; }
|
||||
const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; }
|
||||
const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; }
|
||||
float getScale () { return _scale; }
|
||||
|
||||
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
|
||||
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
float _modeShift;
|
||||
float _linearModeShift;
|
||||
float _modeShiftRate;
|
||||
float _scale;
|
||||
|
||||
void updateFollowMode( float deltaTime );
|
||||
};
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
// getters
|
||||
const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
|
||||
|
||||
// position conversion
|
||||
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
|
||||
|
||||
private:
|
||||
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
||||
Hand(const Hand&);
|
||||
|
@ -66,7 +69,6 @@ private:
|
|||
// private methods
|
||||
void renderHandSpheres();
|
||||
void calculateGeometry();
|
||||
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -128,9 +128,9 @@ void Head::resetHairPhysics() {
|
|||
glm::vec3 up = getUpDirection();
|
||||
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
|
||||
|
||||
_hairTuft[t].length = HAIR_LENGTH;
|
||||
_hairTuft[t].thickness = HAIR_THICKNESS;
|
||||
_hairTuft[t].basePosition = _position + up * _scale * 0.9f;
|
||||
_hairTuft[t].length = _scale * HAIR_LENGTH;
|
||||
_hairTuft[t].thickness = _scale * HAIR_THICKNESS;
|
||||
_hairTuft[t].basePosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f;
|
||||
_hairTuft[t].midPosition = _hairTuft[t].basePosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].endPosition = _hairTuft[t].midPosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -261,13 +261,13 @@ void Head::calculateGeometry() {
|
|||
|
||||
//calculate the eye positions
|
||||
_leftEyePosition = _position
|
||||
- right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
- right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
||||
_rightEyePosition = _position
|
||||
+ right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
+ right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
||||
|
||||
_eyeLevelPosition = _position + up * _scale * EYE_UP_OFFSET;
|
||||
|
||||
|
@ -276,12 +276,12 @@ void Head::calculateGeometry() {
|
|||
_rightEyeBrowPosition = _rightEyePosition;
|
||||
|
||||
//calculate the ear positions
|
||||
_leftEarPosition = _position - right * _scale * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + right * _scale * EAR_RIGHT_OFFSET;
|
||||
_leftEarPosition = _position - right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
|
||||
|
||||
//calculate the mouth position
|
||||
_mouthPosition = _position + up * _scale * MOUTH_UP_OFFSET
|
||||
+ front * _scale;
|
||||
_mouthPosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * MOUTH_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,16 +296,25 @@ void Head::render(float alpha) {
|
|||
|
||||
renderMohawk();
|
||||
renderHeadSphere();
|
||||
renderEyeBalls();
|
||||
renderEyeBalls();
|
||||
renderEars();
|
||||
renderMouth();
|
||||
renderEyeBrows();
|
||||
|
||||
|
||||
if (_renderLookatVectors) {
|
||||
renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void Head::setScale (float scale) {
|
||||
_scale = scale;
|
||||
|
||||
delete[] _mohawkTriangleFan;
|
||||
delete[] _mohawkColors;
|
||||
createMohawk();
|
||||
|
||||
resetHairPhysics();
|
||||
}
|
||||
|
||||
void Head::createMohawk() {
|
||||
uint16_t nodeId = 0;
|
||||
|
@ -318,7 +327,7 @@ void Head::createMohawk() {
|
|||
}
|
||||
}
|
||||
srand(nodeId);
|
||||
float height = 0.08f + randFloat() * 0.05f;
|
||||
float height = _scale * (0.08f + randFloat() * 0.05f);
|
||||
float variance = 0.03 + randFloat() * 0.03f;
|
||||
const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES;
|
||||
_mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
|
@ -326,7 +335,7 @@ void Head::createMohawk() {
|
|||
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
|
||||
glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
|
||||
_mohawkColors[0] = basicColor;
|
||||
|
||||
|
||||
for (int i = 1; i < MOHAWK_TRIANGLES; i++) {
|
||||
_mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance,
|
||||
height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f)
|
||||
|
@ -404,7 +413,9 @@ glm::quat Head::getCameraOrientation () const {
|
|||
void Head::renderHeadSphere() {
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z); //translate to head position
|
||||
glScalef(_scale, _scale, _scale); //scale to head size
|
||||
glScalef(_scale * BODY_BALL_RADIUS_HEAD_BASE,
|
||||
_scale * BODY_BALL_RADIUS_HEAD_BASE,
|
||||
_scale * BODY_BALL_RADIUS_HEAD_BASE); //scale to head size
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glutSolidSphere(1, 30, 30);
|
||||
glPopMatrix();
|
||||
|
@ -415,13 +426,13 @@ void Head::renderEars() {
|
|||
glPushMatrix();
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glTranslatef(_leftEarPosition.x, _leftEarPosition.y, _leftEarPosition.z);
|
||||
glutSolidSphere(0.02, 30, 30);
|
||||
glutSolidSphere(_scale * 0.02, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glTranslatef(_rightEarPosition.x, _rightEarPosition.y, _rightEarPosition.z);
|
||||
glutSolidSphere(0.02, 30, 30);
|
||||
glutSolidSphere(_scale * 0.02, 30, 30);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -434,9 +445,9 @@ void Head::renderMouth() {
|
|||
glm::vec3 up = orientation * IDENTITY_UP;
|
||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
|
||||
glm::vec3 r = right * _scale * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = up * _scale * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = front * _scale * 0.09f;
|
||||
glm::vec3 r = right * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = up * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.09f;
|
||||
|
||||
glm::vec3 middle = _mouthPosition;
|
||||
glm::vec3 leftCorner = _mouthPosition - r * 1.0f;
|
||||
|
@ -449,7 +460,7 @@ void Head::renderMouth() {
|
|||
// constrain all mouth vertices to a sphere slightly larger than the head...
|
||||
const float MOUTH_OFFSET_OFF_FACE = 0.003f;
|
||||
|
||||
float constrainedRadius = _scale + MOUTH_OFFSET_OFF_FACE;
|
||||
float constrainedRadius = _scale * BODY_BALL_RADIUS_HEAD_BASE + MOUTH_OFFSET_OFF_FACE;
|
||||
middle = _position + glm::normalize(middle - _position) * constrainedRadius;
|
||||
leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius;
|
||||
rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius;
|
||||
|
@ -484,9 +495,9 @@ void Head::renderMouth() {
|
|||
|
||||
void Head::renderEyeBrows() {
|
||||
|
||||
float height = _scale * 0.3f + _browAudioLift;
|
||||
float length = _scale * 0.2f;
|
||||
float width = _scale * 0.07f;
|
||||
float height = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.3f + _browAudioLift;
|
||||
float length = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.2f;
|
||||
float width = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.07f;
|
||||
|
||||
glColor3f(0.3f, 0.25f, 0.2f);
|
||||
|
||||
|
@ -505,7 +516,7 @@ void Head::renderEyeBrows() {
|
|||
glm::vec3 r = right * length;
|
||||
glm::vec3 u = up * height;
|
||||
glm::vec3 t = up * (height + width);
|
||||
glm::vec3 f = front * _scale * -0.1f;
|
||||
glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * -0.1f;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
|
@ -553,14 +564,14 @@ void Head::renderEyeBalls() {
|
|||
glPushMatrix();
|
||||
glColor3fv(EYEBALL_COLOR);
|
||||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z);
|
||||
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
//render white ball of right eyeball
|
||||
glPushMatrix();
|
||||
glColor3fv(EYEBALL_COLOR);
|
||||
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
|
||||
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
_irisProgram->bind();
|
||||
|
@ -580,13 +591,15 @@ void Head::renderEyeBalls() {
|
|||
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||
glScalef(_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f),
|
||||
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS));
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
|
||||
|
||||
glutSolidSphere(0.5f, 15, 15);
|
||||
}
|
||||
|
@ -602,13 +615,15 @@ void Head::renderEyeBalls() {
|
|||
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||
glScalef(_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f),
|
||||
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS));
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
|
||||
|
||||
glutSolidSphere(0.5f, 15, 15);
|
||||
}
|
||||
|
@ -626,7 +641,7 @@ void Head::renderEyeBalls() {
|
|||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
|
||||
glm::vec3 rotationAxis = glm::axis(orientation);
|
||||
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS);
|
||||
glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
|
||||
glRotatef(-40 - 50 * _leftEyeBlink, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(180 * _leftEyeBlink, 1, 0, 0);
|
||||
|
@ -639,7 +654,7 @@ void Head::renderEyeBalls() {
|
|||
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position
|
||||
glm::vec3 rotationAxis = glm::axis(orientation);
|
||||
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS);
|
||||
glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
|
||||
glRotatef(-40 - 50 * _rightEyeBlink, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(180 * _rightEyeBlink, 1, 0, 0);
|
||||
|
@ -682,7 +697,7 @@ void Head::updateHairPhysics(float deltaTime) {
|
|||
= front * sinf(radian)
|
||||
+ up * cosf(radian);
|
||||
|
||||
_hairTuft[t].basePosition = _position + _scale * 0.9f * baseDirection;
|
||||
_hairTuft[t].basePosition = _position + _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f * baseDirection;
|
||||
|
||||
glm::vec3 midAxis = _hairTuft[t].midPosition - _hairTuft[t].basePosition;
|
||||
glm::vec3 endAxis = _hairTuft[t].endPosition - _hairTuft[t].midPosition;
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
void render(float alpha);
|
||||
void renderMohawk();
|
||||
|
||||
void setScale (float scale ) { _scale = scale; }
|
||||
void setScale (float scale );
|
||||
void setPosition (glm::vec3 position ) { _position = position; }
|
||||
void setBodyRotation (glm::vec3 bodyRotation ) { _bodyRotation = bodyRotation; }
|
||||
void setGravity (glm::vec3 gravity ) { _gravity = gravity; }
|
||||
|
|
|
@ -12,9 +12,14 @@
|
|||
#include <sstream>
|
||||
|
||||
bool LeapManager::_libraryExists = false;
|
||||
bool LeapManager::_doFakeFingers = false;
|
||||
Leap::Controller* LeapManager::_controller = NULL;
|
||||
HifiLeapListener* LeapManager::_listener = NULL;
|
||||
|
||||
namespace {
|
||||
glm::vec3 fakeHandOffset(0.0f, 50.0f, 50.0f);
|
||||
} // end anonymous namespace
|
||||
|
||||
class HifiLeapListener : public Leap::Listener {
|
||||
public:
|
||||
HifiLeapListener() {}
|
||||
|
@ -76,47 +81,91 @@ void LeapManager::terminate() {
|
|||
}
|
||||
|
||||
void LeapManager::nextFrame() {
|
||||
if (_listener && _controller)
|
||||
if (controllersExist()) {
|
||||
_listener->onFrame(*_controller);
|
||||
}
|
||||
}
|
||||
|
||||
void LeapManager::enableFakeFingers(bool enable) {
|
||||
_doFakeFingers = enable;
|
||||
}
|
||||
|
||||
bool LeapManager::controllersExist() {
|
||||
#ifdef LEAP_STUBS
|
||||
return false;
|
||||
#else
|
||||
return _listener && _controller && _controller->devices().count() > 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::vector<glm::vec3>& LeapManager::getFingerTips() {
|
||||
if (_listener) {
|
||||
if (controllersExist()) {
|
||||
return _listener->fingerTips;
|
||||
}
|
||||
else {
|
||||
static std::vector<glm::vec3> empty;
|
||||
return empty;
|
||||
static std::vector<glm::vec3> stubData;
|
||||
stubData.clear();
|
||||
if (_doFakeFingers) {
|
||||
// Simulated data
|
||||
float scale = 1.5f;
|
||||
stubData.push_back(glm::vec3( -60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( -20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( 20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( 60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( -50.0f, 0.0f, 30.0f) * scale + fakeHandOffset);
|
||||
}
|
||||
return stubData;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<glm::vec3>& LeapManager::getFingerRoots() {
|
||||
if (_listener) {
|
||||
if (controllersExist()) {
|
||||
return _listener->fingerRoots;
|
||||
}
|
||||
else {
|
||||
static std::vector<glm::vec3> empty;
|
||||
return empty;
|
||||
static std::vector<glm::vec3> stubData;
|
||||
stubData.clear();
|
||||
if (_doFakeFingers) {
|
||||
// Simulated data
|
||||
float scale = 0.75f;
|
||||
stubData.push_back(glm::vec3( -60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( -20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( 20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( 60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
|
||||
stubData.push_back(glm::vec3( -50.0f, 0.0f, 30.0f) * scale + fakeHandOffset);
|
||||
}
|
||||
return stubData;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<glm::vec3>& LeapManager::getHandPositions() {
|
||||
if (_listener) {
|
||||
if (controllersExist()) {
|
||||
return _listener->handPositions;
|
||||
}
|
||||
else {
|
||||
static std::vector<glm::vec3> empty;
|
||||
return empty;
|
||||
static std::vector<glm::vec3> stubData;
|
||||
stubData.clear();
|
||||
if (_doFakeFingers) {
|
||||
// Simulated data
|
||||
glm::vec3 handOffset(0.0f, 50.0f, 50.0f);
|
||||
stubData.push_back(glm::vec3( 0.0f, 0.0f, 0.0f) + fakeHandOffset);
|
||||
}
|
||||
return stubData;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<glm::vec3>& LeapManager::getHandNormals() {
|
||||
if (_listener) {
|
||||
if (controllersExist()) {
|
||||
return _listener->handNormals;
|
||||
}
|
||||
else {
|
||||
static std::vector<glm::vec3> empty;
|
||||
return empty;
|
||||
static std::vector<glm::vec3> stubData;
|
||||
stubData.clear();
|
||||
if (_doFakeFingers) {
|
||||
// Simulated data
|
||||
stubData.push_back(glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
return stubData;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ namespace Leap {
|
|||
|
||||
class LeapManager {
|
||||
public:
|
||||
static void nextFrame(); // called once per frame to get new Leap data
|
||||
static void nextFrame(); // called once per frame to get new Leap data
|
||||
static bool controllersExist(); // Returns true if there's at least one active Leap plugged in
|
||||
static void enableFakeFingers(bool enable); // put fake data in if there's no Leap plugged in
|
||||
static const std::vector<glm::vec3>& getFingerTips();
|
||||
static const std::vector<glm::vec3>& getFingerRoots();
|
||||
static const std::vector<glm::vec3>& getHandPositions();
|
||||
|
@ -31,6 +33,7 @@ public:
|
|||
|
||||
private:
|
||||
static bool _libraryExists; // The library is present, so we won't crash if we call it.
|
||||
static bool _doFakeFingers;
|
||||
static Leap::Controller* _controller;
|
||||
static HifiLeapListener* _listener;
|
||||
};
|
||||
|
|
|
@ -11,10 +11,39 @@
|
|||
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f;
|
||||
const float FLOATING_HEIGHT = 0.13f;
|
||||
|
||||
Skeleton::Skeleton() {
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_PELVIS = glm::vec3(0.0, 0.0, 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_TORSO = glm::vec3( 0.0, 0.09, -0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_CHEST = glm::vec3( 0.0, 0.09, -0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_NECK_BASE = glm::vec3( 0.0, 0.14, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_BASE = glm::vec3( 0.0, 0.04, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_TOP = glm::vec3( 0.0, 0.04, 0.00);
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_COLLAR = glm::vec3(-0.06, 0.04, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_SHOULDER = glm::vec3(-0.05, 0.0 , 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_ELBOW = glm::vec3(-0.16, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_WRIST = glm::vec3(-0.12, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_FINGERTIPS = glm::vec3(-0.1, 0.0 , 0.0 );
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_COLLAR = glm::vec3( 0.06, 0.04, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_SHOULDER = glm::vec3( 0.05, 0.0 , 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_ELBOW = glm::vec3( 0.16, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_WRIST = glm::vec3( 0.12, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS = glm::vec3( 0.1, 0.0 , 0.0 );
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HIP = glm::vec3(-0.05, 0.0 , 0.02);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_TOES = glm::vec3( 0.00, 0.00, -0.06);
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HIP = glm::vec3( 0.05, 0.0 , 0.02);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_TOES = glm::vec3( 0.00, 0.00, -0.06);
|
||||
|
||||
Skeleton::Skeleton() : _floatingHeight(FLOATING_HEIGHT){
|
||||
}
|
||||
|
||||
void Skeleton::initialize() {
|
||||
void Skeleton::initialize() {
|
||||
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
joint[b].parent = AVATAR_JOINT_NULL;
|
||||
|
@ -60,35 +89,39 @@ void Skeleton::initialize() {
|
|||
joint[ AVATAR_JOINT_RIGHT_HEEL ].parent = AVATAR_JOINT_RIGHT_KNEE;
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].parent = AVATAR_JOINT_RIGHT_HEEL;
|
||||
|
||||
setScale(1.0f);
|
||||
}
|
||||
|
||||
void Skeleton::setScale(float scale) {
|
||||
// specify the bind pose position
|
||||
joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_TORSO ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_CHEST ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = glm::vec3( 0.0, 0.14, 0.01 );
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 );
|
||||
joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 );
|
||||
joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_PELVIS;
|
||||
joint[ AVATAR_JOINT_TORSO ].bindPosePosition = scale * AVATAR_JOINT_POSITION_TORSO;
|
||||
joint[ AVATAR_JOINT_CHEST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_CHEST;
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_NECK_BASE;
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_BASE;
|
||||
joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_TOP;
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = glm::vec3( -0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = glm::vec3( -0.16, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = glm::vec3( -0.12, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = glm::vec3( -0.1, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_COLLAR;
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_ELBOW;
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_WRIST;
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_FINGERTIPS;
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = glm::vec3( 0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = glm::vec3( 0.16, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = glm::vec3( 0.12, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = glm::vec3( 0.1, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_COLLAR;
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_ELBOW;
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_WRIST;
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS;
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 );
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 );
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 );
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HIP;
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_KNEE;
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HEEL;
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_TOES;
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 );
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 );
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 );
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HIP;
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_KNEE;
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HEEL;
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_TOES;
|
||||
|
||||
// calculate bone length, absolute bind positions/rotations
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
|
@ -99,12 +132,14 @@ void Skeleton::initialize() {
|
|||
joint[b].absoluteBindPoseRotation = glm::quat();
|
||||
} else {
|
||||
joint[b].absoluteBindPosePosition = joint[ joint[b].parent ].absoluteBindPosePosition +
|
||||
joint[b].bindPosePosition;
|
||||
joint[b].bindPosePosition;
|
||||
glm::vec3 parentDirection = joint[ joint[b].parent ].absoluteBindPoseRotation * JOINT_DIRECTION;
|
||||
joint[b].absoluteBindPoseRotation = rotationBetween(parentDirection, joint[b].bindPosePosition) *
|
||||
joint[ joint[b].parent ].absoluteBindPoseRotation;
|
||||
joint[ joint[b].parent ].absoluteBindPoseRotation;
|
||||
}
|
||||
}
|
||||
|
||||
_floatingHeight = scale * FLOATING_HEIGHT;
|
||||
}
|
||||
|
||||
// calculate positions and rotations of all bones by traversing the skeleton tree:
|
||||
|
@ -151,7 +186,7 @@ float Skeleton::getPelvisStandingHeight() {
|
|||
float Skeleton::getPelvisFloatingHeight() {
|
||||
return joint[ AVATAR_JOINT_LEFT_HEEL ].length +
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].length +
|
||||
FLOATING_HEIGHT;
|
||||
_floatingHeight;
|
||||
}
|
||||
|
||||
float Skeleton::getPelvisToHeadLength() {
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
Skeleton();
|
||||
|
||||
void initialize();
|
||||
void setScale(float scale);
|
||||
void update(float deltaTime, const glm::quat&, glm::vec3 position);
|
||||
void render();
|
||||
|
||||
|
@ -72,7 +73,8 @@ public:
|
|||
float length; // the length of vector connecting the joint and its parent
|
||||
};
|
||||
|
||||
AvatarJoint joint[ NUM_AVATAR_JOINTS ];
|
||||
};
|
||||
AvatarJoint joint[ NUM_AVATAR_JOINTS ];
|
||||
float _floatingHeight;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@ AvatarData::AvatarData(Node* owningNode) :
|
|||
_bodyYaw(-90.0),
|
||||
_bodyPitch(0.0),
|
||||
_bodyRoll(0.0),
|
||||
_newScale(1.0f),
|
||||
_handState(0),
|
||||
_cameraPosition(0,0,0),
|
||||
_cameraOrientation(),
|
||||
|
@ -71,6 +72,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
|
||||
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _newScale);
|
||||
|
||||
// Head rotation (NOTE: This needs to become a quaternion to save two bytes)
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_yaw);
|
||||
|
@ -197,7 +199,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyYaw);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyPitch);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll);
|
||||
|
||||
sourceBuffer += unpackFloatRatioFromTwoByte( sourceBuffer, _newScale);
|
||||
|
||||
// Head rotation (NOTE: This needs to become a quaternion to save two bytes)
|
||||
float headYaw, headPitch, headRoll;
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw);
|
||||
|
|
|
@ -112,6 +112,7 @@ protected:
|
|||
float _bodyYaw;
|
||||
float _bodyPitch;
|
||||
float _bodyRoll;
|
||||
float _newScale;
|
||||
|
||||
// Hand state (are we grabbing something or not)
|
||||
char _handState;
|
||||
|
|
|
@ -20,6 +20,8 @@ class HandData {
|
|||
public:
|
||||
HandData(AvatarData* owningAvatar);
|
||||
|
||||
// These methods return the positions in Leap-relative space.
|
||||
// To convert to world coordinates, use Hand::leapPositionToWorldPosition.
|
||||
const std::vector<glm::vec3>& getFingerTips() const { return _fingerTips; }
|
||||
const std::vector<glm::vec3>& getFingerRoots() const { return _fingerRoots; }
|
||||
const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; }
|
||||
|
|
|
@ -53,6 +53,8 @@ Node::Node(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t no
|
|||
} else {
|
||||
_localSocket = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&_mutex, 0);
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
|
@ -60,6 +62,8 @@ Node::~Node() {
|
|||
delete _localSocket;
|
||||
delete _linkedData;
|
||||
delete _bytesReceivedMovingAverage;
|
||||
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
}
|
||||
|
||||
// Names of Node Types
|
||||
|
|
|
@ -65,6 +65,9 @@ public:
|
|||
|
||||
int getPingMs() const { return _pingMs; };
|
||||
void setPingMs(int pingMs) { _pingMs = pingMs; };
|
||||
|
||||
void lock() { pthread_mutex_lock(&_mutex); }
|
||||
void unlock() { pthread_mutex_unlock(&_mutex); }
|
||||
|
||||
static void printLog(Node const&);
|
||||
private:
|
||||
|
@ -83,6 +86,7 @@ private:
|
|||
NodeData* _linkedData;
|
||||
bool _isAlive;
|
||||
int _pingMs;
|
||||
pthread_mutex_t _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ const char SOLO_NODE_TYPES[3] = {
|
|||
NODE_TYPE_VOXEL_SERVER
|
||||
};
|
||||
|
||||
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
|
||||
char DOMAIN_IP[100] = "192.168.1.47"; // IP Address will be re-set by lookup on startup
|
||||
const int DOMAINSERVER_PORT = 40102;
|
||||
const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
|
||||
const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN] = ""; // IP Address will be re-set by lookup on startup
|
||||
const int DEFAULT_DOMAINSERVER_PORT = 40102;
|
||||
|
||||
bool silentNodeThreadStopFlag = false;
|
||||
bool pingUnknownNodeThreadStopFlag = false;
|
||||
|
@ -63,20 +63,37 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) :
|
|||
_ownerType(newOwnerType),
|
||||
_nodeTypesOfInterest(NULL),
|
||||
_ownerID(UNKNOWN_NODE_ID),
|
||||
_lastNodeID(0) {
|
||||
pthread_mutex_init(&mutex, 0);
|
||||
_lastNodeID(0)
|
||||
{
|
||||
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
|
||||
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
|
||||
}
|
||||
|
||||
NodeList::~NodeList() {
|
||||
delete _nodeTypesOfInterest;
|
||||
|
||||
// delete the nodes in our list
|
||||
clear();
|
||||
|
||||
// stop the spawned threads, if they were started
|
||||
stopSilentNodeRemovalThread();
|
||||
}
|
||||
|
||||
void NodeList::setDomainHostname(const char* domainHostname) {
|
||||
memset(_domainHostname, 0, sizeof(_domainHostname));
|
||||
memcpy(_domainHostname, domainHostname, strlen(domainHostname));
|
||||
|
||||
pthread_mutex_destroy(&mutex);
|
||||
// reset the domain IP so the hostname is checked again
|
||||
setDomainIP("");
|
||||
}
|
||||
|
||||
void NodeList::setDomainIP(const char* domainIP) {
|
||||
memset(_domainIP, 0, sizeof(_domainIP));
|
||||
memcpy(_domainIP, domainIP, strlen(domainIP));
|
||||
}
|
||||
|
||||
void NodeList::setDomainIPToLocalhost() {
|
||||
int ip = getLocalAddress();
|
||||
sprintf(_domainIP, "%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
}
|
||||
|
||||
void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
|
||||
|
@ -95,7 +112,14 @@ void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
|
|||
void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetData, size_t dataBytes) {
|
||||
switch (packetData[0]) {
|
||||
case PACKET_TYPE_DOMAIN: {
|
||||
processDomainServerList(packetData, dataBytes);
|
||||
// only process the DS if this is our current domain server
|
||||
sockaddr_in domainServerSocket = *(sockaddr_in*) senderAddress;
|
||||
const char* domainSenderIP = inet_ntoa(domainServerSocket.sin_addr);
|
||||
|
||||
if (memcmp(domainSenderIP, _domainIP, strlen(domainSenderIP)) == 0) {
|
||||
processDomainServerList(packetData, dataBytes);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PACKET_TYPE_PING: {
|
||||
|
@ -113,7 +137,6 @@ void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetDat
|
|||
}
|
||||
|
||||
void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) {
|
||||
lock();
|
||||
|
||||
// find the avatar mixer in our node list and update the lastRecvTime from it
|
||||
Node* bulkSendNode = nodeWithAddress(senderAddress);
|
||||
|
@ -121,38 +144,37 @@ void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packe
|
|||
if (bulkSendNode) {
|
||||
bulkSendNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||
bulkSendNode->recordBytesReceived(numTotalBytes);
|
||||
}
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
|
||||
unsigned char *startPosition = packetData;
|
||||
unsigned char *currentPosition = startPosition + numBytesPacketHeader;
|
||||
unsigned char packetHolder[numTotalBytes];
|
||||
|
||||
// we've already verified packet version for the bulk packet, so all head data in the packet is also up to date
|
||||
populateTypeAndVersion(packetHolder, PACKET_TYPE_HEAD_DATA);
|
||||
|
||||
uint16_t nodeID = -1;
|
||||
|
||||
while ((currentPosition - startPosition) < numTotalBytes) {
|
||||
unpackNodeId(currentPosition, &nodeID);
|
||||
memcpy(packetHolder + numBytesPacketHeader,
|
||||
currentPosition,
|
||||
numTotalBytes - (currentPosition - startPosition));
|
||||
|
||||
Node* matchingNode = nodeWithID(nodeID);
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
|
||||
if (!matchingNode) {
|
||||
// we're missing this node, we need to add it to the list
|
||||
matchingNode = addOrUpdateNode(NULL, NULL, NODE_TYPE_AGENT, nodeID);
|
||||
unsigned char* startPosition = packetData;
|
||||
unsigned char* currentPosition = startPosition + numBytesPacketHeader;
|
||||
unsigned char packetHolder[numTotalBytes];
|
||||
|
||||
// we've already verified packet version for the bulk packet, so all head data in the packet is also up to date
|
||||
populateTypeAndVersion(packetHolder, PACKET_TYPE_HEAD_DATA);
|
||||
|
||||
uint16_t nodeID = -1;
|
||||
|
||||
while ((currentPosition - startPosition) < numTotalBytes) {
|
||||
unpackNodeId(currentPosition, &nodeID);
|
||||
memcpy(packetHolder + numBytesPacketHeader,
|
||||
currentPosition,
|
||||
numTotalBytes - (currentPosition - startPosition));
|
||||
|
||||
Node* matchingNode = nodeWithID(nodeID);
|
||||
|
||||
if (!matchingNode) {
|
||||
// we're missing this node, we need to add it to the list
|
||||
matchingNode = addOrUpdateNode(NULL, NULL, NODE_TYPE_AGENT, nodeID);
|
||||
}
|
||||
|
||||
currentPosition += updateNodeWithData(matchingNode,
|
||||
packetHolder,
|
||||
numTotalBytes - (currentPosition - startPosition));
|
||||
|
||||
}
|
||||
|
||||
currentPosition += updateNodeWithData(matchingNode,
|
||||
packetHolder,
|
||||
numTotalBytes - (currentPosition - startPosition));
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int NodeList::updateNodeWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
|
||||
|
@ -167,6 +189,8 @@ int NodeList::updateNodeWithData(sockaddr *senderAddress, unsigned char *packetD
|
|||
}
|
||||
|
||||
int NodeList::updateNodeWithData(Node *node, unsigned char *packetData, int dataBytes) {
|
||||
node->lock();
|
||||
|
||||
node->setLastHeardMicrostamp(usecTimestampNow());
|
||||
|
||||
if (node->getActiveSocket()) {
|
||||
|
@ -177,7 +201,11 @@ int NodeList::updateNodeWithData(Node *node, unsigned char *packetData, int data
|
|||
linkedDataCreateCallback(node);
|
||||
}
|
||||
|
||||
return node->getLinkedData()->parseData(packetData, dataBytes);
|
||||
int numParsedBytes = node->getLinkedData()->parseData(packetData, dataBytes);
|
||||
|
||||
node->unlock();
|
||||
|
||||
return numParsedBytes;
|
||||
}
|
||||
|
||||
Node* NodeList::nodeWithAddress(sockaddr *senderAddress) {
|
||||
|
@ -218,7 +246,9 @@ void NodeList::clear() {
|
|||
Node** nodeBucket = _nodeBuckets[i / NODES_PER_BUCKET];
|
||||
Node* node = nodeBucket[i % NODES_PER_BUCKET];
|
||||
|
||||
node->lock();
|
||||
delete node;
|
||||
|
||||
node = NULL;
|
||||
}
|
||||
|
||||
|
@ -237,18 +267,19 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
static bool printedDomainServerIP = false;
|
||||
|
||||
// Lookup the IP address of the domain server if we need to
|
||||
if (atoi(DOMAIN_IP) == 0) {
|
||||
if (atoi(_domainIP) == 0) {
|
||||
printf("Looking up %s\n", _domainHostname);
|
||||
struct hostent* pHostInfo;
|
||||
if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) {
|
||||
if ((pHostInfo = gethostbyname(_domainHostname)) != NULL) {
|
||||
sockaddr_in tempAddress;
|
||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
||||
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
|
||||
printLog("Domain Server: %s \n", DOMAIN_HOSTNAME);
|
||||
strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
|
||||
printLog("Domain Server: %s \n", _domainHostname);
|
||||
} else {
|
||||
printLog("Failed domain server lookup\n");
|
||||
}
|
||||
} else if (!printedDomainServerIP) {
|
||||
printLog("Domain Server IP: %s\n", DOMAIN_IP);
|
||||
printLog("Domain Server IP: %s\n", _domainIP);
|
||||
printedDomainServerIP = true;
|
||||
}
|
||||
|
||||
|
@ -295,7 +326,7 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
checkInPacketSize = packetPosition - checkInPacket;
|
||||
}
|
||||
|
||||
_nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize);
|
||||
_nodeSocket.send(_domainIP, DEFAULT_DOMAINSERVER_PORT, checkInPacket, checkInPacketSize);
|
||||
}
|
||||
|
||||
int NodeList::processDomainServerList(unsigned char* packetData, size_t dataBytes) {
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
#ifndef __hifi__NodeList__
|
||||
#define __hifi__NodeList__
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <iterator>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Node.h"
|
||||
#include "NodeTypes.h"
|
||||
|
@ -31,9 +33,11 @@ const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
|
|||
|
||||
extern const char SOLO_NODE_TYPES[3];
|
||||
|
||||
extern char DOMAIN_HOSTNAME[];
|
||||
extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup
|
||||
extern const int DOMAINSERVER_PORT;
|
||||
const int MAX_HOSTNAME_BYTES = 255;
|
||||
|
||||
extern const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES];
|
||||
extern const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN]; // IP Address will be re-set by lookup on startup
|
||||
extern const int DEFAULT_DOMAINSERVER_PORT;
|
||||
|
||||
const int UNKNOWN_NODE_ID = -1;
|
||||
|
||||
|
@ -49,9 +53,16 @@ public:
|
|||
NodeListIterator begin() const;
|
||||
NodeListIterator end() const;
|
||||
|
||||
|
||||
NODE_TYPE getOwnerType() const { return _ownerType; }
|
||||
void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; }
|
||||
|
||||
const char* getDomainHostname() const { return _domainHostname; };
|
||||
void setDomainHostname(const char* domainHostname);
|
||||
|
||||
void setDomainIP(const char* domainIP);
|
||||
void setDomainIPToLocalhost();
|
||||
|
||||
uint16_t getLastNodeID() const { return _lastNodeID; }
|
||||
void increaseNodeID() { ++_lastNodeID; }
|
||||
|
||||
|
@ -69,9 +80,6 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
void lock() { pthread_mutex_lock(&mutex); }
|
||||
void unlock() { pthread_mutex_unlock(&mutex); }
|
||||
|
||||
void setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest);
|
||||
|
||||
void sendDomainServerCheckIn();
|
||||
|
@ -108,6 +116,8 @@ private:
|
|||
|
||||
void addNodeToList(Node* newNode);
|
||||
|
||||
char _domainHostname[MAX_HOSTNAME_BYTES];
|
||||
char _domainIP[INET_ADDRSTRLEN];
|
||||
Node** _nodeBuckets[MAX_NUM_NODES / NODES_PER_BUCKET];
|
||||
int _numNodes;
|
||||
UDPSocket _nodeSocket;
|
||||
|
@ -118,7 +128,6 @@ private:
|
|||
uint16_t _lastNodeID;
|
||||
pthread_t removeSilentNodesThread;
|
||||
pthread_t checkInWithDomainServerThread;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
void handlePingReply(sockaddr *nodeAddress);
|
||||
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||
switch (type) {
|
||||
case PACKET_TYPE_HEAD_DATA:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
|
@ -60,4 +63,4 @@ int numBytesForPacketHeader(unsigned char* packetHeader) {
|
|||
|
||||
// currently this need not be dynamic - there are 2 bytes for each packet header
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ float randFloat () {
|
|||
}
|
||||
|
||||
int randIntInRange (int min, int max) {
|
||||
return min + (rand() % (max - min));
|
||||
return min + (rand() % ((max + 1) - min));
|
||||
}
|
||||
|
||||
float randFloatInRange (float min,float max) {
|
||||
|
@ -48,7 +48,7 @@ float randFloatInRange (float min,float max) {
|
|||
}
|
||||
|
||||
unsigned char randomColorValue(int miniumum) {
|
||||
return miniumum + (rand() % (255 - miniumum));
|
||||
return miniumum + (rand() % (256 - miniumum));
|
||||
}
|
||||
|
||||
bool randomBoolean() {
|
||||
|
|
|
@ -383,8 +383,7 @@ int main(int argc, const char * argv[]) {
|
|||
::wantLocalDomain = cmdOptionExists(argc, argv,local);
|
||||
if (::wantLocalDomain) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
nodeList->setDomainIPToLocalhost();
|
||||
}
|
||||
|
||||
nodeList->linkedDataCreateCallback = &attachVoxelNodeDataToNode;
|
||||
|
|
Loading…
Reference in a new issue