mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:00:43 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into daft
This commit is contained in:
commit
6b229d8d2d
46 changed files with 914 additions and 259 deletions
|
@ -13,9 +13,8 @@
|
||||||
|
|
||||||
#include "AssignmentAction.h"
|
#include "AssignmentAction.h"
|
||||||
|
|
||||||
AssignmentAction::AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
AssignmentAction::AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
_id(id),
|
EntityActionInterface(type, id),
|
||||||
_type(type),
|
|
||||||
_data(QByteArray()),
|
_data(QByteArray()),
|
||||||
_active(false),
|
_active(false),
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
|
@ -28,7 +27,7 @@ void AssignmentAction::removeFromSimulation(EntitySimulation* simulation) const
|
||||||
simulation->removeAction(_id);
|
simulation->removeAction(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AssignmentAction::serialize() {
|
QByteArray AssignmentAction::serialize() const {
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,23 +21,19 @@
|
||||||
|
|
||||||
class AssignmentAction : public EntityActionInterface {
|
class AssignmentAction : public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
AssignmentAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AssignmentAction();
|
virtual ~AssignmentAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
|
||||||
virtual EntityActionType getType() { return _type; }
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid _id;
|
|
||||||
EntityActionType _type;
|
|
||||||
QByteArray _data;
|
QByteArray _data;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
#include "AssignmentActionFactory.h"
|
#include "AssignmentActionFactory.h"
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer assignmentActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
EntityActionPointer assignmentActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
|
||||||
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
|
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
EntityActionPointer AssignmentActionFactory::factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) {
|
QVariantMap arguments) {
|
||||||
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
EntityActionPointer action = assignmentActionFactory(type, id, ownerEntity);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
virtual ~AssignmentActionFactory() { }
|
virtual ~AssignmentActionFactory() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments);
|
QVariantMap arguments);
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
4
cmake/externals/oglplus/CMakeLists.txt
vendored
4
cmake/externals/oglplus/CMakeLists.txt
vendored
|
@ -4,8 +4,8 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
${EXTERNAL_NAME}
|
${EXTERNAL_NAME}
|
||||||
GIT_REPOSITORY https://github.com/matus-chochlik/oglplus.git
|
URL http://iweb.dl.sourceforge.net/project/oglplus/oglplus-0.63.x/oglplus-0.63.0.zip
|
||||||
GIT_TAG a2681383928b1166f176512cbe0f95e96fe68d08
|
URL_MD5 de984ab245b185b45c87415c0e052135
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
|
|
|
@ -12,7 +12,6 @@ Script.load("progress.js");
|
||||||
Script.load("edit.js");
|
Script.load("edit.js");
|
||||||
Script.load("selectAudioDevice.js");
|
Script.load("selectAudioDevice.js");
|
||||||
Script.load("inspect.js");
|
Script.load("inspect.js");
|
||||||
Script.load("lobby.js");
|
|
||||||
Script.load("notifications.js");
|
Script.load("notifications.js");
|
||||||
Script.load("users.js");
|
Script.load("users.js");
|
||||||
Script.load("grab.js");
|
Script.load("grab.js");
|
||||||
|
|
70
examples/example/games/make-dummy.js
Normal file
70
examples/example/games/make-dummy.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
//
|
||||||
|
// make-dummy.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-6-10
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Makes a boxing-dummy that responds to collisions.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
//
|
||||||
|
"use strict";
|
||||||
|
/*jslint vars: true*/
|
||||||
|
var Overlays, Entities, Controller, Script, MyAvatar, Vec3; // Referenced globals provided by High Fidelity.
|
||||||
|
|
||||||
|
var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||||
|
|
||||||
|
var rezButton = Overlays.addOverlay("image", {
|
||||||
|
x: 100,
|
||||||
|
y: 350,
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
imageURL: HIFI_PUBLIC_BUCKET + "images/close.png",
|
||||||
|
color: {
|
||||||
|
red: 255,
|
||||||
|
green: 255,
|
||||||
|
blue: 255
|
||||||
|
},
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function mousePressEvent(event) {
|
||||||
|
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||||
|
x: event.x,
|
||||||
|
y: event.y
|
||||||
|
});
|
||||||
|
|
||||||
|
if (clickedOverlay === rezButton) {
|
||||||
|
var boxId;
|
||||||
|
|
||||||
|
var position = Vec3.sum(MyAvatar.position, {x: 1.0, y: 0.4, z: 0.0});
|
||||||
|
boxId = Entities.addEntity({
|
||||||
|
type: "Box",
|
||||||
|
name: "dummy",
|
||||||
|
position: position,
|
||||||
|
dimensions: {x: 0.3, y: 0.7, z: 0.3},
|
||||||
|
gravity: {x: 0.0, y: -3.0, z: 0.0},
|
||||||
|
damping: 0.2,
|
||||||
|
collisionsWillMove: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var pointToOffsetFrom = Vec3.sum(position, {x: 0.0, y: 2.0, z: 0.0});
|
||||||
|
Entities.addAction("offset", boxId, {pointToOffsetFrom: pointToOffsetFrom,
|
||||||
|
linearDistance: 2.0,
|
||||||
|
// linearTimeScale: 0.005
|
||||||
|
linearTimeScale: 0.1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function scriptEnding() {
|
||||||
|
Overlays.deleteOverlay(rezButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
|
Script.scriptEnding.connect(scriptEnding);
|
269
examples/example/games/sword.js
Normal file
269
examples/example/games/sword.js
Normal file
|
@ -0,0 +1,269 @@
|
||||||
|
// stick.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-6-10
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Allow avatar to hold a stick
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
"use strict";
|
||||||
|
/*jslint vars: true*/
|
||||||
|
var Script, Entities, MyAvatar, Window, Overlays, Controller, Vec3, Quat, print, ToolBar; // Referenced globals provided by High Fidelity.
|
||||||
|
Script.include(["../../libraries/toolBars.js"]);
|
||||||
|
|
||||||
|
var hand = "right";
|
||||||
|
var nullActionID = "00000000-0000-0000-0000-000000000000";
|
||||||
|
var controllerID;
|
||||||
|
var controllerActive;
|
||||||
|
var stickID = null;
|
||||||
|
var actionID = nullActionID;
|
||||||
|
var targetIDs = [];
|
||||||
|
var dimensions = { x: 0.3, y: 0.1, z: 2.0 };
|
||||||
|
var AWAY_ORIENTATION = Quat.fromPitchYawRollDegrees(-90, 0, 0);
|
||||||
|
var BUTTON_SIZE = 32;
|
||||||
|
|
||||||
|
var stickModel = "https://hifi-public.s3.amazonaws.com/eric/models/stick.fbx";
|
||||||
|
var swordModel = "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.fbx";
|
||||||
|
var whichModel = "sword";
|
||||||
|
var attachmentOffset, MOUSE_CONTROLLER_OFFSET = {x: 0.5, y: 0.4, z: 0.0}; // A fudge when using mouse rather than hand-controller, to hit yourself less often.
|
||||||
|
|
||||||
|
var toolBar = new ToolBar(0, 0, ToolBar.vertical, "highfidelity.sword.toolbar", function () {
|
||||||
|
return {x: 100, y: 380};
|
||||||
|
});
|
||||||
|
|
||||||
|
var SWORD_IMAGE = "http://s3.amazonaws.com/hifi-public/images/billiardsReticle.png"; // Toggle between brandishing/sheathing sword (creating if necessary)
|
||||||
|
var TARGET_IMAGE = "http://s3.amazonaws.com/hifi-public/images/puck.png"; // Create a target dummy
|
||||||
|
var CLEANUP_IMAGE = "http://s3.amazonaws.com/hifi-public/images/delete.png"; // Remove sword and all target dummies.f
|
||||||
|
var swordButton = toolBar.addOverlay("image", {
|
||||||
|
width: BUTTON_SIZE,
|
||||||
|
height: BUTTON_SIZE,
|
||||||
|
imageURL: SWORD_IMAGE,
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
var targetButton = toolBar.addOverlay("image", {
|
||||||
|
width: BUTTON_SIZE,
|
||||||
|
height: BUTTON_SIZE,
|
||||||
|
imageURL: TARGET_IMAGE,
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
var cleanupButton = toolBar.addOverlay("image", {
|
||||||
|
width: BUTTON_SIZE,
|
||||||
|
height: BUTTON_SIZE,
|
||||||
|
imageURL: CLEANUP_IMAGE,
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
var flasher;
|
||||||
|
function clearFlash() {
|
||||||
|
if (!flasher) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Script.clearTimeout(flasher.timer);
|
||||||
|
Overlays.deleteOverlay(flasher.overlay);
|
||||||
|
flasher = null;
|
||||||
|
}
|
||||||
|
function flash(color) {
|
||||||
|
clearFlash();
|
||||||
|
flasher = {};
|
||||||
|
flasher.overlay = Overlays.addOverlay("text", {
|
||||||
|
backgroundColor: color,
|
||||||
|
backgroundAlpha: 0.7,
|
||||||
|
width: Window.innerWidth,
|
||||||
|
height: Window.innerHeight
|
||||||
|
});
|
||||||
|
flasher.timer = Script.setTimeout(clearFlash, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var health = 100;
|
||||||
|
var display;
|
||||||
|
var isAway = false;
|
||||||
|
function updateDisplay() {
|
||||||
|
var text = health.toString();
|
||||||
|
if (!display) {
|
||||||
|
health = 100;
|
||||||
|
display = Overlays.addOverlay("text", {
|
||||||
|
text: text,
|
||||||
|
font: { size: 20 },
|
||||||
|
color: {red: 0, green: 255, blue: 0},
|
||||||
|
backgroundColor: {red: 100, green: 100, blue: 100}, // Why doesn't this and the next work?
|
||||||
|
backgroundAlpha: 0.9,
|
||||||
|
x: Window.innerWidth - 50,
|
||||||
|
y: 50
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Overlays.editOverlay(display, {text: text});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function removeDisplay() {
|
||||||
|
if (display) {
|
||||||
|
Overlays.deleteOverlay(display);
|
||||||
|
display = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanUp(leaveButtons) {
|
||||||
|
attachmentOffset = {x: 0, y: 0, z: 0};
|
||||||
|
if (stickID) {
|
||||||
|
Entities.deleteAction(stickID, actionID);
|
||||||
|
Entities.deleteEntity(stickID);
|
||||||
|
stickID = null;
|
||||||
|
actionID = null;
|
||||||
|
}
|
||||||
|
targetIDs.forEach(function (id) {
|
||||||
|
Entities.deleteAction(id.entity, id.action);
|
||||||
|
Entities.deleteEntity(id.entity);
|
||||||
|
});
|
||||||
|
targetIDs = [];
|
||||||
|
removeDisplay();
|
||||||
|
if (!leaveButtons) {
|
||||||
|
toolBar.cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function computeEnergy(collision, entityID) {
|
||||||
|
var id = entityID || collision.idA || collision.idB;
|
||||||
|
var entity = id && Entities.getEntityProperties(id);
|
||||||
|
var mass = entity ? (entity.density * entity.dimensions.x * entity.dimensions.y * entity.dimensions.z) : 1;
|
||||||
|
var linearVelocityChange = Vec3.length(collision.velocityChange);
|
||||||
|
var energy = 0.5 * mass * linearVelocityChange * linearVelocityChange;
|
||||||
|
return Math.min(Math.max(1.0, Math.round(energy)), 20);
|
||||||
|
}
|
||||||
|
function gotHit(collision) {
|
||||||
|
if (isAway) { return; }
|
||||||
|
var energy = computeEnergy(collision);
|
||||||
|
health -= energy;
|
||||||
|
flash({red: 255, green: 0, blue: 0});
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
function scoreHit(idA, idB, collision) {
|
||||||
|
if (isAway) { return; }
|
||||||
|
var energy = computeEnergy(collision, idA);
|
||||||
|
health += energy;
|
||||||
|
flash({red: 0, green: 255, blue: 0});
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
function positionStick(stickOrientation) {
|
||||||
|
var baseOffset = Vec3.sum(attachmentOffset, {x: 0.0, y: 0.0, z: -dimensions.z / 2});
|
||||||
|
var offset = Vec3.multiplyQbyV(stickOrientation, baseOffset);
|
||||||
|
Entities.updateAction(stickID, actionID, {relativePosition: offset,
|
||||||
|
relativeRotation: stickOrientation});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function mouseMoveEvent(event) {
|
||||||
|
attachmentOffset = MOUSE_CONTROLLER_OFFSET;
|
||||||
|
if (!stickID || actionID === nullActionID || isAway) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var windowCenterX = Window.innerWidth / 2;
|
||||||
|
var windowCenterY = Window.innerHeight / 2;
|
||||||
|
var mouseXCenterOffset = event.x - windowCenterX;
|
||||||
|
var mouseYCenterOffset = event.y - windowCenterY;
|
||||||
|
var mouseXRatio = mouseXCenterOffset / windowCenterX;
|
||||||
|
var mouseYRatio = mouseYCenterOffset / windowCenterY;
|
||||||
|
|
||||||
|
var stickOrientation = Quat.fromPitchYawRollDegrees(mouseYRatio * -90, mouseXRatio * -90, 0);
|
||||||
|
positionStick(stickOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initControls() {
|
||||||
|
if (hand === "right") {
|
||||||
|
controllerID = 3; // right handed
|
||||||
|
} else {
|
||||||
|
controllerID = 4; // left handed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
var palmPosition = Controller.getSpatialControlPosition(controllerID);
|
||||||
|
controllerActive = (Vec3.length(palmPosition) > 0);
|
||||||
|
if (!controllerActive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var stickOrientation = Controller.getSpatialControlRawRotation(controllerID);
|
||||||
|
var adjustment = Quat.fromPitchYawRollDegrees(180, 0, 0);
|
||||||
|
stickOrientation = Quat.multiply(stickOrientation, adjustment);
|
||||||
|
|
||||||
|
positionStick(stickOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAway() {
|
||||||
|
isAway = !isAway;
|
||||||
|
if (isAway) {
|
||||||
|
positionStick(AWAY_ORIENTATION);
|
||||||
|
removeDisplay();
|
||||||
|
} else {
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClick(event) {
|
||||||
|
switch (Overlays.getOverlayAtPoint(event)) {
|
||||||
|
case swordButton:
|
||||||
|
if (!stickID) {
|
||||||
|
initControls();
|
||||||
|
stickID = Entities.addEntity({
|
||||||
|
type: "Model",
|
||||||
|
modelURL: (whichModel === "sword") ? swordModel : stickModel,
|
||||||
|
//compoundShapeURL: "https://hifi-public.s3.amazonaws.com/eric/models/stick.obj",
|
||||||
|
shapeType: "box",
|
||||||
|
dimensions: dimensions,
|
||||||
|
position: MyAvatar.getRightPalmPosition(), // initial position doesn't matter, as long as it's close
|
||||||
|
rotation: MyAvatar.orientation,
|
||||||
|
damping: 0.1,
|
||||||
|
collisionSoundURL: "http://public.highfidelity.io/sounds/Collisions-hitsandslaps/swordStrike1.wav",
|
||||||
|
restitution: 0.01,
|
||||||
|
collisionsWillMove: true
|
||||||
|
});
|
||||||
|
actionID = Entities.addAction("hold", stickID, {relativePosition: {x: 0.0, y: 0.0, z: -dimensions.z / 2},
|
||||||
|
hand: hand,
|
||||||
|
timeScale: 0.15});
|
||||||
|
if (actionID === nullActionID) {
|
||||||
|
print('*** FAILED TO MAKE SWORD ACTION ***');
|
||||||
|
cleanUp();
|
||||||
|
}
|
||||||
|
Script.addEventHandler(stickID, 'collisionWithEntity', scoreHit);
|
||||||
|
updateDisplay();
|
||||||
|
} else {
|
||||||
|
toggleAway();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case targetButton:
|
||||||
|
var position = Vec3.sum(MyAvatar.position, {x: 1.0, y: 0.4, z: 0.0});
|
||||||
|
var boxId = Entities.addEntity({
|
||||||
|
type: "Box",
|
||||||
|
name: "dummy",
|
||||||
|
position: position,
|
||||||
|
dimensions: {x: 0.3, y: 0.7, z: 0.3},
|
||||||
|
gravity: {x: 0.0, y: -3.0, z: 0.0},
|
||||||
|
damping: 0.2,
|
||||||
|
collisionsWillMove: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var pointToOffsetFrom = Vec3.sum(position, {x: 0.0, y: 2.0, z: 0.0});
|
||||||
|
var action = Entities.addAction("offset", boxId, {pointToOffsetFrom: pointToOffsetFrom,
|
||||||
|
linearDistance: 2.0,
|
||||||
|
// linearTimeScale: 0.005
|
||||||
|
linearTimeScale: 0.1
|
||||||
|
});
|
||||||
|
targetIDs.push({entity: boxId, action: action});
|
||||||
|
break;
|
||||||
|
case cleanupButton:
|
||||||
|
cleanUp('leaveButtons');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(cleanUp);
|
||||||
|
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||||
|
Controller.mousePressEvent.connect(onClick);
|
||||||
|
Script.update.connect(update);
|
||||||
|
MyAvatar.collisionWithEntity.connect(gotHit);
|
|
@ -1014,6 +1014,7 @@ void Application::paintGL() {
|
||||||
|
|
||||||
void Application::runTests() {
|
void Application::runTests() {
|
||||||
runTimingTests();
|
runTimingTests();
|
||||||
|
runUnitTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::audioMuteToggled() {
|
void Application::audioMuteToggled() {
|
||||||
|
@ -1182,7 +1183,6 @@ bool Application::event(QEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::eventFilter(QObject* object, QEvent* event) {
|
bool Application::eventFilter(QObject* object, QEvent* event) {
|
||||||
|
|
||||||
if (event->type() == QEvent::ShortcutOverride) {
|
if (event->type() == QEvent::ShortcutOverride) {
|
||||||
if (DependencyManager::get<OffscreenUi>()->shouldSwallowShortcut(event)) {
|
if (DependencyManager::get<OffscreenUi>()->shouldSwallowShortcut(event)) {
|
||||||
event->accept();
|
event->accept();
|
||||||
|
@ -1787,6 +1787,7 @@ void Application::checkFPS() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::idle() {
|
void Application::idle() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
static SimpleAverage<float> interIdleDurations;
|
static SimpleAverage<float> interIdleDurations;
|
||||||
static uint64_t lastIdleEnd{ 0 };
|
static uint64_t lastIdleEnd{ 0 };
|
||||||
|
|
||||||
|
@ -2304,38 +2305,42 @@ void Application::updateMyAvatarLookAtPosition() {
|
||||||
bool isLookingAtSomeone = false;
|
bool isLookingAtSomeone = false;
|
||||||
glm::vec3 lookAtSpot;
|
glm::vec3 lookAtSpot;
|
||||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||||
// When I am in mirror mode, just look right at the camera (myself)
|
// When I am in mirror mode, just look right at the camera (myself); don't switch gaze points because when physically
|
||||||
|
// looking in a mirror one's eyes appear steady.
|
||||||
if (!OculusManager::isConnected()) {
|
if (!OculusManager::isConnected()) {
|
||||||
lookAtSpot = _myCamera.getPosition();
|
lookAtSpot = _myCamera.getPosition();
|
||||||
} else {
|
} else {
|
||||||
if (_myAvatar->isLookingAtLeftEye()) {
|
lookAtSpot = _myCamera.getPosition() + OculusManager::getMidEyePosition();
|
||||||
lookAtSpot = OculusManager::getLeftEyePosition();
|
|
||||||
} else {
|
|
||||||
lookAtSpot = OculusManager::getRightEyePosition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().lock();
|
AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().lock();
|
||||||
if (lookingAt && _myAvatar != lookingAt.get()) {
|
if (lookingAt && _myAvatar != lookingAt.get()) {
|
||||||
isLookingAtSomeone = true;
|
|
||||||
// If I am looking at someone else, look directly at one of their eyes
|
// If I am looking at someone else, look directly at one of their eyes
|
||||||
if (tracker && !tracker->isMuted()) {
|
isLookingAtSomeone = true;
|
||||||
// If a face tracker is active, look at the eye for the side my gaze is biased toward
|
Head* lookingAtHead = static_cast<Avatar*>(lookingAt.get())->getHead();
|
||||||
if (tracker->getEstimatedEyeYaw() > _myAvatar->getHead()->getFinalYaw()) {
|
|
||||||
// Look at their right eye
|
const float MAXIMUM_FACE_ANGLE = 65.0f * RADIANS_PER_DEGREE;
|
||||||
lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getRightEyePosition();
|
glm::vec3 lookingAtFaceOrientation = lookingAtHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT;
|
||||||
} else {
|
glm::vec3 fromLookingAtToMe = glm::normalize(_myAvatar->getHead()->getEyePosition()
|
||||||
// Look at their left eye
|
- lookingAtHead->getEyePosition());
|
||||||
lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getLeftEyePosition();
|
float faceAngle = glm::angle(lookingAtFaceOrientation, fromLookingAtToMe);
|
||||||
|
|
||||||
|
if (faceAngle < MAXIMUM_FACE_ANGLE) {
|
||||||
|
// Randomly look back and forth between look targets
|
||||||
|
switch (_myAvatar->getEyeContactTarget()) {
|
||||||
|
case LEFT_EYE:
|
||||||
|
lookAtSpot = lookingAtHead->getLeftEyePosition();
|
||||||
|
break;
|
||||||
|
case RIGHT_EYE:
|
||||||
|
lookAtSpot = lookingAtHead->getRightEyePosition();
|
||||||
|
break;
|
||||||
|
case MOUTH:
|
||||||
|
lookAtSpot = lookingAtHead->getMouthPosition();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Need to add randomly looking back and forth between left and right eye for case with no tracker
|
// Just look at their head (mid point between eyes)
|
||||||
if (_myAvatar->isLookingAtLeftEye()) {
|
lookAtSpot = lookingAtHead->getEyePosition();
|
||||||
lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getLeftEyePosition();
|
|
||||||
} else {
|
|
||||||
lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getRightEyePosition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// I am not looking at anyone else, so just look forward
|
// I am not looking at anyone else, so just look forward
|
||||||
|
@ -2343,14 +2348,13 @@ void Application::updateMyAvatarLookAtPosition() {
|
||||||
(_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
|
(_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// Deflect the eyes a bit to match the detected Gaze from 3D camera if active
|
// Deflect the eyes a bit to match the detected gaze from Faceshift if active.
|
||||||
//
|
// DDE doesn't track eyes.
|
||||||
if (tracker && !tracker->isMuted()) {
|
if (tracker && typeid(*tracker) == typeid(Faceshift) && !tracker->isMuted()) {
|
||||||
float eyePitch = tracker->getEstimatedEyePitch();
|
float eyePitch = tracker->getEstimatedEyePitch();
|
||||||
float eyeYaw = tracker->getEstimatedEyeYaw();
|
float eyeYaw = tracker->getEstimatedEyeYaw();
|
||||||
const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;
|
const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;
|
||||||
// deflect using Faceshift gaze data
|
|
||||||
glm::vec3 origin = _myAvatar->getHead()->getEyePosition();
|
glm::vec3 origin = _myAvatar->getHead()->getEyePosition();
|
||||||
float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
|
float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
|
||||||
float deflection = DependencyManager::get<Faceshift>()->getEyeDeflection();
|
float deflection = DependencyManager::get<Faceshift>()->getEyeDeflection();
|
||||||
|
|
|
@ -58,6 +58,7 @@ void GLCanvas::initializeGL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas::paintGL() {
|
void GLCanvas::paintGL() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
if (!_throttleRendering && !Application::getInstance()->getWindow()->isMinimized()) {
|
if (!_throttleRendering && !Application::getInstance()->getWindow()->isMinimized()) {
|
||||||
Application::getInstance()->paintGL();
|
Application::getInstance()->paintGL();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,16 @@
|
||||||
#include "InterfaceActionFactory.h"
|
#include "InterfaceActionFactory.h"
|
||||||
|
|
||||||
|
|
||||||
EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
|
EntityActionPointer interfaceActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ACTION_TYPE_NONE:
|
case ACTION_TYPE_NONE:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case ACTION_TYPE_OFFSET:
|
case ACTION_TYPE_OFFSET:
|
||||||
return (EntityActionPointer) new ObjectActionOffset(type, id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
|
||||||
case ACTION_TYPE_SPRING:
|
case ACTION_TYPE_SPRING:
|
||||||
return (EntityActionPointer) new ObjectActionSpring(type, id, ownerEntity);
|
return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
|
||||||
case ACTION_TYPE_HOLD:
|
case ACTION_TYPE_HOLD:
|
||||||
return (EntityActionPointer) new AvatarActionHold(type, id, ownerEntity);
|
return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -37,7 +37,7 @@ EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, Enti
|
||||||
|
|
||||||
EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
|
EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) {
|
QVariantMap arguments) {
|
||||||
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
virtual ~InterfaceActionFactory() { }
|
virtual ~InterfaceActionFactory() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments);
|
QVariantMap arguments);
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#include <ByteCountCoding.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <TextRenderer.h>
|
#include <TextRenderer.h>
|
||||||
|
|
||||||
|
@ -229,6 +230,43 @@ void runTimingTests() {
|
||||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||||
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
||||||
(double)(elapsedUsecs / numTests), (double)result);
|
(double)(elapsedUsecs / numTests), (double)result);
|
||||||
|
|
||||||
|
|
||||||
|
quint64 BYTE_CODE_MAX_TEST_VALUE = 99999999;
|
||||||
|
quint64 BYTE_CODE_TESTS_SKIP = 999;
|
||||||
|
|
||||||
|
QByteArray extraJunk;
|
||||||
|
const int EXTRA_JUNK_SIZE = 200;
|
||||||
|
extraJunk.append((unsigned char)255);
|
||||||
|
for (int i = 0; i < EXTRA_JUNK_SIZE; i++) {
|
||||||
|
extraJunk.append(QString("junk"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
startTime.start();
|
||||||
|
quint64 tests = 0;
|
||||||
|
quint64 failed = 0;
|
||||||
|
for (quint64 value = 0; value < BYTE_CODE_MAX_TEST_VALUE; value += BYTE_CODE_TESTS_SKIP) {
|
||||||
|
quint64 valueA = value; // usecTimestampNow();
|
||||||
|
ByteCountCoded<quint64> codedValueA = valueA;
|
||||||
|
QByteArray codedValueABuffer = codedValueA;
|
||||||
|
codedValueABuffer.append(extraJunk);
|
||||||
|
ByteCountCoded<quint64> decodedValueA;
|
||||||
|
decodedValueA.decode(codedValueABuffer);
|
||||||
|
quint64 valueADecoded = decodedValueA;
|
||||||
|
tests++;
|
||||||
|
if (valueA != valueADecoded) {
|
||||||
|
qDebug() << "FAILED! value:" << valueA << "decoded:" << valueADecoded;
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||||
|
qCDebug(interfaceapp) << "ByteCountCoded<quint64> usecs: " << elapsedUsecs
|
||||||
|
<< "per test:" << (double) (elapsedUsecs / tests)
|
||||||
|
<< "tests:" << tests
|
||||||
|
<< "failed:" << failed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
||||||
|
@ -271,3 +309,39 @@ bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadiu
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runUnitTests() {
|
||||||
|
|
||||||
|
quint64 LAST_TEST = 10;
|
||||||
|
quint64 SKIP_BY = 1;
|
||||||
|
|
||||||
|
for (quint64 value = 0; value <= LAST_TEST; value += SKIP_BY) {
|
||||||
|
qDebug() << "value:" << value;
|
||||||
|
|
||||||
|
ByteCountCoded<quint64> codedValue = value;
|
||||||
|
|
||||||
|
QByteArray codedValueBuffer = codedValue;
|
||||||
|
|
||||||
|
codedValueBuffer.append((unsigned char)255);
|
||||||
|
codedValueBuffer.append(QString("junk"));
|
||||||
|
|
||||||
|
qDebug() << "codedValueBuffer:";
|
||||||
|
outputBufferBits((const unsigned char*)codedValueBuffer.constData(), codedValueBuffer.size());
|
||||||
|
|
||||||
|
ByteCountCoded<quint64> valueDecoder;
|
||||||
|
size_t bytesConsumed = valueDecoder.decode(codedValueBuffer);
|
||||||
|
quint64 valueDecoded = valueDecoder;
|
||||||
|
qDebug() << "valueDecoded:" << valueDecoded;
|
||||||
|
qDebug() << "bytesConsumed:" << bytesConsumed;
|
||||||
|
|
||||||
|
|
||||||
|
if (value == valueDecoded) {
|
||||||
|
qDebug() << "SUCCESS!";
|
||||||
|
} else {
|
||||||
|
qDebug() << "FAILED!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ void drawText(int x, int y, float scale, float radians, int mono,
|
||||||
void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0);
|
void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0);
|
||||||
|
|
||||||
void runTimingTests();
|
void runTimingTests();
|
||||||
|
void runUnitTests();
|
||||||
|
|
||||||
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
|
||||||
const glm::vec3& sphereCenter, float sphereRadius, float& distance);
|
const glm::vec3& sphereCenter, float sphereRadius, float& distance);
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
|
|
||||||
const uint16_t AvatarActionHold::holdVersion = 1;
|
const uint16_t AvatarActionHold::holdVersion = 1;
|
||||||
|
|
||||||
AvatarActionHold::AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectActionSpring(type, id, ownerEntity),
|
ObjectActionSpring(id, ownerEntity),
|
||||||
_relativePosition(glm::vec3(0.0f)),
|
_relativePosition(glm::vec3(0.0f)),
|
||||||
_relativeRotation(glm::quat()),
|
_relativeRotation(glm::quat()),
|
||||||
_hand("right"),
|
_hand("right"),
|
||||||
_mine(false)
|
_mine(false)
|
||||||
{
|
{
|
||||||
|
_type = ACTION_TYPE_HOLD;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "AvatarActionHold::AvatarActionHold";
|
qDebug() << "AvatarActionHold::AvatarActionHold";
|
||||||
#endif
|
#endif
|
||||||
|
@ -166,8 +167,7 @@ QVariantMap AvatarActionHold::getArguments() {
|
||||||
|
|
||||||
|
|
||||||
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||||
if (_mine) {
|
if (!_mine) {
|
||||||
return;
|
ObjectActionSpring::deserialize(serializedArguments);
|
||||||
}
|
}
|
||||||
ObjectActionSpring::deserialize(serializedArguments);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,9 @@
|
||||||
|
|
||||||
class AvatarActionHold : public ObjectActionSpring {
|
class AvatarActionHold : public ObjectActionSpring {
|
||||||
public:
|
public:
|
||||||
AvatarActionHold(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AvatarActionHold();
|
virtual ~AvatarActionHold();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_HOLD; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,6 @@ void AvatarManager::handleOutgoingChanges(VectorOfMotionStates& motionStates) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::handleCollisionEvents(CollisionEvents& collisionEvents) {
|
void AvatarManager::handleCollisionEvents(CollisionEvents& collisionEvents) {
|
||||||
// TODO: expose avatar collision events to JS
|
|
||||||
for (Collision collision : collisionEvents) {
|
for (Collision collision : collisionEvents) {
|
||||||
// TODO: Current physics uses null idA or idB for non-entities. The plan is to handle MOTIONSTATE_TYPE_AVATAR,
|
// TODO: Current physics uses null idA or idB for non-entities. The plan is to handle MOTIONSTATE_TYPE_AVATAR,
|
||||||
// and then MOTIONSTATE_TYPE_MYAVATAR. As it is, this code only covers the case of my avatar (in which case one
|
// and then MOTIONSTATE_TYPE_MYAVATAR. As it is, this code only covers the case of my avatar (in which case one
|
||||||
|
@ -285,6 +284,7 @@ void AvatarManager::handleCollisionEvents(CollisionEvents& collisionEvents) {
|
||||||
const float AVATAR_STRETCH_FACTOR = 1.0f;
|
const float AVATAR_STRETCH_FACTOR = 1.0f;
|
||||||
|
|
||||||
AudioInjector::playSound(collisionSoundURL, energyFactorOfFull, AVATAR_STRETCH_FACTOR, myAvatar->getPosition());
|
AudioInjector::playSound(collisionSoundURL, energyFactorOfFull, AVATAR_STRETCH_FACTOR, myAvatar->getPosition());
|
||||||
|
myAvatar->collisionWithEntity(collision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,7 +296,7 @@ void Head::relaxLean(float deltaTime) {
|
||||||
|
|
||||||
void Head::render(RenderArgs* renderArgs, float alpha, ViewFrustum* renderFrustum, bool postLighting) {
|
void Head::render(RenderArgs* renderArgs, float alpha, ViewFrustum* renderFrustum, bool postLighting) {
|
||||||
if (_renderLookatVectors) {
|
if (_renderLookatVectors) {
|
||||||
renderLookatVectors(renderArgs, _leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition());
|
renderLookatVectors(renderArgs, _leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ glm::vec3 Head::getCorrectedLookAtPosition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::setCorrectedLookAtPosition(glm::vec3 correctedLookAtPosition) {
|
void Head::setCorrectedLookAtPosition(glm::vec3 correctedLookAtPosition) {
|
||||||
_isLookingAtMe = true;
|
_isLookingAtMe = true;
|
||||||
_correctedLookAtPosition = correctedLookAtPosition;
|
_correctedLookAtPosition = correctedLookAtPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,6 @@
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
enum eyeContactTargets {
|
|
||||||
LEFT_EYE,
|
|
||||||
RIGHT_EYE,
|
|
||||||
MOUTH
|
|
||||||
};
|
|
||||||
|
|
||||||
const float EYE_EAR_GAP = 0.08f;
|
const float EYE_EAR_GAP = 0.08f;
|
||||||
|
|
||||||
|
@ -77,6 +72,7 @@ public:
|
||||||
const glm::vec3& getLeftEyePosition() const { return _leftEyePosition; }
|
const glm::vec3& getLeftEyePosition() const { return _leftEyePosition; }
|
||||||
glm::vec3 getRightEarPosition() const { return _rightEyePosition + (getRightDirection() * EYE_EAR_GAP) + (getFrontDirection() * -EYE_EAR_GAP); }
|
glm::vec3 getRightEarPosition() const { return _rightEyePosition + (getRightDirection() * EYE_EAR_GAP) + (getFrontDirection() * -EYE_EAR_GAP); }
|
||||||
glm::vec3 getLeftEarPosition() const { return _leftEyePosition + (getRightDirection() * -EYE_EAR_GAP) + (getFrontDirection() * -EYE_EAR_GAP); }
|
glm::vec3 getLeftEarPosition() const { return _leftEyePosition + (getRightDirection() * -EYE_EAR_GAP) + (getFrontDirection() * -EYE_EAR_GAP); }
|
||||||
|
glm::vec3 getMouthPosition() const { return _eyePosition - getUpDirection() * glm::length(_rightEyePosition - _leftEyePosition); }
|
||||||
|
|
||||||
FaceModel& getFaceModel() { return _faceModel; }
|
FaceModel& getFaceModel() { return _faceModel; }
|
||||||
const FaceModel& getFaceModel() const { return _faceModel; }
|
const FaceModel& getFaceModel() const { return _faceModel; }
|
||||||
|
@ -148,7 +144,7 @@ private:
|
||||||
FaceModel _faceModel;
|
FaceModel _faceModel;
|
||||||
|
|
||||||
glm::vec3 _correctedLookAtPosition;
|
glm::vec3 _correctedLookAtPosition;
|
||||||
|
|
||||||
int _leftEyeLookAtID;
|
int _leftEyeLookAtID;
|
||||||
int _rightEyeLookAtID;
|
int _rightEyeLookAtID;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
#include <TextRenderer.h>
|
#include <TextRenderer.h>
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
|
|
||||||
|
#include "devices/Faceshift.h"
|
||||||
|
#include "devices/OculusManager.h"
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "AvatarManager.h"
|
#include "AvatarManager.h"
|
||||||
#include "Environment.h"
|
#include "Environment.h"
|
||||||
|
@ -42,7 +45,6 @@
|
||||||
#include "MyAvatar.h"
|
#include "MyAvatar.h"
|
||||||
#include "Physics.h"
|
#include "Physics.h"
|
||||||
#include "Recorder.h"
|
#include "Recorder.h"
|
||||||
#include "devices/Faceshift.h"
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "InterfaceLogging.h"
|
#include "InterfaceLogging.h"
|
||||||
|
|
||||||
|
@ -97,7 +99,7 @@ MyAvatar::MyAvatar() :
|
||||||
_shouldRender(true),
|
_shouldRender(true),
|
||||||
_billboardValid(false),
|
_billboardValid(false),
|
||||||
_feetTouchFloor(true),
|
_feetTouchFloor(true),
|
||||||
_isLookingAtLeftEye(true),
|
_eyeContactTarget(LEFT_EYE),
|
||||||
_realWorldFieldOfView("realWorldFieldOfView",
|
_realWorldFieldOfView("realWorldFieldOfView",
|
||||||
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
|
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
|
||||||
_firstPersonSkeletonModel(this),
|
_firstPersonSkeletonModel(this),
|
||||||
|
@ -884,7 +886,6 @@ void MyAvatar::updateLookAtTargetAvatar() {
|
||||||
const float KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR = 1.3f;
|
const float KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR = 1.3f;
|
||||||
const float GREATEST_LOOKING_AT_DISTANCE = 10.0f;
|
const float GREATEST_LOOKING_AT_DISTANCE = 10.0f;
|
||||||
|
|
||||||
int howManyLookingAtMe = 0;
|
|
||||||
foreach (const AvatarSharedPointer& avatarPointer, DependencyManager::get<AvatarManager>()->getAvatarHash()) {
|
foreach (const AvatarSharedPointer& avatarPointer, DependencyManager::get<AvatarManager>()->getAvatarHash()) {
|
||||||
Avatar* avatar = static_cast<Avatar*>(avatarPointer.get());
|
Avatar* avatar = static_cast<Avatar*>(avatarPointer.get());
|
||||||
bool isCurrentTarget = avatar->getIsLookAtTarget();
|
bool isCurrentTarget = avatar->getIsLookAtTarget();
|
||||||
|
@ -897,17 +898,22 @@ void MyAvatar::updateLookAtTargetAvatar() {
|
||||||
_targetAvatarPosition = avatarPointer->getPosition();
|
_targetAvatarPosition = avatarPointer->getPosition();
|
||||||
smallestAngleTo = angleTo;
|
smallestAngleTo = angleTo;
|
||||||
}
|
}
|
||||||
// Check if this avatar is looking at me, and fix their gaze on my camera if so
|
|
||||||
if (Application::getInstance()->isLookingAtMyAvatar(avatar)) {
|
if (Application::getInstance()->isLookingAtMyAvatar(avatar)) {
|
||||||
howManyLookingAtMe++;
|
// Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face.
|
||||||
// Have that avatar look directly at my camera
|
// Offset their gaze according to whether they're looking at one of my eyes or my mouth.
|
||||||
// Philip TODO: correct to look at left/right eye
|
glm::vec3 gazeOffset = avatar->getHead()->getLookAtPosition() - getHead()->getEyePosition();
|
||||||
if (qApp->isHMDMode()) {
|
const float HUMAN_EYE_SEPARATION = 0.065f;
|
||||||
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition());
|
float myEyeSeparation = glm::length(getHead()->getLeftEyePosition() - getHead()->getRightEyePosition());
|
||||||
// FIXME what is the point of this?
|
gazeOffset = gazeOffset * HUMAN_EYE_SEPARATION / myEyeSeparation;
|
||||||
// avatar->getHead()->setCorrectedLookAtPosition(OculusManager::getLeftEyePosition());
|
|
||||||
|
if (Application::getInstance()->isHMDMode()) {
|
||||||
|
//avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getCamera()->getPosition()
|
||||||
|
// + OculusManager::getMidEyePosition() + gazeOffset);
|
||||||
|
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
|
||||||
|
+ OculusManager::getMidEyePosition() + gazeOffset);
|
||||||
} else {
|
} else {
|
||||||
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition());
|
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
|
||||||
|
+ gazeOffset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
avatar->getHead()->clearCorrectedLookAtPosition();
|
avatar->getHead()->clearCorrectedLookAtPosition();
|
||||||
|
@ -924,12 +930,24 @@ void MyAvatar::clearLookAtTargetAvatar() {
|
||||||
_lookAtTargetAvatar.reset();
|
_lookAtTargetAvatar.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyAvatar::isLookingAtLeftEye() {
|
eyeContactTarget MyAvatar::getEyeContactTarget() {
|
||||||
float const CHANCE_OF_CHANGING_EYE = 0.01f;
|
float const CHANCE_OF_CHANGING_TARGET = 0.01f;
|
||||||
if (randFloat() < CHANCE_OF_CHANGING_EYE) {
|
if (randFloat() < CHANCE_OF_CHANGING_TARGET) {
|
||||||
_isLookingAtLeftEye = !_isLookingAtLeftEye;
|
float const FIFTY_FIFTY_CHANCE = 0.5f;
|
||||||
|
switch (_eyeContactTarget) {
|
||||||
|
case LEFT_EYE:
|
||||||
|
_eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? MOUTH : RIGHT_EYE;
|
||||||
|
break;
|
||||||
|
case RIGHT_EYE:
|
||||||
|
_eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? LEFT_EYE : MOUTH;
|
||||||
|
break;
|
||||||
|
case MOUTH:
|
||||||
|
_eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? RIGHT_EYE : LEFT_EYE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _isLookingAtLeftEye;
|
|
||||||
|
return _eyeContactTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 MyAvatar::getDefaultEyePosition() const {
|
glm::vec3 MyAvatar::getDefaultEyePosition() const {
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
|
|
||||||
class ModelItemID;
|
class ModelItemID;
|
||||||
|
|
||||||
|
enum eyeContactTarget {
|
||||||
|
LEFT_EYE,
|
||||||
|
RIGHT_EYE,
|
||||||
|
MOUTH
|
||||||
|
};
|
||||||
|
|
||||||
class MyAvatar : public Avatar {
|
class MyAvatar : public Avatar {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally)
|
Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally)
|
||||||
|
@ -94,7 +100,7 @@ public:
|
||||||
|
|
||||||
bool isMyAvatar() const { return true; }
|
bool isMyAvatar() const { return true; }
|
||||||
|
|
||||||
bool isLookingAtLeftEye();
|
eyeContactTarget getEyeContactTarget();
|
||||||
|
|
||||||
virtual int parseDataAtOffset(const QByteArray& packet, int offset);
|
virtual int parseDataAtOffset(const QByteArray& packet, int offset);
|
||||||
|
|
||||||
|
@ -209,6 +215,7 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void transformChanged();
|
void transformChanged();
|
||||||
void newCollisionSoundURL(const QUrl& url);
|
void newCollisionSoundURL(const QUrl& url);
|
||||||
|
void collisionWithEntity(const Collision& collision);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -251,7 +258,7 @@ private:
|
||||||
QList<AnimationHandlePointer> _animationHandles;
|
QList<AnimationHandlePointer> _animationHandles;
|
||||||
|
|
||||||
bool _feetTouchFloor;
|
bool _feetTouchFloor;
|
||||||
bool _isLookingAtLeftEye;
|
eyeContactTarget _eyeContactTarget;
|
||||||
|
|
||||||
RecorderPointer _recorder;
|
RecorderPointer _recorder;
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,7 @@ static ovrVector3f _eyeOffsets[ovrEye_Count];
|
||||||
|
|
||||||
glm::vec3 OculusManager::getLeftEyePosition() { return _eyePositions[ovrEye_Left]; }
|
glm::vec3 OculusManager::getLeftEyePosition() { return _eyePositions[ovrEye_Left]; }
|
||||||
glm::vec3 OculusManager::getRightEyePosition() { return _eyePositions[ovrEye_Right]; }
|
glm::vec3 OculusManager::getRightEyePosition() { return _eyePositions[ovrEye_Right]; }
|
||||||
|
glm::vec3 OculusManager::getMidEyePosition() { return (_eyePositions[ovrEye_Left] + _eyePositions[ovrEye_Right]) / 2.0f; }
|
||||||
|
|
||||||
void OculusManager::connect(QOpenGLContext* shareContext) {
|
void OculusManager::connect(QOpenGLContext* shareContext) {
|
||||||
qCDebug(interfaceapp) << "Oculus SDK" << OVR_VERSION_STRING;
|
qCDebug(interfaceapp) << "Oculus SDK" << OVR_VERSION_STRING;
|
||||||
|
@ -692,13 +693,13 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const
|
||||||
_eyeRenderPoses[eye] = eyePoses[eye];
|
_eyeRenderPoses[eye] = eyePoses[eye];
|
||||||
// Set the camera rotation for this eye
|
// Set the camera rotation for this eye
|
||||||
|
|
||||||
vec3 eyePosition = toGlm(_eyeRenderPoses[eye].Position);
|
_eyePositions[eye] = toGlm(_eyeRenderPoses[eye].Position);
|
||||||
eyePosition = whichCamera.getRotation() * eyePosition;
|
_eyePositions[eye] = whichCamera.getRotation() * _eyePositions[eye];
|
||||||
quat eyeRotation = toGlm(_eyeRenderPoses[eye].Orientation);
|
quat eyeRotation = toGlm(_eyeRenderPoses[eye].Orientation);
|
||||||
|
|
||||||
// Update our camera to what the application camera is doing
|
// Update our camera to what the application camera is doing
|
||||||
_camera->setRotation(whichCamera.getRotation() * eyeRotation);
|
_camera->setRotation(whichCamera.getRotation() * eyeRotation);
|
||||||
_camera->setPosition(whichCamera.getPosition() + eyePosition);
|
_camera->setPosition(whichCamera.getPosition() + _eyePositions[eye]);
|
||||||
configureCamera(*_camera);
|
configureCamera(*_camera);
|
||||||
_camera->update(1.0f / Application::getInstance()->getFps());
|
_camera->update(1.0f / Application::getInstance()->getFps());
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
|
|
||||||
static glm::vec3 getLeftEyePosition();
|
static glm::vec3 getLeftEyePosition();
|
||||||
static glm::vec3 getRightEyePosition();
|
static glm::vec3 getRightEyePosition();
|
||||||
|
static glm::vec3 getMidEyePosition();
|
||||||
|
|
||||||
static int getHMDScreen();
|
static int getHMDScreen();
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,7 @@ namespace render {
|
||||||
template <> void payloadRender(const RenderableModelEntityItemMeta::Pointer& payload, RenderArgs* args) {
|
template <> void payloadRender(const RenderableModelEntityItemMeta::Pointer& payload, RenderArgs* args) {
|
||||||
if (args) {
|
if (args) {
|
||||||
if (payload && payload->entity) {
|
if (payload && payload->entity) {
|
||||||
|
PROFILE_RANGE("MetaModelRender");
|
||||||
payload->entity->render(args);
|
payload->entity->render(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class EntityActionFactoryInterface : public QObject, public Dependency {
|
||||||
virtual ~EntityActionFactoryInterface() { }
|
virtual ~EntityActionFactoryInterface() { }
|
||||||
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
virtual EntityActionPointer factory(EntitySimulation* simulation,
|
||||||
EntityActionType type,
|
EntityActionType type,
|
||||||
QUuid id,
|
const QUuid& id,
|
||||||
EntityItemPointer ownerEntity,
|
EntityItemPointer ownerEntity,
|
||||||
QVariantMap arguments) { assert(false); return nullptr; }
|
QVariantMap arguments) { assert(false); return nullptr; }
|
||||||
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
virtual EntityActionPointer factoryBA(EntitySimulation* simulation,
|
||||||
|
|
|
@ -29,10 +29,10 @@ enum EntityActionType {
|
||||||
|
|
||||||
class EntityActionInterface {
|
class EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
EntityActionInterface() { }
|
EntityActionInterface(EntityActionType type, const QUuid& id) : _id(id), _type(type) { }
|
||||||
virtual ~EntityActionInterface() { }
|
virtual ~EntityActionInterface() { }
|
||||||
virtual const QUuid& getID() const = 0;
|
const QUuid& getID() const { return _id; }
|
||||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
EntityActionType getType() const { return _type; }
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
virtual EntityItemWeakPointer getOwnerEntity() const = 0;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
virtual bool updateArguments(QVariantMap arguments) = 0;
|
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||||
virtual QVariantMap getArguments() = 0;
|
virtual QVariantMap getArguments() = 0;
|
||||||
|
|
||||||
virtual QByteArray serialize() = 0;
|
virtual QByteArray serialize() const = 0;
|
||||||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||||
|
|
||||||
static EntityActionType actionTypeFromString(QString actionTypeString);
|
static EntityActionType actionTypeFromString(QString actionTypeString);
|
||||||
|
@ -68,6 +68,8 @@ protected:
|
||||||
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
||||||
QString argumentName, bool& ok, bool required = true);
|
QString argumentName, bool& ok, bool required = true);
|
||||||
|
|
||||||
|
QUuid _id;
|
||||||
|
EntityActionType _type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,11 @@
|
||||||
#include "EntityItem.h"
|
#include "EntityItem.h"
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtEndian>
|
||||||
|
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
|
#include <BufferParser.h>
|
||||||
#include <ByteCountCoding.h>
|
#include <ByteCountCoding.h>
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
#include <Octree.h>
|
#include <Octree.h>
|
||||||
|
@ -354,50 +356,78 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
// ~27-35 bytes...
|
// ~27-35 bytes...
|
||||||
const int MINIMUM_HEADER_BYTES = 27;
|
const int MINIMUM_HEADER_BYTES = 27;
|
||||||
|
|
||||||
int bytesRead = 0;
|
|
||||||
if (bytesLeftToRead < MINIMUM_HEADER_BYTES) {
|
if (bytesLeftToRead < MINIMUM_HEADER_BYTES) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int clockSkew = args.sourceNode ? args.sourceNode->getClockSkewUsec() : 0;
|
||||||
|
|
||||||
|
BufferParser parser(data, bytesLeftToRead);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define VALIDATE_ENTITY_ITEM_PARSER 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
|
int bytesRead = 0;
|
||||||
int originalLength = bytesLeftToRead;
|
int originalLength = bytesLeftToRead;
|
||||||
// TODO: figure out a way to avoid the big deep copy below.
|
// TODO: figure out a way to avoid the big deep copy below.
|
||||||
QByteArray originalDataBuffer((const char*)data, originalLength); // big deep copy!
|
QByteArray originalDataBuffer((const char*)data, originalLength); // big deep copy!
|
||||||
|
|
||||||
int clockSkew = args.sourceNode ? args.sourceNode->getClockSkewUsec() : 0;
|
|
||||||
|
|
||||||
const unsigned char* dataAt = data;
|
const unsigned char* dataAt = data;
|
||||||
|
#endif
|
||||||
|
|
||||||
// id
|
// id
|
||||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
parser.readUuid(_id);
|
||||||
_id = QUuid::fromRfc4122(encodedID);
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
dataAt += encodedID.size();
|
{
|
||||||
bytesRead += encodedID.size();
|
QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
||||||
|
QUuid id = QUuid::fromRfc4122(encodedID);
|
||||||
|
dataAt += encodedID.size();
|
||||||
|
bytesRead += encodedID.size();
|
||||||
|
Q_ASSERT(id == _id);
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// type
|
// type
|
||||||
|
parser.readCompressedCount<quint32>((quint32&)_type);
|
||||||
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||||
ByteCountCoded<quint32> typeCoder = encodedType;
|
ByteCountCoded<quint32> typeCoder = encodedType;
|
||||||
encodedType = typeCoder; // determine true length
|
encodedType = typeCoder; // determine true length
|
||||||
dataAt += encodedType.size();
|
dataAt += encodedType.size();
|
||||||
bytesRead += encodedType.size();
|
bytesRead += encodedType.size();
|
||||||
quint32 type = typeCoder;
|
quint32 type = typeCoder;
|
||||||
_type = (EntityTypes::EntityType)type;
|
EntityTypes::EntityType oldType = (EntityTypes::EntityType)type;
|
||||||
|
Q_ASSERT(oldType == _type);
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool overwriteLocalData = true; // assume the new content overwrites our local data
|
bool overwriteLocalData = true; // assume the new content overwrites our local data
|
||||||
|
quint64 now = usecTimestampNow();
|
||||||
|
|
||||||
// _created
|
// _created
|
||||||
quint64 createdFromBuffer = 0;
|
{
|
||||||
memcpy(&createdFromBuffer, dataAt, sizeof(createdFromBuffer));
|
quint64 createdFromBuffer = 0;
|
||||||
dataAt += sizeof(createdFromBuffer);
|
parser.readValue(createdFromBuffer);
|
||||||
bytesRead += sizeof(createdFromBuffer);
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
|
{
|
||||||
quint64 now = usecTimestampNow();
|
quint64 createdFromBuffer2 = 0;
|
||||||
if (_created == UNKNOWN_CREATED_TIME) {
|
memcpy(&createdFromBuffer2, dataAt, sizeof(createdFromBuffer2));
|
||||||
// we don't yet have a _created timestamp, so we accept this one
|
dataAt += sizeof(createdFromBuffer2);
|
||||||
createdFromBuffer -= clockSkew;
|
bytesRead += sizeof(createdFromBuffer2);
|
||||||
if (createdFromBuffer > now || createdFromBuffer == UNKNOWN_CREATED_TIME) {
|
Q_ASSERT(createdFromBuffer2 == createdFromBuffer);
|
||||||
createdFromBuffer = now;
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (_created == UNKNOWN_CREATED_TIME) {
|
||||||
|
// we don't yet have a _created timestamp, so we accept this one
|
||||||
|
createdFromBuffer -= clockSkew;
|
||||||
|
if (createdFromBuffer > now || createdFromBuffer == UNKNOWN_CREATED_TIME) {
|
||||||
|
createdFromBuffer = now;
|
||||||
|
}
|
||||||
|
_created = createdFromBuffer;
|
||||||
}
|
}
|
||||||
_created = createdFromBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -417,15 +447,21 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
quint64 lastEditedFromBuffer = 0;
|
quint64 lastEditedFromBuffer = 0;
|
||||||
quint64 lastEditedFromBufferAdjusted = 0;
|
|
||||||
|
|
||||||
// TODO: we could make this encoded as a delta from _created
|
// TODO: we could make this encoded as a delta from _created
|
||||||
// _lastEdited
|
// _lastEdited
|
||||||
memcpy(&lastEditedFromBuffer, dataAt, sizeof(lastEditedFromBuffer));
|
parser.readValue(lastEditedFromBuffer);
|
||||||
dataAt += sizeof(lastEditedFromBuffer);
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
bytesRead += sizeof(lastEditedFromBuffer);
|
{
|
||||||
lastEditedFromBufferAdjusted = lastEditedFromBuffer - clockSkew;
|
quint64 lastEditedFromBuffer2 = 0;
|
||||||
|
memcpy(&lastEditedFromBuffer2, dataAt, sizeof(lastEditedFromBuffer2));
|
||||||
|
dataAt += sizeof(lastEditedFromBuffer2);
|
||||||
|
bytesRead += sizeof(lastEditedFromBuffer2);
|
||||||
|
Q_ASSERT(lastEditedFromBuffer2 == lastEditedFromBuffer);
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
quint64 lastEditedFromBufferAdjusted = lastEditedFromBuffer - clockSkew;
|
||||||
if (lastEditedFromBufferAdjusted > now) {
|
if (lastEditedFromBufferAdjusted > now) {
|
||||||
lastEditedFromBufferAdjusted = now;
|
lastEditedFromBufferAdjusted = now;
|
||||||
}
|
}
|
||||||
|
@ -487,9 +523,21 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
}
|
}
|
||||||
|
|
||||||
// last updated is stored as ByteCountCoded delta from lastEdited
|
// last updated is stored as ByteCountCoded delta from lastEdited
|
||||||
QByteArray encodedUpdateDelta = originalDataBuffer.mid(bytesRead); // maximum possible size
|
quint64 updateDelta;
|
||||||
ByteCountCoded<quint64> updateDeltaCoder = encodedUpdateDelta;
|
parser.readCompressedCount(updateDelta);
|
||||||
quint64 updateDelta = updateDeltaCoder;
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
|
{
|
||||||
|
QByteArray encodedUpdateDelta = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||||
|
ByteCountCoded<quint64> updateDeltaCoder = encodedUpdateDelta;
|
||||||
|
quint64 updateDelta2 = updateDeltaCoder;
|
||||||
|
Q_ASSERT(updateDelta == updateDelta2);
|
||||||
|
encodedUpdateDelta = updateDeltaCoder; // determine true length
|
||||||
|
dataAt += encodedUpdateDelta.size();
|
||||||
|
bytesRead += encodedUpdateDelta.size();
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (overwriteLocalData) {
|
if (overwriteLocalData) {
|
||||||
_lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that
|
_lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -499,17 +547,25 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedUpdateDelta = updateDeltaCoder; // determine true length
|
|
||||||
dataAt += encodedUpdateDelta.size();
|
|
||||||
bytesRead += encodedUpdateDelta.size();
|
|
||||||
|
|
||||||
// Newer bitstreams will have a last simulated and a last updated value
|
// Newer bitstreams will have a last simulated and a last updated value
|
||||||
quint64 lastSimulatedFromBufferAdjusted = now;
|
quint64 lastSimulatedFromBufferAdjusted = now;
|
||||||
if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_LAST_SIMULATED_TIME) {
|
if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_LAST_SIMULATED_TIME) {
|
||||||
// last simulated is stored as ByteCountCoded delta from lastEdited
|
// last simulated is stored as ByteCountCoded delta from lastEdited
|
||||||
QByteArray encodedSimulatedDelta = originalDataBuffer.mid(bytesRead); // maximum possible size
|
quint64 simulatedDelta;
|
||||||
ByteCountCoded<quint64> simulatedDeltaCoder = encodedSimulatedDelta;
|
parser.readCompressedCount(simulatedDelta);
|
||||||
quint64 simulatedDelta = simulatedDeltaCoder;
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
|
{
|
||||||
|
QByteArray encodedSimulatedDelta = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||||
|
ByteCountCoded<quint64> simulatedDeltaCoder = encodedSimulatedDelta;
|
||||||
|
quint64 simulatedDelta2 = simulatedDeltaCoder;
|
||||||
|
Q_ASSERT(simulatedDelta2 == simulatedDelta);
|
||||||
|
encodedSimulatedDelta = simulatedDeltaCoder; // determine true length
|
||||||
|
dataAt += encodedSimulatedDelta.size();
|
||||||
|
bytesRead += encodedSimulatedDelta.size();
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (overwriteLocalData) {
|
if (overwriteLocalData) {
|
||||||
lastSimulatedFromBufferAdjusted = lastEditedFromBufferAdjusted + simulatedDelta; // don't adjust for clock skew since we already did that
|
lastSimulatedFromBufferAdjusted = lastEditedFromBufferAdjusted + simulatedDelta; // don't adjust for clock skew since we already did that
|
||||||
if (lastSimulatedFromBufferAdjusted > now) {
|
if (lastSimulatedFromBufferAdjusted > now) {
|
||||||
|
@ -521,9 +577,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
qCDebug(entities) << " lastSimulatedFromBufferAdjusted:" << debugTime(lastSimulatedFromBufferAdjusted, now);
|
qCDebug(entities) << " lastSimulatedFromBufferAdjusted:" << debugTime(lastSimulatedFromBufferAdjusted, now);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
encodedSimulatedDelta = simulatedDeltaCoder; // determine true length
|
|
||||||
dataAt += encodedSimulatedDelta.size();
|
|
||||||
bytesRead += encodedSimulatedDelta.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -537,10 +590,26 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
|
|
||||||
|
|
||||||
// Property Flags
|
// Property Flags
|
||||||
QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size
|
EntityPropertyFlags propertyFlags;
|
||||||
EntityPropertyFlags propertyFlags = encodedPropertyFlags;
|
parser.readFlags(propertyFlags);
|
||||||
dataAt += propertyFlags.getEncodedLength();
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
bytesRead += propertyFlags.getEncodedLength();
|
{
|
||||||
|
QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||||
|
EntityPropertyFlags propertyFlags2 = encodedPropertyFlags;
|
||||||
|
dataAt += propertyFlags.getEncodedLength();
|
||||||
|
bytesRead += propertyFlags.getEncodedLength();
|
||||||
|
Q_ASSERT(propertyFlags2 == propertyFlags);
|
||||||
|
Q_ASSERT(parser.offset() == bytesRead);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VALIDATE_ENTITY_ITEM_PARSER
|
||||||
|
Q_ASSERT(parser.data() + parser.offset() == dataAt);
|
||||||
|
#else
|
||||||
|
const unsigned char* dataAt = parser.data() + parser.offset();
|
||||||
|
int bytesRead = parser.offset();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE) {
|
if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE) {
|
||||||
// pack SimulationOwner and terse update properties near each other
|
// pack SimulationOwner and terse update properties near each other
|
||||||
|
@ -549,6 +618,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
// even when we would otherwise ignore the rest of the packet.
|
// even when we would otherwise ignore the rest of the packet.
|
||||||
|
|
||||||
if (propertyFlags.getHasProperty(PROP_SIMULATION_OWNER)) {
|
if (propertyFlags.getHasProperty(PROP_SIMULATION_OWNER)) {
|
||||||
|
|
||||||
QByteArray simOwnerData;
|
QByteArray simOwnerData;
|
||||||
int bytes = OctreePacketData::unpackDataFromBytes(dataAt, simOwnerData);
|
int bytes = OctreePacketData::unpackDataFromBytes(dataAt, simOwnerData);
|
||||||
SimulationOwner newSimOwner;
|
SimulationOwner newSimOwner;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <BufferParser.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
|
|
||||||
#include "RegisteredMetaTypes.h"
|
#include "RegisteredMetaTypes.h"
|
||||||
|
@ -33,11 +33,8 @@ EntityItemID::EntityItemID(const QUuid& id) : QUuid(id)
|
||||||
|
|
||||||
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
||||||
EntityItemID result;
|
EntityItemID result;
|
||||||
|
|
||||||
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
||||||
// id
|
BufferParser(data, bytesLeftToRead).readUuid(result);
|
||||||
QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID);
|
|
||||||
result = QUuid::fromRfc4122(encodedID);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,13 +92,11 @@ void EntityTree::postAddEntity(EntityItemPointer entity) {
|
||||||
bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
|
bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
|
||||||
EntityTreeElement* containingElement = getContainingElement(entityID);
|
EntityTreeElement* containingElement = getContainingElement(entityID);
|
||||||
if (!containingElement) {
|
if (!containingElement) {
|
||||||
qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entityID doesn't exist!!! entityID=" << entityID;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemPointer existingEntity = containingElement->getEntityWithEntityItemID(entityID);
|
EntityItemPointer existingEntity = containingElement->getEntityWithEntityItemID(entityID);
|
||||||
if (!existingEntity) {
|
if (!existingEntity) {
|
||||||
qCDebug(entities) << "UNEXPECTED!!!! don't call updateEntity() on entity items that don't exist. entityID=" << entityID;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +106,6 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp
|
||||||
bool EntityTree::updateEntity(EntityItemPointer entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
|
bool EntityTree::updateEntity(EntityItemPointer entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
|
||||||
EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID());
|
EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID());
|
||||||
if (!containingElement) {
|
if (!containingElement) {
|
||||||
qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID="
|
|
||||||
<< entity->getEntityItemID();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return updateEntityWithElement(entity, properties, containingElement, senderNode);
|
return updateEntityWithElement(entity, properties, containingElement, senderNode);
|
||||||
|
|
|
@ -12,6 +12,17 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#if defined(NSIGHT_FOUND)
|
||||||
|
#include "nvToolsExt.h"
|
||||||
|
|
||||||
|
ProfileRange::ProfileRange(const char *name) {
|
||||||
|
nvtxRangePush(name);
|
||||||
|
}
|
||||||
|
ProfileRange::~ProfileRange() {
|
||||||
|
nvtxRangePop();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size());
|
#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size());
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
|
@ -26,17 +26,11 @@
|
||||||
#include "Framebuffer.h"
|
#include "Framebuffer.h"
|
||||||
|
|
||||||
#if defined(NSIGHT_FOUND)
|
#if defined(NSIGHT_FOUND)
|
||||||
#include "nvToolsExt.h"
|
|
||||||
class ProfileRange {
|
class ProfileRange {
|
||||||
public:
|
public:
|
||||||
ProfileRange(const char *name) {
|
ProfileRange(const char *name);
|
||||||
nvtxRangePush(name);
|
~ProfileRange();
|
||||||
}
|
|
||||||
~ProfileRange() {
|
|
||||||
nvtxRangePop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PROFILE_RANGE(name) ProfileRange profileRangeThis(name);
|
#define PROFILE_RANGE(name) ProfileRange profileRangeThis(name);
|
||||||
#else
|
#else
|
||||||
#define PROFILE_RANGE(name)
|
#define PROFILE_RANGE(name)
|
||||||
|
|
|
@ -33,9 +33,11 @@ bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::render(Batch& batch) {
|
void Context::render(Batch& batch) {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
_backend->render(batch);
|
_backend->render(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::syncCache() {
|
void Context::syncCache() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
_backend->syncCache();
|
_backend->syncCache();
|
||||||
}
|
}
|
|
@ -13,9 +13,9 @@
|
||||||
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
ObjectAction::ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectAction::ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
btActionInterface(),
|
btActionInterface(),
|
||||||
_id(id),
|
EntityActionInterface(type, id),
|
||||||
_active(false),
|
_active(false),
|
||||||
_ownerEntity(ownerEntity) {
|
_ownerEntity(ownerEntity) {
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ ObjectAction::~ObjectAction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
|
||||||
if (!_active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_ownerEntity.expired()) {
|
if (_ownerEntity.expired()) {
|
||||||
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
|
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
|
||||||
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
|
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
|
||||||
dynamicsWorld->removeAction(this);
|
dynamicsWorld->removeAction(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
updateActionWorker(deltaTimeStep);
|
updateActionWorker(deltaTimeStep);
|
||||||
}
|
}
|
||||||
|
@ -129,11 +129,3 @@ void ObjectAction::setAngularVelocity(glm::vec3 angularVelocity) {
|
||||||
rigidBody->activate();
|
rigidBody->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectAction::serialize() {
|
|
||||||
assert(false);
|
|
||||||
return QByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectAction::deserialize(QByteArray serializedArguments) {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
#include <EntityItem.h>
|
|
||||||
|
|
||||||
#include "ObjectMotionState.h"
|
#include "ObjectMotionState.h"
|
||||||
#include "BulletUtil.h"
|
#include "BulletUtil.h"
|
||||||
#include "EntityActionInterface.h"
|
#include "EntityActionInterface.h"
|
||||||
|
@ -26,31 +24,25 @@
|
||||||
|
|
||||||
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
class ObjectAction : public btActionInterface, public EntityActionInterface {
|
||||||
public:
|
public:
|
||||||
ObjectAction(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectAction();
|
virtual ~ObjectAction();
|
||||||
|
|
||||||
const QUuid& getID() const { return _id; }
|
|
||||||
virtual EntityActionType getType() { assert(false); return ACTION_TYPE_NONE; }
|
|
||||||
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
virtual void removeFromSimulation(EntitySimulation* simulation) const;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments) { return false; }
|
virtual bool updateArguments(QVariantMap arguments) = 0;
|
||||||
virtual QVariantMap getArguments() { return QVariantMap(); }
|
virtual QVariantMap getArguments() = 0;
|
||||||
|
|
||||||
// this is called from updateAction and should be overridden by subclasses
|
// this is called from updateAction and should be overridden by subclasses
|
||||||
virtual void updateActionWorker(float deltaTimeStep) {}
|
virtual void updateActionWorker(float deltaTimeStep) = 0;
|
||||||
|
|
||||||
// these are from btActionInterface
|
// these are from btActionInterface
|
||||||
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
virtual void updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep);
|
||||||
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
virtual void debugDraw(btIDebugDraw* debugDrawer);
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const = 0;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||||
|
|
||||||
private:
|
|
||||||
QUuid _id;
|
|
||||||
QReadWriteLock _lock;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -70,6 +62,10 @@ protected:
|
||||||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||||
void unlock() { _lock.unlock(); }
|
void unlock() { _lock.unlock(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QReadWriteLock _lock;
|
||||||
|
|
||||||
|
protected:
|
||||||
bool _active;
|
bool _active;
|
||||||
EntityItemWeakPointer _ownerEntity;
|
EntityItemWeakPointer _ownerEntity;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
const uint16_t ObjectActionOffset::offsetVersion = 1;
|
||||||
|
|
||||||
ObjectActionOffset::ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionOffset::ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(type, id, ownerEntity) {
|
ObjectAction(ACTION_TYPE_OFFSET, id, ownerEntity) {
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
qDebug() << "ObjectActionOffset::ObjectActionOffset";
|
||||||
#endif
|
#endif
|
||||||
|
@ -127,7 +127,7 @@ QVariantMap ObjectActionOffset::getArguments() {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectActionOffset::serialize() {
|
QByteArray ObjectActionOffset::serialize() const {
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
QDataStream dataStream(&ba, QIODevice::WriteOnly);
|
||||||
dataStream << getType();
|
dataStream << getType();
|
||||||
|
@ -146,13 +146,14 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
|
||||||
QDataStream dataStream(serializedArguments);
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
EntityActionType type;
|
EntityActionType type;
|
||||||
QUuid id;
|
|
||||||
uint16_t serializationVersion;
|
|
||||||
|
|
||||||
dataStream >> type;
|
dataStream >> type;
|
||||||
assert(type == getType());
|
assert(type == getType());
|
||||||
|
|
||||||
|
QUuid id;
|
||||||
dataStream >> id;
|
dataStream >> id;
|
||||||
assert(id == getID());
|
assert(id == getID());
|
||||||
|
|
||||||
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectActionOffset::offsetVersion) {
|
if (serializationVersion != ObjectActionOffset::offsetVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,17 +19,15 @@
|
||||||
|
|
||||||
class ObjectActionOffset : public ObjectAction {
|
class ObjectActionOffset : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionOffset(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionOffset(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionOffset();
|
virtual ~ObjectActionOffset();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_OFFSET; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -17,8 +17,8 @@ const float SPRING_MAX_SPEED = 10.0f;
|
||||||
|
|
||||||
const uint16_t ObjectActionSpring::springVersion = 1;
|
const uint16_t ObjectActionSpring::springVersion = 1;
|
||||||
|
|
||||||
ObjectActionSpring::ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) :
|
ObjectActionSpring::ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectAction(type, id, ownerEntity),
|
ObjectAction(ACTION_TYPE_SPRING, id, ownerEntity),
|
||||||
_positionalTarget(glm::vec3(0.0f)),
|
_positionalTarget(glm::vec3(0.0f)),
|
||||||
_linearTimeScale(0.2f),
|
_linearTimeScale(0.2f),
|
||||||
_positionalTargetSet(false),
|
_positionalTargetSet(false),
|
||||||
|
@ -206,7 +206,7 @@ QVariantMap ObjectActionSpring::getArguments() {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ObjectActionSpring::serialize() {
|
QByteArray ObjectActionSpring::serialize() const {
|
||||||
QByteArray serializedActionArguments;
|
QByteArray serializedActionArguments;
|
||||||
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
@ -229,13 +229,14 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
|
||||||
QDataStream dataStream(serializedArguments);
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
EntityActionType type;
|
EntityActionType type;
|
||||||
QUuid id;
|
|
||||||
uint16_t serializationVersion;
|
|
||||||
|
|
||||||
dataStream >> type;
|
dataStream >> type;
|
||||||
assert(type == getType());
|
assert(type == getType());
|
||||||
|
|
||||||
|
QUuid id;
|
||||||
dataStream >> id;
|
dataStream >> id;
|
||||||
assert(id == getID());
|
assert(id == getID());
|
||||||
|
|
||||||
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectActionSpring::springVersion) {
|
if (serializationVersion != ObjectActionSpring::springVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -12,24 +12,19 @@
|
||||||
#ifndef hifi_ObjectActionSpring_h
|
#ifndef hifi_ObjectActionSpring_h
|
||||||
#define hifi_ObjectActionSpring_h
|
#define hifi_ObjectActionSpring_h
|
||||||
|
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
#include <EntityItem.h>
|
|
||||||
#include "ObjectAction.h"
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
class ObjectActionSpring : public ObjectAction {
|
class ObjectActionSpring : public ObjectAction {
|
||||||
public:
|
public:
|
||||||
ObjectActionSpring(EntityActionType type, QUuid id, EntityItemPointer ownerEntity);
|
ObjectActionSpring(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectActionSpring();
|
virtual ~ObjectActionSpring();
|
||||||
|
|
||||||
virtual EntityActionType getType() { return ACTION_TYPE_SPRING; }
|
|
||||||
|
|
||||||
virtual bool updateArguments(QVariantMap arguments);
|
virtual bool updateArguments(QVariantMap arguments);
|
||||||
virtual QVariantMap getArguments();
|
virtual QVariantMap getArguments();
|
||||||
|
|
||||||
virtual void updateActionWorker(float deltaTimeStep);
|
virtual void updateActionWorker(float deltaTimeStep);
|
||||||
|
|
||||||
virtual QByteArray serialize();
|
virtual QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -417,6 +417,7 @@ void Model::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::updateGeometry() {
|
bool Model::updateGeometry() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
bool needFullUpdate = false;
|
bool needFullUpdate = false;
|
||||||
|
|
||||||
bool needToRebuild = false;
|
bool needToRebuild = false;
|
||||||
|
@ -690,6 +691,7 @@ void Model::recalculateMeshPartOffsets() {
|
||||||
// entity-scripts to call. I think it would be best to do the picking once-per-frame (in cpu, or gpu if possible)
|
// entity-scripts to call. I think it would be best to do the picking once-per-frame (in cpu, or gpu if possible)
|
||||||
// and then the calls use the most recent such result.
|
// and then the calls use the most recent such result.
|
||||||
void Model::recalculateMeshBoxes(bool pickAgainstTriangles) {
|
void Model::recalculateMeshBoxes(bool pickAgainstTriangles) {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
||||||
|
|
||||||
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded || (!_calculatedMeshPartBoxesValid && pickAgainstTriangles) ) {
|
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded || (!_calculatedMeshPartBoxesValid && pickAgainstTriangles) ) {
|
||||||
|
@ -1281,6 +1283,7 @@ Blender::Blender(Model* model, int blendNumber, const QWeakPointer<NetworkGeomet
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blender::run() {
|
void Blender::run() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
QVector<glm::vec3> vertices, normals;
|
QVector<glm::vec3> vertices, normals;
|
||||||
if (!_model.isNull()) {
|
if (!_model.isNull()) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
@ -1392,6 +1395,7 @@ void Model::snapToRegistrationPoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::simulate(float deltaTime, bool fullUpdate) {
|
void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit)
|
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit)
|
||||||
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
|
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
|
||||||
|
|
||||||
|
@ -1829,6 +1833,7 @@ void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AABox Model::getPartBounds(int meshIndex, int partIndex) {
|
AABox Model::getPartBounds(int meshIndex, int partIndex) {
|
||||||
|
|
||||||
if (meshIndex < _meshStates.size()) {
|
if (meshIndex < _meshStates.size()) {
|
||||||
const MeshState& state = _meshStates.at(meshIndex);
|
const MeshState& state = _meshStates.at(meshIndex);
|
||||||
bool isSkinned = state.clusterMatrices.size() > 1;
|
bool isSkinned = state.clusterMatrices.size() > 1;
|
||||||
|
@ -1859,6 +1864,7 @@ AABox Model::getPartBounds(int meshIndex, int partIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool translucent) {
|
void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool translucent) {
|
||||||
|
// PROFILE_RANGE(__FUNCTION__);
|
||||||
PerformanceTimer perfTimer("Model::renderPart");
|
PerformanceTimer perfTimer("Model::renderPart");
|
||||||
if (!_readyWhenAdded) {
|
if (!_readyWhenAdded) {
|
||||||
return; // bail asap
|
return; // bail asap
|
||||||
|
@ -1933,7 +1939,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran
|
||||||
pickPrograms(batch, mode, translucentMesh, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, wireframe,
|
pickPrograms(batch, mode, translucentMesh, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, wireframe,
|
||||||
args, locations);
|
args, locations);
|
||||||
|
|
||||||
updateVisibleJointStates();
|
{
|
||||||
|
updateVisibleJointStates();
|
||||||
|
}
|
||||||
|
|
||||||
// if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshGroupsKnown
|
// if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshGroupsKnown
|
||||||
// to false to rebuild out mesh groups.
|
// to false to rebuild out mesh groups.
|
||||||
|
@ -2076,9 +2084,13 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.lock();
|
qint64 offset;
|
||||||
qint64 offset = _calculatedMeshPartOffset[QPair<int,int>(meshIndex, partIndex)];
|
{
|
||||||
_mutex.unlock();
|
// FIXME_STUTTER: We should n't have any lock here
|
||||||
|
_mutex.lock();
|
||||||
|
offset = _calculatedMeshPartOffset[QPair<int,int>(meshIndex, partIndex)];
|
||||||
|
_mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
if (part.quadIndices.size() > 0) {
|
if (part.quadIndices.size() > 0) {
|
||||||
batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset);
|
batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset);
|
||||||
|
|
|
@ -9,4 +9,16 @@ add_dependency_external_projects(glm)
|
||||||
find_package(GLM REQUIRED)
|
find_package(GLM REQUIRED)
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
|
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
|
||||||
|
|
||||||
link_hifi_libraries(shared gpu model)
|
link_hifi_libraries(shared gpu model)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
if (USE_NSIGHT)
|
||||||
|
# try to find the Nsight package and add it to the build if we find it
|
||||||
|
find_package(NSIGHT)
|
||||||
|
if (NSIGHT_FOUND)
|
||||||
|
include_directories(${NSIGHT_INCLUDE_DIRS})
|
||||||
|
add_definitions(-DNSIGHT_FOUND)
|
||||||
|
target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}")
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
endif (WIN32)
|
|
@ -11,6 +11,7 @@
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include "gpu/Batch.h"
|
||||||
|
|
||||||
using namespace render;
|
using namespace render;
|
||||||
|
|
||||||
|
@ -167,6 +168,7 @@ void consolidateChangeQueue(PendingChangesQueue& queue, PendingChanges& singleBa
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::processPendingChangesQueue() {
|
void Scene::processPendingChangesQueue() {
|
||||||
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
_changeQueueMutex.lock();
|
_changeQueueMutex.lock();
|
||||||
PendingChanges consolidatedPendingChanges;
|
PendingChanges consolidatedPendingChanges;
|
||||||
consolidateChangeQueue(_changeQueue, consolidatedPendingChanges);
|
consolidateChangeQueue(_changeQueue, consolidatedPendingChanges);
|
||||||
|
|
122
libraries/shared/src/BufferParser.h
Normal file
122
libraries/shared/src/BufferParser.h
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
//
|
||||||
|
// Created by Bradley Austin Davis on 2015/07/08
|
||||||
|
// Copyright 2013-2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef hifi_BufferParser_h
|
||||||
|
#define hifi_BufferParser_h
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QtEndian>
|
||||||
|
|
||||||
|
#include "GLMHelpers.h"
|
||||||
|
#include "ByteCountCoding.h"
|
||||||
|
#include "PropertyFlags.h"
|
||||||
|
|
||||||
|
class BufferParser {
|
||||||
|
public:
|
||||||
|
BufferParser(const uint8_t* data, size_t size, size_t offset = 0) :
|
||||||
|
_offset(offset), _data(data), _size(size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void readValue(T& result) {
|
||||||
|
Q_ASSERT(remaining() >= sizeof(T));
|
||||||
|
memcpy(&result, _data + _offset, sizeof(T));
|
||||||
|
_offset += sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void readUuid(QUuid& result) {
|
||||||
|
readValue(result.data1);
|
||||||
|
readValue(result.data2);
|
||||||
|
readValue(result.data3);
|
||||||
|
readValue(result.data4);
|
||||||
|
result.data1 = qFromBigEndian<quint32>(result.data1);
|
||||||
|
result.data2 = qFromBigEndian<quint16>(result.data2);
|
||||||
|
result.data3 = qFromBigEndian<quint16>(result.data3);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void readFlags(PropertyFlags<T>& result) {
|
||||||
|
// FIXME doing heap allocation
|
||||||
|
QByteArray encoded((const char*)(_data + _offset), remaining());
|
||||||
|
result.decode(encoded);
|
||||||
|
_offset += result.getEncodedLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void readCompressedCount(T& result) {
|
||||||
|
// FIXME switch to a heapless implementation as soon as Brad provides it.
|
||||||
|
ByteCountCoded<T> codec;
|
||||||
|
_offset += codec.decode(reinterpret_cast<const char*>(_data + _offset), remaining());
|
||||||
|
result = codec.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t remaining() const {
|
||||||
|
return _size - _offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t offset() const {
|
||||||
|
return _offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const uint8_t* data() const {
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
size_t _offset{ 0 };
|
||||||
|
const uint8_t* const _data;
|
||||||
|
const size_t _size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue<quat>(quat& result) {
|
||||||
|
size_t advance = unpackOrientationQuatFromBytes(_data + _offset, result);
|
||||||
|
_offset += advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue(QString& result) {
|
||||||
|
uint16_t length; readValue(length);
|
||||||
|
result = QString((const char*)_data + _offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue(QUuid& result) {
|
||||||
|
uint16_t length; readValue(length);
|
||||||
|
Q_ASSERT(16 == length);
|
||||||
|
readUuid(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue(xColor& result) {
|
||||||
|
readValue(result.red);
|
||||||
|
readValue(result.blue);
|
||||||
|
readValue(result.green);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue(QVector<glm::vec3>& result) {
|
||||||
|
uint16_t length; readValue(length);
|
||||||
|
result.resize(length);
|
||||||
|
memcpy(result.data(), _data + _offset, sizeof(glm::vec3) * length);
|
||||||
|
_offset += sizeof(glm::vec3) * length;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BufferParser::readValue(QByteArray& result) {
|
||||||
|
uint16_t length; readValue(length);
|
||||||
|
result = QByteArray((char*)_data + _offset, (int)length);
|
||||||
|
_offset += length;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -21,9 +21,13 @@
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
#include "NumericalConstants.h"
|
#include "NumericalConstants.h"
|
||||||
|
|
||||||
template<typename T> class ByteCountCoded {
|
template<typename T> class ByteCountCoded {
|
||||||
|
@ -37,7 +41,8 @@ public:
|
||||||
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
||||||
|
|
||||||
QByteArray encode() const;
|
QByteArray encode() const;
|
||||||
void decode(const QByteArray& fromEncoded);
|
size_t decode(const QByteArray& fromEncoded);
|
||||||
|
size_t decode(const char* encodedBuffer, int encodedSize);
|
||||||
|
|
||||||
bool operator==(const ByteCountCoded& other) const { return data == other.data; }
|
bool operator==(const ByteCountCoded& other) const { return data == other.data; }
|
||||||
bool operator!=(const ByteCountCoded& other) const { return data != other.data; }
|
bool operator!=(const ByteCountCoded& other) const { return data != other.data; }
|
||||||
|
@ -110,52 +115,63 @@ template<typename T> inline QByteArray ByteCountCoded<T>::encode() const {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
template<typename T> inline size_t ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
||||||
|
return decode(fromEncodedBytes.constData(), fromEncodedBytes.size());
|
||||||
|
}
|
||||||
|
|
||||||
// first convert the ByteArray into a BitArray...
|
template<typename T> inline size_t ByteCountCoded<T>::decode(const char* encodedBuffer, int encodedSize) {
|
||||||
QBitArray encodedBits;
|
data = 0; // reset data
|
||||||
int bitCount = BITS_IN_BYTE * fromEncodedBytes.count();
|
size_t bytesConsumed = 0;
|
||||||
encodedBits.resize(bitCount);
|
int bitCount = BITS_IN_BYTE * encodedSize;
|
||||||
|
|
||||||
|
int encodedByteCount = 1; // there is at least 1 byte (after the leadBits)
|
||||||
|
int leadBits = 1; // there is always at least 1 lead bit
|
||||||
|
bool inLeadBits = true;
|
||||||
|
int bitAt = 0;
|
||||||
|
int expectedBitCount; // unknown at this point
|
||||||
|
int lastValueBit;
|
||||||
|
T bitValue = 1;
|
||||||
|
|
||||||
for(int byte = 0; byte < fromEncodedBytes.count(); byte++) {
|
for(int byte = 0; byte < encodedSize; byte++) {
|
||||||
char originalByte = fromEncodedBytes.at(byte);
|
char originalByte = encodedBuffer[byte];
|
||||||
|
bytesConsumed++;
|
||||||
|
unsigned char maskBit = 128; // LEFT MOST BIT set
|
||||||
for(int bit = 0; bit < BITS_IN_BYTE; bit++) {
|
for(int bit = 0; bit < BITS_IN_BYTE; bit++) {
|
||||||
int shiftBy = BITS_IN_BYTE - (bit + 1);
|
bool bitIsSet = originalByte & maskBit;
|
||||||
char maskBit = ( 1 << shiftBy);
|
|
||||||
bool bitValue = originalByte & maskBit;
|
// Processing of the lead bits
|
||||||
encodedBits.setBit(byte * BITS_IN_BYTE + bit, bitValue);
|
if (inLeadBits) {
|
||||||
|
if (bitIsSet) {
|
||||||
|
encodedByteCount++;
|
||||||
|
leadBits++;
|
||||||
|
} else {
|
||||||
|
inLeadBits = false; // once we hit our first 0, we know we're out of the lead bits
|
||||||
|
expectedBitCount = (encodedByteCount * BITS_IN_BYTE) - leadBits;
|
||||||
|
lastValueBit = expectedBitCount + bitAt;
|
||||||
|
|
||||||
|
// check to see if the remainder of our buffer is sufficient
|
||||||
|
if (expectedBitCount > (bitCount - leadBits)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (bitAt > lastValueBit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bitIsSet) {
|
||||||
|
data += bitValue;
|
||||||
|
}
|
||||||
|
bitValue *= 2;
|
||||||
|
}
|
||||||
|
bitAt++;
|
||||||
|
maskBit = maskBit >> 1;
|
||||||
}
|
}
|
||||||
}
|
if (!inLeadBits && bitAt > lastValueBit) {
|
||||||
|
|
||||||
// next, read the leading bits to determine the correct number of bytes to decode (may not match the QByteArray)
|
|
||||||
int encodedByteCount = 0;
|
|
||||||
int leadBits = 1;
|
|
||||||
int bitAt;
|
|
||||||
for (bitAt = 0; bitAt < bitCount; bitAt++) {
|
|
||||||
if (encodedBits.at(bitAt)) {
|
|
||||||
encodedByteCount++;
|
|
||||||
leadBits++;
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encodedByteCount++; // always at least one byte
|
return bytesConsumed;
|
||||||
int expectedBitCount = encodedByteCount * BITS_IN_BYTE;
|
|
||||||
|
|
||||||
T value = 0;
|
|
||||||
|
|
||||||
if (expectedBitCount <= (encodedBits.size() - leadBits)) {
|
|
||||||
// Now, keep reading...
|
|
||||||
int valueStartsAt = bitAt + 1;
|
|
||||||
T bitValue = 1;
|
|
||||||
for (bitAt = valueStartsAt; bitAt < expectedBitCount; bitAt++) {
|
|
||||||
if(encodedBits.at(bitAt)) {
|
|
||||||
value += bitValue;
|
|
||||||
}
|
|
||||||
bitValue *= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data = value;
|
|
||||||
}
|
}
|
||||||
#endif // hifi_ByteCountCoding_h
|
#endif // hifi_ByteCountCoding_h
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ QVariantList glmToQList(const glm::quat& g) {
|
||||||
return QVariantList() << g.x << g.y << g.z << g.w;
|
return QVariantList() << g.x << g.y << g.z << g.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList rgbColorToQList(rgbColor& v) {
|
QVariantList rgbColorToQList(const rgbColor& v) {
|
||||||
return QVariantList() << (int)(v[0]) << (int)(v[1]) << (int)(v[2]);
|
return QVariantList() << (int)(v[0]) << (int)(v[1]) << (int)(v[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +42,12 @@ QVariantMap glmToQMap(const glm::quat& glmQuat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 qListToGlmVec3(const QVariant q) {
|
glm::vec3 qListToGlmVec3(const QVariant& q) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
return glm::vec3(qList[RED_INDEX].toFloat(), qList[GREEN_INDEX].toFloat(), qList[BLUE_INDEX].toFloat());
|
return glm::vec3(qList[RED_INDEX].toFloat(), qList[GREEN_INDEX].toFloat(), qList[BLUE_INDEX].toFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat qListToGlmQuat(const QVariant q) {
|
glm::quat qListToGlmQuat(const QVariant& q) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
float x = qList[0].toFloat();
|
float x = qList[0].toFloat();
|
||||||
float y = qList[1].toFloat();
|
float y = qList[1].toFloat();
|
||||||
|
@ -56,7 +56,7 @@ glm::quat qListToGlmQuat(const QVariant q) {
|
||||||
return glm::quat(w, x, y, z);
|
return glm::quat(w, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue) {
|
void qListtoRgbColor(const QVariant& q, rgbColor& returnValue) {
|
||||||
QVariantList qList = q.toList();
|
QVariantList qList = q.toList();
|
||||||
returnValue[RED_INDEX] = qList[RED_INDEX].toInt();
|
returnValue[RED_INDEX] = qList[RED_INDEX].toInt();
|
||||||
returnValue[GREEN_INDEX] = qList[GREEN_INDEX].toInt();
|
returnValue[GREEN_INDEX] = qList[GREEN_INDEX].toInt();
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
QVariantList glmToQList(const glm::vec3& g);
|
QVariantList glmToQList(const glm::vec3& g);
|
||||||
QVariantList glmToQList(const glm::quat& g);
|
QVariantList glmToQList(const glm::quat& g);
|
||||||
QVariantList rgbColorToQList(rgbColor& v);
|
QVariantList rgbColorToQList(const rgbColor& v);
|
||||||
|
|
||||||
QVariantMap glmToQMap(const glm::vec3& glmVector);
|
QVariantMap glmToQMap(const glm::vec3& glmVector);
|
||||||
QVariantMap glmToQMap(const glm::quat& glmQuat);
|
QVariantMap glmToQMap(const glm::quat& glmQuat);
|
||||||
|
|
||||||
glm::vec3 qListToGlmVec3(const QVariant q);
|
glm::vec3 qListToGlmVec3(const QVariant& q);
|
||||||
glm::quat qListToGlmQuat(const QVariant q);
|
glm::quat qListToGlmQuat(const QVariant& q);
|
||||||
void qListtoRgbColor(const QVariant q, rgbColor returnValue);
|
void qListtoRgbColor(const QVariant& q, rgbColor& returnValue);
|
||||||
|
|
|
@ -229,6 +229,7 @@ QScriptValue collisionToScriptValue(QScriptEngine* engine, const Collision& coll
|
||||||
obj.setProperty("idB", quuidToScriptValue(engine, collision.idB));
|
obj.setProperty("idB", quuidToScriptValue(engine, collision.idB));
|
||||||
obj.setProperty("penetration", vec3toScriptValue(engine, collision.penetration));
|
obj.setProperty("penetration", vec3toScriptValue(engine, collision.penetration));
|
||||||
obj.setProperty("contactPoint", vec3toScriptValue(engine, collision.contactPoint));
|
obj.setProperty("contactPoint", vec3toScriptValue(engine, collision.contactPoint));
|
||||||
|
obj.setProperty("velocityChange", vec3toScriptValue(engine, collision.velocityChange));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue