Esempio n. 1
0
bool VoxelNodeData::updateCurrentViewFrustum() {
    bool currentViewFrustumChanged = false;
    ViewFrustum newestViewFrustum;
    // get position and orientation details from the camera
    newestViewFrustum.setPosition(getCameraPosition());
    newestViewFrustum.setOrientation(getCameraOrientation());

    // Also make sure it's got the correct lens details from the camera
    float originalFOV = getCameraFov();
    float wideFOV = originalFOV + VIEW_FRUSTUM_FOV_OVERSEND;
    
    newestViewFrustum.setFieldOfView(wideFOV); // hack
    newestViewFrustum.setAspectRatio(getCameraAspectRatio());
    newestViewFrustum.setNearClip(getCameraNearClip());
    newestViewFrustum.setFarClip(getCameraFarClip());
    newestViewFrustum.setEyeOffsetPosition(getCameraEyeOffsetPosition());
    
    // if there has been a change, then recalculate
    if (!newestViewFrustum.matches(_currentViewFrustum)) {
        _currentViewFrustum = newestViewFrustum;
        _currentViewFrustum.calculate();
        currentViewFrustumChanged = true;
    }
    
    // When we first detect that the view stopped changing, we record this.
    // but we don't change it back to false until we've completely sent this
    // scene.
    if (_viewFrustumChanging && !currentViewFrustumChanged) {
        _viewFrustumJustStoppedChanging = true;
    }
    _viewFrustumChanging = currentViewFrustumChanged;
    return currentViewFrustumChanged;
}
Esempio n. 2
0
Matrix4f const *Node::getCamera(void)
{
	Matrix4f projectionM, cameraPos, cameraOrientation;
	getPerspctiveProjection(projectionM);
	getCameraTranslation(cameraPos);
	getCameraOrientation(cameraOrientation);

	_cameraMatrix = projectionM * cameraOrientation * cameraPos;
	return &_cameraMatrix;
}
Esempio n. 3
0
bool OctreeQueryNode::updateCurrentViewFrustum() {
    // if shutting down, return immediately
    if (_isShuttingDown) {
        return false;
    }

    bool currentViewFrustumChanged = false;
    ViewFrustum newestViewFrustum;
    // get position and orientation details from the camera
    newestViewFrustum.setPosition(getCameraPosition());
    newestViewFrustum.setOrientation(getCameraOrientation());

    // Also make sure it's got the correct lens details from the camera
    float originalFOV = getCameraFov();
    float wideFOV = originalFOV + VIEW_FRUSTUM_FOV_OVERSEND;

    newestViewFrustum.setFieldOfView(wideFOV); // hack
    newestViewFrustum.setAspectRatio(getCameraAspectRatio());
    newestViewFrustum.setNearClip(getCameraNearClip());
    newestViewFrustum.setFarClip(getCameraFarClip());
    newestViewFrustum.setEyeOffsetPosition(getCameraEyeOffsetPosition());

    // if there has been a change, then recalculate
    if (!newestViewFrustum.isVerySimilar(_currentViewFrustum)) {
        _currentViewFrustum = newestViewFrustum;
        _currentViewFrustum.calculate();
        currentViewFrustumChanged = true;
    }

    // Also check for LOD changes from the client
    if (_lodInitialized) {
        if (_lastClientBoundaryLevelAdjust != getBoundaryLevelAdjust()) {
            _lastClientBoundaryLevelAdjust = getBoundaryLevelAdjust();
            _lodChanged = true;
        }
        if (_lastClientOctreeSizeScale != getOctreeSizeScale()) {
            _lastClientOctreeSizeScale = getOctreeSizeScale();
            _lodChanged = true;
        }
    } else {
        _lodInitialized = true;
        _lastClientOctreeSizeScale = getOctreeSizeScale();
        _lastClientBoundaryLevelAdjust = getBoundaryLevelAdjust();
        _lodChanged = false;
    }

    // When we first detect that the view stopped changing, we record this.
    // but we don't change it back to false until we've completely sent this
    // scene.
    if (_viewFrustumChanging && !currentViewFrustumChanged) {
        _viewFrustumJustStoppedChanging = true;
    }
    _viewFrustumChanging = currentViewFrustumChanged;
    return currentViewFrustumChanged;
}
Esempio n. 4
0
Lab::Lab()
    : m_cameraOrientation(-M_PI * 0.5f)
    , m_cameraPosition(0.0f, 0.0f, 10.0f)
    , m_boxModelOrientation(0.0f) {

    // set state
    GLCheck(glEnable(GL_DEPTH_TEST));
    GLCheck(glDepthFunc(GL_LESS));
    GLCheck(glEnable(GL_CULL_FACE));
    GLCheck(glCullFace(GL_BACK));
    GLCheck(glFrontFace(GL_CCW));

    // load entities
    m_planeModelMatrix = glm::mat4(1, 0, 0, 0,
                                   0, 1, 0, 0,
                                   0, 0, 1, 0,
                                   0, -3, 0, 1);
    m_planeEntity = std::shared_ptr<Entity>(new Entity("resources/meshes/cobblestone-plane.obj"));
    m_planeEntity->setModelMatrix(m_planeModelMatrix);
    m_boxEntity = std::shared_ptr<Entity>(new Entity("resources/meshes/crate.obj"));

    // setup the lights
    m_pointLight.m_intensity = glm::vec3(0.8, 0.8, 0.8);
    m_pointLight.m_position = glm::vec4(0.0f, 3.0, 6.0, 1.0);
    m_ambientLight = glm::vec3(0.2, 0.2, 0.2);

    // setup the camera
    m_camera.setUp(glm::vec3(0.0f, 1.0f, 0.0f));
    m_camera.setFacing(getCameraOrientation(m_cameraOrientation));
    m_camera.setPosition(glm::vec3(0.0f, 0.0f, 25.0f));

    // initialize OpenAL
    if (!alutInit(NULL, NULL)) {
        std::cerr << "Failed to initialize OpenAL" << std::endl;
    }

    m_listener.m_position = m_cameraPosition;
    m_listener.m_facing = getCameraOrientation(m_cameraOrientation);
    m_sound = std::shared_ptr<WAVHandle>(new WAVHandle("resources/sounds/wind-howl-01.wav"));
    m_source = std::shared_ptr<SoundSource>(new SoundSource(m_sound, glm::vec3(0.0f, 0.0f, 0.0f), true, m_listener));
    m_source->play();
}
Esempio n. 5
0
Matrix4f const *Node::getMatrix(void)
{
	Matrix4f translationM, rotationM, scalingM, projectionM, cameraPos, cameraOrientation;
	getObjectScaling(scalingM);
	getObjectTranslation(translationM);
	getObjectRotation(rotationM);
	getPerspctiveProjection(projectionM);
	getCameraTranslation(cameraPos);
	getCameraOrientation(cameraOrientation);

	_transformationMatrix = projectionM * cameraOrientation * cameraPos * translationM * rotationM * scalingM;
	return &_transformationMatrix;
}
Esempio n. 6
0
void Lab::onUpdate(float dt, const InputState& currentInput, const InputState& previousInput) {
    if (currentInput.m_keyboard.m_keys[GLFW_KEY_RIGHT] || currentInput.m_keyboard.m_keys['D'])
        m_cameraOrientation += M_PI * dt;
    if (currentInput.m_keyboard.m_keys[GLFW_KEY_LEFT] || currentInput.m_keyboard.m_keys['A'])
        m_cameraOrientation -= M_PI * dt;

    glm::vec3 cameraOrientation = getCameraOrientation(m_cameraOrientation);

    if (currentInput.m_keyboard.m_keys[GLFW_KEY_UP] || currentInput.m_keyboard.m_keys['W'])
        m_cameraPosition += cameraOrientation * 10.0f * dt;
    if (currentInput.m_keyboard.m_keys[GLFW_KEY_DOWN] || currentInput.m_keyboard.m_keys['S'])
        m_cameraPosition -= cameraOrientation * 10.0f * dt;


    glm::vec3 rightOrientation = glm::cross(cameraOrientation, glm::vec3(0.0f, 1.0f, 0.0f));
    if (currentInput.m_keyboard.m_keys['E'])
        m_cameraPosition += rightOrientation * 10.0f * dt;
    if (currentInput.m_keyboard.m_keys['Q'])
        m_cameraPosition -= rightOrientation * 10.0f * dt;

    m_camera.setPosition(m_cameraPosition);
    m_camera.setFacing(cameraOrientation);
    m_camera.commit();

    // set the listener by the camera
    m_listener.m_position = m_cameraPosition;
    m_listener.m_facing = cameraOrientation;

    // rotate the box at a constant speed
    m_boxModelOrientation += M_PI * 0.1f * dt;
    m_boxModelMatrix = glm::mat4(cos(m_boxModelOrientation),  0, sin(m_boxModelOrientation), 0,
                                 0,						   1, 0,						     0,
                                 -sin(m_boxModelOrientation), 0, cos(m_boxModelOrientation), 0,
                                 0,						   0, 0,						     1);
    m_boxEntity->setModelMatrix(m_boxModelMatrix);

    // update sound source
    m_source->update();
}
Esempio n. 7
0
bool OctreeQueryNode::updateCurrentViewFrustum() {
    // if shutting down, return immediately
    if (_isShuttingDown) {
        return false;
    }
    
    if (!_usesFrustum) {
        // this client does not use a view frustum so the view frustum for this query has not changed
        return false;
    } else {
        bool currentViewFrustumChanged = false;
        
        ViewFrustum newestViewFrustum;
        // get position and orientation details from the camera
        newestViewFrustum.setPosition(getCameraPosition());
        newestViewFrustum.setOrientation(getCameraOrientation());
        
        newestViewFrustum.setCenterRadius(getCameraCenterRadius());
        
        // Also make sure it's got the correct lens details from the camera
        float originalFOV = getCameraFov();
        float wideFOV = originalFOV + VIEW_FRUSTUM_FOV_OVERSEND;
        
        if (0.0f != getCameraAspectRatio() &&
            0.0f != getCameraNearClip() &&
            0.0f != getCameraFarClip() &&
            getCameraNearClip() != getCameraFarClip()) {
            newestViewFrustum.setProjection(glm::perspective(
                                                             glm::radians(wideFOV), // hack
                                                             getCameraAspectRatio(),
                                                             getCameraNearClip(),
                                                             getCameraFarClip()));
            newestViewFrustum.calculate();
        }
        
        
        { // if there has been a change, then recalculate
            QMutexLocker viewLocker(&_viewMutex);
            if (!newestViewFrustum.isVerySimilar(_currentViewFrustum)) {
                _currentViewFrustum = newestViewFrustum;
                currentViewFrustumChanged = true;
            }
        }
        
        // Also check for LOD changes from the client
        if (_lodInitialized) {
            if (_lastClientBoundaryLevelAdjust != getBoundaryLevelAdjust()) {
                _lastClientBoundaryLevelAdjust = getBoundaryLevelAdjust();
                _lodChanged = true;
            }
            if (_lastClientOctreeSizeScale != getOctreeSizeScale()) {
                _lastClientOctreeSizeScale = getOctreeSizeScale();
                _lodChanged = true;
            }
        } else {
            _lodInitialized = true;
            _lastClientOctreeSizeScale = getOctreeSizeScale();
            _lastClientBoundaryLevelAdjust = getBoundaryLevelAdjust();
            _lodChanged = false;
        }
        
        // When we first detect that the view stopped changing, we record this.
        // but we don't change it back to false until we've completely sent this
        // scene.
        if (_viewFrustumChanging && !currentViewFrustumChanged) {
            _viewFrustumJustStoppedChanging = true;
        }
        _viewFrustumChanging = currentViewFrustumChanged;
        return currentViewFrustumChanged;
    }
}