mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
Merge remote-tracking branch 'hifi/master'
This commit is contained in:
commit
80323e8b69
52 changed files with 1767 additions and 950 deletions
|
@ -19,14 +19,17 @@ function setupMenus() {
|
|||
if (!Menu.menuExists("Developer > Entities")) {
|
||||
Menu.addMenu("Developer > Entities");
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Children", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt to Reduce Material Switches", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false });
|
||||
Menu.addMenu("Developer > Entities > Culling");
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Out Of View Mesh Parts", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Too Small Mesh Parts", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2554,7 +2554,7 @@ function mousePressEvent(event) {
|
|||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
Vec3.print("[Mouse] Looking at: ", pickRay.origin);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay, true); // we want precision picking here
|
||||
|
||||
if(!foundIntersection.accurate) {
|
||||
return;
|
||||
|
|
|
@ -465,7 +465,7 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
|||
function findClickedEntity(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay, true); // want precision picking
|
||||
|
||||
if (!foundIntersection.accurate) {
|
||||
return null;
|
||||
|
|
598
examples/virtualKeyboard.js
Normal file
598
examples/virtualKeyboard.js
Normal file
|
@ -0,0 +1,598 @@
|
|||
//
|
||||
// virtualKeyboard.js
|
||||
// examples
|
||||
//
|
||||
// Created by Thijs Wenker on 11/18/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Control a virtual keyboard using your favorite HMD.
|
||||
// Usage: Enable VR-mode and go to First person mode,
|
||||
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
||||
//
|
||||
// leased some code from newEditEntities.js for Text Entity example
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
Script.include("libraries/globals.js");
|
||||
|
||||
const KBD_UPPERCASE_DEFAULT = 0;
|
||||
const KBD_LOWERCASE_DEFAULT = 1;
|
||||
const KBD_UPPERCASE_HOVER = 2;
|
||||
const KBD_LOWERCASE_HOVER = 3;
|
||||
const KBD_BACKGROUND = 4;
|
||||
|
||||
const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg";
|
||||
const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg";
|
||||
|
||||
const SPACEBAR_CHARCODE = 32;
|
||||
|
||||
const KEYBOARD_WIDTH = 1174.7;
|
||||
const KEYBOARD_HEIGHT = 434.1;
|
||||
|
||||
const CURSOR_WIDTH = 33.9;
|
||||
const CURSOR_HEIGHT = 33.9;
|
||||
|
||||
// VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement.
|
||||
// Try setting it to 60 if it goes too fast for you.
|
||||
const VIEW_ANGLE = 40.0;
|
||||
const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2;
|
||||
|
||||
const SPAWN_DISTANCE = 1;
|
||||
const DEFAULT_TEXT_DIMENSION_Z = 0.02;
|
||||
|
||||
const BOUND_X = 0;
|
||||
const BOUND_Y = 1;
|
||||
const BOUND_W = 2;
|
||||
const BOUND_H = 3;
|
||||
|
||||
const KEY_STATE_LOWER = 0;
|
||||
const KEY_STATE_UPPER = 1;
|
||||
|
||||
const TEXT_MARGIN_TOP = 0.15;
|
||||
const TEXT_MARGIN_LEFT = 0.15;
|
||||
const TEXT_MARGIN_RIGHT = 0.17;
|
||||
const TEXT_MARGIN_BOTTOM = 0.17;
|
||||
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
var cursor = null;
|
||||
var keyboard = new Keyboard();
|
||||
var textFontSize = 9;
|
||||
var text = null;
|
||||
var textText = "";
|
||||
var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false});
|
||||
|
||||
function appendChar(char) {
|
||||
textText += char;
|
||||
updateTextOverlay();
|
||||
Overlays.editOverlay(text, {text: textText});
|
||||
}
|
||||
|
||||
function deleteChar() {
|
||||
if (textText.length > 0) {
|
||||
textText = textText.substring(0, textText.length - 1);
|
||||
updateTextOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
function updateTextOverlay() {
|
||||
var textLines = textText.split("\n");
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(text, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90;
|
||||
var maxFontSize = 190 / textLines.length;
|
||||
textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize;
|
||||
var topMargin = (250 - (textFontSize * textLines.length)) / 4;
|
||||
Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin});
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(text, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2});
|
||||
}
|
||||
|
||||
keyboard.onKeyPress = function(event) {
|
||||
if (event.event == 'keypress') {
|
||||
appendChar(event.char);
|
||||
} else if (event.event == 'enter') {
|
||||
appendChar("\n");
|
||||
}
|
||||
};
|
||||
|
||||
keyboard.onKeyRelease = function(event) {
|
||||
print("Key release event test");
|
||||
// you can cancel a key by releasing its focusing before releasing it
|
||||
if (event.focus) {
|
||||
if (event.event == 'delete') {
|
||||
deleteChar();
|
||||
} else if (event.event == 'submit') {
|
||||
print(textText);
|
||||
|
||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||
|
||||
var textLines = textText.split("\n");
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(textSizeMeasureOverlay, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
var usernameLine = "--" + GlobalServices.myUsername;
|
||||
var usernameWidth = Overlays.textWidth(textSizeMeasureOverlay, usernameLine);
|
||||
if (maxLineWidth < usernameWidth) {
|
||||
maxLineWidth = usernameWidth;
|
||||
} else {
|
||||
var spaceableWidth = maxLineWidth - usernameWidth;
|
||||
var spaceWidth = Overlays.textWidth(textSizeMeasureOverlay, " ");
|
||||
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
|
||||
for (var i = 0; i < numberOfSpaces; i++) {
|
||||
usernameLine = " " + usernameLine;
|
||||
}
|
||||
}
|
||||
var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
|
||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||
Entities.addEntity({
|
||||
type: "Text",
|
||||
rotation: MyAvatar.orientation,
|
||||
position: position,
|
||||
dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z },
|
||||
backgroundColor: { red: 0, green: 0, blue: 0 },
|
||||
textColor: { red: 255, green: 255, blue: 255 },
|
||||
text: textText + "\n" + usernameLine
|
||||
});
|
||||
}
|
||||
textText = "";
|
||||
updateTextOverlay();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
keyboard.onFullyLoaded = function() {
|
||||
print("Virtual-keyboard fully loaded.");
|
||||
var dimensions = Controller.getViewportDimensions();
|
||||
text = Overlays.addOverlay("text", {
|
||||
x: 0,
|
||||
y: dimensions.y - keyboard.height() - 260,
|
||||
width: dimensions.x,
|
||||
height: 250,
|
||||
backgroundColor: { red: 255, green: 255, blue: 255},
|
||||
color: { red: 0, green: 0, blue: 0},
|
||||
topMargin: 5,
|
||||
leftMargin: 0,
|
||||
font: {size: textFontSize},
|
||||
text: "",
|
||||
alpha: 0.8
|
||||
});
|
||||
updateTextOverlay();
|
||||
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
|
||||
cursor = new Cursor();
|
||||
cursor.onUpdate = function(position) {
|
||||
keyboard.setFocusPosition(position.x, position.y);
|
||||
};
|
||||
};
|
||||
|
||||
function KeyboardKey(keyboard, keyProperties) {
|
||||
var tthis = this;
|
||||
this._focus = false;
|
||||
this._beingPressed = false;
|
||||
this.event = keyProperties.event != undefined ?
|
||||
keyProperties.event : 'keypress';
|
||||
this.bounds = keyProperties.bounds;
|
||||
this.states = keyProperties.states;
|
||||
this.keyboard = keyboard;
|
||||
this.keyState = keyProperties.keyState != undefined ? keyProperties.keyState : KBD_LOWERCASE_DEFAULT;
|
||||
// one overlay per bound vector [this.bounds]
|
||||
this.overlays = [];
|
||||
this.getKeyEvent = function() {
|
||||
if (tthis.event == 'keypress') {
|
||||
var state = tthis.states[(tthis.keyboard.shift ? 1 : 2) % tthis.states.length];
|
||||
return {key: state.charCode, char: state.char, event: tthis.event, focus: tthis._focus};
|
||||
}
|
||||
return {event: tthis.event, focus: tthis._focus};
|
||||
};
|
||||
this.containsCoord = function(x, y) {
|
||||
for (var i = 0; i < this.bounds.length; i++) {
|
||||
if (x >= this.bounds[i][BOUND_X] &&
|
||||
x <= (this.bounds[i][BOUND_X] + this.bounds[i][BOUND_W]) &&
|
||||
y >= this.bounds[i][BOUND_Y] &&
|
||||
y <= (this.bounds[i][BOUND_Y] + this.bounds[i][BOUND_H]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
this.updateState = function() {
|
||||
tthis.setState(eval('KBD_' + (tthis.keyboard.shift ? 'UPPERCASE' : 'LOWERCASE') + '_' + (tthis._focus ? 'HOVER' : 'DEFAULT')));
|
||||
};
|
||||
this.updateColor = function() {
|
||||
var colorIntensity = this._beingPressed ? 128 : 255;
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i],
|
||||
{color: {red: colorIntensity, green: colorIntensity, blue: colorIntensity}}
|
||||
);
|
||||
}
|
||||
};
|
||||
this.press = function() {
|
||||
tthis._beingPressed = true;
|
||||
tthis.updateColor();
|
||||
};
|
||||
this.release = function() {
|
||||
tthis._beingPressed = false;
|
||||
tthis.updateColor();
|
||||
};
|
||||
this.blur = function() {
|
||||
tthis._focus = false;
|
||||
tthis.updateState();
|
||||
};
|
||||
this.focus = function() {
|
||||
tthis._focus = true;
|
||||
tthis.updateState();
|
||||
};
|
||||
this.setState = function(state) {
|
||||
tthis.keyState = state;
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i], {
|
||||
subImage: {width: tthis.bounds[i][BOUND_W], height: tthis.bounds[i][BOUND_H], x: tthis.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * tthis.keyState) + tthis.bounds[i][BOUND_Y]}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.rescale = function() {
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i], {
|
||||
x: tthis.keyboard.getX() + tthis.bounds[i][BOUND_X] * keyboard.scale,
|
||||
y: tthis.keyboard.getY() + tthis.bounds[i][BOUND_Y] * keyboard.scale,
|
||||
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||
height: this.bounds[i][BOUND_H] * keyboard.scale
|
||||
});
|
||||
}
|
||||
};
|
||||
this.remove = function() {
|
||||
for (var i = 0; i < this.overlays.length; i++) {
|
||||
Overlays.deleteOverlay(this.overlays[i]);
|
||||
}
|
||||
};
|
||||
this.isLoaded = function() {
|
||||
for (var i = 0; i < this.overlays.length; i++) {
|
||||
if (!Overlays.isLoaded(this.overlays[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
for (var i = 0; i < this.bounds.length; i++) {
|
||||
var newOverlay = Overlays.cloneOverlay(this.keyboard.background);
|
||||
Overlays.editOverlay(newOverlay, {
|
||||
x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale,
|
||||
y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale,
|
||||
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||
height: this.bounds[i][BOUND_H] * keyboard.scale,
|
||||
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
|
||||
alpha: 1
|
||||
});
|
||||
this.overlays.push(newOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
function Keyboard() {
|
||||
var tthis = this;
|
||||
this.focussed_key = -1;
|
||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
||||
this.shift = false;
|
||||
this.width = function() {
|
||||
return KEYBOARD_WIDTH * tthis.scale;
|
||||
};
|
||||
this.height = function() {
|
||||
return KEYBOARD_HEIGHT * tthis.scale;
|
||||
};
|
||||
this.getX = function() {
|
||||
return (windowDimensions.x / 2) - (this.width() / 2);
|
||||
};
|
||||
this.getY = function() {
|
||||
return windowDimensions.y - this.height();
|
||||
};
|
||||
this.background = Overlays.addOverlay("image", {
|
||||
x: this.getX(),
|
||||
y: this.getY(),
|
||||
width: this.width(),
|
||||
height: this.height(),
|
||||
subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND},
|
||||
imageURL: KEYBOARD_URL,
|
||||
alpha: 1
|
||||
});
|
||||
this.rescale = function() {
|
||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
||||
Overlays.editOverlay(tthis.background, {
|
||||
x: this.getX(),
|
||||
y: this.getY(),
|
||||
width: this.width(),
|
||||
height: this.height()
|
||||
});
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
tthis.keys[i].rescale();
|
||||
}
|
||||
};
|
||||
|
||||
this.setFocusPosition = function(x, y) {
|
||||
// set to local unscaled position
|
||||
var localx = (x - tthis.getX()) / tthis.scale;
|
||||
var localy = (y - tthis.getY()) / tthis.scale;
|
||||
var new_focus_key = -1;
|
||||
if (localx >= 0 && localy >= 0 && localx <= KEYBOARD_WIDTH && localy <= KEYBOARD_HEIGHT) {
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
if (tthis.keys[i].containsCoord(localx, localy)) {
|
||||
new_focus_key = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (new_focus_key != tthis.focussed_key) {
|
||||
if (tthis.focussed_key != -1) {
|
||||
tthis.keys[tthis.focussed_key].blur();
|
||||
}
|
||||
tthis.focussed_key = new_focus_key;
|
||||
if (tthis.focussed_key != -1) {
|
||||
tthis.keys[tthis.focussed_key].focus();
|
||||
}
|
||||
}
|
||||
return tthis;
|
||||
};
|
||||
|
||||
this.pressFocussedKey = function() {
|
||||
if (tthis.focussed_key != -1) {
|
||||
if (tthis.keys[tthis.focussed_key].event == 'shift') {
|
||||
tthis.toggleShift();
|
||||
} else {
|
||||
tthis.keys[tthis.focussed_key].press();
|
||||
}
|
||||
if (this.onKeyPress != null) {
|
||||
this.onKeyPress(tthis.keys[tthis.focussed_key].getKeyEvent());
|
||||
}
|
||||
}
|
||||
|
||||
return tthis;
|
||||
};
|
||||
|
||||
this.releaseKeys = function() {
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
if (tthis.keys[i]._beingPressed) {
|
||||
if (tthis.keys[i].event != 'shift') {
|
||||
tthis.keys[i].release();
|
||||
}
|
||||
if (this.onKeyRelease != null) {
|
||||
this.onKeyRelease(tthis.keys[i].getKeyEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.toggleShift = function() {
|
||||
tthis.shift = !tthis.shift;
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
tthis.keys[i].updateState();
|
||||
if (tthis.keys[i].event == 'shift') {
|
||||
if (tthis.shift) {
|
||||
tthis.keys[i].press();
|
||||
continue;
|
||||
}
|
||||
tthis.keys[i].release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.getFocussedKey = function() {
|
||||
if (tthis.focussed_key == -1) {
|
||||
return null;
|
||||
}
|
||||
return tthis.keys[tthis.focussed_key];
|
||||
};
|
||||
|
||||
this.remove = function() {
|
||||
Overlays.deleteOverlay(this.background);
|
||||
for (var i = 0; i < this.keys.length; i++) {
|
||||
this.keys[i].remove();
|
||||
}
|
||||
};
|
||||
|
||||
this.onKeyPress = null;
|
||||
this.onKeyRelease = null;
|
||||
this.onSubmit = null;
|
||||
this.onFullyLoaded = null;
|
||||
|
||||
this.keys = [];
|
||||
//
|
||||
// keyProperties contains the key data
|
||||
//
|
||||
// coords [[x,y,w,h],[x,y,w,h]]
|
||||
// states array of 1 or 2 objects [lowercase, uppercase] each object contains a charCode and a char
|
||||
var keyProperties = [
|
||||
{bounds: [[12, 12, 65, 52]], states: [{charCode: 126, char: '~'}]},
|
||||
{bounds: [[84, 12, 65, 52]], states: [{charCode: 33, char: '!'}]},
|
||||
{bounds: [[156, 12, 65, 52]], states: [{charCode: 64, char: '@'}]},
|
||||
{bounds: [[228, 12, 65, 52]], states: [{charCode: 35, char: '#'}]},
|
||||
{bounds: [[300, 12, 65, 52]], states: [{charCode: 36, char: '$'}]},
|
||||
{bounds: [[372, 12, 65, 52]], states: [{charCode: 37, char: '%'}]},
|
||||
{bounds: [[445, 12, 65, 52]], states: [{charCode: 94, char: '^'}]},
|
||||
{bounds: [[517, 12, 65, 52]], states: [{charCode: 38, char: '&'}]},
|
||||
{bounds: [[589, 12, 65, 52]], states: [{charCode: 42, char: '*'}]},
|
||||
{bounds: [[662, 12, 65, 52]], states: [{charCode: 40, char: '('}]},
|
||||
{bounds: [[734, 12, 65, 52]], states: [{charCode: 41, char: ')'}]},
|
||||
{bounds: [[806, 12, 65, 52]], states: [{charCode: 95, char: '_'}]},
|
||||
{bounds: [[881, 12, 65, 52]], states: [{charCode: 123, char: '{'}]},
|
||||
{bounds: [[953, 12, 65, 52]], states: [{charCode: 125, char: '}'}]},
|
||||
{bounds: [[1025, 12, 65, 52]], states: [{charCode: 60, char: '<'}]},
|
||||
{bounds: [[1097, 12, 65, 52]], states: [{charCode: 62, char: '>'}]},
|
||||
|
||||
{bounds: [[12, 71, 65, 63]], states: [{charCode: 96, char: '`'}]},
|
||||
{bounds: [[84, 71, 65, 63]], states: [{charCode: 49, char: '1'}]},
|
||||
{bounds: [[156, 71, 65, 63]], states: [{charCode: 50, char: '2'}]},
|
||||
{bounds: [[228, 71, 65, 63]], states: [{charCode: 51, char: '3'}]},
|
||||
{bounds: [[300, 71, 65, 63]], states: [{charCode: 52, char: '4'}]},
|
||||
{bounds: [[372, 71, 65, 63]], states: [{charCode: 53, char: '5'}]},
|
||||
{bounds: [[445, 71, 65, 63]], states: [{charCode: 54, char: '6'}]},
|
||||
{bounds: [[517, 71, 65, 63]], states: [{charCode: 55, char: '7'}]},
|
||||
{bounds: [[589, 71, 65, 63]], states: [{charCode: 56, char: '8'}]},
|
||||
{bounds: [[661, 71, 65, 63]], states: [{charCode: 57, char: '9'}]},
|
||||
{bounds: [[733, 71, 65, 63]], states: [{charCode: 48, char: '0'}]},
|
||||
{bounds: [[806, 71, 65, 63]], states: [{charCode: 45, char: '-'}]},
|
||||
{bounds: [[880, 71, 65, 63]], states: [{charCode: 61, char: '='}]},
|
||||
{bounds: [[953, 71, 65, 63]], states: [{charCode: 43, char: '+'}]},
|
||||
{bounds: [[1024, 71, 139, 63]], event: 'delete'},
|
||||
|
||||
// enter key has 2 bounds and one state
|
||||
{bounds: [[11, 143, 98, 71], [11, 213, 121, 62]], event: 'enter'},
|
||||
|
||||
{bounds: [[118, 142, 64, 63]], states: [{charCode: 113, char: 'q'}, {charCode: 81, char: 'Q'}]},
|
||||
{bounds: [[190, 142, 64, 63]], states: [{charCode: 119, char: 'w'}, {charCode: 87, char: 'W'}]},
|
||||
{bounds: [[262, 142, 64, 63]], states: [{charCode: 101, char: 'e'}, {charCode: 69, char: 'E'}]},
|
||||
{bounds: [[334, 142, 64, 63]], states: [{charCode: 114, char: 'r'}, {charCode: 82, char: 'R'}]},
|
||||
{bounds: [[407, 142, 64, 63]], states: [{charCode: 116, char: 't'}, {charCode: 84, char: 'T'}]},
|
||||
{bounds: [[479, 142, 64, 63]], states: [{charCode: 121, char: 'y'}, {charCode: 89, char: 'Y'}]},
|
||||
{bounds: [[551, 142, 65, 63]], states: [{charCode: 117, char: 'u'}, {charCode: 85, char: 'U'}]},
|
||||
{bounds: [[623, 142, 65, 63]], states: [{charCode: 105, char: 'i'}, {charCode: 73, char: 'I'}]},
|
||||
{bounds: [[695, 142, 65, 63]], states: [{charCode: 111, char: 'o'}, {charCode: 79, char: 'O'}]},
|
||||
{bounds: [[768, 142, 64, 63]], states: [{charCode: 112, char: 'p'}, {charCode: 80, char: 'P'}]},
|
||||
{bounds: [[840, 142, 64, 63]], states: [{charCode: 91, char: '['}]},
|
||||
{bounds: [[912, 142, 65, 63]], states: [{charCode: 93, char: ']'}]},
|
||||
{bounds: [[984, 142, 65, 63]], states: [{charCode: 92, char: '\\'}]},
|
||||
{bounds: [[1055, 142, 65, 63]], states: [{charCode: 124, char: '|'}]},
|
||||
|
||||
{bounds: [[1126, 143, 35, 72], [1008, 214, 153, 62]], event: 'enter'},
|
||||
|
||||
{bounds: [[140, 213, 65, 63]], states: [{charCode: 97, char: 'a'}, {charCode: 65, char: 'A'}]},
|
||||
{bounds: [[211, 213, 64, 63]], states: [{charCode: 115, char: 's'}, {charCode: 83, char: 'S'}]},
|
||||
{bounds: [[283, 213, 65, 63]], states: [{charCode: 100, char: 'd'}, {charCode: 68, char: 'D'}]},
|
||||
{bounds: [[355, 213, 65, 63]], states: [{charCode: 102, char: 'f'}, {charCode: 70, char: 'F'}]},
|
||||
{bounds: [[428, 213, 64, 63]], states: [{charCode: 103, char: 'g'}, {charCode: 71, char: 'G'}]},
|
||||
{bounds: [[500, 213, 64, 63]], states: [{charCode: 104, char: 'h'}, {charCode: 72, char: 'H'}]},
|
||||
{bounds: [[572, 213, 65, 63]], states: [{charCode: 106, char: 'j'}, {charCode: 74, char: 'J'}]},
|
||||
{bounds: [[644, 213, 65, 63]], states: [{charCode: 107, char: 'k'}, {charCode: 75, char: 'K'}]},
|
||||
{bounds: [[716, 213, 65, 63]], states: [{charCode: 108, char: 'l'}, {charCode: 76, char: 'L'}]},
|
||||
{bounds: [[789, 213, 64, 63]], states: [{charCode: 59, char: ';'}]},
|
||||
{bounds: [[861, 213, 64, 63]], states: [{charCode: 39, char: '\''}]},
|
||||
{bounds: [[934, 213, 65, 63]], states: [{charCode: 58, char: ':'}]},
|
||||
|
||||
{bounds: [[12, 283, 157, 63]], event: 'shift'},
|
||||
|
||||
{bounds: [[176, 283, 65, 63]], states: [{charCode: 122, char: 'z'}, {charCode: 90, char: 'Z'}]},
|
||||
{bounds: [[249, 283, 64, 63]], states: [{charCode: 120, char: 'x'}, {charCode: 88, char: 'X'}]},
|
||||
{bounds: [[321, 283, 64, 63]], states: [{charCode: 99, char: 'c'}, {charCode: 67, char: 'C'}]},
|
||||
{bounds: [[393, 283, 64, 63]], states: [{charCode: 118, char: 'v'}, {charCode: 86, char: 'V'}]},
|
||||
{bounds: [[465, 283, 65, 63]], states: [{charCode: 98, char: 'b'}, {charCode: 66, char: 'B'}]},
|
||||
{bounds: [[537, 283, 65, 63]], states: [{charCode: 110, char: 'n'}, {charCode: 78, char: 'N'}]},
|
||||
{bounds: [[610, 283, 64, 63]], states: [{charCode: 109, char: 'm'}, {charCode: 77, char: 'M'}]},
|
||||
{bounds: [[682, 283, 64, 63]], states: [{charCode: 44, char: ','}]},
|
||||
{bounds: [[754, 283, 65, 63]], states: [{charCode: 46, char: '.'}]},
|
||||
{bounds: [[826, 283, 65, 63]], states: [{charCode: 47, char: '/'}]},
|
||||
{bounds: [[899, 283, 64, 63]], states: [{charCode: 63, char: '?'}]},
|
||||
|
||||
{bounds: [[972, 283, 190, 63]], event: 'shift'},
|
||||
|
||||
{bounds: [[249, 355, 573, 67]], states: [{charCode: 32, char: ' '}]},
|
||||
|
||||
{bounds: [[899, 355, 263, 67]], event: 'submit'}
|
||||
];
|
||||
|
||||
this.keyboardTextureLoaded = function() {
|
||||
if (Overlays.isLoaded(tthis.background)) {
|
||||
Script.clearInterval(tthis.keyboardTextureLoaded_timer);
|
||||
for (var i = 0; i < keyProperties.length; i++) {
|
||||
tthis.keys.push(new KeyboardKey(tthis, keyProperties[i]));
|
||||
}
|
||||
if (keyboard.onFullyLoaded != null) {
|
||||
tthis.onFullyLoaded();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250);
|
||||
}
|
||||
|
||||
function Cursor() {
|
||||
var tthis = this;
|
||||
this.x = windowDimensions.x / 2;
|
||||
this.y = windowDimensions.y / 2;
|
||||
this.overlay = Overlays.addOverlay("image", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: CURSOR_WIDTH,
|
||||
height: CURSOR_HEIGHT,
|
||||
imageURL: CURSOR_URL,
|
||||
alpha: 1
|
||||
});
|
||||
this.remove = function() {
|
||||
Overlays.deleteOverlay(this.overlay);
|
||||
};
|
||||
this.getPosition = function() {
|
||||
return {x: tthis.getX(), y: tthis.getY()};
|
||||
};
|
||||
this.getX = function() {
|
||||
return tthis.x;
|
||||
};
|
||||
this.getY = function() {
|
||||
return tthis.y;
|
||||
};
|
||||
this.onUpdate = null;
|
||||
this.update = function() {
|
||||
var newWindowDimensions = Controller.getViewportDimensions();
|
||||
if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) {
|
||||
windowDimensions = newWindowDimensions;
|
||||
keyboard.rescale();
|
||||
Overlays.editOverlay(text, {
|
||||
y: windowDimensions.y - keyboard.height() - 260,
|
||||
width: windowDimensions.x
|
||||
});
|
||||
}
|
||||
var editobject = {};
|
||||
if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.x = angle * windowDimensions.x;
|
||||
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
|
||||
}
|
||||
if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.y = angle * windowDimensions.y;
|
||||
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
|
||||
}
|
||||
if (Object.keys(editobject).length > 0) {
|
||||
Overlays.editOverlay(tthis.overlay, editobject);
|
||||
if (tthis.onUpdate != null) {
|
||||
tthis.onUpdate(tthis.getPosition());
|
||||
}
|
||||
}
|
||||
};
|
||||
Script.update.connect(this.update);
|
||||
}
|
||||
|
||||
function keyPressEvent(event) {
|
||||
if (event.key === SPACEBAR_CHARCODE) {
|
||||
keyboard.pressFocussedKey();
|
||||
}
|
||||
}
|
||||
|
||||
function keyReleaseEvent(event) {
|
||||
if (event.key === SPACEBAR_CHARCODE) {
|
||||
keyboard.releaseKeys();
|
||||
}
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
keyboard.remove();
|
||||
cursor.remove();
|
||||
Overlays.deleteOverlay(text);
|
||||
Overlays.deleteOverlay(textSizeMeasureOverlay);
|
||||
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
|
||||
}
|
||||
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
|
@ -165,8 +165,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_scaleMirror(1.0f),
|
||||
_rotateMirror(0.0f),
|
||||
_raiseMirror(0.0f),
|
||||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
_lastMouseMove(usecTimestampNow()),
|
||||
_lastMouseMoveWasSimulated(false),
|
||||
_mouseHidden(false),
|
||||
|
@ -1132,7 +1130,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
if (!event->isAutoRepeat()) {
|
||||
// this starts an HFActionEvent
|
||||
HFActionEvent startActionEvent(HFActionEvent::startType(),
|
||||
_viewFrustum.computePickRay(0.5f, 0.5f));
|
||||
_myCamera.computeViewPickRay(0.5f, 0.5f));
|
||||
sendEvent(this, &startActionEvent);
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1221,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
|||
case Qt::Key_Space: {
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this ends the HFActionEvent
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), _viewFrustum.computePickRay(0.5f, 0.5f));
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f));
|
||||
sendEvent(this, &endActionEvent);
|
||||
}
|
||||
|
||||
|
@ -1254,7 +1252,6 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
|||
}
|
||||
|
||||
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
|
||||
bool showMouse = true;
|
||||
|
||||
// Used by application overlay to determine how to draw cursor(s)
|
||||
|
@ -1283,13 +1280,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
_mouseHidden = false;
|
||||
_seenMouseMove = true;
|
||||
}
|
||||
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
}
|
||||
|
||||
void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
|
||||
if (!_aboutToQuit) {
|
||||
_entities.mousePressEvent(event, deviceID);
|
||||
}
|
||||
|
@ -1304,20 +1297,20 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
if (activeWindow() == _window) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mouseDragStartedX = _mouseX;
|
||||
_mouseDragStartedY = _mouseY;
|
||||
_mouseDragStartedX = getTrueMouseX();
|
||||
_mouseDragStartedY = getTrueMouseY();
|
||||
_mousePressed = true;
|
||||
|
||||
if (_audio.mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
|
||||
if (mouseOnScreen()) {
|
||||
if (_audio.mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// nobody handled this - make it an action event on the _window object
|
||||
|
@ -1346,15 +1339,14 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
if (activeWindow() == _window) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mousePressed = false;
|
||||
|
||||
checkBandwidthMeterClick();
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && mouseOnScreen()) {
|
||||
// let's set horizontal offset to give stats some margin to mirror
|
||||
int horizontalOffset = MIRROR_VIEW_WIDTH;
|
||||
Stats::getInstance()->checkClick(_mouseX, _mouseY, _mouseDragStartedX, _mouseDragStartedY, horizontalOffset);
|
||||
Stats::getInstance()->checkClick(getMouseX(), getMouseY(),
|
||||
getMouseDragStartedX(), getMouseDragStartedY(), horizontalOffset);
|
||||
checkBandwidthMeterClick();
|
||||
}
|
||||
|
||||
// fire an action end event
|
||||
|
@ -1547,13 +1539,13 @@ void Application::idle() {
|
|||
|
||||
void Application::checkBandwidthMeterClick() {
|
||||
// ... to be called upon button release
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::Stats) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) &&
|
||||
glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY)))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) {
|
||||
glm::compMax(glm::abs(glm::ivec2(getMouseX() - getMouseDragStartedX(),
|
||||
getMouseY() - getMouseDragStartedY())))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), _glWidget->width(), _glWidget->height())) {
|
||||
|
||||
// The bandwidth meter is visible, the click didn't get dragged too far and
|
||||
// we actually hit the bandwidth meter
|
||||
|
@ -1667,6 +1659,48 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox
|
|||
(mouseVoxel.z + mouseVoxel.s / 2.0f) * TREE_SCALE);
|
||||
}
|
||||
|
||||
bool Application::mouseOnScreen() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
|
||||
getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Application::getMouseX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseX();
|
||||
}
|
||||
|
||||
int Application::getMouseY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseY();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseDragStartedX();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseDragStartedY();
|
||||
}
|
||||
|
||||
FaceTracker* Application::getActiveFaceTracker() {
|
||||
return (_dde.isActive() ? static_cast<FaceTracker*>(&_dde) :
|
||||
(_faceshift.isActive() ? static_cast<FaceTracker*>(&_faceshift) :
|
||||
|
@ -1897,10 +1931,6 @@ void Application::init() {
|
|||
_voxelShader.init();
|
||||
_pointShader.init();
|
||||
|
||||
_mouseX = _glWidget->width() / 2;
|
||||
_mouseY = _glWidget->height() / 2;
|
||||
QCursor::setPos(_mouseX, _mouseY);
|
||||
|
||||
// TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
|
||||
_avatarManager.init();
|
||||
_myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
|
||||
|
@ -2077,11 +2107,13 @@ void Application::updateMouseRay() {
|
|||
// if the mouse pointer isn't visible, act like it's at the center of the screen
|
||||
float x = 0.5f, y = 0.5f;
|
||||
if (!_mouseHidden) {
|
||||
x = _mouseX / (float)_glWidget->width();
|
||||
y = _mouseY / (float)_glWidget->height();
|
||||
x = getTrueMouseX() / (float)_glWidget->width();
|
||||
y = getTrueMouseY() / (float)_glWidget->height();
|
||||
}
|
||||
_viewFrustum.computePickRay(x, y, _mouseRayOrigin, _mouseRayDirection);
|
||||
|
||||
PickRay pickRay = _myCamera.computeViewPickRay(x, y);
|
||||
_mouseRayOrigin = pickRay.origin;
|
||||
_mouseRayDirection = pickRay.direction;
|
||||
|
||||
// adjust for mirroring
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
glm::vec3 mouseRayOffset = _mouseRayOrigin - _viewFrustum.getPosition();
|
||||
|
@ -2310,7 +2342,20 @@ void Application::update(float deltaTime) {
|
|||
_prioVR.update(deltaTime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static QCursor cursor;
|
||||
if (OculusManager::isConnected() &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){
|
||||
if (_window->cursor().shape() != Qt::BlankCursor) {
|
||||
qDebug() << "Hiding cursor" << _window->cursor().shape();
|
||||
cursor = _window->cursor();
|
||||
_window->setCursor(QCursor(Qt::BlankCursor));
|
||||
}
|
||||
} else if(_window->cursor().shape() == Qt::BlankCursor) {
|
||||
qDebug() << "Showing cursor" << _window->cursor().shape();
|
||||
_window->setCursor(cursor);
|
||||
}
|
||||
|
||||
// Dispatch input events
|
||||
_controllerScriptingInterface.updateInputControllers();
|
||||
|
||||
|
@ -3513,9 +3558,6 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) {
|
|||
}
|
||||
|
||||
void Application::resetSensors() {
|
||||
_mouseX = _glWidget->width() / 2;
|
||||
_mouseY = _glWidget->height() / 2;
|
||||
|
||||
_faceshift.reset();
|
||||
_visage.reset();
|
||||
_dde.reset();
|
||||
|
@ -3528,7 +3570,7 @@ void Application::resetSensors() {
|
|||
QScreen* currentScreen = _window->windowHandle()->screen();
|
||||
QWindow* mainWindow = _window->windowHandle();
|
||||
QPoint windowCenter = mainWindow->geometry().center();
|
||||
QCursor::setPos(currentScreen, windowCenter);
|
||||
_glWidget->cursor().setPos(currentScreen, windowCenter);
|
||||
|
||||
_myAvatar->reset();
|
||||
|
||||
|
|
|
@ -214,8 +214,15 @@ public:
|
|||
bool isMouseHidden() const { return _mouseHidden; }
|
||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
int getMouseX() const { return _mouseX; }
|
||||
int getMouseY() const { return _mouseY; }
|
||||
bool mouseOnScreen() const;
|
||||
int getMouseX() const;
|
||||
int getMouseY() const;
|
||||
int getTrueMouseX() const { return _glWidget->mapFromGlobal(QCursor::pos()).x(); }
|
||||
int getTrueMouseY() const { return _glWidget->mapFromGlobal(QCursor::pos()).y(); }
|
||||
int getMouseDragStartedX() const;
|
||||
int getMouseDragStartedY() const;
|
||||
int getTrueMouseDragStartedX() const { return _mouseDragStartedX; }
|
||||
int getTrueMouseDragStartedY() const { return _mouseDragStartedY; }
|
||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated;; }
|
||||
Faceshift* getFaceshift() { return &_faceshift; }
|
||||
Visage* getVisage() { return &_visage; }
|
||||
|
@ -556,8 +563,6 @@ private:
|
|||
|
||||
Environment _environment;
|
||||
|
||||
int _mouseX;
|
||||
int _mouseY;
|
||||
int _mouseDragStartedX;
|
||||
int _mouseDragStartedY;
|
||||
quint64 _lastMouseMove;
|
||||
|
|
|
@ -97,20 +97,17 @@ void Camera::setFarClip(float f) {
|
|||
PickRay Camera::computePickRay(float x, float y) {
|
||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||
PickRay result;
|
||||
if (OculusManager::isConnected()) {
|
||||
result.origin = getPosition();
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||
} else {
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(x / screenWidth, y / screenHeight,
|
||||
result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
|
||||
return computeViewPickRay(x / screenWidth, y / screenHeight);
|
||||
}
|
||||
|
||||
PickRay Camera::computeViewPickRay(float xRatio, float yRatio) {
|
||||
PickRay result;
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
if (OculusManager::isConnected()) {
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
} else {
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -367,6 +367,7 @@ namespace MenuOption {
|
|||
const QString DontCullTooSmallMeshParts = "Don't Cull Too Small Mesh Parts";
|
||||
const QString DontReduceMaterialSwitches = "Don't Attempt to Reduce Material Switches";
|
||||
const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene";
|
||||
const QString DontDoPrecisionPicking = "Don't Do Precision Picking";
|
||||
const QString DecreaseAvatarSize = "Decrease Avatar Size";
|
||||
const QString DecreaseVoxelSize = "Decrease Voxel Size";
|
||||
const QString DisableActivityLogger = "Disable Activity Logger";
|
||||
|
@ -378,6 +379,7 @@ namespace MenuOption {
|
|||
const QString DisplayHandTargets = "Show Hand Targets";
|
||||
const QString DisplayHermiteData = "Display Hermite Data";
|
||||
const QString DisplayModelBounds = "Display Model Bounds";
|
||||
const QString DisplayModelTriangles = "Display Model Triangles";
|
||||
const QString DisplayModelElementChildProxies = "Display Model Element Children";
|
||||
const QString DisplayModelElementProxy = "Display Model Element Bounds";
|
||||
const QString DisplayTimingDetails = "Display Timing Details";
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <glm/gtx/transform.hpp>
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include <MetavoxelMessages.h>
|
||||
|
@ -1095,30 +1096,6 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>
|
|||
_materials(materials) {
|
||||
}
|
||||
|
||||
static bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
||||
glm::vec3 firstSide = v0 - v1;
|
||||
glm::vec3 secondSide = v2 - v1;
|
||||
glm::vec3 normal = glm::cross(secondSide, firstSide);
|
||||
float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
|
||||
if (dividend > 0.0f) {
|
||||
return false; // origin below plane
|
||||
}
|
||||
float divisor = glm::dot(normal, direction);
|
||||
if (divisor > -EPSILON) {
|
||||
return false;
|
||||
}
|
||||
float t = dividend / divisor;
|
||||
glm::vec3 point = origin + direction * t;
|
||||
if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
|
||||
distance = t;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
|
||||
const glm::vec3& direction, float& distance) const {
|
||||
float highest = _size - 1.0f;
|
||||
|
|
|
@ -540,8 +540,6 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) {
|
|||
//a magnification window was clicked on
|
||||
int clickX = pos.x();
|
||||
int clickY = pos.y();
|
||||
//Checks for magnification window click
|
||||
application->getApplicationOverlay().getClickLocation(clickX, clickY);
|
||||
//Set pos to the new click location, which may be the same if no magnification window is open
|
||||
pos.setX(clickX);
|
||||
pos.setY(clickY);
|
||||
|
|
|
@ -635,22 +635,12 @@ void EntityTreeRenderer::deleteReleasedModels() {
|
|||
}
|
||||
|
||||
PickRay EntityTreeRenderer::computePickRay(float x, float y) {
|
||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||
PickRay result;
|
||||
if (OculusManager::isConnected()) {
|
||||
Camera* camera = Application::getInstance()->getCamera();
|
||||
result.origin = camera->getPosition();
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||
} else {
|
||||
ViewFrustum* viewFrustum = Application::getInstance()->getViewFrustum();
|
||||
viewFrustum->computePickRay(x / screenWidth, y / screenHeight, result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
return Application::getInstance()->getCamera()->computePickRay(x, y);
|
||||
}
|
||||
|
||||
|
||||
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType) {
|
||||
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking) {
|
||||
RayToEntityIntersectionResult result;
|
||||
if (_tree) {
|
||||
EntityTree* entityTree = static_cast<EntityTree*>(_tree);
|
||||
|
@ -658,7 +648,8 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
|
|||
OctreeElement* element;
|
||||
EntityItem* intersectedEntity = NULL;
|
||||
result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||
precisionPicking);
|
||||
if (result.intersects && intersectedEntity) {
|
||||
result.entityID = intersectedEntity->getEntityItemID();
|
||||
result.properties = intersectedEntity->getProperties();
|
||||
|
@ -710,7 +701,9 @@ QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entity
|
|||
void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
||||
|
||||
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
//qDebug() << "mousePressEvent over entity:" << rayPickResult.entityID;
|
||||
emit mousePressOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||
|
@ -734,7 +727,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
|
|||
void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseReleaseEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
||||
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
//qDebug() << "mouseReleaseEvent over entity:" << rayPickResult.entityID;
|
||||
emit mouseReleaseOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||
|
@ -768,7 +762,9 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
|
|||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent");
|
||||
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock);
|
||||
|
||||
bool precisionPicking = false; // for mouse moves we do not do precision picking
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
|
||||
|
||||
|
|
|
@ -117,7 +117,8 @@ private:
|
|||
QList<Model*> _releasedModels;
|
||||
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
||||
PickRay computePickRay(float x, float y);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking);
|
||||
|
||||
EntityItemID _currentHoverOverEntityID;
|
||||
EntityItemID _currentClickingOnEntityID;
|
||||
|
|
|
@ -93,7 +93,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
|
|||
|
||||
bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
// TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's
|
||||
// EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -173,10 +173,18 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
// is significantly more expensive. Is there a way to call this that doesn't cost us as much?
|
||||
PerformanceTimer perfTimer("model->render");
|
||||
bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene);
|
||||
if (dontRenderAsScene) {
|
||||
_model->render(alpha, modelRenderMode, args);
|
||||
} else {
|
||||
_model->renderInScene(alpha, args);
|
||||
bool displayModelTriangles = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelTriangles);
|
||||
bool rendered = false;
|
||||
if (displayModelTriangles) {
|
||||
rendered = _model->renderTriangleProxies();
|
||||
}
|
||||
|
||||
if (!rendered) {
|
||||
if (dontRenderAsScene) {
|
||||
_model->render(alpha, modelRenderMode, args);
|
||||
} else {
|
||||
_model->renderInScene(alpha, args);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if we couldn't get a model, then just draw a cube
|
||||
|
@ -257,7 +265,26 @@ EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
|||
return properties;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
glm::vec3 originInMeters = origin * (float)TREE_SCALE;
|
||||
QString extraInfo;
|
||||
float localDistance;
|
||||
|
||||
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection() precisionPicking:" << precisionPicking;
|
||||
|
||||
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction,
|
||||
localDistance, face, extraInfo, precisionPicking);
|
||||
|
||||
if (intersectsModel) {
|
||||
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
||||
// results in tree scale.
|
||||
distance = localDistance / (float)TREE_SCALE;
|
||||
}
|
||||
|
||||
return intersectsModel; // we only got here if we intersected our non-aabox
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,6 +51,11 @@ public:
|
|||
virtual void somethingChangedNotification() { _needsInitialSimulation = true; }
|
||||
|
||||
virtual void render(RenderArgs* args);
|
||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
Model* getModel(EntityTreeRenderer* renderer);
|
||||
private:
|
||||
void remapTextures();
|
||||
|
|
|
@ -54,6 +54,7 @@ Model::Model(QObject* parent) :
|
|||
_blendNumber(0),
|
||||
_appliedBlendNumber(0),
|
||||
_calculatedMeshBoxesValid(false),
|
||||
_calculatedMeshTrianglesValid(false),
|
||||
_meshGroupsKnown(false) {
|
||||
|
||||
// we may have been created in the network thread, but we live in the main thread
|
||||
|
@ -269,7 +270,7 @@ void Model::init() {
|
|||
_program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert");
|
||||
_program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag");
|
||||
_program.link();
|
||||
|
||||
|
||||
initProgram(_program, _locations);
|
||||
|
||||
_normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
|
@ -515,8 +516,61 @@ void Model::setJointStates(QVector<JointState> states) {
|
|||
_boundingRadius = radius;
|
||||
}
|
||||
|
||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
bool Model::renderTriangleProxies() {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
}
|
||||
if (_calculatedMeshTrianglesValid) {
|
||||
int color = 0;
|
||||
foreach (const QVector<Triangle>& meshTriangles, _calculatedMeshTriangles) {
|
||||
switch(color) {
|
||||
case 0: glColor3ub( 0, 0, 255); break;
|
||||
case 1: glColor3ub( 0, 255, 0); break;
|
||||
case 2: glColor3ub( 0, 255, 255); break;
|
||||
case 3: glColor3ub(255, 0, 0); break;
|
||||
case 4: glColor3ub(255, 0, 255); break;
|
||||
case 5: glColor3ub(255, 255, 0); break;
|
||||
case 6: glColor3ub( 0, 0, 128); break;
|
||||
case 7: glColor3ub( 0, 128, 0); break;
|
||||
case 8: glColor3ub( 0, 128, 128); break;
|
||||
case 9: glColor3ub(128, 0, 0); break;
|
||||
case 10: glColor3ub(128, 0, 128); break;
|
||||
case 11: glColor3ub(128, 128, 0); break;
|
||||
case 12: glColor3ub(128, 128, 255); break;
|
||||
case 13: glColor3ub(128, 255, 128); break;
|
||||
case 14: glColor3ub(128, 255, 255); break;
|
||||
case 15: glColor3ub(255, 128, 128); break;
|
||||
case 16: glColor3ub(255, 128, 255); break;
|
||||
case 17: glColor3ub(255, 255, 128); break;
|
||||
default: glColor3ub(255,255, 255); break;
|
||||
}
|
||||
|
||||
if (_calculatedMeshBoxes.size() > color) {
|
||||
const AABox& box = _calculatedMeshBoxes[color];
|
||||
glm::vec3 center = box.calcCenter();
|
||||
glm::vec3 dimensions = box.getDimensions();
|
||||
glPushMatrix();
|
||||
glTranslatef(center.x, center.y, center.z);
|
||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||
Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
foreach (const Triangle& triangle, meshTriangles) {
|
||||
glVertex3f( triangle.v0.x, triangle.v0.y, triangle.v0.z);
|
||||
glVertex3f( triangle.v1.x, triangle.v1.y, triangle.v1.z);
|
||||
glVertex3f( triangle.v2.x, triangle.v2.y, triangle.v2.z);
|
||||
}
|
||||
glEnd();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
return _calculatedMeshTrianglesValid;
|
||||
}
|
||||
|
||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles) {
|
||||
|
||||
bool intersectedSomething = false;
|
||||
|
||||
|
@ -524,7 +578,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
if (!isActive()) {
|
||||
return intersectedSomething;
|
||||
}
|
||||
|
||||
|
||||
// extents is the entity relative, scaled, centered extents of the entity
|
||||
glm::vec3 position = _translation;
|
||||
glm::mat4 rotation = glm::mat4_cast(_rotation);
|
||||
|
@ -535,35 +589,70 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
Extents modelExtents = getMeshExtents(); // NOTE: unrotated
|
||||
|
||||
glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
|
||||
glm::vec3 corner = dimensions * -0.5f; // since we're going to do the ray picking in the model frame of reference
|
||||
AABox overlayFrameBox(corner, dimensions);
|
||||
glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference
|
||||
AABox modelFrameBox(corner, dimensions);
|
||||
|
||||
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
||||
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
|
||||
|
||||
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
||||
// and testing intersection there.
|
||||
if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
||||
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
||||
|
||||
float bestDistance = std::numeric_limits<float>::max();
|
||||
float bestTriangleDistance = std::numeric_limits<float>::max();
|
||||
bool someTriangleHit = false;
|
||||
|
||||
float distanceToSubMesh;
|
||||
BoxFace subMeshFace;
|
||||
int subMeshIndex = 0;
|
||||
|
||||
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
||||
// If we hit the models box, then consider the submeshes...
|
||||
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
||||
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
||||
if (distanceToSubMesh < bestDistance) {
|
||||
bestDistance = distanceToSubMesh;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
if (pickAgainstTriangles) {
|
||||
someTriangleHit = false;
|
||||
if (!_calculatedMeshTrianglesValid) {
|
||||
recalculateMeshBoxes(pickAgainstTriangles);
|
||||
}
|
||||
// check our triangles here....
|
||||
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
||||
int t = 0;
|
||||
foreach (const Triangle& triangle, meshTriangles) {
|
||||
t++;
|
||||
|
||||
float thisTriangleDistance;
|
||||
if (findRayTriangleIntersection(origin, direction, triangle, thisTriangleDistance)) {
|
||||
if (thisTriangleDistance < bestDistance) {
|
||||
bestTriangleDistance = thisTriangleDistance;
|
||||
someTriangleHit = true;
|
||||
|
||||
bestDistance = thisTriangleDistance;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// this is the non-triangle picking case...
|
||||
bestDistance = distanceToSubMesh;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subMeshIndex++;
|
||||
}
|
||||
|
||||
if (intersectedSomething) {
|
||||
distance = bestDistance;
|
||||
}
|
||||
|
||||
return intersectedSomething;
|
||||
}
|
||||
|
@ -571,18 +660,81 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
return intersectedSomething;
|
||||
}
|
||||
|
||||
void Model::recalcuateMeshBoxes() {
|
||||
if (!_calculatedMeshBoxesValid) {
|
||||
// TODO: we seem to call this too often when things haven't actually changed... look into optimizing this
|
||||
void Model::recalculateMeshBoxes(bool pickAgainstTriangles) {
|
||||
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
||||
|
||||
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) {
|
||||
PerformanceTimer perfTimer("calculatedMeshBoxes");
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
int numberOfMeshes = geometry.meshes.size();
|
||||
_calculatedMeshBoxes.resize(numberOfMeshes);
|
||||
_calculatedMeshTriangles.clear();
|
||||
_calculatedMeshTriangles.resize(numberOfMeshes);
|
||||
for (int i = 0; i < numberOfMeshes; i++) {
|
||||
const FBXMesh& mesh = geometry.meshes.at(i);
|
||||
Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents);
|
||||
|
||||
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
||||
|
||||
if (pickAgainstTriangles) {
|
||||
QVector<Triangle> thisMeshTriangles;
|
||||
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||
const FBXMeshPart& part = mesh.parts.at(j);
|
||||
|
||||
const int INDICES_PER_TRIANGLE = 3;
|
||||
const int INDICES_PER_QUAD = 4;
|
||||
|
||||
if (part.quadIndices.size() > 0) {
|
||||
int numberOfQuads = part.quadIndices.size() / INDICES_PER_QUAD;
|
||||
int vIndex = 0;
|
||||
for (int q = 0; q < numberOfQuads; q++) {
|
||||
int i0 = part.quadIndices[vIndex++];
|
||||
int i1 = part.quadIndices[vIndex++];
|
||||
int i2 = part.quadIndices[vIndex++];
|
||||
int i3 = part.quadIndices[vIndex++];
|
||||
|
||||
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||
glm::vec3 v3 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i3], 1.0f)));
|
||||
|
||||
// Sam's recommended triangle slices
|
||||
Triangle tri1 = { v0, v1, v3 };
|
||||
Triangle tri2 = { v1, v2, v3 };
|
||||
|
||||
// NOTE: Random guy on the internet's recommended triangle slices
|
||||
//Triangle tri1 = { v0, v1, v2 };
|
||||
//Triangle tri2 = { v2, v3, v0 };
|
||||
|
||||
thisMeshTriangles.push_back(tri1);
|
||||
thisMeshTriangles.push_back(tri2);
|
||||
}
|
||||
}
|
||||
|
||||
if (part.triangleIndices.size() > 0) {
|
||||
int numberOfTris = part.triangleIndices.size() / INDICES_PER_TRIANGLE;
|
||||
int vIndex = 0;
|
||||
for (int t = 0; t < numberOfTris; t++) {
|
||||
int i0 = part.triangleIndices[vIndex++];
|
||||
int i1 = part.triangleIndices[vIndex++];
|
||||
int i2 = part.triangleIndices[vIndex++];
|
||||
|
||||
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||
|
||||
Triangle tri = { v0, v1, v2 };
|
||||
|
||||
thisMeshTriangles.push_back(tri);
|
||||
}
|
||||
}
|
||||
}
|
||||
_calculatedMeshTriangles[i] = thisMeshTriangles;
|
||||
}
|
||||
}
|
||||
_calculatedMeshBoxesValid = true;
|
||||
_calculatedMeshTrianglesValid = pickAgainstTriangles;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,7 +744,7 @@ void Model::renderSetup(RenderArgs* args) {
|
|||
// against. We cache the results of these calculations so long as the model hasn't been
|
||||
// simulated and the mesh hasn't changed.
|
||||
if (args && !_calculatedMeshBoxesValid) {
|
||||
recalcuateMeshBoxes();
|
||||
recalculateMeshBoxes();
|
||||
}
|
||||
|
||||
// set up dilated textures on first render after load/simulate
|
||||
|
@ -844,6 +996,15 @@ Extents Model::calculateScaledOffsetExtents(const Extents& extents) const {
|
|||
return translatedExtents;
|
||||
}
|
||||
|
||||
glm::vec3 Model::calculateScaledOffsetPoint(const glm::vec3& point) const {
|
||||
// we need to include any fst scaling, translation, and rotation, which is captured in the offset matrix
|
||||
glm::vec3 offsetPoint = glm::vec3(_geometry->getFBXGeometry().offset * glm::vec4(point, 1.0f));
|
||||
glm::vec3 scaledPoint = ((offsetPoint + _offset) * _scale);
|
||||
glm::vec3 rotatedPoint = _rotation * scaledPoint;
|
||||
glm::vec3 translatedPoint = rotatedPoint + _translation;
|
||||
return translatedPoint;
|
||||
}
|
||||
|
||||
|
||||
bool Model::getJointState(int index, glm::quat& rotation) const {
|
||||
if (index == -1 || index >= _jointStates.size()) {
|
||||
|
@ -1142,6 +1303,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
|||
|
||||
if (isActive() && fullUpdate) {
|
||||
_calculatedMeshBoxesValid = false; // if we have to simulate, we need to assume our mesh boxes are all invalid
|
||||
_calculatedMeshTrianglesValid = false;
|
||||
|
||||
// check for scale to fit
|
||||
if (_scaleToFit && !_scaledToFit) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "Transform.h"
|
||||
#include <AABox.h>
|
||||
#include <AnimationCache.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <PhysicsEntity.h>
|
||||
|
||||
#include "AnimationHandle.h"
|
||||
|
@ -34,7 +35,6 @@ class Shape;
|
|||
#include "RenderArgs.h"
|
||||
class ViewFrustum;
|
||||
|
||||
|
||||
#include "gpu/Stream.h"
|
||||
#include "gpu/Batch.h"
|
||||
|
||||
|
@ -89,6 +89,7 @@ public:
|
|||
enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE };
|
||||
|
||||
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL);
|
||||
bool renderTriangleProxies();
|
||||
|
||||
// Scene rendering support
|
||||
static void startScene(RenderArgs::RenderSide renderSide);
|
||||
|
@ -119,6 +120,9 @@ public:
|
|||
/// Returns the scaled equivalent of some extents in model space.
|
||||
Extents calculateScaledOffsetExtents(const Extents& extents) const;
|
||||
|
||||
/// Returns the scaled equivalent of a point in model space.
|
||||
glm::vec3 calculateScaledOffsetPoint(const glm::vec3& point) const;
|
||||
|
||||
/// Returns a reference to the shared geometry.
|
||||
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
||||
|
||||
|
@ -193,8 +197,8 @@ public:
|
|||
Q_INVOKABLE void setTextureWithNameToURL(const QString& name, const QUrl& url)
|
||||
{ _geometry->setTextureWithNameToURL(name, url); }
|
||||
|
||||
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles = false);
|
||||
|
||||
protected:
|
||||
QSharedPointer<NetworkGeometry> _geometry;
|
||||
|
@ -318,7 +322,7 @@ private:
|
|||
static ProgramObject _skinTranslucentProgram;
|
||||
|
||||
static ProgramObject _skinShadowProgram;
|
||||
|
||||
|
||||
static int _normalMapTangentLocation;
|
||||
static int _normalSpecularMapTangentLocation;
|
||||
|
||||
|
@ -361,10 +365,13 @@ private:
|
|||
|
||||
static void initSkinProgram(ProgramObject& program, SkinLocations& locations, int specularTextureUnit = 1);
|
||||
|
||||
QVector<AABox> _calculatedMeshBoxes;
|
||||
QVector<AABox> _calculatedMeshBoxes; // world coordinate AABoxes for all sub mesh boxes
|
||||
bool _calculatedMeshBoxesValid;
|
||||
|
||||
QVector< QVector<Triangle> > _calculatedMeshTriangles; // world coordinate triangles for all sub meshes
|
||||
bool _calculatedMeshTrianglesValid;
|
||||
|
||||
void recalcuateMeshBoxes();
|
||||
void recalculateMeshBoxes(bool pickAgainstTriangles = false);
|
||||
|
||||
void segregateMeshGroups(); // used to calculate our list of translucent vs opaque meshes
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ void JoystickScriptingInterface::update() {
|
|||
|
||||
// global action events fire in the center of the screen
|
||||
HFActionEvent actionEvent(actionType,
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(0.5f, 0.5f));
|
||||
Application::getInstance()->getCamera()->computeViewPickRay(0.5f, 0.5f));
|
||||
qApp->sendEvent(qApp, &actionEvent);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,14 +15,13 @@
|
|||
class Overlays;
|
||||
class QOpenGLFramebufferObject;
|
||||
|
||||
const float MAGNIFY_WIDTH = 160.0f;
|
||||
const float MAGNIFY_HEIGHT = 80.0f;
|
||||
const float MAGNIFY_MULT = 4.0f;
|
||||
const float MAGNIFY_WIDTH = 220.0f;
|
||||
const float MAGNIFY_HEIGHT = 100.0f;
|
||||
const float MAGNIFY_MULT = 2.0f;
|
||||
|
||||
// Handles the drawing of the overlays to the screen
|
||||
class ApplicationOverlay {
|
||||
public:
|
||||
|
||||
ApplicationOverlay();
|
||||
~ApplicationOverlay();
|
||||
|
||||
|
@ -30,16 +29,25 @@ public:
|
|||
void displayOverlayTexture();
|
||||
void displayOverlayTextureOculus(Camera& whichCamera);
|
||||
void displayOverlayTexture3DTV(Camera& whichCamera, float aspectRatio, float fov);
|
||||
void computeOculusPickRay(float x, float y, glm::vec3& direction) const;
|
||||
void getClickLocation(int &x, int &y) const;
|
||||
|
||||
void computeOculusPickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const;
|
||||
QPoint getPalmClickLocation(const PalmData *palm) const;
|
||||
bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const;
|
||||
|
||||
|
||||
// Getters
|
||||
QOpenGLFramebufferObject* getFramebufferObject();
|
||||
float getAlpha() const { return _alpha; }
|
||||
|
||||
|
||||
// Converter from one frame of reference to another.
|
||||
// Frame of reference:
|
||||
// Screen: Position on the screen (x,y)
|
||||
// Spherical: Pitch and yaw that gives the position on the sphere we project on (yaw,pitch)
|
||||
// Overlay: Position on the overlay (x,y)
|
||||
// (x,y) in Overlay are similar than (x,y) in Screen except they can be outside of the bound of te screen.
|
||||
// This allows for picking outside of the screen projection in 3D.
|
||||
glm::vec2 screenToSpherical(glm::vec2 screenPos) const;
|
||||
glm::vec2 sphericalToScreen(glm::vec2 sphericalPos) const;
|
||||
glm::vec2 sphericalToOverlay(glm::vec2 sphericalPos) const;
|
||||
glm::vec2 overlayToSpherical(glm::vec2 overlayPos) const;
|
||||
glm::vec2 screenToOverlay(glm::vec2 screenPos) const;
|
||||
glm::vec2 overlayToScreen(glm::vec2 overlayPos) const;
|
||||
|
||||
private:
|
||||
// Interleaved vertex data
|
||||
struct TextureVertex {
|
||||
|
@ -48,31 +56,54 @@ private:
|
|||
};
|
||||
|
||||
typedef QPair<GLuint, GLuint> VerticesIndices;
|
||||
|
||||
void renderPointers();
|
||||
class TexturedHemisphere {
|
||||
public:
|
||||
TexturedHemisphere();
|
||||
~TexturedHemisphere();
|
||||
|
||||
void bind();
|
||||
void release();
|
||||
void bindTexture();
|
||||
void releaseTexture();
|
||||
|
||||
void buildFramebufferObject();
|
||||
void buildVBO(const float fov, const float aspectRatio, const int slices, const int stacks);
|
||||
void render();
|
||||
|
||||
private:
|
||||
void cleanupVBO();
|
||||
|
||||
GLuint _vertices;
|
||||
GLuint _indices;
|
||||
QOpenGLFramebufferObject* _framebufferObject;
|
||||
VerticesIndices _vbo;
|
||||
};
|
||||
|
||||
void renderPointers();;
|
||||
void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const;
|
||||
|
||||
void renderControllerPointers();
|
||||
void renderPointersOculus(const glm::vec3& eyePos);
|
||||
void renderMagnifier(int mouseX, int mouseY, float sizeMult, bool showBorder) const;
|
||||
|
||||
void renderAudioMeter();
|
||||
void renderStatsAndLogs();
|
||||
void renderTexturedHemisphere();
|
||||
void renderDomainConnectionStatusBorder();
|
||||
|
||||
QOpenGLFramebufferObject* _framebufferObject;
|
||||
float _trailingAudioLoudness;
|
||||
float _textureFov;
|
||||
TexturedHemisphere _overlays;
|
||||
|
||||
enum MagnifyDevices { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_MAGNIFIERS = RIGHT_CONTROLLER + 1 };
|
||||
bool _reticleActive[NUMBER_OF_MAGNIFIERS];
|
||||
int _mouseX[NUMBER_OF_MAGNIFIERS];
|
||||
int _mouseY[NUMBER_OF_MAGNIFIERS];
|
||||
bool _magActive[NUMBER_OF_MAGNIFIERS];
|
||||
int _magX[NUMBER_OF_MAGNIFIERS];
|
||||
int _magY[NUMBER_OF_MAGNIFIERS];
|
||||
float _magSizeMult[NUMBER_OF_MAGNIFIERS];
|
||||
float _textureFov;
|
||||
float _textureAspectRatio;
|
||||
|
||||
enum Reticules { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_RETICULES };
|
||||
bool _reticleActive[NUMBER_OF_RETICULES];
|
||||
QPoint _reticulePosition[NUMBER_OF_RETICULES];
|
||||
bool _magActive[NUMBER_OF_RETICULES];
|
||||
float _magSizeMult[NUMBER_OF_RETICULES];
|
||||
quint64 _lastMouseMove;
|
||||
|
||||
float _alpha;
|
||||
float _oculusuiRadius;
|
||||
float _oculusUIRadius;
|
||||
float _trailingAudioLoudness;
|
||||
|
||||
GLuint _crosshairTexture;
|
||||
};
|
||||
|
|
|
@ -38,12 +38,7 @@ void NodeBounds::draw() {
|
|||
// Compute ray to find selected nodes later on. We can't use the pre-computed ray in Application because it centers
|
||||
// itself after the cursor disappears.
|
||||
Application* application = Application::getInstance();
|
||||
GLCanvas* glWidget = application->getGLWidget();
|
||||
float mouseX = application->getMouseX() / (float)glWidget->width();
|
||||
float mouseY = application->getMouseY() / (float)glWidget->height();
|
||||
glm::vec3 mouseRayOrigin;
|
||||
glm::vec3 mouseRayDirection;
|
||||
application->getViewFrustum()->computePickRay(mouseX, mouseY, mouseRayOrigin, mouseRayDirection);
|
||||
PickRay pickRay = application->getCamera()->computeViewPickRay(application->getTrueMouseX(), application->getTrueMouseY());
|
||||
|
||||
// Variables to keep track of the selected node and properties to draw the cube later if needed
|
||||
Node* selectedNode = NULL;
|
||||
|
@ -106,8 +101,8 @@ void NodeBounds::draw() {
|
|||
|
||||
float distance;
|
||||
BoxFace face;
|
||||
bool inside = serverBounds.contains(mouseRayOrigin);
|
||||
bool colliding = serverBounds.findRayIntersection(mouseRayOrigin, mouseRayDirection, distance, face);
|
||||
bool inside = serverBounds.contains(pickRay.origin);
|
||||
bool colliding = serverBounds.findRayIntersection(pickRay.origin, pickRay.direction, distance, face);
|
||||
|
||||
// If the camera is inside a node it will be "selected" if you don't have your cursor over another node
|
||||
// that you aren't inside.
|
||||
|
@ -225,8 +220,8 @@ void NodeBounds::drawOverlay() {
|
|||
const int MOUSE_OFFSET = 10;
|
||||
const int BACKGROUND_BEVEL = 3;
|
||||
|
||||
int mouseX = application->getMouseX(),
|
||||
mouseY = application->getMouseY(),
|
||||
int mouseX = application->getTrueMouseX(),
|
||||
mouseY = application->getTrueMouseY(),
|
||||
textWidth = widthText(TEXT_SCALE, 0, _overlayText);
|
||||
glColor4f(0.4f, 0.4f, 0.4f, 0.6f);
|
||||
renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING,
|
||||
|
|
|
@ -167,7 +167,7 @@ QScriptValue Base3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
float& distance, BoxFace& face, QString& extraInfo) {
|
||||
return findRayIntersection(origin, direction, distance, face);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ void BillboardOverlay::replyFinished() {
|
|||
}
|
||||
|
||||
bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
if (_billboardTexture) {
|
||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual BillboardOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ QScriptValue Circle3DOverlay::getProperty(const QString& property) {
|
|||
|
||||
|
||||
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||
const glm::vec3& direction, float& distance, BoxFace& face) const {
|
||||
const glm::vec3& direction, float& distance, BoxFace& face) {
|
||||
|
||||
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
||||
if (intersects) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
void setMajorTickMarksColor(const xColor& value) { _majorTickMarksColor = value; }
|
||||
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual Circle3DOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -170,14 +170,14 @@ QScriptValue ModelOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
QString subMeshNameTemp;
|
||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, subMeshNameTemp);
|
||||
}
|
||||
|
||||
bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
float& distance, BoxFace& face, QString& extraInfo) {
|
||||
|
||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ public:
|
|||
virtual void render(RenderArgs* args);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||
float& distance, BoxFace& face, QString& extraInfo);
|
||||
|
||||
virtual ModelOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <limits>
|
||||
#include <typeinfo>
|
||||
#include <Application.h>
|
||||
#include <devices/OculusManager.h>
|
||||
#include <Menu.h>
|
||||
#include <QScriptValueIterator>
|
||||
|
||||
|
@ -244,6 +245,11 @@ void Overlays::deleteOverlay(unsigned int id) {
|
|||
}
|
||||
|
||||
unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
||||
glm::vec2 pointCopy = point;
|
||||
if (OculusManager::isConnected()) {
|
||||
pointCopy = Application::getInstance()->getApplicationOverlay().screenToOverlay(point);
|
||||
}
|
||||
|
||||
QReadLocker lock(&_lock);
|
||||
QMapIterator<unsigned int, Overlay*> i(_overlays2D);
|
||||
i.toBack();
|
||||
|
@ -251,7 +257,8 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
|||
i.previous();
|
||||
unsigned int thisID = i.key();
|
||||
Overlay2D* thisOverlay = static_cast<Overlay2D*>(i.value());
|
||||
if (thisOverlay->getVisible() && thisOverlay->isLoaded() && thisOverlay->getBounds().contains(point.x, point.y, false)) {
|
||||
if (thisOverlay->getVisible() && thisOverlay->isLoaded() &&
|
||||
thisOverlay->getBounds().contains(pointCopy.x, pointCopy.y, false)) {
|
||||
return thisID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin;
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
protected:
|
||||
glm::vec2 _dimensions;
|
||||
|
|
|
@ -100,7 +100,7 @@ QScriptValue Volume3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
// extents is the entity relative, scaled, centered extents of the entity
|
||||
glm::vec3 position = getPosition();
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
protected:
|
||||
glm::vec3 _dimensions;
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return false; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const { return true; }
|
||||
void** intersectedObject, bool precisionPicking) const { return true; }
|
||||
|
||||
// attributes applicable to all entity types
|
||||
EntityTypes::EntityType getType() const { return _type; }
|
||||
|
|
|
@ -196,22 +196,26 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
|
|||
return result;
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray) {
|
||||
return findRayIntersectionWorker(ray, Octree::TryLock);
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking) {
|
||||
return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) {
|
||||
return findRayIntersectionWorker(ray, Octree::Lock);
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking) {
|
||||
return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
|
||||
Octree::lockType lockType) {
|
||||
Octree::lockType lockType,
|
||||
bool precisionPicking) {
|
||||
|
||||
|
||||
RayToEntityIntersectionResult result;
|
||||
if (_entityTree) {
|
||||
OctreeElement* element;
|
||||
EntityItem* intersectedEntity = NULL;
|
||||
result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||
precisionPicking);
|
||||
if (result.intersects && intersectedEntity) {
|
||||
result.entityID = intersectedEntity->getEntityItemID();
|
||||
result.properties = intersectedEntity->getProperties();
|
||||
|
|
|
@ -90,11 +90,11 @@ public slots:
|
|||
/// If the scripting context has visible voxels, this will determine a ray intersection, the results
|
||||
/// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate
|
||||
/// will be false.
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray);
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false);
|
||||
|
||||
/// If the scripting context has visible voxels, this will determine a ray intersection, and will block in
|
||||
/// order to return an accurate result
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray);
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking = false);
|
||||
|
||||
Q_INVOKABLE void setLightsArePickable(bool value);
|
||||
Q_INVOKABLE bool getLightsArePickable() const;
|
||||
|
@ -124,7 +124,8 @@ private:
|
|||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||
|
||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking);
|
||||
|
||||
uint32_t _nextCreatorTokenID;
|
||||
EntityTree* _entityTree;
|
||||
|
|
|
@ -475,13 +475,17 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3
|
|||
|
||||
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) {
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube) {
|
||||
|
||||
// only called if we do intersect our bounding cube, but find if we actually intersect with entities...
|
||||
int entityNumber = 0;
|
||||
|
||||
QList<EntityItem*>::iterator entityItr = _entityItems->begin();
|
||||
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
||||
bool somethingIntersected = false;
|
||||
|
||||
//float bestEntityDistance = distance;
|
||||
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem* entity = (*entityItr);
|
||||
|
||||
|
@ -513,10 +517,9 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
if (localDistance < distance) {
|
||||
// now ask the entity if we actually intersect
|
||||
if (entity->supportsDetailedRayIntersection()) {
|
||||
|
||||
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
||||
localFace, intersectedObject)) {
|
||||
|
||||
localFace, intersectedObject, precisionPicking)) {
|
||||
|
||||
if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
|
@ -538,6 +541,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
}
|
||||
|
||||
++entityItr;
|
||||
entityNumber++;
|
||||
}
|
||||
return somethingIntersected;
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ public:
|
|||
virtual bool canRayIntersect() const { return hasEntities(); }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject);
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube);
|
||||
|
||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||
glm::vec3& penetration, void** penetratedObject) const;
|
||||
|
|
|
@ -96,7 +96,7 @@ void SphereEntityItem::recalculateCollisionShape() {
|
|||
|
||||
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
||||
// do a little math to make these match each other.
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
protected:
|
||||
virtual void recalculateCollisionShape();
|
||||
|
|
|
@ -118,7 +118,7 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
|
|||
|
||||
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
static const QString DEFAULT_TEXT;
|
||||
void setText(const QString& value) { _text = value; }
|
||||
|
|
|
@ -2044,6 +2044,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
|
||||
extracted.mesh.meshExtents.minimum = glm::min(extracted.mesh.meshExtents.minimum, transformedVertex);
|
||||
extracted.mesh.meshExtents.maximum = glm::max(extracted.mesh.meshExtents.maximum, transformedVertex);
|
||||
extracted.mesh.modelTransform = modelTransform;
|
||||
}
|
||||
|
||||
// look for textures, material properties
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
QVector<FBXCluster> clusters;
|
||||
|
||||
Extents meshExtents;
|
||||
glm::mat4 modelTransform;
|
||||
|
||||
bool isEye;
|
||||
|
||||
|
|
|
@ -693,13 +693,14 @@ public:
|
|||
BoxFace& face;
|
||||
void** intersectedObject;
|
||||
bool found;
|
||||
bool precisionPicking;
|
||||
};
|
||||
|
||||
bool findRayIntersectionOp(OctreeElement* element, void* extraData) {
|
||||
RayArgs* args = static_cast<RayArgs*>(extraData);
|
||||
bool keepSearching = true;
|
||||
if (element->findRayIntersection(args->origin, args->direction, keepSearching,
|
||||
args->element, args->distance, args->face, args->intersectedObject)) {
|
||||
args->element, args->distance, args->face, args->intersectedObject, args->precisionPicking)) {
|
||||
args->found = true;
|
||||
}
|
||||
return keepSearching;
|
||||
|
@ -707,8 +708,9 @@ bool findRayIntersectionOp(OctreeElement* element, void* extraData) {
|
|||
|
||||
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject,
|
||||
Octree::lockType lockType, bool* accurateResult) {
|
||||
RayArgs args = { origin / (float)(TREE_SCALE), direction, element, distance, face, intersectedObject, false};
|
||||
Octree::lockType lockType, bool* accurateResult, bool precisionPicking) {
|
||||
RayArgs args = { origin / (float)(TREE_SCALE), direction, element, distance, face,
|
||||
intersectedObject, false, precisionPicking};
|
||||
distance = FLT_MAX;
|
||||
|
||||
bool gotLock = false;
|
||||
|
|
|
@ -298,7 +298,9 @@ public:
|
|||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
OctreeElement*& node, float& distance, BoxFace& face,
|
||||
void** intersectedObject = NULL,
|
||||
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
||||
Octree::lockType lockType = Octree::TryLock,
|
||||
bool* accurateResult = NULL,
|
||||
bool precisionPicking = false);
|
||||
|
||||
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject = NULL,
|
||||
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
||||
|
|
|
@ -1334,16 +1334,20 @@ void OctreeElement::notifyUpdateHooks() {
|
|||
|
||||
bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) {
|
||||
void** intersectedObject, bool precisionPicking) {
|
||||
|
||||
keepSearching = true; // assume that we will continue searching after this.
|
||||
|
||||
AACube cube = getAACube();
|
||||
float localDistance;
|
||||
float distanceToElementCube = std::numeric_limits<float>::max();
|
||||
float distanceToElementDetails = distance;
|
||||
BoxFace localFace;
|
||||
|
||||
AACube debugCube = cube;
|
||||
debugCube.scale((float)TREE_SCALE);
|
||||
|
||||
// if the ray doesn't intersect with our cube, we can stop searching!
|
||||
if (!cube.findRayIntersection(origin, direction, localDistance, localFace)) {
|
||||
if (!cube.findRayIntersection(origin, direction, distanceToElementCube, localFace)) {
|
||||
keepSearching = false; // no point in continuing to search
|
||||
return false; // we did not intersect
|
||||
}
|
||||
|
@ -1353,14 +1357,18 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
|||
return false; // we don't intersect with non-leaves, and we keep searching
|
||||
}
|
||||
|
||||
// we did hit this element, so calculate appropriate distances
|
||||
localDistance *= TREE_SCALE;
|
||||
if (localDistance < distance) {
|
||||
if (findDetailedRayIntersection(origin, direction, keepSearching,
|
||||
element, distance, face, intersectedObject)) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
return true;
|
||||
// if the distance to the element cube is not less than the current best distance, then it's not possible
|
||||
// for any details inside the cube to be closer so we don't need to consider them.
|
||||
if (cube.contains(origin) || distanceToElementCube < distance) {
|
||||
|
||||
if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails,
|
||||
face, intersectedObject, precisionPicking, distanceToElementCube)) {
|
||||
|
||||
if (distanceToElementDetails < distance) {
|
||||
distance = distanceToElementDetails;
|
||||
face = localFace;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -1368,11 +1376,12 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
|||
|
||||
bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) {
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube) {
|
||||
|
||||
// we did hit this element, so calculate appropriate distances
|
||||
if (hasContent()) {
|
||||
element = this;
|
||||
distance = distanceToElementCube;
|
||||
if (intersectedObject) {
|
||||
*intersectedObject = this;
|
||||
}
|
||||
|
|
|
@ -119,11 +119,11 @@ public:
|
|||
virtual bool canRayIntersect() const { return isLeaf(); }
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& node, float& distance, BoxFace& face,
|
||||
void** intersectedObject = NULL);
|
||||
void** intersectedObject = NULL, bool precisionPicking = false);
|
||||
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject);
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube);
|
||||
|
||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||
glm::vec3& penetration, void** penetratedObject) const;
|
||||
|
|
|
@ -252,6 +252,30 @@ bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direct
|
|||
return true;
|
||||
}
|
||||
|
||||
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
||||
glm::vec3 firstSide = v0 - v1;
|
||||
glm::vec3 secondSide = v2 - v1;
|
||||
glm::vec3 normal = glm::cross(secondSide, firstSide);
|
||||
float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
|
||||
if (dividend > 0.0f) {
|
||||
return false; // origin below plane
|
||||
}
|
||||
float divisor = glm::dot(normal, direction);
|
||||
if (divisor > -EPSILON) {
|
||||
return false;
|
||||
}
|
||||
float t = dividend / divisor;
|
||||
glm::vec3 point = origin + direction * t;
|
||||
if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
|
||||
distance = t;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do line segments (r1p1.x, r1p1.y)--(r1p2.x, r1p2.y) and (r2p1.x, r2p1.y)--(r2p2.x, r2p2.y) intersect?
|
||||
// from: http://ptspts.blogspot.com/2010/06/how-to-determine-if-two-line-segments.html
|
||||
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2) {
|
||||
|
|
|
@ -76,6 +76,22 @@ bool findRaySphereIntersection(const glm::vec3& origin, const glm::vec3& directi
|
|||
bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& start, const glm::vec3& end, float radius, float& distance);
|
||||
|
||||
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance);
|
||||
|
||||
class Triangle {
|
||||
public:
|
||||
glm::vec3 v0;
|
||||
glm::vec3 v1;
|
||||
glm::vec3 v2;
|
||||
};
|
||||
|
||||
inline bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const Triangle& triangle, float& distance) {
|
||||
return findRayTriangleIntersection(origin, direction, triangle.v0, triangle.v1, triangle.v2, distance);
|
||||
}
|
||||
|
||||
|
||||
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2);
|
||||
bool isOnSegment(float xi, float yi, float xj, float yj, float xk, float yk);
|
||||
int computeDirection(float xi, float yi, float xj, float yj, float xk, float yk);
|
||||
|
|
Loading…
Reference in a new issue