Fixed conflicts

This commit is contained in:
Philip Rosedale 2013-05-21 15:04:12 -07:00
commit 330c59b36b
13 changed files with 156 additions and 21 deletions

View file

@ -82,39 +82,39 @@ protected:
};
void GLCanvas::initializeGL() {
static_cast<Application*>(QCoreApplication::instance())->initializeGL();
Application::getInstance()->initializeGL();
}
void GLCanvas::paintGL() {
static_cast<Application*>(QCoreApplication::instance())->paintGL();
Application::getInstance()->paintGL();
}
void GLCanvas::resizeGL(int width, int height) {
static_cast<Application*>(QCoreApplication::instance())->resizeGL(width, height);
Application::getInstance()->resizeGL(width, height);
}
void GLCanvas::keyPressEvent(QKeyEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->keyPressEvent(event);
Application::getInstance()->keyPressEvent(event);
}
void GLCanvas::keyReleaseEvent(QKeyEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->keyReleaseEvent(event);
Application::getInstance()->keyReleaseEvent(event);
}
void GLCanvas::mouseMoveEvent(QMouseEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->mouseMoveEvent(event);
Application::getInstance()->mouseMoveEvent(event);
}
void GLCanvas::mousePressEvent(QMouseEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->mousePressEvent(event);
Application::getInstance()->mousePressEvent(event);
}
void GLCanvas::mouseReleaseEvent(QMouseEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->mouseReleaseEvent(event);
Application::getInstance()->mouseReleaseEvent(event);
}
void GLCanvas::wheelEvent(QWheelEvent* event) {
static_cast<Application*>(QCoreApplication::instance())->wheelEvent(event);
Application::getInstance()->wheelEvent(event);
}
Application::Application(int& argc, char** argv) :
@ -2114,7 +2114,7 @@ void* Application::networkReceive(void* args) {
sockaddr senderAddress;
ssize_t bytesReceived;
Application* app = static_cast<Application*>(QCoreApplication::instance());
Application* app = Application::getInstance();
while (!app->_stopNetworkReceiveThread) {
// check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
if (app->_wantToKillLocalVoxels) {

View file

@ -44,6 +44,8 @@ class Application : public QApplication {
Q_OBJECT
public:
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
Application(int& argc, char** argv);
void initializeGL();
@ -60,6 +62,7 @@ public:
void wheelEvent(QWheelEvent* event);
Avatar* getAvatar() { return &_myAvatar; }
VoxelSystem* getVoxels() { return &_voxels; }
private slots:

View file

@ -84,7 +84,7 @@ int audioCallback (const void* inputBuffer,
Audio* parentAudio = (Audio*) userData;
AgentList* agentList = AgentList::getInstance();
Application* interface = (Application*) QCoreApplication::instance();
Application* interface = Application::getInstance();
Avatar* interfaceAvatar = interface->getAvatar();
int16_t* inputLeft = ((int16_t**) inputBuffer)[0];
@ -306,8 +306,6 @@ Audio::Audio(Oscilloscope* scope) :
_averagedLatency(0.0),
_measuredJitter(0),
_jitterBufferLengthMsecs(12.0),
_jitterBufferSamples(_jitterBufferLengthMsecs *
NUM_AUDIO_CHANNELS * (SAMPLE_RATE / 1000.0)),
_wasStarved(0),
_lastInputLoudness(0),
_mixerLoopbackFlag(false),

View file

@ -49,7 +49,6 @@ private:
float _averagedLatency;
float _measuredJitter;
float _jitterBufferLengthMsecs;
short _jitterBufferSamples;
int _wasStarved;
float _lastInputLoudness;
bool _mixerLoopbackFlag;

View file

@ -10,6 +10,7 @@
#include <lodepng.h>
#include <SharedUtil.h>
#include "world.h"
#include "Application.h"
#include "Avatar.h"
#include "Head.h"
#include "Log.h"
@ -254,6 +255,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime);
}
// collision response with voxels
if (_isMine) {
updateCollisionWithVoxels(deltaTime);
}
// driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
if (_isMine) {
@ -583,6 +589,20 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d
}
}
void Avatar::updateCollisionWithVoxels(float deltaTime) {
VoxelSystem* voxels = Application::getInstance()->getVoxels();
float radius = _height * 0.125f;
glm::vec3 halfVector = glm::vec3(0.0f, _height * ONE_HALF - radius, 0.0f);
glm::vec3 penetration;
if (voxels->findCapsulePenetration(_position - halfVector, _position + halfVector, radius, penetration)) {
_position += penetration;
// reflect the velocity component in the direction of penetration
glm::vec3 direction = glm::normalize(penetration);
_velocity -= 2.0f * glm::dot(_velocity, direction) * direction * BOUNCE;
}
}
void Avatar::updateAvatarCollisions(float deltaTime) {
// Reset detector for nearest avatar

View file

@ -194,6 +194,7 @@ private:
void updateHandMovementAndTouching(float deltaTime);
void updateAvatarCollisions(float deltaTime);
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
void updateCollisionWithVoxels(float deltaTime);
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime);
void checkForMouseRayTouching();

View file

@ -35,4 +35,4 @@ private:
glm::vec3 _estimatedRotation;
#endif /* defined(__hifi__Transmitter__) */
};
};

View file

@ -663,7 +663,8 @@ void VoxelSystem::render(bool texture) {
// draw the number of voxels we have
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID);
glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
glDrawElements(GL_TRIANGLES, 36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTICES_PER_VOXEL * _voxelsInReadArrays,
36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
@ -929,6 +930,20 @@ bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3&
return true;
}
bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) {
pthread_mutex_lock(&_treeLock);
bool result = _tree->findSpherePenetration(center, radius, penetration);
pthread_mutex_unlock(&_treeLock);
return result;
}
bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
pthread_mutex_lock(&_treeLock);
bool result = _tree->findCapsulePenetration(start, end, radius, penetration);
pthread_mutex_unlock(&_treeLock);
return result;
}
class falseColorizeRandomEveryOtherArgs {
public:
falseColorizeRandomEveryOtherArgs() : totalNodes(0), colorableNodes(0), coloredNodes(0), colorThis(true) {};

View file

@ -69,7 +69,10 @@ public:
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelDetail& detail, float& distance, BoxFace& face);
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration);
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration);
void collectStatsForTreesAndVBOs();
void deleteVoxelAt(float x, float y, float z, float s);

View file

@ -247,6 +247,10 @@ void VoxelNode::printDebugDetails(const char* label) const {
printOctalCode(_octalCode);
}
float VoxelNode::getEnclosingRadius() const {
return getScale() * sqrtf(3.0f) / 2.0f;
}
bool VoxelNode::isInView(const ViewFrustum& viewFrustum) const {
AABox box = _box; // use temporary box so we can scale it
box.scale(TREE_SCALE);

View file

@ -57,6 +57,8 @@ public:
float getScale() const { return _box.getSize().x; /* voxelScale = (1 / powf(2, *node->getOctalCode())); */ };
int getLevel() const { return *_octalCode + 1; /* one based or zero based? */ };
float getEnclosingRadius() const;
bool isColored() const { return (_trueColor[3]==1); };
bool isInView(const ViewFrustum& viewFrustum) const;
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;

View file

@ -652,7 +652,7 @@ public:
bool found;
};
bool findRayOperation(VoxelNode* node, void* extraData) {
bool findRayIntersectionOp(VoxelNode* node, void* extraData) {
RayArgs* args = static_cast<RayArgs*>(extraData);
AABox box = node->getAABox();
float distance;
@ -674,10 +674,97 @@ bool findRayOperation(VoxelNode* node, void* extraData) {
}
bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelNode*& node, float& distance, BoxFace& face)
{
VoxelNode*& node, float& distance, BoxFace& face) {
RayArgs args = { origin / (float)TREE_SCALE, direction, node, distance, face };
recurseTreeWithOperation(findRayOperation, &args);
recurseTreeWithOperation(findRayIntersectionOp, &args);
return args.found;
}
class SphereArgs {
public:
glm::vec3 center;
float radius;
glm::vec3& penetration;
bool found;
};
bool findSpherePenetrationOp(VoxelNode* node, void* extraData) {
SphereArgs* args = static_cast<SphereArgs*>(extraData);
// currently, we treat each node as a sphere enveloping the box
const glm::vec3& nodeCenter = node->getCenter();
glm::vec3 vector = args->center - nodeCenter;
float vectorLength = glm::length(vector);
float distance = vectorLength - node->getEnclosingRadius() - args->radius;
if (distance >= 0.0f) {
return false;
}
if (!node->isLeaf()) {
return true; // recurse on children
}
if (node->isColored()) {
args->penetration += vector * (-distance * TREE_SCALE / vectorLength);
args->found = true;
}
return false;
}
bool VoxelTree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) {
SphereArgs args = { center / (float)TREE_SCALE, radius / TREE_SCALE, penetration };
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
recurseTreeWithOperation(findSpherePenetrationOp, &args);
return args.found;
}
class CapsuleArgs {
public:
glm::vec3 start;
glm::vec3 end;
float radius;
glm::vec3& penetration;
bool found;
};
glm::vec3 computeVectorFromPointToSegment(const glm::vec3& point, const glm::vec3& start, const glm::vec3& end) {
// compute the projection of the point vector onto the segment vector
glm::vec3 segmentVector = end - start;
float proj = glm::dot(point - start, segmentVector) / glm::dot(segmentVector, segmentVector);
if (proj <= 0.0f) { // closest to the start
return start - point;
} else if (proj >= 1.0f) { // closest to the end
return end - point;
} else { // closest to the middle
return start + segmentVector*proj - point;
}
}
bool findCapsulePenetrationOp(VoxelNode* node, void* extraData) {
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
// currently, we treat each node as a sphere enveloping the box
const glm::vec3& nodeCenter = node->getCenter();
glm::vec3 vector = computeVectorFromPointToSegment(nodeCenter, args->start, args->end);
float vectorLength = glm::length(vector);
float distance = vectorLength - node->getEnclosingRadius() - args->radius;
if (distance >= 0.0f) {
return false;
}
if (!node->isLeaf()) {
return true; // recurse on children
}
if (node->isColored()) {
args->penetration += vector * (-distance * TREE_SCALE / vectorLength);
args->found = true;
}
return false;
}
bool VoxelTree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
CapsuleArgs args = { start / (float)TREE_SCALE, end / (float)TREE_SCALE, radius / TREE_SCALE, penetration };
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
recurseTreeWithOperation(findCapsulePenetrationOp, &args);
return args.found;
}

View file

@ -71,6 +71,9 @@ public:
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelNode*& node, float& distance, BoxFace& face);
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration);
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration);
// Note: this assumes the fileFormat is the HIO individual voxels code files
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);