mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 17:23:29 +02:00
Merge branch 'master' of https://github.com/worklist/hifi into 20638
This commit is contained in:
commit
1664792e00
7 changed files with 1545 additions and 105 deletions
439
examples/example/widgets-example.js
Normal file
439
examples/example/widgets-example.js
Normal file
|
@ -0,0 +1,439 @@
|
|||
//
|
||||
// widgets-example.js
|
||||
// games
|
||||
//
|
||||
// Copyright 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
|
||||
//
|
||||
|
||||
var paddingX = 8;
|
||||
var paddingY = 8;
|
||||
var buttonWidth = 30;
|
||||
var buttonHeight = 30;
|
||||
|
||||
var ICONS_URL = 'https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Scripts/planets/images/';
|
||||
|
||||
var panelX = 1250;
|
||||
var panelY = 500;
|
||||
var panelWidth = 50;
|
||||
var panelHeight = 210;
|
||||
|
||||
// var mainPanel = new UIPanel(panelX, panelY, panelWidth, panelHeight);
|
||||
// var systemViewButton = mainPanel.addImage('solarsystems');
|
||||
// var zoomButton = mainPanel.addImage('magnifier');
|
||||
// var satelliteButton = mainPanel.addImage('satellite');
|
||||
// var settingsButton = mainPanel.addImage('settings');
|
||||
// var stopButton = mainPanel.addImage('close');
|
||||
//
|
||||
// mainPanel.show();
|
||||
//
|
||||
// var systemViewPanel = new UIPanel(panelX - 120, panelY, 120, 40);
|
||||
// var reverseButton = systemViewPanel.addImage('reverse');
|
||||
// var pauseButton = systemViewPanel.addImage('playpause');
|
||||
// var forwardButton = systemViewPanel.addImage('forward');
|
||||
//
|
||||
// var zoomPanel = new UIPanel(panelX - 60, panelY + buttonHeight + paddingY, 650, 50);
|
||||
// for (var i = 0; i < planets.length; ++i) {
|
||||
// zoomPanel.addText(planets[i].name);
|
||||
// }
|
||||
Script.include('../libraries/uiwidgets.js');
|
||||
|
||||
UI.setDefaultVisibility(true);
|
||||
UI.setErrorHandler(function(err) {
|
||||
teardown();
|
||||
// print(err);
|
||||
// Script.stop();
|
||||
});
|
||||
|
||||
// Controller.mouseMoveEvent.connect(function panelMouseMoveEvent(event) { return settings.mouseMoveEvent(event); });
|
||||
// Controller.mousePressEvent.connect( function panelMousePressEvent(event) { return settings.mousePressEvent(event); });
|
||||
// Controller.mouseDoublePressEvent.connect( function panelMouseDoublePressEvent(event) { return settings.mouseDoublePressEvent(event); });
|
||||
// Controller.mouseReleaseEvent.connect(function(event) { return settings.mouseReleaseEvent(event); });
|
||||
// Controller.keyPressEvent.connect(function(event) { return settings.keyPressEvent(event); });
|
||||
|
||||
// var ICON_WIDTH = 50.0;
|
||||
// var ICON_HEIGHT = 50.0;
|
||||
var ICON_WIDTH = 40.0;
|
||||
var ICON_HEIGHT = 40.0;
|
||||
var ICON_COLOR = UI.rgba(45, 45, 45, 0.7);
|
||||
var FOCUSED_COLOR = UI.rgba(250, 250, 250, 1.0);
|
||||
|
||||
var PANEL_BACKGROUND_COLOR = UI.rgba(50, 50, 50, 0.7);
|
||||
|
||||
var PANEL_PADDING = 7.0;
|
||||
var PANEL_BORDER = 12.0;
|
||||
var SUBPANEL_GAP = 1.0;
|
||||
|
||||
var icons = [];
|
||||
function addImage(panel, iconId) {
|
||||
var icon = panel.add(new UI.Image({
|
||||
'imageURL': ICONS_URL + iconId + '.svg',
|
||||
'width': ICON_WIDTH,
|
||||
'height': ICON_HEIGHT,
|
||||
'color': ICON_COLOR,
|
||||
'alpha': ICON_COLOR.a
|
||||
}));
|
||||
icons.push(icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
var panels = [];
|
||||
function addPanel (properties) {
|
||||
properties.background = properties.background || {};
|
||||
properties.background.backgroundColor = properties.background.backgroundColor ||
|
||||
PANEL_BACKGROUND_COLOR;
|
||||
properties.background.backgroundAlpha = properties.background.backgroundAlpha ||
|
||||
PANEL_BACKGROUND_COLOR.a;
|
||||
properties.padding = properties.padding || { x: PANEL_PADDING, y: PANEL_PADDING };
|
||||
properties.border = properties.border || { x: PANEL_BORDER, y: PANEL_BORDER };
|
||||
|
||||
var panel = new UI.WidgetStack(properties);
|
||||
panels.push(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
function makeDraggable (panel, target) {
|
||||
if (!target)
|
||||
target = panel;
|
||||
|
||||
var dragStart = null;
|
||||
var initialPos = null;
|
||||
|
||||
panel.addAction('onDragBegin', function (event) {
|
||||
dragStart = { x: event.x, y: event.y };
|
||||
initialPos = { x: target.position.x, y: target.position.y };
|
||||
});
|
||||
panel.addAction('onDragUpdate', function (event) {
|
||||
target.setPosition(
|
||||
initialPos.x + event.x - dragStart.x,
|
||||
initialPos.y + event.y - dragStart.y
|
||||
);
|
||||
UI.updateLayout();
|
||||
});
|
||||
panel.addAction('onDragEnd', function () {
|
||||
dragStart = dragEnd = null;
|
||||
});
|
||||
}
|
||||
|
||||
// var panelContainer = new UI.WidgetContainer();
|
||||
// panelContainer.setPosition(500, 250);
|
||||
// panelContainer.setVisible(true);
|
||||
|
||||
var demoPane = addPanel({ dir: '+y' });
|
||||
var demoLabel = demoPane.add(new UI.Label({
|
||||
text: "< no events >",
|
||||
width: 400, height: 20
|
||||
}));
|
||||
var demoButton = demoPane.add(new UI.Box({
|
||||
width: 200, height: 80,
|
||||
text: "Button"
|
||||
}));
|
||||
function setText(text) {
|
||||
return function () {
|
||||
demoLabel.setText(text);
|
||||
UI.updateLayout();
|
||||
};
|
||||
}
|
||||
function addDebugActions(widget, msg, actions) {
|
||||
actions.forEach(function(action) {
|
||||
widget.addAction(action, setText(action + " " + msg + widget));
|
||||
});
|
||||
}
|
||||
|
||||
var debugEvents = [
|
||||
'onMouseOver',
|
||||
'onMouseExit',
|
||||
'onMouseDown',
|
||||
'onMouseUp',
|
||||
'onDragBegin',
|
||||
'onDragEnd',
|
||||
'onDragUpdate'
|
||||
];
|
||||
addDebugActions(demoPane, "(container) ", debugEvents);
|
||||
addDebugActions(demoButton, "(button) ", debugEvents);
|
||||
addDebugActions(demoLabel, "(label) ", debugEvents);
|
||||
|
||||
// demoPane.addAction('onMouseOver', setText("onMouseOver " + demoPane));
|
||||
// demoPane.addAction('onMouseExit', setText("onMouseExit " + demoPane));
|
||||
// demoPane.addAction('onMouseDown', setText("onMouseDown " + demoPane));
|
||||
// demoPane.addAction('onMouseUp', setText("onMouseUp " + demoPane));
|
||||
makeDraggable(demoPane, demoPane);
|
||||
demoPane.setPosition(600, 200);
|
||||
|
||||
// demoButton.addAction('onMouseOver', setText("onMouseOver " + demoButton));
|
||||
// demoButton.addAction('onMouseExit', setText("onMouseExit " + demoButton));
|
||||
// demoButton.addAction()
|
||||
|
||||
// var resizablePanel = new UI.Label({
|
||||
// text: "Resizable panel",
|
||||
// width: 200, height: 200,
|
||||
// backgroundAlpha: 0.5
|
||||
// });
|
||||
// resizablePanel.setPosition(1100, 200);
|
||||
|
||||
var debugToggle = new UI.Box({
|
||||
text: "debug", width: 150, height: 20
|
||||
});
|
||||
debugToggle.setPosition(200, 0);
|
||||
debugToggle.addAction('onClick', function () {
|
||||
UI.debug.setVisible(!UI.debug.isVisible());
|
||||
});
|
||||
|
||||
// debugEvents.forEach(function (action) {
|
||||
// resizablePanel.addAction(action, function (event, widget) {
|
||||
// widget.setText(action + " " + widget);
|
||||
// });
|
||||
// })
|
||||
|
||||
function join(obj) {
|
||||
var s = "{";
|
||||
var sep = "\n";
|
||||
for (var k in obj) {
|
||||
s += sep + k + ": " + (""+obj[k]).replace("\n", "\n");
|
||||
sep = ",\n";
|
||||
}
|
||||
if (s.length > 1)
|
||||
return s + " }";
|
||||
return s + "}";
|
||||
}
|
||||
|
||||
// resizablePanel.getOverlay().update({
|
||||
// text: "" + join(resizablePanel.actions)
|
||||
// });
|
||||
|
||||
|
||||
setText = addDebugActions = undefined;
|
||||
|
||||
|
||||
var tooltipWidget = new UI.Label({
|
||||
text: "<tooltip>",
|
||||
width: 500, height: 20,
|
||||
visible: false
|
||||
});
|
||||
function addTooltip (widget, text) {
|
||||
widget.addAction('onMouseOver', function (event, widget) {
|
||||
tooltipWidget.setVisible(true);
|
||||
tooltipWidget.setPosition(widget.position.x + widget.getWidth() + 20, widget.position.y);
|
||||
tooltipWidget.setText(text);
|
||||
UI.updateLayout();
|
||||
});
|
||||
widget.addAction('onMouseExit', function () {
|
||||
tooltipWidget.setVisible(false);
|
||||
UI.updateLayout();
|
||||
});
|
||||
}
|
||||
|
||||
var mainPanel = addPanel({ dir: '+y' });
|
||||
mainPanel.setPosition(500, 250);
|
||||
mainPanel.setVisible(true);
|
||||
|
||||
var systemViewButton = addImage(mainPanel, 'solarsystems');
|
||||
var zoomButton = addImage(mainPanel, 'magnifier');
|
||||
var satelliteButton = addImage(mainPanel, 'satellite');
|
||||
var settingsButton = addImage(mainPanel, 'settings');
|
||||
var stopButton = addImage(mainPanel, 'close');
|
||||
|
||||
|
||||
addTooltip(systemViewButton, "system view");
|
||||
addTooltip(zoomButton, "zoom");
|
||||
addTooltip(satelliteButton, "satelite view");
|
||||
addTooltip(settingsButton, "settings");
|
||||
addTooltip(stopButton, "exit");
|
||||
|
||||
var systemViewPanel = addPanel({ dir: '+x', visible: false });
|
||||
var reverseButton = addImage(systemViewPanel, 'reverse');
|
||||
var pauseButton = addImage(systemViewPanel, 'playpause');
|
||||
var forwardButton = addImage(systemViewPanel, 'forward');
|
||||
|
||||
var zoomPanel = addPanel({ dir: '+y', visible: true });
|
||||
var label = new UI.Label({
|
||||
text: "Foo",
|
||||
width: 120,
|
||||
height: 15,
|
||||
color: UI.rgb(245, 290, 20),
|
||||
alpha: 1.0,
|
||||
backgroundColor: UI.rgb(10, 10, 10),
|
||||
backgroundAlpha: 0.0
|
||||
});
|
||||
zoomPanel.add(label);
|
||||
label.addAction('onMouseOver', function () {
|
||||
label.setText("Bar");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.addAction('onMouseExit', function () {
|
||||
label.setText("Foo");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.setText("Label id: " + label.id + ", parent id " + label.parent.id);
|
||||
label.parent.addAction('onMouseOver', function () {
|
||||
label.setText("on parent");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.parent.addAction('onMouseExit', function () {
|
||||
label.setText('exited parent');
|
||||
UI.updateLayout();
|
||||
});
|
||||
|
||||
var sliderLayout = zoomPanel.add(new UI.WidgetStack({
|
||||
dir: '+x', visible: true, backgroundAlpha: 0.0
|
||||
}));
|
||||
var sliderLabel = sliderLayout.add(new UI.Label({
|
||||
text: " ", width: 45, height: 20
|
||||
}));
|
||||
var slider = sliderLayout.add(new UI.Slider({
|
||||
value: 10, maxValue: 100, minValue: 0,
|
||||
width: 300, height: 20,
|
||||
backgroundColor: UI.rgb(10, 10, 10),
|
||||
backgroundAlpha: 1.0,
|
||||
slider: { // slider knob
|
||||
width: 30,
|
||||
height: 18,
|
||||
backgroundColor: UI.rgb(120, 120, 120),
|
||||
backgroundAlpha: 1.0
|
||||
}
|
||||
}));
|
||||
sliderLabel.setText("" + (+slider.getValue().toFixed(1)));
|
||||
slider.onValueChanged = function (value) {
|
||||
sliderLabel.setText("" + (+value.toFixed(1)));
|
||||
UI.updateLayout();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var checkBoxLayout = zoomPanel.add(new UI.WidgetStack({
|
||||
dir: '+x', visible: true, backgroundAlpha: 0.0
|
||||
}));
|
||||
// var padding = checkBoxLayout.add(new UI.Label({
|
||||
// text: " ", width: 45, height: 20
|
||||
// }));
|
||||
var checkBoxLabel = checkBoxLayout.add(new UI.Label({
|
||||
text: "set red", width: 60, height: 20,
|
||||
backgroundAlpha: 0.0
|
||||
}));
|
||||
checkBoxLabel.setText("set red");
|
||||
|
||||
var defaultColor = UI.rgb(10, 10, 10);
|
||||
var redColor = UI.rgb(210, 80, 80);
|
||||
|
||||
var checkbox = checkBoxLayout.add(new UI.Checkbox({
|
||||
width: 20, height: 20, padding: { x: 3, y: 3 },
|
||||
backgroundColor: defaultColor,
|
||||
backgroundAlpha: 0.9,
|
||||
checked: false,
|
||||
onValueChanged: function (red) {
|
||||
zoomPanel.getOverlay().update({
|
||||
// backgroundAlpha: 0.1,
|
||||
backgroundColor: red ? redColor : defaultColor
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
addImage(zoomPanel, 'reverse');
|
||||
UI.updateLayout();
|
||||
|
||||
var subpanels = [ systemViewPanel, zoomPanel ];
|
||||
function hideSubpanelsExcept (panel) {
|
||||
subpanels.forEach(function (x) {
|
||||
if (x != panel) {
|
||||
x.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function attachPanel (panel, button) {
|
||||
button.addAction('onClick', function () {
|
||||
hideSubpanelsExcept(panel);
|
||||
panel.setVisible(!panel.isVisible());
|
||||
UI.updateLayout();
|
||||
})
|
||||
|
||||
UI.addAttachment(panel, button, function (target, rel) {
|
||||
target.setPosition(
|
||||
rel.position.x - (target.getWidth() + target.border.x + SUBPANEL_GAP),
|
||||
rel.position.y - target.border.y
|
||||
);
|
||||
});
|
||||
}
|
||||
attachPanel(systemViewPanel, systemViewButton);
|
||||
attachPanel(zoomPanel, zoomButton);
|
||||
|
||||
var addColorToggle = function (widget) {
|
||||
widget.addAction('onMouseOver', function () {
|
||||
widget.setColor(FOCUSED_COLOR);
|
||||
});
|
||||
widget.addAction('onMouseExit', function () {
|
||||
widget.setColor(ICON_COLOR);
|
||||
});
|
||||
}
|
||||
|
||||
reverseButton.addAction('onClick', function() {});
|
||||
|
||||
systemViewPanel.addAction('onMouseOver', function() {
|
||||
hideSubpanels();
|
||||
UI.updateLayout();
|
||||
});
|
||||
|
||||
|
||||
zoomButton.addAction('onClick', function() {
|
||||
hideSubpanels();
|
||||
UI.updateLayout();
|
||||
});
|
||||
UI.updateLayout();
|
||||
|
||||
stopButton.addAction('onClick', function() {
|
||||
// Script.stop();
|
||||
teardown();
|
||||
});
|
||||
|
||||
// Panel drag behavior
|
||||
// (click + drag on border to drag)
|
||||
(function () {
|
||||
var dragged = null;
|
||||
this.startDrag = function (dragAction) {
|
||||
dragged = dragAction;
|
||||
}
|
||||
this.updateDrag = function (event) {
|
||||
if (dragged) {
|
||||
print("Update drag");
|
||||
dragged.updateDrag(event);
|
||||
}
|
||||
}
|
||||
this.clearDrag = function (event) {
|
||||
if (dragged)
|
||||
print("End drag");
|
||||
dragged = null;
|
||||
}
|
||||
})();
|
||||
|
||||
var buttons = icons;
|
||||
|
||||
buttons.map(addColorToggle);
|
||||
panels.map(function (panel) { makeDraggable(panel, mainPanel); });
|
||||
|
||||
// Cleanup script resources
|
||||
function teardown() {
|
||||
UI.teardown();
|
||||
|
||||
// etc...
|
||||
};
|
||||
|
||||
var inputHandler = {
|
||||
onMouseMove: function (event) {
|
||||
updateDrag(event);
|
||||
UI.handleMouseMove(event);
|
||||
},
|
||||
onMousePress: function (event) {
|
||||
UI.handleMousePress(event);
|
||||
},
|
||||
onMouseRelease: function (event) {
|
||||
clearDrag(event);
|
||||
UI.handleMouseRelease(event);
|
||||
}
|
||||
};
|
||||
Controller.mousePressEvent.connect(inputHandler.onMousePress);
|
||||
Controller.mouseMoveEvent.connect(inputHandler.onMouseMove);
|
||||
Controller.mouseReleaseEvent.connect(inputHandler.onMouseRelease);
|
||||
|
||||
Script.scriptEnding.connect(teardown);
|
1021
examples/libraries/uiwidgets.js
Normal file
1021
examples/libraries/uiwidgets.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -161,16 +161,6 @@ QByteArray AvatarData::toByteArray() {
|
|||
// Body scale
|
||||
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale);
|
||||
|
||||
// Head rotation
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalPitch());
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw());
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll());
|
||||
|
||||
// Body lean
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist);
|
||||
|
||||
// Lookat Position
|
||||
memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition));
|
||||
destinationBuffer += sizeof(_headData->_lookAtPosition);
|
||||
|
@ -278,25 +268,20 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
quint64 now = usecTimestampNow();
|
||||
|
||||
// The absolute minimum size of the update data is as follows:
|
||||
// 50 bytes of "plain old data" {
|
||||
// 36 bytes of "plain old data" {
|
||||
// position = 12 bytes
|
||||
// bodyYaw = 2 (compressed float)
|
||||
// bodyPitch = 2 (compressed float)
|
||||
// bodyRoll = 2 (compressed float)
|
||||
// targetScale = 2 (compressed float)
|
||||
// headPitch = 2 (compressed float)
|
||||
// headYaw = 2 (compressed float)
|
||||
// headRoll = 2 (compressed float)
|
||||
// leanForward = 2 (compressed float)
|
||||
// leanSideways = 2 (compressed float)
|
||||
// torsoTwist = 2 (compressed float)
|
||||
// lookAt = 12
|
||||
// audioLoudness = 4
|
||||
// }
|
||||
// + 1 byte for varying data
|
||||
// + 1 byte for pupilSize
|
||||
// + 1 byte for numJoints (0)
|
||||
// = 51 bytes
|
||||
int minPossibleSize = 51;
|
||||
// = 39 bytes
|
||||
int minPossibleSize = 39;
|
||||
|
||||
int maxAvailableSize = buffer.size();
|
||||
if (minPossibleSize > maxAvailableSize) {
|
||||
|
@ -354,39 +339,6 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
_targetScale = scale;
|
||||
} // 20 bytes
|
||||
|
||||
{ // Head rotation
|
||||
//(NOTE: This needs to become a quaternion to save two bytes)
|
||||
float headYaw, headPitch, headRoll;
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headPitch);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headRoll);
|
||||
if (glm::isnan(headYaw) || glm::isnan(headPitch) || glm::isnan(headRoll)) {
|
||||
if (shouldLogError(now)) {
|
||||
qCDebug(avatars) << "Discard nan AvatarData::headYaw,headPitch,headRoll; displayName = '" << _displayName << "'";
|
||||
}
|
||||
return maxAvailableSize;
|
||||
}
|
||||
_headData->setBasePitch(headPitch);
|
||||
_headData->setBaseYaw(headYaw);
|
||||
_headData->setBaseRoll(headRoll);
|
||||
} // 6 bytes
|
||||
|
||||
{ // Head lean (relative to pelvis)
|
||||
float leanForward, leanSideways, torsoTwist;
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanForward);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanSideways);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &torsoTwist);
|
||||
if (glm::isnan(leanForward) || glm::isnan(leanSideways)) {
|
||||
if (shouldLogError(now)) {
|
||||
qCDebug(avatars) << "Discard nan AvatarData::leanForward,leanSideways,torsoTwise; displayName = '" << _displayName << "'";
|
||||
}
|
||||
return maxAvailableSize;
|
||||
}
|
||||
_headData->_leanForward = leanForward;
|
||||
_headData->_leanSideways = leanSideways;
|
||||
_headData->_torsoTwist = torsoTwist;
|
||||
} // 6 bytes
|
||||
|
||||
{ // Lookat Position
|
||||
glm::vec3 lookAt;
|
||||
memcpy(&lookAt, sourceBuffer, sizeof(lookAt));
|
||||
|
|
|
@ -1185,74 +1185,84 @@ void EntityItem::setDimensions(const glm::vec3& value) {
|
|||
return;
|
||||
}
|
||||
_transform.setScale(value);
|
||||
requiresRecalcBoxes();
|
||||
}
|
||||
|
||||
/// The maximum bounding cube for the entity, independent of it's rotation.
|
||||
/// This accounts for the registration point (upon which rotation occurs around).
|
||||
///
|
||||
AACube EntityItem::getMaximumAACube() const {
|
||||
// * we know that the position is the center of rotation
|
||||
glm::vec3 centerOfRotation = getPosition(); // also where _registration point is
|
||||
const AACube& EntityItem::getMaximumAACube() const {
|
||||
if (_recalcMaxAACube) {
|
||||
// * we know that the position is the center of rotation
|
||||
glm::vec3 centerOfRotation = getPosition(); // also where _registration point is
|
||||
|
||||
// * we know that the registration point is the center of rotation
|
||||
// * we can calculate the length of the furthest extent from the registration point
|
||||
// as the dimensions * max (registrationPoint, (1.0,1.0,1.0) - registrationPoint)
|
||||
glm::vec3 registrationPoint = (getDimensions() * getRegistrationPoint());
|
||||
glm::vec3 registrationRemainder = (getDimensions() * (glm::vec3(1.0f, 1.0f, 1.0f) - getRegistrationPoint()));
|
||||
glm::vec3 furthestExtentFromRegistration = glm::max(registrationPoint, registrationRemainder);
|
||||
// * we know that the registration point is the center of rotation
|
||||
// * we can calculate the length of the furthest extent from the registration point
|
||||
// as the dimensions * max (registrationPoint, (1.0,1.0,1.0) - registrationPoint)
|
||||
glm::vec3 registrationPoint = (getDimensions() * getRegistrationPoint());
|
||||
glm::vec3 registrationRemainder = (getDimensions() * (glm::vec3(1.0f, 1.0f, 1.0f) - getRegistrationPoint()));
|
||||
glm::vec3 furthestExtentFromRegistration = glm::max(registrationPoint, registrationRemainder);
|
||||
|
||||
// * we know that if you rotate in any direction you would create a sphere
|
||||
// that has a radius of the length of furthest extent from registration point
|
||||
float radius = glm::length(furthestExtentFromRegistration);
|
||||
// * we know that if you rotate in any direction you would create a sphere
|
||||
// that has a radius of the length of furthest extent from registration point
|
||||
float radius = glm::length(furthestExtentFromRegistration);
|
||||
|
||||
// * we know that the minimum bounding cube of this maximum possible sphere is
|
||||
// (center - radius) to (center + radius)
|
||||
glm::vec3 minimumCorner = centerOfRotation - glm::vec3(radius, radius, radius);
|
||||
// * we know that the minimum bounding cube of this maximum possible sphere is
|
||||
// (center - radius) to (center + radius)
|
||||
glm::vec3 minimumCorner = centerOfRotation - glm::vec3(radius, radius, radius);
|
||||
|
||||
AACube boundingCube(minimumCorner, radius * 2.0f);
|
||||
return boundingCube;
|
||||
_maxAACube = AACube(minimumCorner, radius * 2.0f);
|
||||
_recalcMaxAACube = false;
|
||||
}
|
||||
return _maxAACube;
|
||||
}
|
||||
|
||||
/// The minimum bounding cube for the entity accounting for it's rotation.
|
||||
/// This accounts for the registration point (upon which rotation occurs around).
|
||||
///
|
||||
AACube EntityItem::getMinimumAACube() const {
|
||||
// _position represents the position of the registration point.
|
||||
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
|
||||
const AACube& EntityItem::getMinimumAACube() const {
|
||||
if (_recalcMinAACube) {
|
||||
// _position represents the position of the registration point.
|
||||
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
|
||||
|
||||
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * getRegistrationPoint());
|
||||
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
|
||||
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
|
||||
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
|
||||
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * getRegistrationPoint());
|
||||
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
|
||||
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
|
||||
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
|
||||
|
||||
// shift the extents to be relative to the position/registration point
|
||||
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
|
||||
// shift the extents to be relative to the position/registration point
|
||||
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
|
||||
|
||||
// the cube that best encompasses extents is...
|
||||
AABox box(rotatedExtentsRelativeToRegistrationPoint);
|
||||
glm::vec3 centerOfBox = box.calcCenter();
|
||||
float longestSide = box.getLargestDimension();
|
||||
float halfLongestSide = longestSide / 2.0f;
|
||||
glm::vec3 cornerOfCube = centerOfBox - glm::vec3(halfLongestSide, halfLongestSide, halfLongestSide);
|
||||
// the cube that best encompasses extents is...
|
||||
AABox box(rotatedExtentsRelativeToRegistrationPoint);
|
||||
glm::vec3 centerOfBox = box.calcCenter();
|
||||
float longestSide = box.getLargestDimension();
|
||||
float halfLongestSide = longestSide / 2.0f;
|
||||
glm::vec3 cornerOfCube = centerOfBox - glm::vec3(halfLongestSide, halfLongestSide, halfLongestSide);
|
||||
|
||||
|
||||
// old implementation... not correct!!!
|
||||
return AACube(cornerOfCube, longestSide);
|
||||
_minAACube = AACube(cornerOfCube, longestSide);
|
||||
_recalcMinAACube = false;
|
||||
}
|
||||
return _minAACube;
|
||||
}
|
||||
|
||||
AABox EntityItem::getAABox() const {
|
||||
// _position represents the position of the registration point.
|
||||
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
|
||||
const AABox& EntityItem::getAABox() const {
|
||||
if (_recalcAABox) {
|
||||
// _position represents the position of the registration point.
|
||||
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
|
||||
|
||||
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * _registrationPoint);
|
||||
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
|
||||
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
|
||||
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
|
||||
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * _registrationPoint);
|
||||
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
|
||||
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
|
||||
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
|
||||
|
||||
// shift the extents to be relative to the position/registration point
|
||||
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
|
||||
// shift the extents to be relative to the position/registration point
|
||||
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
|
||||
|
||||
return AABox(rotatedExtentsRelativeToRegistrationPoint);
|
||||
_cachedAABox = AABox(rotatedExtentsRelativeToRegistrationPoint);
|
||||
_recalcAABox = false;
|
||||
}
|
||||
return _cachedAABox;
|
||||
}
|
||||
|
||||
// NOTE: This should only be used in cases of old bitstreams which only contain radius data
|
||||
|
|
|
@ -214,14 +214,16 @@ public:
|
|||
void setTranformToCenter(const Transform& transform);
|
||||
|
||||
inline const Transform& getTransform() const { return _transform; }
|
||||
inline void setTransform(const Transform& transform) { _transform = transform; }
|
||||
inline void setTransform(const Transform& transform) { _transform = transform; requiresRecalcBoxes(); }
|
||||
|
||||
/// Position in meters (0.0 - TREE_SCALE)
|
||||
inline const glm::vec3& getPosition() const { return _transform.getTranslation(); }
|
||||
inline void setPosition(const glm::vec3& value) { _transform.setTranslation(value); }
|
||||
inline void setPosition(const glm::vec3& value) { _transform.setTranslation(value); requiresRecalcBoxes(); }
|
||||
|
||||
inline const glm::quat& getRotation() const { return _transform.getRotation(); }
|
||||
inline void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); }
|
||||
inline void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); requiresRecalcBoxes(); }
|
||||
|
||||
inline void requiresRecalcBoxes() { _recalcAABox = true; _recalcMinAACube = true; _recalcMaxAACube = true; }
|
||||
|
||||
// Hyperlink related getters and setters
|
||||
QString getHref() const { return _href; }
|
||||
|
@ -286,9 +288,9 @@ public:
|
|||
quint64 getExpiry() const;
|
||||
|
||||
// position, size, and bounds related helpers
|
||||
AACube getMaximumAACube() const;
|
||||
AACube getMinimumAACube() const;
|
||||
AABox getAABox() const; /// axis aligned bounding box in world-frame (meters)
|
||||
const AACube& getMaximumAACube() const;
|
||||
const AACube& getMinimumAACube() const;
|
||||
const AABox& getAABox() const; /// axis aligned bounding box in world-frame (meters)
|
||||
|
||||
const QString& getScript() const { return _script; }
|
||||
void setScript(const QString& value) { _script = value; }
|
||||
|
@ -303,7 +305,7 @@ public:
|
|||
|
||||
/// registration point as ratio of entity
|
||||
void setRegistrationPoint(const glm::vec3& value)
|
||||
{ _registrationPoint = glm::clamp(value, 0.0f, 1.0f); }
|
||||
{ _registrationPoint = glm::clamp(value, 0.0f, 1.0f); requiresRecalcBoxes(); }
|
||||
|
||||
const glm::vec3& getAngularVelocity() const { return _angularVelocity; }
|
||||
void setAngularVelocity(const glm::vec3& value) { _angularVelocity = value; }
|
||||
|
@ -434,6 +436,13 @@ protected:
|
|||
quint64 _changedOnServer;
|
||||
|
||||
Transform _transform;
|
||||
mutable AABox _cachedAABox;
|
||||
mutable AACube _maxAACube;
|
||||
mutable AACube _minAACube;
|
||||
mutable bool _recalcAABox = true;
|
||||
mutable bool _recalcMinAACube = true;
|
||||
mutable bool _recalcMaxAACube = true;
|
||||
|
||||
float _glowLevel;
|
||||
float _localRenderAlpha;
|
||||
float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3
|
||||
|
|
|
@ -65,7 +65,14 @@ ViveControllerManager::ViveControllerManager() :
|
|||
|
||||
bool ViveControllerManager::isSupported() const {
|
||||
#ifdef Q_OS_WIN
|
||||
return vr::VR_IsHmdPresent();
|
||||
bool success = vr::VR_IsHmdPresent();
|
||||
if (success) {
|
||||
vr::HmdError eError = vr::HmdError_None;
|
||||
auto hmd = vr::VR_Init(&eError);
|
||||
success = (hmd != nullptr);
|
||||
vr::VR_Shutdown();
|
||||
}
|
||||
return success;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
|
@ -68,6 +68,8 @@ PacketVersion versionForPacketType(PacketType::Value packetType) {
|
|||
case EntityEdit:
|
||||
case EntityData:
|
||||
return VERSION_ENTITIES_POLYLINE;
|
||||
case AvatarData:
|
||||
return 12;
|
||||
default:
|
||||
return 11;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue