mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge branch 'master' of github.com:worklist/hifi
This commit is contained in:
commit
a433ea3fff
10 changed files with 227 additions and 57 deletions
|
@ -7,7 +7,10 @@
|
|||
//
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <Assignment.h>
|
||||
#include <AudioMixer.h>
|
||||
|
@ -18,13 +21,22 @@
|
|||
|
||||
const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
pid_t* childForks = NULL;
|
||||
sockaddr_in customAssignmentSocket = {};
|
||||
const char* assignmentPool = NULL;
|
||||
int numForks = 0;
|
||||
|
||||
void childClient() {
|
||||
// this is one of the child forks or there is a single assignment client, continue assignment-client execution
|
||||
|
||||
// create a NodeList as an unassigned client
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
|
||||
|
||||
// set the custom assignment socket if we have it
|
||||
if (customAssignmentSocket.sin_addr.s_addr != 0) {
|
||||
nodeList->setAssignmentServerSocket((sockaddr*) &customAssignmentSocket);
|
||||
}
|
||||
|
||||
// change the timeout on the nodelist socket to be as often as we want to re-request
|
||||
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
||||
|
||||
|
@ -33,12 +45,6 @@ int main(int argc, const char* argv[]) {
|
|||
unsigned char packetData[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
// grab the assignment pool from argv, if it was passed
|
||||
const char* assignmentPool = getCmdOption(argc, argv, "-p");
|
||||
|
||||
// set the overriden assignment-server hostname from argv, if it exists
|
||||
nodeList->setAssignmentServerHostname(getCmdOption(argc, argv, "-a"));
|
||||
|
||||
// create a request assignment, accept all assignments, pass the desired pool (if it exists)
|
||||
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
||||
|
||||
|
@ -46,7 +52,6 @@ int main(int argc, const char* argv[]) {
|
|||
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
||||
gettimeofday(&lastRequest, NULL);
|
||||
// if we're here we have no assignment, so send a request
|
||||
qDebug() << "Sending an assignment request -" << requestAssignment;
|
||||
nodeList->sendAssignment(requestAssignment);
|
||||
}
|
||||
|
||||
|
@ -69,7 +74,6 @@ int main(int argc, const char* argv[]) {
|
|||
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
||||
AudioMixer::run();
|
||||
} else {
|
||||
qDebug() << "Running as an avatar mixer!";
|
||||
AvatarMixer::run();
|
||||
}
|
||||
|
||||
|
@ -80,4 +84,108 @@ int main(int argc, const char* argv[]) {
|
|||
nodeList->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sigchldHandler(int sig) {
|
||||
pid_t processID;
|
||||
int status;
|
||||
|
||||
while ((processID = waitpid(-1, &status, WNOHANG)) != -1) {
|
||||
if (processID == 0) {
|
||||
// there are no more children to process, break out of here
|
||||
break;
|
||||
}
|
||||
|
||||
qDebug() << "Handling death of" << processID;
|
||||
|
||||
int newForkProcessID = 0;
|
||||
|
||||
// find the dead process in the array of child forks
|
||||
for (int i = 0; i < ::numForks; i++) {
|
||||
if (::childForks[i] == processID) {
|
||||
qDebug() << "Matched" << ::childForks[i] << "with" << processID;
|
||||
|
||||
newForkProcessID = fork();
|
||||
if (newForkProcessID == 0) {
|
||||
// this is the child, call childClient
|
||||
childClient();
|
||||
|
||||
// break out so we don't fork bomb
|
||||
break;
|
||||
} else {
|
||||
// this is the parent, replace the dead process with the new one
|
||||
::childForks[i] = newForkProcessID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parentMonitor() {
|
||||
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = sigchldHandler;
|
||||
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
pid_t childID = 0;
|
||||
|
||||
// don't bail until all children have finished
|
||||
while ((childID = waitpid(-1, NULL, 0))) {
|
||||
if (errno == ECHILD) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// delete the array of pid_t holding the forked process IDs
|
||||
delete[] ::childForks;
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
// grab the overriden assignment-server hostname from argv, if it exists
|
||||
const char* customAssignmentServer = getCmdOption(argc, argv, "-a");
|
||||
if (customAssignmentServer) {
|
||||
::customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServer, ASSIGNMENT_SERVER_PORT);
|
||||
}
|
||||
|
||||
const char* NUM_FORKS_PARAMETER = "-n";
|
||||
const char* numForksString = getCmdOption(argc, argv, NUM_FORKS_PARAMETER);
|
||||
|
||||
// grab the assignment pool from argv, if it was passed
|
||||
const char* ASSIGNMENT_POOL_PARAMETER = "-p";
|
||||
::assignmentPool = getCmdOption(argc, argv, ASSIGNMENT_POOL_PARAMETER);
|
||||
|
||||
int processID = 0;
|
||||
|
||||
if (numForksString) {
|
||||
::numForks = atoi(numForksString);
|
||||
qDebug() << "Starting" << numForks << "assignment clients.";
|
||||
|
||||
::childForks = new pid_t[numForks];
|
||||
|
||||
// fire off as many children as we need (this is one less than the parent since the parent will run as well)
|
||||
for (int i = 0; i < numForks; i++) {
|
||||
processID = fork();
|
||||
|
||||
if (processID == 0) {
|
||||
// this is in one of the children, break so we don't start a fork bomb
|
||||
break;
|
||||
} else {
|
||||
// this is in the parent, save the ID of the forked process
|
||||
childForks[i] = processID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (processID == 0 || numForks == 0) {
|
||||
childClient();
|
||||
} else {
|
||||
parentMonitor();
|
||||
}
|
||||
}
|
|
@ -85,19 +85,26 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
timeval lastStatSendTime = {};
|
||||
|
||||
const char ASSIGNMENT_POOL_OPTION[] = "-p";
|
||||
const char ASSIGNMENT_SERVER_OPTION[] = "-a";
|
||||
|
||||
// set our assignment pool from argv, if it exists
|
||||
const char* assignmentPool = getCmdOption(argc, argv, "-p");
|
||||
const char* assignmentPool = getCmdOption(argc, argv, ASSIGNMENT_POOL_OPTION);
|
||||
|
||||
// grab the overriden assignment-server hostname from argv, if it exists
|
||||
nodeList->setAssignmentServerHostname(getCmdOption(argc, argv, "-a"));
|
||||
const char* customAssignmentServer = getCmdOption(argc, argv, ASSIGNMENT_SERVER_OPTION);
|
||||
if (customAssignmentServer) {
|
||||
sockaddr_in customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServer, ASSIGNMENT_SERVER_PORT);
|
||||
nodeList->setAssignmentServerSocket((sockaddr*) &customAssignmentSocket);
|
||||
}
|
||||
|
||||
// use a map to keep track of iterations of silence for assignment creation requests
|
||||
const long long ASSIGNMENT_SILENCE_MAX_USECS = 5 * 1000 * 1000;
|
||||
|
||||
// as a domain-server we will always want an audio mixer and avatar mixer
|
||||
// setup the create assignment pointers for those
|
||||
Assignment *audioAssignment = NULL;
|
||||
Assignment *avatarAssignment = NULL;
|
||||
Assignment* audioAssignment = NULL;
|
||||
Assignment* avatarAssignment = NULL;
|
||||
|
||||
while (true) {
|
||||
if (!nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER)) {
|
||||
|
|
|
@ -44,8 +44,7 @@ float texCoordToViewSpaceZ(vec2 texCoord) {
|
|||
// given a texture coordinate, returns the 3D view space coordinate
|
||||
vec3 texCoordToViewSpace(vec2 texCoord) {
|
||||
float z = texCoordToViewSpaceZ(texCoord);
|
||||
return vec3(((texCoord * 2.0 - vec2(1.0 - gl_ProjectionMatrix[2][0], 1.0)) *
|
||||
(rightTop - leftBottom) + rightTop + leftBottom) * z / (-2.0 * near), z);
|
||||
return vec3((leftBottom + texCoord * (rightTop - leftBottom)) * (-z / near), z);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
|
|
|
@ -423,9 +423,6 @@ void Application::resizeGL(int width, int height) {
|
|||
resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height);
|
||||
resetCamerasOnResizeGL(_myCamera, width, height);
|
||||
|
||||
// Tell our viewFrustum about this change, using the application camera
|
||||
loadViewFrustum(_myCamera, _viewFrustum);
|
||||
|
||||
glViewport(0, 0, width, height); // shouldn't this account for the menu???
|
||||
|
||||
updateProjectionMatrix();
|
||||
|
@ -436,9 +433,12 @@ void Application::updateProjectionMatrix() {
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Tell our viewFrustum about this change, using the application camera
|
||||
loadViewFrustum(_myCamera, _viewFrustum);
|
||||
|
||||
float left, right, bottom, top, nearVal, farVal;
|
||||
glm::vec4 nearClipPlane, farClipPlane;
|
||||
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
|
||||
// If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the
|
||||
// _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum
|
||||
|
@ -631,8 +631,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
|
||||
case Qt::Key_J:
|
||||
if (isShifted) {
|
||||
_myCamera.setEyeOffsetOrientation(glm::normalize(
|
||||
glm::quat(glm::vec3(0, 0.002f, 0)) * _myCamera.getEyeOffsetOrientation()));
|
||||
_viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f);
|
||||
|
||||
} else {
|
||||
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0));
|
||||
}
|
||||
|
@ -641,8 +641,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
|
||||
case Qt::Key_M:
|
||||
if (isShifted) {
|
||||
_myCamera.setEyeOffsetOrientation(glm::normalize(
|
||||
glm::quat(glm::vec3(0, -0.002f, 0)) * _myCamera.getEyeOffsetOrientation()));
|
||||
_viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f);
|
||||
|
||||
} else {
|
||||
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0));
|
||||
}
|
||||
|
@ -1805,15 +1805,17 @@ void Application::update(float deltaTime) {
|
|||
}
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) {
|
||||
float xSign = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) ? 1.0f : -1.0f;
|
||||
if (_faceshift.isActive()) {
|
||||
const float EYE_OFFSET_SCALE = 0.005f;
|
||||
const float EYE_OFFSET_SCALE = 0.025f;
|
||||
glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE;
|
||||
_myCamera.setEyeOffsetPosition(glm::vec3(-position.x, position.y, position.z));
|
||||
_myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, position.y, position.z));
|
||||
updateProjectionMatrix();
|
||||
|
||||
} else if (_webcam.isActive()) {
|
||||
const float EYE_OFFSET_SCALE = 5.0f;
|
||||
_myCamera.setEyeOffsetPosition(_webcam.getEstimatedPosition() * EYE_OFFSET_SCALE);
|
||||
const float EYE_OFFSET_SCALE = 0.5f;
|
||||
glm::vec3 position = _webcam.getEstimatedPosition() * EYE_OFFSET_SCALE;
|
||||
_myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, -position.y, position.z));
|
||||
updateProjectionMatrix();
|
||||
}
|
||||
}
|
||||
|
@ -2135,6 +2137,19 @@ void Application::setupWorldLight(Camera& whichCamera) {
|
|||
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
||||
}
|
||||
|
||||
void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near,
|
||||
float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
|
||||
|
||||
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, near, far, nearClipPlane, farClipPlane);
|
||||
|
||||
// when mirrored, we must flip left and right
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
|
||||
float tmp = left;
|
||||
left = -right;
|
||||
right = -tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::displaySide(Camera& whichCamera) {
|
||||
// transform by eye offset
|
||||
|
||||
|
@ -2918,6 +2933,30 @@ void Application::renderViewFrustum(ViewFrustum& viewFrustum) {
|
|||
// left plane - top edge - viewFrustum.getNear to distant
|
||||
glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
|
||||
glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
|
||||
|
||||
// focal plane - bottom edge
|
||||
glColor3f(1.0f, 0.0f, 1.0f);
|
||||
float focalProportion = (viewFrustum.getFocalLength() - viewFrustum.getNearClip()) /
|
||||
(viewFrustum.getFarClip() - viewFrustum.getNearClip());
|
||||
glm::vec3 focalBottomLeft = glm::mix(viewFrustum.getNearBottomLeft(), viewFrustum.getFarBottomLeft(), focalProportion);
|
||||
glm::vec3 focalBottomRight = glm::mix(viewFrustum.getNearBottomRight(),
|
||||
viewFrustum.getFarBottomRight(), focalProportion);
|
||||
glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z);
|
||||
glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z);
|
||||
|
||||
// focal plane - top edge
|
||||
glm::vec3 focalTopLeft = glm::mix(viewFrustum.getNearTopLeft(), viewFrustum.getFarTopLeft(), focalProportion);
|
||||
glm::vec3 focalTopRight = glm::mix(viewFrustum.getNearTopRight(), viewFrustum.getFarTopRight(), focalProportion);
|
||||
glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z);
|
||||
glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z);
|
||||
|
||||
// focal plane - left edge
|
||||
glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z);
|
||||
glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z);
|
||||
|
||||
// focal plane - right edge
|
||||
glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z);
|
||||
glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z);
|
||||
}
|
||||
glEnd();
|
||||
glEnable(GL_LIGHTING);
|
||||
|
|
|
@ -135,6 +135,10 @@ public:
|
|||
|
||||
void setupWorldLight(Camera& whichCamera);
|
||||
|
||||
/// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account.
|
||||
void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near,
|
||||
float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
|
||||
|
||||
virtual void nodeAdded(Node* node);
|
||||
virtual void nodeKilled(Node* node);
|
||||
virtual void packetSentNotification(ssize_t length);
|
||||
|
|
|
@ -103,7 +103,7 @@ void AmbientOcclusionEffect::render() {
|
|||
|
||||
float left, right, bottom, top, nearVal, farVal;
|
||||
glm::vec4 nearClipPlane, farClipPlane;
|
||||
Application::getInstance()->getViewFrustum()->computeOffAxisFrustum(
|
||||
Application::getInstance()->computeOffAxisFrustum(
|
||||
left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
|
||||
_occlusionProgram->bind();
|
||||
|
|
|
@ -65,7 +65,8 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
|||
_nodeTypesOfInterest(NULL),
|
||||
_ownerID(UNKNOWN_NODE_ID),
|
||||
_lastNodeID(UNKNOWN_NODE_ID + 1),
|
||||
_numNoReplyDomainCheckIns(0)
|
||||
_numNoReplyDomainCheckIns(0),
|
||||
_assignmentServerSocket(NULL)
|
||||
{
|
||||
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
|
||||
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
|
||||
|
@ -376,7 +377,8 @@ int NodeList::processDomainServerList(unsigned char* packetData, size_t dataByte
|
|||
}
|
||||
|
||||
const char GLOBAL_ASSIGNMENT_SERVER_HOSTNAME[] = "assignment.highfidelity.io";
|
||||
|
||||
const sockaddr_in GLOBAL_ASSIGNMENT_SOCKET = socketForHostnameAndHostOrderPort(GLOBAL_ASSIGNMENT_SERVER_HOSTNAME,
|
||||
ASSIGNMENT_SERVER_PORT);
|
||||
void NodeList::sendAssignment(Assignment& assignment) {
|
||||
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
||||
|
||||
|
@ -387,13 +389,11 @@ void NodeList::sendAssignment(Assignment& assignment) {
|
|||
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
|
||||
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
||||
|
||||
// setup the assignmentServerSocket once, use a custom assignmentServerHostname if it is present
|
||||
static sockaddr_in assignmentServerSocket = socketForHostnameAndHostOrderPort((_assignmentServerHostname != NULL
|
||||
? (const char*) _assignmentServerHostname
|
||||
: GLOBAL_ASSIGNMENT_SERVER_HOSTNAME),
|
||||
ASSIGNMENT_SERVER_PORT);
|
||||
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
||||
sockaddr* assignmentServerSocket = (_assignmentServerSocket == NULL)
|
||||
? (sockaddr*) &GLOBAL_ASSIGNMENT_SOCKET
|
||||
: _assignmentServerSocket;
|
||||
|
||||
_nodeSocket.send((sockaddr*) assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
||||
}
|
||||
|
||||
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) {
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
void sendDomainServerCheckIn();
|
||||
int processDomainServerList(unsigned char *packetData, size_t dataBytes);
|
||||
|
||||
void setAssignmentServerHostname(const char* serverHostname) { _assignmentServerHostname = serverHostname; }
|
||||
void setAssignmentServerSocket(sockaddr* serverSocket) { _assignmentServerSocket = serverSocket; }
|
||||
void sendAssignment(Assignment& assignment);
|
||||
|
||||
Node* nodeWithAddress(sockaddr *senderAddress);
|
||||
|
@ -152,7 +152,7 @@ private:
|
|||
pthread_t removeSilentNodesThread;
|
||||
pthread_t checkInWithDomainServerThread;
|
||||
int _numNoReplyDomainCheckIns;
|
||||
const char* _assignmentServerHostname;
|
||||
sockaddr* _assignmentServerSocket;
|
||||
|
||||
void handlePingReply(sockaddr *nodeAddress);
|
||||
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);
|
||||
|
|
|
@ -32,6 +32,7 @@ ViewFrustum::ViewFrustum() :
|
|||
_aspectRatio(1.0),
|
||||
_nearClip(0.1),
|
||||
_farClip(500.0),
|
||||
_focalLength(0.25f),
|
||||
_keyholeRadius(DEFAULT_KEYHOLE_RADIUS),
|
||||
_farTopLeft(0,0,0),
|
||||
_farTopRight(0,0,0),
|
||||
|
@ -310,15 +311,16 @@ bool testMatches(float lhs, float rhs) {
|
|||
|
||||
bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
|
||||
bool result =
|
||||
testMatches(compareTo._position, _position ) &&
|
||||
testMatches(compareTo._direction, _direction ) &&
|
||||
testMatches(compareTo._up, _up ) &&
|
||||
testMatches(compareTo._right, _right ) &&
|
||||
testMatches(compareTo._fieldOfView, _fieldOfView ) &&
|
||||
testMatches(compareTo._aspectRatio, _aspectRatio ) &&
|
||||
testMatches(compareTo._nearClip, _nearClip ) &&
|
||||
testMatches(compareTo._farClip, _farClip ) &&
|
||||
testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition ) &&
|
||||
testMatches(compareTo._position, _position) &&
|
||||
testMatches(compareTo._direction, _direction) &&
|
||||
testMatches(compareTo._up, _up) &&
|
||||
testMatches(compareTo._right, _right) &&
|
||||
testMatches(compareTo._fieldOfView, _fieldOfView) &&
|
||||
testMatches(compareTo._aspectRatio, _aspectRatio) &&
|
||||
testMatches(compareTo._nearClip, _nearClip) &&
|
||||
testMatches(compareTo._farClip, _farClip) &&
|
||||
testMatches(compareTo._focalLength, _focalLength) &&
|
||||
testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition) &&
|
||||
testMatches(compareTo._eyeOffsetOrientation, _eyeOffsetOrientation);
|
||||
|
||||
if (!result && debug) {
|
||||
|
@ -351,6 +353,9 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
|
|||
qDebug("%s -- compareTo._farClip=%f _farClip=%f\n",
|
||||
(testMatches(compareTo._farClip, _farClip) ? "MATCHES " : "NO MATCH"),
|
||||
compareTo._farClip, _farClip);
|
||||
qDebug("%s -- compareTo._focalLength=%f _focalLength=%f\n",
|
||||
(testMatches(compareTo._focalLength, _focalLength) ? "MATCHES " : "NO MATCH"),
|
||||
compareTo._focalLength, _focalLength);
|
||||
qDebug("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n",
|
||||
(testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition) ? "MATCHES " : "NO MATCH"),
|
||||
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z,
|
||||
|
@ -401,13 +406,17 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom
|
|||
nearClipPlane = glm::vec4(-normal.x, -normal.y, -normal.z, glm::dot(normal, corners[0]));
|
||||
farClipPlane = glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, corners[4]));
|
||||
|
||||
// compute the focal proportion (zero is near clip, one is far clip)
|
||||
float focalProportion = (_focalLength - _nearClip) / (_farClip - _nearClip);
|
||||
|
||||
// get the extents at Z = -near
|
||||
left = FLT_MAX;
|
||||
right = -FLT_MAX;
|
||||
bottom = FLT_MAX;
|
||||
top = -FLT_MAX;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
glm::vec4 intersection = corners[i] * (-near / corners[i].z);
|
||||
glm::vec4 corner = glm::mix(corners[i], corners[i + 4], focalProportion);
|
||||
glm::vec4 intersection = corner * (-near / corner.z);
|
||||
left = min(left, intersection.x);
|
||||
right = max(right, intersection.x);
|
||||
bottom = min(bottom, intersection.y);
|
||||
|
@ -426,6 +435,7 @@ void ViewFrustum::printDebugDetails() const {
|
|||
qDebug("_keyHoleRadius=%f\n", _keyholeRadius);
|
||||
qDebug("_nearClip=%f\n", _nearClip);
|
||||
qDebug("_farClip=%f\n", _farClip);
|
||||
qDebug("_focalLength=%f\n", _focalLength);
|
||||
qDebug("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z );
|
||||
qDebug("_eyeOffsetOrientation=%f,%f,%f,%f\n", _eyeOffsetOrientation.x, _eyeOffsetOrientation.y, _eyeOffsetOrientation.z,
|
||||
_eyeOffsetOrientation.w );
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
void setAspectRatio(float a) { _aspectRatio = a; }
|
||||
void setNearClip(float n) { _nearClip = n; }
|
||||
void setFarClip(float f) { _farClip = f; }
|
||||
void setFocalLength(float length) { _focalLength = length; }
|
||||
void setEyeOffsetPosition(const glm::vec3& p) { _eyeOffsetPosition = p; }
|
||||
void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; }
|
||||
|
||||
|
@ -47,6 +48,7 @@ public:
|
|||
float getAspectRatio() const { return _aspectRatio; }
|
||||
float getNearClip() const { return _nearClip; }
|
||||
float getFarClip() const { return _farClip; }
|
||||
float getFocalLength() const { return _focalLength; }
|
||||
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
|
||||
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
|
||||
|
||||
|
@ -111,12 +113,13 @@ private:
|
|||
glm::vec3 _right;
|
||||
|
||||
// Lens attributes
|
||||
float _fieldOfView;
|
||||
float _aspectRatio;
|
||||
float _nearClip;
|
||||
float _farClip;
|
||||
glm::vec3 _eyeOffsetPosition;
|
||||
glm::quat _eyeOffsetOrientation;
|
||||
float _fieldOfView;
|
||||
float _aspectRatio;
|
||||
float _nearClip;
|
||||
float _farClip;
|
||||
float _focalLength;
|
||||
glm::vec3 _eyeOffsetPosition;
|
||||
glm::quat _eyeOffsetOrientation;
|
||||
|
||||
// keyhole attributes
|
||||
float _keyholeRadius;
|
||||
|
|
Loading…
Reference in a new issue