Skip to content

Commit cc5ea2a

Browse files
committedMar 28, 2014
Merge branch 'master' of https://github.com/highfidelity/hifi into metavoxels
2 parents fd5f378 + 4acb146 commit cc5ea2a

33 files changed

+518
-403
lines changed
 

‎assignment-client/src/AssignmentClient.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <SharedUtil.h>
1919

2020
#include "AssignmentFactory.h"
21+
#include "AssignmentThread.h"
2122

2223
#include "AssignmentClient.h"
2324

@@ -28,7 +29,7 @@ int hifiSockAddrMeta = qRegisterMetaType<HifiSockAddr>("HifiSockAddr");
2829

2930
AssignmentClient::AssignmentClient(int &argc, char **argv) :
3031
QCoreApplication(argc, argv),
31-
_currentAssignment(NULL)
32+
_currentAssignment()
3233
{
3334
setOrganizationName("High Fidelity");
3435
setOrganizationDomain("highfidelity.io");
@@ -124,7 +125,7 @@ void AssignmentClient::readPendingDatagrams() {
124125
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
125126
if (packetTypeForPacket(receivedPacket) == PacketTypeCreateAssignment) {
126127
// construct the deployed assignment from the packet data
127-
_currentAssignment = AssignmentFactory::unpackAssignment(receivedPacket);
128+
_currentAssignment = SharedAssignmentPointer(AssignmentFactory::unpackAssignment(receivedPacket));
128129

129130
if (_currentAssignment) {
130131
qDebug() << "Received an assignment -" << *_currentAssignment;
@@ -137,14 +138,13 @@ void AssignmentClient::readPendingDatagrams() {
137138
qDebug() << "Destination IP for assignment is" << nodeList->getDomainInfo().getIP().toString();
138139

139140
// start the deployed assignment
140-
QThread* workerThread = new QThread(this);
141+
AssignmentThread* workerThread = new AssignmentThread(_currentAssignment, this);
141142

142-
connect(workerThread, SIGNAL(started()), _currentAssignment, SLOT(run()));
143-
144-
connect(_currentAssignment, SIGNAL(finished()), this, SLOT(assignmentCompleted()));
145-
connect(_currentAssignment, SIGNAL(finished()), workerThread, SLOT(quit()));
146-
connect(_currentAssignment, SIGNAL(finished()), _currentAssignment, SLOT(deleteLater()));
147-
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
143+
connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run);
144+
connect(_currentAssignment.data(), &ThreadedAssignment::finished, workerThread, &QThread::quit);
145+
connect(_currentAssignment.data(), &ThreadedAssignment::finished,
146+
this, &AssignmentClient::assignmentCompleted);
147+
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
148148

149149
_currentAssignment->moveToThread(workerThread);
150150

@@ -153,7 +153,7 @@ void AssignmentClient::readPendingDatagrams() {
153153

154154
// let the assignment handle the incoming datagrams for its duration
155155
disconnect(&nodeList->getNodeSocket(), 0, this, 0);
156-
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _currentAssignment,
156+
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _currentAssignment.data(),
157157
&ThreadedAssignment::readPendingDatagrams);
158158

159159
// Starts an event loop, and emits workerThread->started()
@@ -202,10 +202,12 @@ void AssignmentClient::assignmentCompleted() {
202202
NodeList* nodeList = NodeList::getInstance();
203203

204204
// have us handle incoming NodeList datagrams again
205-
disconnect(&nodeList->getNodeSocket(), 0, _currentAssignment, 0);
205+
disconnect(&nodeList->getNodeSocket(), 0, _currentAssignment.data(), 0);
206206
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams);
207207

208-
_currentAssignment = NULL;
208+
// clear our current assignment shared pointer now that we're done with it
209+
// if the assignment thread is still around it has its own shared pointer to the assignment
210+
_currentAssignment.clear();
209211

210212
// reset our NodeList by switching back to unassigned and clearing the list
211213
nodeList->setOwnerType(NodeType::Unassigned);

‎assignment-client/src/AssignmentClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private slots:
2424
void handleAuthenticationRequest();
2525
private:
2626
Assignment _requestAssignment;
27-
ThreadedAssignment* _currentAssignment;
27+
SharedAssignmentPointer _currentAssignment;
2828
};
2929

3030
#endif /* defined(__hifi__AssignmentClient__) */
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// AssignmentThread.cpp
3+
// hifi
4+
//
5+
// Created by Stephen Birarda on 2014-03-28.
6+
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
7+
//
8+
9+
#include "AssignmentThread.h"
10+
11+
AssignmentThread::AssignmentThread(const SharedAssignmentPointer& assignment, QObject* parent) :
12+
QThread(parent),
13+
_assignment(assignment)
14+
{
15+
16+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// AssignmentThread.h
3+
// hifi
4+
//
5+
// Created by Stephen Birarda on 2014-03-28.
6+
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
7+
//
8+
9+
#ifndef __hifi__AssignmentThread__
10+
#define __hifi__AssignmentThread__
11+
12+
#include <QtCore/QThread>
13+
14+
#include <ThreadedAssignment.h>
15+
16+
class AssignmentThread : public QThread {
17+
public:
18+
AssignmentThread(const SharedAssignmentPointer& assignment, QObject* parent);
19+
private:
20+
SharedAssignmentPointer _assignment;
21+
};
22+
23+
#endif /* defined(__hifi__AssignmentThread__) */

‎interface/interface_en.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,54 @@
1414
<translation type="unfinished"></translation>
1515
</message>
1616
<message>
17-
<location filename="src/Application.cpp" line="3610"/>
17+
<location filename="src/Application.cpp" line="3617"/>
1818
<source>Open Script</source>
1919
<translation type="unfinished"></translation>
2020
</message>
2121
<message>
22-
<location filename="src/Application.cpp" line="3611"/>
22+
<location filename="src/Application.cpp" line="3618"/>
2323
<source>JavaScript Files (*.js)</source>
2424
<translation type="unfinished"></translation>
2525
</message>
2626
</context>
2727
<context>
2828
<name>ChatWindow</name>
2929
<message>
30-
<location filename="ui/chatWindow.ui" line="20"/>
31-
<location filename="../build/interface/ui_chatWindow.h" line="143"/>
30+
<location filename="ui/chatWindow.ui" line="29"/>
31+
<location filename="../build/interface/ui_chatWindow.h" line="153"/>
3232
<source>Chat</source>
3333
<translation type="unfinished"></translation>
3434
</message>
3535
<message>
36-
<location filename="ui/chatWindow.ui" line="50"/>
37-
<location filename="../build/interface/ui_chatWindow.h" line="144"/>
36+
<location filename="ui/chatWindow.ui" line="57"/>
37+
<location filename="../build/interface/ui_chatWindow.h" line="154"/>
3838
<source>Connecting to XMPP...</source>
3939
<translation type="unfinished"></translation>
4040
</message>
4141
<message>
42-
<location filename="ui/chatWindow.ui" line="71"/>
43-
<location filename="../build/interface/ui_chatWindow.h" line="145"/>
42+
<location filename="ui/chatWindow.ui" line="78"/>
43+
<location filename="../build/interface/ui_chatWindow.h" line="155"/>
4444
<source> online now:</source>
4545
<translation type="unfinished"></translation>
4646
</message>
4747
<message numerus="yes">
48-
<location filename="src/ui/ChatWindow.cpp" line="128"/>
48+
<location filename="src/ui/ChatWindow.cpp" line="135"/>
4949
<source>day</source>
5050
<translation>
5151
<numerusform>%n day</numerusform>
5252
<numerusform>%n days</numerusform>
5353
</translation>
5454
</message>
5555
<message numerus="yes">
56-
<location filename="src/ui/ChatWindow.cpp" line="128"/>
56+
<location filename="src/ui/ChatWindow.cpp" line="135"/>
5757
<source>hour</source>
5858
<translation>
5959
<numerusform>%n hour</numerusform>
6060
<numerusform>%n hours</numerusform>
6161
</translation>
6262
</message>
6363
<message numerus="yes">
64-
<location filename="src/ui/ChatWindow.cpp" line="128"/>
64+
<location filename="src/ui/ChatWindow.cpp" line="135"/>
6565
<source>minute</source>
6666
<translation>
6767
<numerusform>%n minute</numerusform>
@@ -76,7 +76,7 @@
7676
</translation>
7777
</message>
7878
<message>
79-
<location filename="src/ui/ChatWindow.cpp" line="183"/>
79+
<location filename="src/ui/ChatWindow.cpp" line="191"/>
8080
<source>%1 online now:</source>
8181
<translation type="unfinished"></translation>
8282
</message>

‎interface/src/Application.cpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -2189,19 +2189,26 @@ void Application::updateShadowMap() {
21892189
(_viewFrustum.getFarClip() - _viewFrustum.getNearClip());
21902190
loadViewFrustum(_myCamera, _viewFrustum);
21912191
glm::vec3 points[] = {
2192-
inverseRotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale)),
2193-
inverseRotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale)),
2194-
inverseRotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale)),
2195-
inverseRotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale)),
2196-
inverseRotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale)),
2197-
inverseRotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale)),
2198-
inverseRotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale)),
2199-
inverseRotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale)) };
2200-
glm::vec3 minima(FLT_MAX, FLT_MAX, FLT_MAX), maxima(-FLT_MAX, -FLT_MAX, -FLT_MAX);
2192+
glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale),
2193+
glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale),
2194+
glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale),
2195+
glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale),
2196+
glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale),
2197+
glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale),
2198+
glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale),
2199+
glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) };
2200+
glm::vec3 center;
22012201
for (size_t i = 0; i < sizeof(points) / sizeof(points[0]); i++) {
2202-
minima = glm::min(minima, points[i]);
2203-
maxima = glm::max(maxima, points[i]);
2202+
center += points[i];
22042203
}
2204+
center /= (float)(sizeof(points) / sizeof(points[0]));
2205+
float radius = 0.0f;
2206+
for (size_t i = 0; i < sizeof(points) / sizeof(points[0]); i++) {
2207+
radius = qMax(radius, glm::distance(points[i], center));
2208+
}
2209+
center = inverseRotation * center;
2210+
glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius);
2211+
glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius);
22052212

22062213
// stretch out our extents in z so that we get all of the avatars
22072214
minima.z -= _viewFrustum.getFarClip() * 0.5f;

‎interface/src/Audio.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void Audio::handleAudioInput() {
522522
if (audioMixer && audioMixer->getActiveSocket()) {
523523
MyAvatar* interfaceAvatar = Application::getInstance()->getAvatar();
524524
glm::vec3 headPosition = interfaceAvatar->getHead()->getPosition();
525-
glm::quat headOrientation = interfaceAvatar->getHead()->getTweakedOrientation();
525+
glm::quat headOrientation = interfaceAvatar->getHead()->getFinalOrientation();
526526

527527
// we need the amount of bytes in the buffer + 1 for type
528528
// + 12 for 3 floats for position + float for bearing + 1 attenuation byte

‎interface/src/Menu.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -924,14 +924,17 @@ void Menu::goTo() {
924924

925925
int dialogReturn = gotoDialog.exec();
926926
if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) {
927-
LocationManager* manager = &LocationManager::getInstance();
928-
manager->goTo(gotoDialog.textValue());
929-
connect(manager, &LocationManager::multipleDestinationsFound, this, &Menu::multipleDestinationsDecision);
927+
goToUser(gotoDialog.textValue());
930928
}
931-
932929
sendFakeEnterEvent();
933930
}
934931

932+
void Menu::goToUser(const QString& user) {
933+
LocationManager* manager = &LocationManager::getInstance();
934+
manager->goTo(user);
935+
connect(manager, &LocationManager::multipleDestinationsFound, this, &Menu::multipleDestinationsDecision);
936+
}
937+
935938
void Menu::multipleDestinationsDecision(const QJsonObject& userData, const QJsonObject& placeData) {
936939
QMessageBox msgBox;
937940
msgBox.setText("Both user and location exists with same name");
@@ -1099,13 +1102,23 @@ void Menu::showMetavoxelEditor() {
10991102
}
11001103

11011104
void Menu::showChat() {
1105+
QMainWindow* mainWindow = Application::getInstance()->getWindow();
11021106
if (!_chatWindow) {
1103-
Application::getInstance()->getWindow()->addDockWidget(Qt::RightDockWidgetArea, _chatWindow = new ChatWindow());
1104-
1105-
} else {
1106-
if (!_chatWindow->toggleViewAction()->isChecked()) {
1107-
_chatWindow->toggleViewAction()->trigger();
1108-
}
1107+
mainWindow->addDockWidget(Qt::NoDockWidgetArea, _chatWindow = new ChatWindow());
1108+
}
1109+
if (!_chatWindow->toggleViewAction()->isChecked()) {
1110+
int width = _chatWindow->width();
1111+
int y = qMax((mainWindow->height() - _chatWindow->height()) / 2, 0);
1112+
_chatWindow->move(mainWindow->width(), y);
1113+
_chatWindow->resize(0, _chatWindow->height());
1114+
_chatWindow->toggleViewAction()->trigger();
1115+
1116+
QPropertyAnimation* slideAnimation = new QPropertyAnimation(_chatWindow, "geometry", _chatWindow);
1117+
slideAnimation->setStartValue(_chatWindow->geometry());
1118+
slideAnimation->setEndValue(QRect(mainWindow->width() - width, _chatWindow->y(),
1119+
width, _chatWindow->height()));
1120+
slideAnimation->setDuration(250);
1121+
slideAnimation->start(QAbstractAnimation::DeleteWhenStopped);
11091122
}
11101123
}
11111124

‎interface/src/Menu.h

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public slots:
122122
void importSettings();
123123
void exportSettings();
124124
void goTo();
125+
void goToUser(const QString& user);
125126
void pasteToVoxel();
126127

127128
void toggleLoginMenuItem();

‎interface/src/avatar/Avatar.cpp

+3-23
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) {
246246

247247
const float DISPLAYNAME_DISTANCE = 10.0f;
248248
setShowDisplayName(renderMode == NORMAL_RENDER_MODE && distanceToTarget < DISPLAYNAME_DISTANCE);
249-
if (renderMode != NORMAL_RENDER_MODE) {
249+
if (renderMode != NORMAL_RENDER_MODE || (isMyAvatar() &&
250+
Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON)) {
250251
return;
251252
}
252253
renderDisplayName();
@@ -312,9 +313,7 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
312313
void Avatar::renderBody(RenderMode renderMode) {
313314
if (_shouldRenderBillboard || !(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) {
314315
// render the billboard until both models are loaded
315-
if (renderMode != SHADOW_RENDER_MODE) {
316-
renderBillboard();
317-
}
316+
renderBillboard();
318317
return;
319318
}
320319
_skeletonModel.render(1.0f, renderMode == SHADOW_RENDER_MODE);
@@ -762,25 +761,6 @@ bool Avatar::collisionWouldMoveAvatar(CollisionInfo& collision) const {
762761
return false;
763762
}
764763

765-
void Avatar::applyCollision(const glm::vec3& contactPoint, const glm::vec3& penetration) {
766-
// compute lean angles
767-
glm::vec3 leverAxis = contactPoint - getPosition();
768-
float leverLength = glm::length(leverAxis);
769-
if (leverLength > EPSILON) {
770-
glm::quat bodyRotation = getOrientation();
771-
glm::vec3 xAxis = bodyRotation * glm::vec3(1.f, 0.f, 0.f);
772-
glm::vec3 zAxis = bodyRotation * glm::vec3(0.f, 0.f, 1.f);
773-
774-
leverAxis = leverAxis / leverLength;
775-
glm::vec3 effectivePenetration = penetration - glm::dot(penetration, leverAxis) * leverAxis;
776-
// we use the small-angle approximation for sine below to compute the length of
777-
// the opposite side of a narrow right triangle
778-
float sideways = - glm::dot(effectivePenetration, xAxis) / leverLength;
779-
float forward = glm::dot(effectivePenetration, zAxis) / leverLength;
780-
getHead()->addLean(sideways, forward);
781-
}
782-
}
783-
784764
float Avatar::getBoundingRadius() const {
785765
// TODO: also use head model when computing the avatar's bounding radius
786766
return _skeletonModel.getBoundingRadius();

‎interface/src/avatar/Avatar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Avatar : public AvatarData {
145145
/// \return true if we expect the avatar would move as a result of the collision
146146
bool collisionWouldMoveAvatar(CollisionInfo& collision) const;
147147

148-
void applyCollision(const glm::vec3& contactPoint, const glm::vec3& penetration);
148+
virtual void applyCollision(const glm::vec3& contactPoint, const glm::vec3& penetration) { }
149149

150150
/// \return bounding radius of avatar
151151
virtual float getBoundingRadius() const;

‎interface/src/avatar/FaceModel.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX
5050
glm::mat3 axes = glm::mat3_cast(_rotation);
5151
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.transform * glm::translate(state.translation) *
5252
joint.preTransform * glm::mat4_cast(joint.preRotation)));
53-
state.rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getTweakedRoll(), glm::normalize(inverse * axes[2]))
54-
* glm::angleAxis(RADIANS_PER_DEGREE * _owningHead->getTweakedYaw(), glm::normalize(inverse * axes[1]))
55-
* glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getTweakedPitch(), glm::normalize(inverse * axes[0]))
53+
state.rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalRoll(), glm::normalize(inverse * axes[2]))
54+
* glm::angleAxis(RADIANS_PER_DEGREE * _owningHead->getFinalYaw(), glm::normalize(inverse * axes[1]))
55+
* glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalPitch(), glm::normalize(inverse * axes[0]))
5656
* joint.rotation;
5757
}
5858

5959
void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
6060
// likewise with the eye joints
6161
glm::mat4 inverse = glm::inverse(parentState.transform * glm::translate(state.translation) *
6262
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation));
63-
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getTweakedOrientation() * IDENTITY_FRONT, 0.0f));
63+
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientation() * IDENTITY_FRONT, 0.0f));
6464
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() +
6565
_owningHead->getSaccade() - _translation, 1.0f));
6666
glm::quat between = rotationBetween(front, lookAt);

‎interface/src/avatar/Hand.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ void Hand::collideAgainstAvatar(Avatar* avatar, bool isMyHand) {
156156
//palm.addToPenetration(averagePenetration);
157157
} else {
158158
// someone else's hand against MyAvatar
159-
averageContactPoint /= float(handCollisions.size());
159+
// TODO: submit collision info to MyAvatar which should lean accordingly
160+
averageContactPoint /= (float)handCollisions.size();
160161
avatar->applyCollision(averageContactPoint, totalPenetration);
161162
}
162163
}

0 commit comments

Comments
 (0)
Please sign in to comment.