mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
merge upstream/master into andrew/inertia
This commit is contained in:
commit
a141ce37e4
19 changed files with 346 additions and 311 deletions
|
@ -1,131 +1,3 @@
|
||||||
// Add your JavaScript for assignment below this line
|
// Here you can put a script that will be run by an assignment-client (AC)
|
||||||
|
// For examples, please go to http://public.highfidelity.io/scripts
|
||||||
// The following is an example of Conway's Game of Life (http://en.wikipedia.org/wiki/Conway's_Game_of_Life)
|
// The directory named acScripts contains assignment-client specific scripts you can try.
|
||||||
|
|
||||||
var NUMBER_OF_CELLS_EACH_DIMENSION = 64;
|
|
||||||
var NUMBER_OF_CELLS = NUMBER_OF_CELLS_EACH_DIMENSION * NUMBER_OF_CELLS_EACH_DIMENSION;
|
|
||||||
|
|
||||||
var currentCells = [];
|
|
||||||
var nextCells = [];
|
|
||||||
|
|
||||||
var METER_LENGTH = 1;
|
|
||||||
var cellScale = (NUMBER_OF_CELLS_EACH_DIMENSION * METER_LENGTH) / NUMBER_OF_CELLS_EACH_DIMENSION;
|
|
||||||
|
|
||||||
// randomly populate the cell start values
|
|
||||||
for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
|
||||||
// create the array to hold this row
|
|
||||||
currentCells[i] = [];
|
|
||||||
|
|
||||||
// create the array to hold this row in the nextCells array
|
|
||||||
nextCells[i] = [];
|
|
||||||
|
|
||||||
for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
|
||||||
currentCells[i][j] = Math.floor(Math.random() * 2);
|
|
||||||
|
|
||||||
// put the same value in the nextCells array for first board draw
|
|
||||||
nextCells[i][j] = currentCells[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isNeighbourAlive(i, j) {
|
|
||||||
if (i < 0 || i >= NUMBER_OF_CELLS_EACH_DIMENSION
|
|
||||||
|| i < 0 || j >= NUMBER_OF_CELLS_EACH_DIMENSION) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return currentCells[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCells() {
|
|
||||||
var i = 0;
|
|
||||||
var j = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
|
||||||
for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
|
||||||
// figure out the number of live neighbours for the i-j cell
|
|
||||||
var liveNeighbours =
|
|
||||||
isNeighbourAlive(i + 1, j - 1) + isNeighbourAlive(i + 1, j) + isNeighbourAlive(i + 1, j + 1) +
|
|
||||||
isNeighbourAlive(i, j - 1) + isNeighbourAlive(i, j + 1) +
|
|
||||||
isNeighbourAlive(i - 1, j - 1) + isNeighbourAlive(i - 1, j) + isNeighbourAlive(i - 1, j + 1);
|
|
||||||
|
|
||||||
if (currentCells[i][j]) {
|
|
||||||
// live cell
|
|
||||||
|
|
||||||
if (liveNeighbours < 2) {
|
|
||||||
// rule #1 - under-population - this cell will die
|
|
||||||
// mark it zero to mark the change
|
|
||||||
nextCells[i][j] = 0;
|
|
||||||
} else if (liveNeighbours < 4) {
|
|
||||||
// rule #2 - this cell lives
|
|
||||||
// mark it -1 to mark no change
|
|
||||||
nextCells[i][j] = -1;
|
|
||||||
} else {
|
|
||||||
// rule #3 - overcrowding - this cell dies
|
|
||||||
// mark it zero to mark the change
|
|
||||||
nextCells[i][j] = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// dead cell
|
|
||||||
if (liveNeighbours == 3) {
|
|
||||||
// rule #4 - reproduction - this cell revives
|
|
||||||
// mark it one to mark the change
|
|
||||||
nextCells[i][j] = 1;
|
|
||||||
} else {
|
|
||||||
// this cell stays dead
|
|
||||||
// mark it -1 for no change
|
|
||||||
nextCells[i][j] = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.random() < 0.001) {
|
|
||||||
// Random mutation to keep things interesting in there.
|
|
||||||
nextCells[i][j] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
|
||||||
for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
|
||||||
if (nextCells[i][j] != -1) {
|
|
||||||
// there has been a change to this cell, change the value in the currentCells array
|
|
||||||
currentCells[i][j] = nextCells[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendNextCells() {
|
|
||||||
for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
|
||||||
for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
|
||||||
if (nextCells[i][j] != -1) {
|
|
||||||
// there has been a change to the state of this cell, send it
|
|
||||||
|
|
||||||
// find the x and y position for this voxel, z = 0
|
|
||||||
var x = j * cellScale;
|
|
||||||
var y = i * cellScale;
|
|
||||||
|
|
||||||
// queue a packet to add a voxel for the new cell
|
|
||||||
var color = (nextCells[i][j] == 1) ? 255 : 1;
|
|
||||||
Voxels.setVoxel(x, y, 0, cellScale, color, color, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var sentFirstBoard = false;
|
|
||||||
|
|
||||||
function step(deltaTime) {
|
|
||||||
if (sentFirstBoard) {
|
|
||||||
// we've already sent the first full board, perform a step in time
|
|
||||||
updateCells();
|
|
||||||
} else {
|
|
||||||
// this will be our first board send
|
|
||||||
sentFirstBoard = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendNextCells();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Script.update.connect(step);
|
|
||||||
Voxels.setPacketsPerSecond(200);
|
|
||||||
|
|
|
@ -5,19 +5,89 @@
|
||||||
// Created by Clément Brisset on 7/18/14.
|
// Created by Clément Brisset on 7/18/14.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
|
// If using Hydra controllers, pulling the triggers makes laser pointers emanate from the respective hands.
|
||||||
|
// If using a Leap Motion or similar to control your avatar's hands and fingers, pointing with your index fingers makes
|
||||||
|
// laser pointers emanate from the respective index fingers.
|
||||||
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
var LEFT = 0;
|
var laserPointer = (function () {
|
||||||
var RIGHT = 1;
|
|
||||||
var LEFT_HAND_FLAG = 1;
|
|
||||||
var RIGHT_HAND_FLAG = 2;
|
|
||||||
|
|
||||||
function update() {
|
var NUM_FINGERs = 4, // Excluding thumb
|
||||||
var state = ((Controller.getTriggerValue(LEFT) > 0.9) ? LEFT_HAND_FLAG : 0) +
|
fingers = [
|
||||||
((Controller.getTriggerValue(RIGHT) > 0.9) ? RIGHT_HAND_FLAG : 0);
|
[ "LeftHandIndex", "LeftHandMiddle", "LeftHandRing", "LeftHandPinky" ],
|
||||||
MyAvatar.setHandState(state);
|
[ "RightHandIndex", "RightHandMiddle", "RightHandRing", "RightHandPinky" ]
|
||||||
}
|
];
|
||||||
|
|
||||||
Script.update.connect(update);
|
function isHandPointing(hand) {
|
||||||
|
var MINIMUM_TRIGGER_PULL = 0.9;
|
||||||
|
return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isFingerPointing(hand) {
|
||||||
|
// Index finger is pointing if final two bones of middle, ring, and pinky fingers are > 90 degrees w.r.t. index finger
|
||||||
|
|
||||||
|
var pointing,
|
||||||
|
indexDirection,
|
||||||
|
otherDirection,
|
||||||
|
f;
|
||||||
|
|
||||||
|
pointing = true;
|
||||||
|
|
||||||
|
indexDirection = Vec3.subtract(
|
||||||
|
MyAvatar.getJointPosition(fingers[hand][0] + "4"),
|
||||||
|
MyAvatar.getJointPosition(fingers[hand][0] + "2")
|
||||||
|
);
|
||||||
|
|
||||||
|
for (f = 1; f < NUM_FINGERs; f += 1) {
|
||||||
|
otherDirection = Vec3.subtract(
|
||||||
|
MyAvatar.getJointPosition(fingers[hand][f] + "4"),
|
||||||
|
MyAvatar.getJointPosition(fingers[hand][f] + "2")
|
||||||
|
);
|
||||||
|
pointing = pointing && Vec3.dot(indexDirection, otherDirection) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pointing;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
var LEFT_HAND = 0,
|
||||||
|
RIGHT_HAND = 1,
|
||||||
|
LEFT_HAND_POINTING_FLAG = 1,
|
||||||
|
RIGHT_HAND_POINTING_FLAG = 2,
|
||||||
|
FINGER_POINTING_FLAG = 4,
|
||||||
|
handState;
|
||||||
|
|
||||||
|
handState = 0;
|
||||||
|
|
||||||
|
if (isHandPointing(LEFT_HAND)) {
|
||||||
|
handState += LEFT_HAND_POINTING_FLAG;
|
||||||
|
}
|
||||||
|
if (isHandPointing(RIGHT_HAND)) {
|
||||||
|
handState += RIGHT_HAND_POINTING_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handState === 0) {
|
||||||
|
if (isFingerPointing(LEFT_HAND)) {
|
||||||
|
handState += LEFT_HAND_POINTING_FLAG;
|
||||||
|
}
|
||||||
|
if (isFingerPointing(RIGHT_HAND)) {
|
||||||
|
handState += RIGHT_HAND_POINTING_FLAG;
|
||||||
|
}
|
||||||
|
if (handState !== 0) {
|
||||||
|
handState += FINGER_POINTING_FLAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MyAvatar.setHandState(handState);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
update: update
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
Script.update.connect(laserPointer.update);
|
||||||
|
|
|
@ -541,8 +541,6 @@ void Application::initializeGL() {
|
||||||
} else {
|
} else {
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
int argc = 0;
|
|
||||||
glutInit(&argc, 0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -3593,7 +3591,7 @@ void Application::renderViewFrustum(ViewFrustum& viewFrustum) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glColor4f(1, 1, 0, 1);
|
glColor4f(1, 1, 0, 1);
|
||||||
glTranslatef(position.x, position.y, position.z); // where we actually want it!
|
glTranslatef(position.x, position.y, position.z); // where we actually want it!
|
||||||
glutWireSphere(keyholeRadius, 20, 20);
|
DependencyManager::get<GeometryCache>()->renderSphere(keyholeRadius, 20, 20, false);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,6 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// no clue which versions are affected...
|
|
||||||
#define WORKAROUND_BROKEN_GLUT_STROKES
|
|
||||||
// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void renderWorldBox() {
|
void renderWorldBox() {
|
||||||
// Show edge of world
|
// Show edge of world
|
||||||
float red[] = {1, 0, 0};
|
float red[] = {1, 0, 0};
|
||||||
|
|
|
@ -282,43 +282,64 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool
|
||||||
// render pointing lasers
|
// render pointing lasers
|
||||||
glm::vec3 laserColor = glm::vec3(1.0f, 0.0f, 1.0f);
|
glm::vec3 laserColor = glm::vec3(1.0f, 0.0f, 1.0f);
|
||||||
float laserLength = 50.0f;
|
float laserLength = 50.0f;
|
||||||
if (_handState == HAND_STATE_LEFT_POINTING ||
|
glm::vec3 position;
|
||||||
_handState == HAND_STATE_BOTH_POINTING) {
|
glm::quat rotation;
|
||||||
int leftIndex = _skeletonModel.getLeftHandJointIndex();
|
bool havePosition, haveRotation;
|
||||||
glm::vec3 leftPosition;
|
|
||||||
glm::quat leftRotation;
|
if (_handState & LEFT_HAND_POINTING_FLAG) {
|
||||||
_skeletonModel.getJointPositionInWorldFrame(leftIndex, leftPosition);
|
|
||||||
_skeletonModel.getJointRotationInWorldFrame(leftIndex, leftRotation);
|
if (_handState & IS_FINGER_POINTING_FLAG) {
|
||||||
glPushMatrix(); {
|
int leftIndexTip = getJointIndex("LeftHandIndex4");
|
||||||
glTranslatef(leftPosition.x, leftPosition.y, leftPosition.z);
|
int leftIndexTipJoint = getJointIndex("LeftHandIndex3");
|
||||||
float angle = glm::degrees(glm::angle(leftRotation));
|
havePosition = _skeletonModel.getJointPositionInWorldFrame(leftIndexTip, position);
|
||||||
glm::vec3 axis = glm::axis(leftRotation);
|
haveRotation = _skeletonModel.getJointRotationInWorldFrame(leftIndexTipJoint, rotation);
|
||||||
glRotatef(angle, axis.x, axis.y, axis.z);
|
} else {
|
||||||
glBegin(GL_LINES);
|
int leftHand = _skeletonModel.getLeftHandJointIndex();
|
||||||
glColor3f(laserColor.x, laserColor.y, laserColor.z);
|
havePosition = _skeletonModel.getJointPositionInWorldFrame(leftHand, position);
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
haveRotation = _skeletonModel.getJointRotationInWorldFrame(leftHand, rotation);
|
||||||
glVertex3f(0.0f, laserLength, 0.0f);
|
}
|
||||||
glEnd();
|
|
||||||
} glPopMatrix();
|
if (havePosition && haveRotation) {
|
||||||
|
glPushMatrix(); {
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
float angle = glm::degrees(glm::angle(rotation));
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(angle, axis.x, axis.y, axis.z);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(laserColor.x, laserColor.y, laserColor.z);
|
||||||
|
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(0.0f, laserLength, 0.0f);
|
||||||
|
glEnd();
|
||||||
|
} glPopMatrix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_handState == HAND_STATE_RIGHT_POINTING ||
|
|
||||||
_handState == HAND_STATE_BOTH_POINTING) {
|
if (_handState & RIGHT_HAND_POINTING_FLAG) {
|
||||||
int rightIndex = _skeletonModel.getRightHandJointIndex();
|
|
||||||
glm::vec3 rightPosition;
|
if (_handState & IS_FINGER_POINTING_FLAG) {
|
||||||
glm::quat rightRotation;
|
int rightIndexTip = getJointIndex("RightHandIndex4");
|
||||||
_skeletonModel.getJointPositionInWorldFrame(rightIndex, rightPosition);
|
int rightIndexTipJoint = getJointIndex("RightHandIndex3");
|
||||||
_skeletonModel.getJointRotationInWorldFrame(rightIndex, rightRotation);
|
havePosition = _skeletonModel.getJointPositionInWorldFrame(rightIndexTip, position);
|
||||||
glPushMatrix(); {
|
haveRotation = _skeletonModel.getJointRotationInWorldFrame(rightIndexTipJoint, rotation);
|
||||||
glTranslatef(rightPosition.x, rightPosition.y, rightPosition.z);
|
} else {
|
||||||
float angle = glm::degrees(glm::angle(rightRotation));
|
int rightHand = _skeletonModel.getRightHandJointIndex();
|
||||||
glm::vec3 axis = glm::axis(rightRotation);
|
havePosition = _skeletonModel.getJointPositionInWorldFrame(rightHand, position);
|
||||||
glRotatef(angle, axis.x, axis.y, axis.z);
|
haveRotation = _skeletonModel.getJointRotationInWorldFrame(rightHand, rotation);
|
||||||
glBegin(GL_LINES);
|
}
|
||||||
glColor3f(laserColor.x, laserColor.y, laserColor.z);
|
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
if (havePosition && haveRotation) {
|
||||||
glVertex3f(0.0f, laserLength, 0.0f);
|
glPushMatrix(); {
|
||||||
glEnd();
|
glTranslatef(position.x, position.y, position.z);
|
||||||
} glPopMatrix();
|
float angle = glm::degrees(glm::angle(rotation));
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(angle, axis.x, axis.y, axis.z);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(laserColor.x, laserColor.y, laserColor.z);
|
||||||
|
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(0.0f, laserLength, 0.0f);
|
||||||
|
glEnd();
|
||||||
|
} glPopMatrix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ void Hand::renderHandTargets(bool isMine) {
|
||||||
|
|
||||||
const float collisionRadius = 0.05f;
|
const float collisionRadius = 0.05f;
|
||||||
glColor4f(0.5f,0.5f,0.5f, alpha);
|
glColor4f(0.5f,0.5f,0.5f, alpha);
|
||||||
glutWireSphere(collisionRadius, 10.0f, 10.0f);
|
DependencyManager::get<GeometryCache>()->renderSphere(collisionRadius, 10, 10, false);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,6 @@
|
||||||
|
|
||||||
class ModelItemID;
|
class ModelItemID;
|
||||||
|
|
||||||
enum AvatarHandState
|
|
||||||
{
|
|
||||||
HAND_STATE_NULL = 0,
|
|
||||||
HAND_STATE_LEFT_POINTING,
|
|
||||||
HAND_STATE_RIGHT_POINTING,
|
|
||||||
HAND_STATE_BOTH_POINTING,
|
|
||||||
NUM_HAND_STATES
|
|
||||||
};
|
|
||||||
|
|
||||||
class MyAvatar : public Avatar {
|
class MyAvatar : public Avatar {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally)
|
Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally)
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include <AttributeRegistry.h>
|
#include <AttributeRegistry.h>
|
||||||
|
#include <GeometryCache.h>
|
||||||
#include <MetavoxelMessages.h>
|
#include <MetavoxelMessages.h>
|
||||||
#include <MetavoxelUtil.h>
|
#include <MetavoxelUtil.h>
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
|
@ -492,12 +493,11 @@ void BoxTool::render() {
|
||||||
glColor4f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, BOX_ALPHA);
|
glColor4f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, BOX_ALPHA);
|
||||||
}
|
}
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glutSolidCube(1.0);
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
}
|
}
|
||||||
glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS);
|
glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS);
|
||||||
glutWireCube(1.0);
|
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <GeometryCache.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
@ -132,7 +134,7 @@ void NodeBounds::draw() {
|
||||||
getColorForNodeType(selectedNode->getType(), red, green, blue);
|
getColorForNodeType(selectedNode->getType(), red, green, blue);
|
||||||
|
|
||||||
glColor4f(red, green, blue, 0.2f);
|
glColor4f(red, green, blue, 0.2f);
|
||||||
glutSolidCube(1.0);
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
|
@ -62,11 +62,7 @@ void Sphere3DOverlay::render(RenderArgs* args) {
|
||||||
glm::vec3 positionToCenter = center - position;
|
glm::vec3 positionToCenter = center - position;
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
if (_isSolid) {
|
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, _isSolid);
|
||||||
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES);
|
|
||||||
} else {
|
|
||||||
glutWireSphere(1.0f, SLICES, SLICES);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
#include <GlowEffect.h>
|
#include <GlowEffect.h>
|
||||||
|
#include <GeometryCache.h>
|
||||||
#include <VoxelConstants.h>
|
#include <VoxelConstants.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
@ -47,7 +48,7 @@ void VoxelFade::render() {
|
||||||
voxelDetails.y + voxelDetails.s * 0.5f,
|
voxelDetails.y + voxelDetails.s * 0.5f,
|
||||||
voxelDetails.z + voxelDetails.s * 0.5f);
|
voxelDetails.z + voxelDetails.s * 0.5f);
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
glutSolidCube(voxelDetails.s);
|
DependencyManager::get<GeometryCache>()->renderSolidCube(voxelDetails.s);
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
|
|
@ -188,7 +188,11 @@ QByteArray AvatarData::toByteArray() {
|
||||||
// key state
|
// key state
|
||||||
setSemiNibbleAt(bitItems,KEY_STATE_START_BIT,_keyState);
|
setSemiNibbleAt(bitItems,KEY_STATE_START_BIT,_keyState);
|
||||||
// hand state
|
// hand state
|
||||||
setSemiNibbleAt(bitItems,HAND_STATE_START_BIT,_handState);
|
bool isFingerPointing = _handState & IS_FINGER_POINTING_FLAG;
|
||||||
|
setSemiNibbleAt(bitItems, HAND_STATE_START_BIT, _handState & ~IS_FINGER_POINTING_FLAG);
|
||||||
|
if (isFingerPointing) {
|
||||||
|
setAtBit(bitItems, HAND_STATE_FINGER_POINTING_BIT);
|
||||||
|
}
|
||||||
// faceshift state
|
// faceshift state
|
||||||
if (_headData->_isFaceshiftConnected) {
|
if (_headData->_isFaceshiftConnected) {
|
||||||
setAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
setAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
||||||
|
@ -439,8 +443,9 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) {
|
||||||
|
|
||||||
// key state, stored as a semi-nibble in the bitItems
|
// key state, stored as a semi-nibble in the bitItems
|
||||||
_keyState = (KeyState)getSemiNibbleAt(bitItems,KEY_STATE_START_BIT);
|
_keyState = (KeyState)getSemiNibbleAt(bitItems,KEY_STATE_START_BIT);
|
||||||
// hand state, stored as a semi-nibble in the bitItems
|
// hand state, stored as a semi-nibble plus a bit in the bitItems
|
||||||
_handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT);
|
_handState = getSemiNibbleAt(bitItems, HAND_STATE_START_BIT)
|
||||||
|
+ (oneAtBit(bitItems, HAND_STATE_FINGER_POINTING_BIT) ? IS_FINGER_POINTING_FLAG : 0);
|
||||||
|
|
||||||
_headData->_isFaceshiftConnected = oneAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
_headData->_isFaceshiftConnected = oneAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
||||||
_isChatCirclingEnabled = oneAtBit(bitItems, IS_CHAT_CIRCLING_ENABLED);
|
_isChatCirclingEnabled = oneAtBit(bitItems, IS_CHAT_CIRCLING_ENABLED);
|
||||||
|
|
|
@ -82,6 +82,12 @@ const int HAND_STATE_START_BIT = 2; // 3rd and 4th bits
|
||||||
const int IS_FACESHIFT_CONNECTED = 4; // 5th bit
|
const int IS_FACESHIFT_CONNECTED = 4; // 5th bit
|
||||||
const int IS_CHAT_CIRCLING_ENABLED = 5; // 6th bit
|
const int IS_CHAT_CIRCLING_ENABLED = 5; // 6th bit
|
||||||
const int HAS_REFERENTIAL = 6; // 7th bit
|
const int HAS_REFERENTIAL = 6; // 7th bit
|
||||||
|
const int HAND_STATE_FINGER_POINTING_BIT = 7; // 8th bit
|
||||||
|
|
||||||
|
const char HAND_STATE_NULL = 0;
|
||||||
|
const char LEFT_HAND_POINTING_FLAG = 1;
|
||||||
|
const char RIGHT_HAND_POINTING_FLAG = 2;
|
||||||
|
const char IS_FINGER_POINTING_FLAG = 4;
|
||||||
|
|
||||||
static const float MAX_AVATAR_SCALE = 1000.0f;
|
static const float MAX_AVATAR_SCALE = 1000.0f;
|
||||||
static const float MIN_AVATAR_SCALE = .005f;
|
static const float MIN_AVATAR_SCALE = .005f;
|
||||||
|
|
|
@ -28,79 +28,23 @@ void RenderableBoxEntityItem::render(RenderArgs* args) {
|
||||||
glm::vec3 position = getPositionInMeters();
|
glm::vec3 position = getPositionInMeters();
|
||||||
glm::vec3 center = getCenter() * (float)TREE_SCALE;
|
glm::vec3 center = getCenter() * (float)TREE_SCALE;
|
||||||
glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE;
|
glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE;
|
||||||
glm::vec3 halfDimensions = dimensions / 2.0f;
|
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
const bool useGlutCube = true;
|
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
|
|
||||||
if (useGlutCube) {
|
glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR,
|
||||||
glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR,
|
getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha());
|
||||||
getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha());
|
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(position.x, position.y, position.z);
|
glm::vec3 positionToCenter = center - position;
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
glPushMatrix();
|
DependencyManager::get<DeferredLightingEffect>()->renderSolidCube(1.0f);
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
|
||||||
DependencyManager::get<DeferredLightingEffect>()->renderSolidCube(1.0f);
|
|
||||||
glPopMatrix();
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
} else {
|
glPopMatrix();
|
||||||
static GLfloat vertices[] = { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front)
|
|
||||||
1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right)
|
|
||||||
1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0,v5,v6,v1 (top)
|
|
||||||
-1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1,v6,v7,v2 (left)
|
|
||||||
-1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7,v4,v3,v2 (bottom)
|
|
||||||
1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 }; // v4,v7,v6,v5 (back)
|
|
||||||
|
|
||||||
// normal array
|
|
||||||
static GLfloat normals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0,v1,v2,v3 (front)
|
|
||||||
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0,v3,v4,v5 (right)
|
|
||||||
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0,v5,v6,v1 (top)
|
|
||||||
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1,v6,v7,v2 (left)
|
|
||||||
0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom)
|
|
||||||
0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back)
|
|
||||||
|
|
||||||
// index array of vertex array for glDrawElements() & glDrawRangeElement()
|
|
||||||
static GLubyte indices[] = { 0, 1, 2, 2, 3, 0, // front
|
|
||||||
4, 5, 6, 6, 7, 4, // right
|
|
||||||
8, 9,10, 10,11, 8, // top
|
|
||||||
12,13,14, 14,15,12, // left
|
|
||||||
16,17,18, 18,19,16, // bottom
|
|
||||||
20,21,22, 22,23,20 }; // back
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glNormalPointer(GL_FLOAT, 0, normals);
|
|
||||||
glVertexPointer(3, GL_FLOAT, 0, vertices);
|
|
||||||
|
|
||||||
glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR,
|
|
||||||
getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha());
|
|
||||||
|
|
||||||
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram();
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glPushMatrix();
|
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
// we need to do half the size because the geometry in the VBOs are from -1,-1,-1 to 1,1,1
|
|
||||||
glScalef(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
|
||||||
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
|
|
||||||
glPopMatrix();
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
DependencyManager::get<DeferredLightingEffect>()->releaseSimpleProgram();
|
|
||||||
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
//
|
|
||||||
// GPUConfig.h
|
|
||||||
// libraries/gpu/src/gpu
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 12/17/14.
|
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef gpu__GLUTConfig__
|
|
||||||
#define gpu__GLUTConfig__
|
|
||||||
|
|
||||||
// TODO: remove these once we migrate away from GLUT calls
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include <GLUT/glut.h>
|
|
||||||
#elif defined(WIN32)
|
|
||||||
#include <GL/glut.h>
|
|
||||||
#else
|
|
||||||
#include <GL/glut.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // gpu__GLUTConfig__
|
|
|
@ -12,8 +12,6 @@
|
||||||
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
|
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
|
||||||
#include <gpu/GPUConfig.h>
|
#include <gpu/GPUConfig.h>
|
||||||
|
|
||||||
#include <gpu/GLUTConfig.h> // TODO - we need to get rid of this ASAP
|
|
||||||
|
|
||||||
#include <QOpenGLFramebufferObject>
|
#include <QOpenGLFramebufferObject>
|
||||||
|
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
|
@ -68,19 +66,19 @@ void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int sta
|
||||||
|
|
||||||
void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks) {
|
void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks) {
|
||||||
bindSimpleProgram();
|
bindSimpleProgram();
|
||||||
glutWireSphere(radius, slices, stacks);
|
DependencyManager::get<GeometryCache>()->renderSphere(radius, slices, stacks, false);
|
||||||
releaseSimpleProgram();
|
releaseSimpleProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::renderSolidCube(float size) {
|
void DeferredLightingEffect::renderSolidCube(float size) {
|
||||||
bindSimpleProgram();
|
bindSimpleProgram();
|
||||||
glutSolidCube(size);
|
DependencyManager::get<GeometryCache>()->renderSolidCube(size);
|
||||||
releaseSimpleProgram();
|
releaseSimpleProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::renderWireCube(float size) {
|
void DeferredLightingEffect::renderWireCube(float size) {
|
||||||
bindSimpleProgram();
|
bindSimpleProgram();
|
||||||
glutWireCube(size);
|
DependencyManager::get<GeometryCache>()->renderWireCube(size);
|
||||||
releaseSimpleProgram();
|
releaseSimpleProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,7 @@ public:
|
||||||
|
|
||||||
void init(AbstractViewStateInterface* viewState);
|
void init(AbstractViewStateInterface* viewState);
|
||||||
|
|
||||||
/// Returns a reference to a simple program suitable for rendering static
|
/// Returns a reference to a simple program suitable for rendering static untextured geometry
|
||||||
/// untextured geometry (such as that generated by glutSolidSphere, etc.)
|
|
||||||
ProgramObject& getSimpleProgram() { return _simpleProgram; }
|
ProgramObject& getSimpleProgram() { return _simpleProgram; }
|
||||||
|
|
||||||
/// Sets up the state necessary to render static untextured geometry with the simple program.
|
/// Sets up the state necessary to render static untextured geometry with the simple program.
|
||||||
|
|
|
@ -119,7 +119,7 @@ const int NUM_COORDS_PER_VERTEX = 3;
|
||||||
const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat);
|
const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat);
|
||||||
const int NUM_BYTES_PER_INDEX = sizeof(GLushort);
|
const int NUM_BYTES_PER_INDEX = sizeof(GLushort);
|
||||||
|
|
||||||
void GeometryCache::renderSphere(float radius, int slices, int stacks) {
|
void GeometryCache::renderSphere(float radius, int slices, int stacks, bool solid) {
|
||||||
VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)];
|
VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)];
|
||||||
int vertices = slices * (stacks - 1) + 2;
|
int vertices = slices * (stacks - 1) + 2;
|
||||||
int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD;
|
int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD;
|
||||||
|
@ -211,7 +211,11 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) {
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glScalef(radius, radius, radius);
|
glScalef(radius, radius, radius);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
if (solid) {
|
||||||
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
} else {
|
||||||
|
glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
@ -503,6 +507,161 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryCache::renderSolidCube(float size) {
|
||||||
|
VerticesIndices& vbo = _solidCubeVBOs[size];
|
||||||
|
const int FLOATS_PER_VERTEX = 3;
|
||||||
|
const int VERTICES_PER_FACE = 4;
|
||||||
|
const int NUMBER_OF_FACES = 6;
|
||||||
|
const int TRIANGLES_PER_FACE = 2;
|
||||||
|
const int VERTICES_PER_TRIANGLE = 3;
|
||||||
|
const int vertices = NUMBER_OF_FACES * VERTICES_PER_FACE * FLOATS_PER_VERTEX;
|
||||||
|
const int indices = NUMBER_OF_FACES * TRIANGLES_PER_FACE * VERTICES_PER_TRIANGLE;
|
||||||
|
const int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
|
if (vbo.first == 0) {
|
||||||
|
GLfloat* vertexData = new GLfloat[vertexPoints * 2]; // vertices and normals
|
||||||
|
GLfloat* vertex = vertexData;
|
||||||
|
float halfSize = size / 2.0f;
|
||||||
|
|
||||||
|
static GLfloat cannonicalVertices[vertexPoints] =
|
||||||
|
{ 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front)
|
||||||
|
1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right)
|
||||||
|
1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0,v5,v6,v1 (top)
|
||||||
|
-1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1,v6,v7,v2 (left)
|
||||||
|
-1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7,v4,v3,v2 (bottom)
|
||||||
|
1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 }; // v4,v7,v6,v5 (back)
|
||||||
|
|
||||||
|
// normal array
|
||||||
|
static GLfloat cannonicalNormals[vertexPoints] =
|
||||||
|
{ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0,v1,v2,v3 (front)
|
||||||
|
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0,v3,v4,v5 (right)
|
||||||
|
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0,v5,v6,v1 (top)
|
||||||
|
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1,v6,v7,v2 (left)
|
||||||
|
0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom)
|
||||||
|
0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back)
|
||||||
|
|
||||||
|
// index array of vertex array for glDrawElements() & glDrawRangeElement()
|
||||||
|
static GLubyte cannonicalIndices[indices] =
|
||||||
|
{ 0, 1, 2, 2, 3, 0, // front
|
||||||
|
4, 5, 6, 6, 7, 4, // right
|
||||||
|
8, 9,10, 10,11, 8, // top
|
||||||
|
12,13,14, 14,15,12, // left
|
||||||
|
16,17,18, 18,19,16, // bottom
|
||||||
|
20,21,22, 22,23,20 }; // back
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GLfloat* cannonicalVertex = &cannonicalVertices[0];
|
||||||
|
GLfloat* cannonicalNormal = &cannonicalNormals[0];
|
||||||
|
|
||||||
|
for (int i = 0; i < vertices; i++) {
|
||||||
|
//normals
|
||||||
|
*(vertex++) = *cannonicalNormal++;
|
||||||
|
*(vertex++) = *cannonicalNormal++;
|
||||||
|
*(vertex++) = *cannonicalNormal++;
|
||||||
|
|
||||||
|
// vertices
|
||||||
|
*(vertex++) = halfSize * *cannonicalVertex++;
|
||||||
|
*(vertex++) = halfSize * *cannonicalVertex++;
|
||||||
|
*(vertex++) = halfSize * *cannonicalVertex++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.first);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
|
||||||
|
delete[] vertexData;
|
||||||
|
|
||||||
|
GLushort* indexData = new GLushort[indices];
|
||||||
|
GLushort* index = indexData;
|
||||||
|
for (int i = 0; i < indices; i++) {
|
||||||
|
index[i] = cannonicalIndices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.second);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
|
||||||
|
delete[] indexData;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
}
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0);
|
||||||
|
glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float)));
|
||||||
|
|
||||||
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryCache::renderWireCube(float size) {
|
||||||
|
VerticesIndices& vbo = _wireCubeVBOs[size];
|
||||||
|
const int FLOATS_PER_VERTEX = 3;
|
||||||
|
const int VERTICES_PER_EDGE = 2;
|
||||||
|
const int TOP_EDGES = 4;
|
||||||
|
const int BOTTOM_EDGES = 4;
|
||||||
|
const int SIDE_EDGES = 4;
|
||||||
|
const int vertices = 8;
|
||||||
|
const int indices = (TOP_EDGES + BOTTOM_EDGES + SIDE_EDGES) * VERTICES_PER_EDGE;
|
||||||
|
if (vbo.first == 0) {
|
||||||
|
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
|
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a wire cube
|
||||||
|
GLfloat* vertex = vertexData;
|
||||||
|
float halfSize = size / 2.0f;
|
||||||
|
|
||||||
|
static GLfloat cannonicalVertices[] =
|
||||||
|
{ 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0, v1, v2, v3 (top)
|
||||||
|
1,-1, 1, 1,-1,-1, -1,-1,-1, -1,-1, 1 // v4, v5, v6, v7 (bottom)
|
||||||
|
};
|
||||||
|
|
||||||
|
// index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge
|
||||||
|
static GLubyte cannonicalIndices[indices] = {
|
||||||
|
0, 1, 1, 2, 2, 3, 3, 0, // (top)
|
||||||
|
4, 5, 5, 6, 6, 7, 7, 4, // (bottom)
|
||||||
|
0, 4, 1, 5, 2, 6, 3, 7, // (side edges)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < vertexPoints; i++) {
|
||||||
|
vertex[i] = cannonicalVertices[i] * halfSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.first);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
|
||||||
|
delete[] vertexData;
|
||||||
|
|
||||||
|
GLushort* indexData = new GLushort[indices];
|
||||||
|
GLushort* index = indexData;
|
||||||
|
for (int i = 0; i < indices; i++) {
|
||||||
|
index[i] = cannonicalIndices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.second);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
|
||||||
|
delete[] indexData;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
}
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0);
|
||||||
|
glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
|
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
|
||||||
return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();
|
return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,13 @@ class GeometryCache : public ResourceCache {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void renderHemisphere(int slices, int stacks);
|
void renderHemisphere(int slices, int stacks);
|
||||||
void renderSphere(float radius, int slices, int stacks);
|
void renderSphere(float radius, int slices, int stacks, bool solid = true);
|
||||||
void renderSquare(int xDivisions, int yDivisions);
|
void renderSquare(int xDivisions, int yDivisions);
|
||||||
void renderHalfCylinder(int slices, int stacks);
|
void renderHalfCylinder(int slices, int stacks);
|
||||||
void renderCone(float base, float height, int slices, int stacks);
|
void renderCone(float base, float height, int slices, int stacks);
|
||||||
void renderGrid(int xDivisions, int yDivisions);
|
void renderGrid(int xDivisions, int yDivisions);
|
||||||
|
void renderSolidCube(float size);
|
||||||
|
void renderWireCube(float size);
|
||||||
|
|
||||||
/// Loads geometry from the specified URL.
|
/// Loads geometry from the specified URL.
|
||||||
/// \param fallback a fallback URL to load if the desired one is unavailable
|
/// \param fallback a fallback URL to load if the desired one is unavailable
|
||||||
|
@ -66,6 +68,8 @@ private:
|
||||||
QHash<IntPair, VerticesIndices> _squareVBOs;
|
QHash<IntPair, VerticesIndices> _squareVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _coneVBOs;
|
QHash<IntPair, VerticesIndices> _coneVBOs;
|
||||||
|
QHash<float, VerticesIndices> _wireCubeVBOs;
|
||||||
|
QHash<float, VerticesIndices> _solidCubeVBOs;
|
||||||
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
||||||
|
|
||||||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||||
|
|
Loading…
Reference in a new issue