mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into collision-sound-tuning
This commit is contained in:
commit
56bc4dc079
2 changed files with 84 additions and 5 deletions
76
examples/pointer.js
Normal file
76
examples/pointer.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
|
||||
var lineEntityID = null;
|
||||
var lineIsRezzed = false;
|
||||
|
||||
|
||||
function nearLinePoint(targetPosition) {
|
||||
var handPosition = MyAvatar.getRightPalmPosition();
|
||||
var along = Vec3.subtract(targetPosition, handPosition);
|
||||
along = Vec3.normalize(along);
|
||||
along = Vec3.multiply(along, 0.4);
|
||||
return Vec3.sum(handPosition, along);
|
||||
}
|
||||
|
||||
|
||||
function removeLine() {
|
||||
if (lineIsRezzed) {
|
||||
Entities.deleteEntity(lineEntityID);
|
||||
lineEntityID = null;
|
||||
lineIsRezzed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createOrUpdateLine(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
|
||||
|
||||
if (lineIsRezzed) {
|
||||
Entities.editEntity(lineEntityID, {
|
||||
position: nearLinePoint(intersection.intersection),
|
||||
dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)),
|
||||
lifetime: 30 // renew lifetime
|
||||
});
|
||||
|
||||
} else {
|
||||
lineIsRezzed = true;
|
||||
lineEntityID = Entities.addEntity({
|
||||
type: "Line",
|
||||
position: nearLinePoint(intersection.intersection),
|
||||
dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)),
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
lifetime: 30 // if someone crashes while pointing, don't leave the line there forever.
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if (!event.isLeftButton) {
|
||||
return;
|
||||
}
|
||||
if (lineIsRezzed) {
|
||||
return;
|
||||
}
|
||||
createOrUpdateLine(event);
|
||||
if (lineIsRezzed) {
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
createOrUpdateLine(event);
|
||||
}
|
||||
|
||||
|
||||
function mouseReleaseEvent() {
|
||||
if (lineIsRezzed) {
|
||||
Controller.mouseMoveEvent.disconnect(mouseMoveEvent);
|
||||
}
|
||||
removeLine();
|
||||
}
|
||||
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
|
@ -12,6 +12,7 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkConfiguration>
|
||||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
|
||||
|
@ -35,7 +36,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is
|
|||
isPending = true;
|
||||
bool alreadyWaiting = _scriptUsers.contains(url);
|
||||
_scriptUsers.insert(url, scriptUser);
|
||||
|
||||
|
||||
if (alreadyWaiting) {
|
||||
qCDebug(scriptengine) << "Already downloading script at:" << url.toString();
|
||||
} else {
|
||||
|
@ -43,7 +44,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is
|
|||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
|
||||
qCDebug(scriptengine) << "Downloading script at:" << url.toString();
|
||||
qCDebug(scriptengine) << "Downloading script at" << url.toString();
|
||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||
connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded);
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ void ScriptCache::scriptDownloaded() {
|
|||
QUrl url = reply->url();
|
||||
QList<ScriptUser*> scriptUsers = _scriptUsers.values(url);
|
||||
_scriptUsers.remove(url);
|
||||
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptCache[url] = reply->readAll();
|
||||
qCDebug(scriptengine) << "Done downloading script at:" << url.toString();
|
||||
|
@ -65,7 +66,9 @@ void ScriptCache::scriptDownloaded() {
|
|||
user->scriptContentsAvailable(url, _scriptCache[url]);
|
||||
}
|
||||
} else {
|
||||
qCDebug(scriptengine) << "ERROR Loading file:" << reply->url().toString();
|
||||
qCWarning(scriptengine) << "Error loading script from URL " << reply->url().toString()
|
||||
<< "- HTTP status code is" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()
|
||||
<< "and error from QNetworkReply is" << reply->errorString();
|
||||
foreach(ScriptUser* user, scriptUsers) {
|
||||
user->errorInLoadingScript(url);
|
||||
}
|
||||
|
@ -73,4 +76,4 @@ void ScriptCache::scriptDownloaded() {
|
|||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue