void GPUAsyncLoader::_update3DTexture() { if( !_storageTexture3D ) { LBERROR << "Can't update 3D texture size - 3D texture is not initialized" << std::endl; return; } if( _bytesNumNew != 1 && _bytesNumNew != 2 ) { LBERROR << "Can't update 3D texture size - only 1 or 2 bytes per value is currently allowed" << std::endl; return; } if( !_cacheIndexNew ) { LBERROR << "GPUAsyncLoader is not initialized with _cacheIndexNew properly" << std::endl; return; } if( _cacheIndex && *_cacheIndex == *_cacheIndexNew && _bytesNum == _bytesNumNew ) return; _cacheIndex = _cacheIndexNew; _bytesNum = _bytesNumNew; const uint32_t blockSize = hlpFuncs::cubed( _cacheIndex->getBlockDim() ); _compressedBS = _ramPool->getDataHDDIO()->getMaxBlockSize(); _uncompressedBS = blockSize*_bytesNum; LBWARN << "Compressed BS: " << _compressedBS << " Uncompressed BS: " << _uncompressedBS << std::endl; LBASSERT( _compressedBS <= _uncompressedBS ); EQ_GL_CALL( glBindTexture( GL_TEXTURE_3D, _storageTexture3D )); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); const Vec3_ui32 cacheDim = _cacheIndex->totalCacheTextureDim(); LBWARN << "trying to create 3D texture of the size: " << cacheDim << ((_bytesNum==2)?" x2 bytes":" x1 byte") << std::endl; GLint internalFormat3D = (_bytesNum == 2) ? GL_ALPHA16 : GL_ALPHA; _byteFormat3D = (_bytesNum == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE; EQ_GL_CALL( glTexImage3D( GL_TEXTURE_3D, 0, internalFormat3D, cacheDim.w, cacheDim.h, cacheDim.d, 0, GL_ALPHA, _byteFormat3D, 0 )); // init volume tree from window Node* pipe = dynamic_cast<Node*>(getWindow()->getNode()); LBASSERT( pipe ); _volumeTree = pipe->getVolumeTree(); LBASSERT( _volumeTree ); _pbo = PboSPtr( new eq::util::PixelBufferObject( glewGetContext(), false )); if( !_pbo->setup( _uncompressedBS, GL_WRITE_ONLY_ARB )) LBERROR << "PBO initialization failed: " << _pbo->getError() << std::endl; // check that PBO has proper size _pbo->bind(); int pboSize = 0; glGetBufferParameteriv( GL_PIXEL_UNPACK_BUFFER, GL_BUFFER_SIZE, (GLint*)&pboSize ); if( (uint32_t)pboSize != _uncompressedBS ) LBERROR << "PBO allocation failed" << std::endl; _pbo->unbind(); _decompressor = Decompressors::select( _ramPool->getDataHDDIO(), _volumeTree, _pbo, _cacheIndex->capacity() ); EQ_GL_CALL( glFinish( )); }
int32_t EditListControl::addItem(const vector<wstring> &vec) { return insertItem(static_cast<int32_t>(SendMessageW(getWindow(), LVM_GETITEMCOUNT, 0, 0)), vec); }
// swap front and back buffers bool XWindow::doSwap(void) { glXSwapBuffers(getDisplay(), getWindow()); return true; }
// Default constructor LLFloaterAbout::LLFloaterAbout() : LLFloater(std::string("floater_about"), std::string("FloaterAboutRect"), LLStringUtil::null) { LLUICtrlFactory::getInstance()->buildFloater(this, "floater_about.xml"); // Support for changing product name. std::string title("About "); title += LLAppViewer::instance()->getSecondLifeTitle(); setTitle(title); LLViewerTextEditor *support_widget = getChild<LLViewerTextEditor>("support_editor", true); LLViewerTextEditor *credits_widget = getChild<LLViewerTextEditor>("credits_editor", true); if (!support_widget || !credits_widget) { return; } // For some reason, adding style doesn't work unless this is true. support_widget->setParseHTML(TRUE); // Text styles for release notes hyperlinks LLStyleSP viewer_link_style(new LLStyle); viewer_link_style->setVisible(true); viewer_link_style->setFontName(LLStringUtil::null); viewer_link_style->setLinkHREF(get_viewer_release_notes_url()); viewer_link_style->setColor(gSavedSettings.getColor4("HTMLLinkColor")); // Version string std::string version = llformat( "%s %d.%d.%d %s / %s %d.%d.%d (%d), %s %s\n", IMP_VIEWER_NAME, IMP_VERSION_MAJOR, IMP_VERSION_MINOR, IMP_VERSION_PATCH, IMP_VERSION_TEST, LL_VIEWER_NAME, LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VIEWER_BUILD, __DATE__, __TIME__); support_widget->appendColoredText(version, FALSE, FALSE, gColors.getColor("TextFgReadOnlyColor")); support_widget->appendStyledText(LLTrans::getString("ReleaseNotes"), false, false, viewer_link_style); std::string support; support.append("\n\n"); #if LL_MSVC support.append(llformat("Built with MSVC version %d\n\n", _MSC_VER)); #endif #if LL_GNUC support.append(llformat("Built with GCC version %d\n\n", GCC_VERSION)); #endif // Position LLViewerRegion* region = gAgent.getRegion(); // [RLVa:KB] - Version: 1.22.11 | Checked: 2009-07-04 (RLVa-1.0.0a) if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) { support.append(rlv_handler_t::cstrHidden); support.append("\n\n"); } else if (region) // [/RLVa:KB] // if (region) { LLStyleSP server_link_style(new LLStyle); server_link_style->setVisible(true); server_link_style->setFontName(LLStringUtil::null); server_link_style->setLinkHREF(region->getCapability("ServerReleaseNotes")); server_link_style->setColor(gSavedSettings.getColor4("HTMLLinkColor")); const LLVector3d &pos = gAgent.getPositionGlobal(); LLUIString pos_text = getString("you_are_at"); pos_text.setArg("[POSITION]", llformat("%.1f, %.1f, %.1f ", pos.mdV[VX], pos.mdV[VY], pos.mdV[VZ])); support.append(pos_text); std::string region_text = llformat("in %s located at ", gAgent.getRegion()->getName().c_str()); support.append(region_text); std::string buffer; buffer = gAgent.getRegion()->getHost().getHostName(); support.append(buffer); support.append(" ("); buffer = gAgent.getRegion()->getHost().getString(); support.append(buffer); support.append(")\n"); support.append(gLastVersionChannel); support.append("\n"); support_widget->appendColoredText(support, FALSE, FALSE, gColors.getColor("TextFgReadOnlyColor")); support_widget->appendStyledText(LLTrans::getString("ReleaseNotes"), false, false, server_link_style); support = "\n\n"; } // *NOTE: Do not translate text like GPU, Graphics Card, etc - // Most PC users that know what these mean will be used to the english versions, // and this info sometimes gets sent to support // CPU support.append("CPU: "); support.append( gSysCPU.getCPUString() ); support.append("\n"); U32 memory = gSysMemory.getPhysicalMemoryKB() / 1024; // Moved hack adjustment to Windows memory size into llsys.cpp std::string mem_text = llformat("Memory: %u MB\n", memory ); support.append(mem_text); support.append("OS Version: "); support.append( LLAppViewer::instance()->getOSInfo().getOSString() ); support.append("\n"); support.append("Graphics Card Vendor: "); support.append( (const char*) glGetString(GL_VENDOR) ); support.append("\n"); support.append("Graphics Card: "); support.append( (const char*) glGetString(GL_RENDERER) ); support.append("\n"); #if LL_WINDOWS getWindow()->incBusyCount(); getWindow()->setCursor(UI_CURSOR_ARROW); support.append("Windows Graphics Driver Version: "); LLSD driver_info = gDXHardware.getDisplayInfo(); if (driver_info.has("DriverVersion")) { support.append(driver_info["DriverVersion"]); } support.append("\n"); getWindow()->decBusyCount(); getWindow()->setCursor(UI_CURSOR_ARROW); #endif support.append("OpenGL Version: "); support.append( (const char*) glGetString(GL_VERSION) ); support.append("\n"); support.append("\n"); support.append("libcurl Version: "); support.append( LLCurl::getVersionString() ); support.append("\n"); support.append("J2C Decoder Version: "); support.append( LLImageJ2C::getEngineInfo() ); support.append("\n"); support.append("Audio Driver Version: "); bool want_fullname = true; support.append( gAudiop ? gAudiop->getDriverName(want_fullname) : "(none)" ); support.append("\n"); LLMediaManager *mgr = LLMediaManager::getInstance(); if (mgr) { LLMediaBase *gstreamer = mgr->createSourceFromMimeType("http", "audio/mpeg"); if (gstreamer) { support.append("GStreamer Version: "); support.append( gstreamer->getVersion() ); support.append("\n"); } LLMediaBase *media_source = mgr->createSourceFromMimeType("http", "text/html"); if (media_source) { support.append("LLMozLib Version: "); support.append(media_source->getVersion()); support.append("\n"); mgr->destroySource(media_source); } } if (gPacketsIn > 0) { std::string packet_loss = llformat("Packets Lost: %.0f/%.0f (%.1f%%)", LLViewerStats::getInstance()->mPacketsLostStat.getCurrent(), F32(gPacketsIn), 100.f*LLViewerStats::getInstance()->mPacketsLostStat.getCurrent() / F32(gPacketsIn) ); support.append(packet_loss); support.append("\n"); } support_widget->appendColoredText(support, FALSE, FALSE, gColors.getColor("TextFgReadOnlyColor")); // Fix views support_widget->setCursorPos(0); support_widget->setEnabled(FALSE); support_widget->setTakesFocus(TRUE); support_widget->setHandleEditKeysDirectly(TRUE); credits_widget->setCursorPos(0); credits_widget->setEnabled(FALSE); credits_widget->setTakesFocus(TRUE); credits_widget->setHandleEditKeysDirectly(TRUE); center(); sInstance = this; }
void LLComboBox::showList() { // Make sure we don't go off top of screen. LLCoordWindow window_size; getWindow()->getSize(&window_size); //HACK: shouldn't have to know about scale here mList->fitContents( 192, llfloor((F32)window_size.mY / LLUI::sGLScaleFactor.mV[VY]) - 50 ); // Make sure that we can see the whole list LLRect root_view_local; LLView* root_view = getRootView(); root_view->localRectToOtherView(root_view->getLocalRect(), &root_view_local, this); LLRect rect = mList->getRect(); S32 min_width = getRect().getWidth(); S32 max_width = llmax(min_width, MAX_COMBO_WIDTH); // make sure we have up to date content width metrics mList->calcColumnWidths(); S32 list_width = llclamp(mList->getMaxContentWidth(), min_width, max_width); if (mListPosition == BELOW) { if (rect.getHeight() <= -root_view_local.mBottom) { // Move rect so it hangs off the bottom of this view rect.setLeftTopAndSize(0, 0, list_width, rect.getHeight() ); } else { // stack on top or bottom, depending on which has more room if (-root_view_local.mBottom > root_view_local.mTop - getRect().getHeight()) { // Move rect so it hangs off the bottom of this view rect.setLeftTopAndSize(0, 0, list_width, llmin(-root_view_local.mBottom, rect.getHeight())); } else { // move rect so it stacks on top of this view (clipped to size of screen) rect.setOriginAndSize(0, getRect().getHeight(), list_width, llmin(root_view_local.mTop - getRect().getHeight(), rect.getHeight())); } } } else // ABOVE { if (rect.getHeight() <= root_view_local.mTop - getRect().getHeight()) { // move rect so it stacks on top of this view (clipped to size of screen) rect.setOriginAndSize(0, getRect().getHeight(), list_width, llmin(root_view_local.mTop - getRect().getHeight(), rect.getHeight())); } else { // stack on top or bottom, depending on which has more room if (-root_view_local.mBottom > root_view_local.mTop - getRect().getHeight()) { // Move rect so it hangs off the bottom of this view rect.setLeftTopAndSize(0, 0, list_width, llmin(-root_view_local.mBottom, rect.getHeight())); } else { // move rect so it stacks on top of this view (clipped to size of screen) rect.setOriginAndSize(0, getRect().getHeight(), list_width, llmin(root_view_local.mTop - getRect().getHeight(), rect.getHeight())); } } } mList->setOrigin(rect.mLeft, rect.mBottom); mList->reshape(rect.getWidth(), rect.getHeight()); mList->translateIntoRect(root_view_local, FALSE); // Make sure we didn't go off bottom of screen S32 x, y; mList->localPointToScreen(0, 0, &x, &y); if (y < 0) { mList->translate(0, -y); } // NB: this call will trigger the focuslost callback which will hide the list, so do it first // before finally showing the list mList->setFocus(TRUE); // Show the list and push the button down mButton->setToggleState(TRUE); mList->setVisible(TRUE); LLUI::addPopup(this); setUseBoundingRect(TRUE); // updateBoundingRect(); }
void LLPanelPrimMediaControls::updateShape() { LLViewerMediaImpl* media_impl = getTargetMediaImpl(); LLViewerObject* objectp = getTargetObject(); if(!media_impl || gFloaterTools->getVisible()) { setVisible(FALSE); return; } LLPluginClassMedia* media_plugin = NULL; if(media_impl->hasMedia()) { media_plugin = media_impl->getMediaPlugin(); } LLParcel *parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); bool can_navigate = parcel->getMediaAllowNavigate(); bool enabled = false; bool is_zoomed = (mCurrentZoom != ZOOM_NONE) && (mTargetObjectID == mZoomObjectID) && (mTargetObjectFace == mZoomObjectFace); // There is no such thing as "has_focus" being different from normal controls set // anymore (as of user feedback from bri 10/09). So we cheat here and force 'has_focus' // to 'true' (or, actually, we use a setting) bool has_focus = (gSavedSettings.getBOOL("PrimMediaControlsUseHoverControlSet")) ? media_impl->hasFocus() : true; setVisible(enabled); if (objectp) { bool mini_controls = false; LLMediaEntry *media_data = objectp->getTE(mTargetObjectFace)->getMediaData(); if (media_data && NULL != dynamic_cast<LLVOVolume*>(objectp)) { // Don't show the media controls if we do not have permissions enabled = dynamic_cast<LLVOVolume*>(objectp)->hasMediaPermission(media_data, LLVOVolume::MEDIA_PERM_CONTROL); mini_controls = (LLMediaEntry::MINI == media_data->getControls()); } const bool is_hud = objectp->isHUDAttachment(); // // Set the state of the buttons // // XXX RSP: TODO: FIXME: clean this up so that it is clearer what mode we are in, // and that only the proper controls get made visible/enabled according to that mode. mBackCtrl->setVisible(has_focus); mFwdCtrl->setVisible(has_focus); mReloadCtrl->setVisible(has_focus); mStopCtrl->setVisible(false); mHomeCtrl->setVisible(has_focus); mZoomCtrl->setVisible(!is_zoomed); mUnzoomCtrl->setVisible(is_zoomed); mOpenCtrl->setVisible(true); mMediaAddressCtrl->setVisible(has_focus && !mini_controls); mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls); mVolumeCtrl->setVisible(false); mWhitelistIcon->setVisible(!mini_controls && (media_data)?media_data->getWhiteListEnable():false); // Disable zoom if HUD mZoomCtrl->setEnabled(!is_hud); mUnzoomCtrl->setEnabled(!is_hud); mSecureLockIcon->setVisible(false); mCurrentURL = media_impl->getCurrentMediaURL(); mBackCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateBack() && can_navigate); mFwdCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateForward() && can_navigate); mStopCtrl->setEnabled(has_focus && can_navigate); mHomeCtrl->setEnabled(has_focus && can_navigate); LLPluginClassMediaOwner::EMediaStatus result = ((media_impl != NULL) && media_impl->hasMedia()) ? media_plugin->getStatus() : LLPluginClassMediaOwner::MEDIA_NONE; mVolumeCtrl->setVisible(has_focus); mVolumeCtrl->setEnabled(has_focus); mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible()); mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible()); if(media_plugin && media_plugin->pluginSupportsMediaTime()) { mReloadCtrl->setEnabled(false); mReloadCtrl->setVisible(false); mMediaStopCtrl->setVisible(has_focus); mHomeCtrl->setVisible(has_focus); mBackCtrl->setVisible(false); mFwdCtrl->setVisible(false); mMediaAddressCtrl->setVisible(false); mMediaAddressCtrl->setEnabled(false); mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls); mMediaPlaySliderPanel->setEnabled(has_focus && !mini_controls); mSkipFwdCtrl->setVisible(has_focus && !mini_controls); mSkipFwdCtrl->setEnabled(has_focus && !mini_controls); mSkipBackCtrl->setVisible(has_focus && !mini_controls); mSkipBackCtrl->setEnabled(has_focus && !mini_controls); mVolumeCtrl->setVisible(has_focus); mVolumeCtrl->setEnabled(has_focus); mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible()); mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible()); mWhitelistIcon->setVisible(false); mSecureLockIcon->setVisible(false); if (mMediaPanelScroll) { mMediaPanelScroll->setVisible(false); mScrollUpCtrl->setVisible(false); mScrollDownCtrl->setVisible(false); mScrollRightCtrl->setVisible(false); mScrollDownCtrl->setVisible(false); } F32 volume = media_impl->getVolume(); // movie's url changed if(mCurrentURL!=mPreviousURL) { mMovieDuration = media_plugin->getDuration(); mPreviousURL = mCurrentURL; } if(mMovieDuration == 0) { mMovieDuration = media_plugin->getDuration(); mMediaPlaySliderCtrl->setValue(0); mMediaPlaySliderCtrl->setEnabled(false); } // TODO: What if it's not fully loaded if(mUpdateSlider && mMovieDuration!= 0) { F64 current_time = media_plugin->getCurrentTime(); F32 percent = current_time / mMovieDuration; mMediaPlaySliderCtrl->setValue(percent); mMediaPlaySliderCtrl->setEnabled(true); } // video vloume if(volume <= 0.0) { mMuteBtn->setToggleState(true); } else if (volume >= 1.0) { mMuteBtn->setToggleState(false); } else { mMuteBtn->setToggleState(false); } switch(result) { case LLPluginClassMediaOwner::MEDIA_PLAYING: mPlayCtrl->setEnabled(FALSE); mPlayCtrl->setVisible(FALSE); mPauseCtrl->setEnabled(TRUE); mPauseCtrl->setVisible(has_focus); break; case LLPluginClassMediaOwner::MEDIA_PAUSED: default: mPauseCtrl->setEnabled(FALSE); mPauseCtrl->setVisible(FALSE); mPlayCtrl->setEnabled(TRUE); mPlayCtrl->setVisible(has_focus); break; } } else // web based { if(media_plugin) { mCurrentURL = media_plugin->getLocation(); } else { mCurrentURL.clear(); } mPlayCtrl->setVisible(FALSE); mPauseCtrl->setVisible(FALSE); mMediaStopCtrl->setVisible(FALSE); mMediaAddressCtrl->setVisible(has_focus && !mini_controls); mMediaAddressCtrl->setEnabled(has_focus && !mini_controls); mMediaPlaySliderPanel->setVisible(FALSE); mMediaPlaySliderPanel->setEnabled(FALSE); mSkipFwdCtrl->setVisible(FALSE); mSkipFwdCtrl->setEnabled(FALSE); mSkipBackCtrl->setVisible(FALSE); mSkipBackCtrl->setEnabled(FALSE); if(media_impl->getVolume() <= 0.0) { mMuteBtn->setToggleState(true); } else { mMuteBtn->setToggleState(false); } if (mMediaPanelScroll) { mMediaPanelScroll->setVisible(has_focus); mScrollUpCtrl->setVisible(has_focus); mScrollDownCtrl->setVisible(has_focus); mScrollRightCtrl->setVisible(has_focus); mScrollDownCtrl->setVisible(has_focus); } // TODO: get the secure lock bool from media plug in std::string prefix = std::string("https://"); std::string test_prefix = mCurrentURL.substr(0, prefix.length()); LLStringUtil::toLower(test_prefix); if(test_prefix == prefix) { mSecureLockIcon->setVisible(has_focus); } if(mCurrentURL!=mPreviousURL) { setCurrentURL(); mPreviousURL = mCurrentURL; } if(result == LLPluginClassMediaOwner::MEDIA_LOADING) { mReloadCtrl->setEnabled(FALSE); mReloadCtrl->setVisible(FALSE); mStopCtrl->setEnabled(TRUE); mStopCtrl->setVisible(has_focus); } else { mReloadCtrl->setEnabled(TRUE); mReloadCtrl->setVisible(has_focus); mStopCtrl->setEnabled(FALSE); mStopCtrl->setVisible(FALSE); } } if(media_plugin) { // // Handle progress bar // if(LLPluginClassMediaOwner::MEDIA_LOADING == media_plugin->getStatus()) { mMediaProgressPanel->setVisible(true); mMediaProgressBar->setValue(media_plugin->getProgressPercent()); } else { mMediaProgressPanel->setVisible(false); } } if(media_impl) { // // Handle Scrolling // switch (mScrollState) { case SCROLL_UP: media_impl->scrollWheel(0, -1, MASK_NONE); break; case SCROLL_DOWN: media_impl->scrollWheel(0, 1, MASK_NONE); break; case SCROLL_LEFT: media_impl->scrollWheel(1, 0, MASK_NONE); // media_impl->handleKeyHere(KEY_LEFT, MASK_NONE); break; case SCROLL_RIGHT: media_impl->scrollWheel(-1, 0, MASK_NONE); // media_impl->handleKeyHere(KEY_RIGHT, MASK_NONE); break; case SCROLL_NONE: default: break; } } setVisible(enabled); // // Calculate position and shape of the controls // std::vector<LLVector3>::iterator vert_it; std::vector<LLVector3>::iterator vert_end; std::vector<LLVector3> vect_face; LLVolume* volume = objectp->getVolume(); if (volume) { const LLVolumeFace& vf = volume->getVolumeFace(mTargetObjectFace); LLVector3 ext[2]; ext[0].set(vf.mExtents[0].getF32ptr()); ext[1].set(vf.mExtents[1].getF32ptr()); LLVector3 center = (ext[0]+ext[1])*0.5f; LLVector3 size = (ext[1]-ext[0])*0.5f; LLVector3 vert[] = { center + size.scaledVec(LLVector3(1,1,1)), center + size.scaledVec(LLVector3(-1,1,1)), center + size.scaledVec(LLVector3(1,-1,1)), center + size.scaledVec(LLVector3(-1,-1,1)), center + size.scaledVec(LLVector3(1,1,-1)), center + size.scaledVec(LLVector3(-1,1,-1)), center + size.scaledVec(LLVector3(1,-1,-1)), center + size.scaledVec(LLVector3(-1,-1,-1)), }; LLVOVolume* vo = (LLVOVolume*) objectp; for (U32 i = 0; i < 8; i++) { vect_face.push_back(vo->volumePositionToAgent(vert[i])); } } vert_it = vect_face.begin(); vert_end = vect_face.end(); LLMatrix4a mat; if (!is_hud) { mat.setMul(glh_get_current_projection(),glh_get_current_modelview()); } else { LLMatrix4a proj, modelview; if (get_hud_matrices(proj, modelview)) { //mat = proj * modelview; mat.setMul(proj,modelview); } } LLVector4a min; min.splat(1.f); LLVector4a max; max.splat(-1.f); for(; vert_it != vert_end; ++vert_it) { // project silhouette vertices into screen space LLVector4a screen_vert; screen_vert.load3(vert_it->mV,1.f); mat.perspectiveTransform(screen_vert,screen_vert); // add to screenspace bounding box min.setMin(screen_vert,min); max.setMax(screen_vert,max); } // convert screenspace bbox to pixels (in screen coords) LLRect window_rect = gViewerWindow->getWorldViewRectScaled(); LLCoordGL screen_min; screen_min.mX = ll_round((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (min.getF32ptr()[VX] + 1.f) * 0.5f); screen_min.mY = ll_round((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (min.getF32ptr()[VY] + 1.f) * 0.5f); LLCoordGL screen_max; screen_max.mX = ll_round((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (max.getF32ptr()[VX] + 1.f) * 0.5f); screen_max.mY = ll_round((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (max.getF32ptr()[VY] + 1.f) * 0.5f); // grow panel so that screenspace bounding box fits inside "media_region" element of panel LLRect media_panel_rect; // Get the height of the controls (less the volume slider) S32 controls_height = mMediaControlsStack->getRect().getHeight() - mVolumeSliderCtrl->getRect().getHeight(); getParent()->screenRectToLocal(LLRect(screen_min.mX, screen_max.mY, screen_max.mX, screen_min.mY), &media_panel_rect); media_panel_rect.mTop += controls_height; // keep all parts of panel on-screen // Area of the top of the world view to avoid putting the controls window_rect.mTop -= mTopWorldViewAvoidZone; // Don't include "spacing" bookends on left & right of the media controls window_rect.mLeft -= mLeftBookend->getRect().getWidth(); window_rect.mRight += mRightBookend->getRect().getWidth(); // Don't include the volume slider window_rect.mBottom -= mVolumeSliderCtrl->getRect().getHeight(); media_panel_rect.intersectWith(window_rect); // clamp to minimum size, keeping rect inside window S32 centerX = media_panel_rect.getCenterX(); S32 centerY = media_panel_rect.getCenterY(); // Shrink screen rect by min width and height, to ensure containment window_rect.stretch(-mMinWidth/2, -mMinHeight/2); window_rect.clampPointToRect(centerX, centerY); media_panel_rect.setCenterAndSize(centerX, centerY, llmax(mMinWidth, media_panel_rect.getWidth()), llmax(mMinHeight, media_panel_rect.getHeight())); // Finally set the size of the panel setShape(media_panel_rect, true); // Test mouse position to see if the cursor is stationary LLCoordWindow cursor_pos_window; getWindow()->getCursorPosition(&cursor_pos_window); // If last pos is not equal to current pos, the mouse has moved // We need to reset the timer, and make sure the panel is visible if(cursor_pos_window.mX != mLastCursorPos.mX || cursor_pos_window.mY != mLastCursorPos.mY || mScrollState != SCROLL_NONE) { mInactivityTimer.start(); mLastCursorPos = cursor_pos_window; } if(isMouseOver() || hasFocus()) { // Never fade the controls if the mouse is over them or they have keyboard focus. mFadeTimer.stop(); } else if(!mClearFaceOnFade && (mInactivityTimer.getElapsedTimeF32() < mInactiveTimeout)) { // Mouse is over the object, but has not been stationary for long enough to fade the UI mFadeTimer.stop(); } else if(! mFadeTimer.getStarted() ) { // we need to start fading the UI (and we have not already started) mFadeTimer.reset(); mFadeTimer.start(); } else { // I don't think this is correct anymore. This is done in draw() after the fade has completed. // setVisible(FALSE); } } }
uint16_t Packet::getWindowSize() { return getWindow((struct TCPHeader *)&m_header); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_addEvalOnStartLoading(JNIEnv* env, jobject self, jstring script) { Berkelium_Java_Env jEnv(env); getWindow(self)->addEvalOnStartLoading(jstring2WideString(script)); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_clearStartLoading(JNIEnv* env, jobject self) { Berkelium_Java_Env jEnv(env); getWindow(self)->clearStartLoading(); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_goForward(JNIEnv* env, jobject self) { Berkelium_Java_Env jEnv(env); getWindow(self)->goForward(); }
JNIEXPORT jboolean JNICALL Java_org_berkelium_java_impl_WindowImpl_canGoForward(JNIEnv* env, jobject self) { Berkelium_Java_Env jEnv(env); return getWindow(self)->canGoForward(); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl__1setDelegate(JNIEnv* env, jobject self, jobject dlg) { Berkelium_Java_Env jEnv(env); getWindow(self)->setDelegate(new JavaWindowDelegateProxy(dlg)); }
BOOL LLTextureCtrl::handleHover(S32 x, S32 y, MASK mask) { getWindow()->setCursor(mBorder->parentPointInView(x,y) ? UI_CURSOR_HAND : UI_CURSOR_ARROW); return TRUE; }
/** * Function for creating and holding of shared context. * Generation and uploading of new textures over some period with sleep time. */ void GPUAsyncLoader::runLocal() { LBASSERT( !_storageTexture3D ); EQ_GL_CALL( glGenTextures( 1, &_storageTexture3D )); // confirm successfull loading _loadResponds.push( GPULoadRespond( GPULoadRequest(), GPULoadStatus::INITIALIZED )); // start fresh in paused state postCommand( GPUCommand::PAUSE ); std::string name = std::string( "GPU_Loader " ).append( strUtil::toString<>(this) ); util::EventLogger* events = util::StatLogger::instance().createLogger( name ); LBASSERT( events ); uint64_t blocksLoaded = 0; LBINFO << "async GPU fetcher initialized: " << getWindow() << std::endl; LBINFO << "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl; lunchbox::Clock clock; while( true ) { // try to read new loading request bool sleepWait = true; GPULoadRequest loadRequestTmp; if( _loadRequests.getFront( loadRequestTmp )) { // LBWARN << "GPUAsyncLoader: trying to load request" << std::endl; sleepWait = false; _loadResponds.push( GPULoadRespond( loadRequestTmp, GPULoadStatus::STARTED )); GPULoadRequest loadRequest; bool loadingFailed = true; if( _decompressor && _ramPool && _loadRequests.tryPop( loadRequest ) && loadRequest == loadRequestTmp ) { // load / request new texture const RAMDataElement* dataEl = _ramPool->getData( loadRequest.nodeId, _dataVersion, loadRequest.reload ); bool sizePassed = true; if( dataEl && dataEl->size() < _compressedBS ) { LBERROR << "size of the data returned by RAM Pool is smaller than required by GPU" << std::endl; sizePassed = false; } if( dataEl && sizePassed ) { clock.reset(); // LBWARN << "GPUAsyncLoader: got positive feedback from RAM Pool" << std::endl; const Box_i32 coords = _cacheIndex->getBlockCoordinates( loadRequest.posOnGPU ); if( coords != Box_i32( )) { if( blocksLoaded == 0 ) LBWARN << "Loaded blocks to GPU: " << blocksLoaded << std::endl; // LBWARN << loadRequest << std::endl; _decompressor->load( dataEl, loadRequest ); const uint32_t blockDim = _cacheIndex->getBlockDim(); _pbo->bind(); EQ_GL_CALL( glBindTexture( GL_TEXTURE_3D, _storageTexture3D )); EQ_GL_CALL( glTexSubImage3D( GL_TEXTURE_3D, 0, coords.s.x, coords.s.y, coords.s.z, blockDim, blockDim, blockDim, GL_ALPHA, _byteFormat3D, NULL )); _pbo->unbind(); EQ_GL_CALL( glFinish( )); _loadResponds.push( GPULoadRespond( loadRequest, GPULoadStatus::FINISHED )); loadingFailed = false; const uint32_t compressedSize = _ramPool->getDataHDDIO()->getBlockSize_( loadRequest.treePos ); double timeD = clock.getTimed(); double speedC = (compressedSize / (1024.f * 1024.f)) / timeD; double speedD = ((blockDim*blockDim*blockDim*sizeof(float)) / (1024.f * 1024.f)) / timeD; *events << "GBL (GPU_Block_Loaded) " << (++blocksLoaded) << " in " << timeD << " ms, at " << speedC << " MB/s (" << speedD << " MB/s)" <<std::endl; if( blocksLoaded % 100 == 0 ) LBWARN << "Loaded blocks to GPU: " << blocksLoaded << std::endl; } } } if( loadingFailed ) _loadResponds.push( GPULoadRespond( loadRequestTmp, GPULoadStatus::FAILED )); } // check for commands if( _processCommands( sleepWait )) return; // in case there were no commands it will sleep a bit till the next check if( sleepWait ) { lunchbox::sleep( 20 ); // time in ms if( _processCommands( sleepWait )) return; // check again for new commands } } }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_adjustZoom(JNIEnv* env, jobject self, jint mode) { Berkelium_Java_Env jEnv(env); getWindow(self)->adjustZoom(mode); }
JNIEXPORT jint JNICALL Java_org_berkelium_java_impl_WindowImpl_getId(JNIEnv* env, jobject self) { Berkelium_Java_Env jEnv(env); return getWindow(self)->getId(); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_executeJavascript(JNIEnv* env, jobject self, jstring script) { Berkelium_Java_Env jEnv(env); getWindow(self)->executeJavascript(jstring2WideString(script)); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_setTransparent(JNIEnv* env, jobject self, jboolean val) { Berkelium_Java_Env jEnv(env); getWindow(self)->setTransparent(val ? true : false); }
void Application::newConnection() { QLocalSocket *socket = m_localServer->nextPendingConnection(); if (!socket) { return; } socket->waitForReadyRead(1000); MainWindow *window = (getWindows().isEmpty() ? NULL : getWindow()); QString data; QTextStream stream(socket); stream >> data; const QStringList encodedArguments = QString(QByteArray::fromBase64(data.toUtf8())).split(QLatin1Char(' ')); QStringList decodedArguments; for (int i = 0; i < encodedArguments.count(); ++i) { decodedArguments.append(QString(QByteArray::fromBase64(encodedArguments.at(i).toUtf8()))); } m_commandLineParser.parse(decodedArguments); const QString session = m_commandLineParser.value(QLatin1String("session")); const bool isPrivate = m_commandLineParser.isSet(QLatin1String("privatesession")); if (session.isEmpty()) { if (!window || !SettingsManager::getValue(QLatin1String("Browser/OpenLinksInNewTab")).toBool() || (isPrivate && !window->getWindowsManager()->isPrivate())) { window = createWindow(isPrivate); } } else { const SessionInformation sessionData = SessionsManager::getSession(session); if (sessionData.clean || QMessageBox::warning(NULL, tr("Warning"), tr("This session was not saved correctly.\nAre you sure that you want to restore this session anyway?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { for (int i = 0; i < sessionData.windows.count(); ++i) { createWindow(isPrivate, false, sessionData.windows.at(i)); } } } if (window) { if (m_commandLineParser.positionalArguments().isEmpty()) { window->triggerAction(ActionsManager::NewTabAction); } else { const QStringList urls = m_commandLineParser.positionalArguments(); for (int i = 0; i < urls.count(); ++i) { window->openUrl(urls.at(i)); } } } delete socket; if (window) { window->raise(); window->activateWindow(); if (m_isHidden) { setHidden(false); } else { window->storeWindowState(); window->restoreWindowState(); } } }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_unfocus(JNIEnv* env, jobject self) { Berkelium_Java_Env jEnv(env); getWindow(self)->unfocus(); }
void SelectionField::setToDefault() { selection = defaultSelection; if( getWindow() ) getWindow()->update(); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_mouseButton(JNIEnv* env, jobject self, jint b, jboolean down) { Berkelium_Java_Env jEnv(env); getWindow(self)->mouseButton(b, down ? true : false); }
int PlayerWin::run() { FileUtils::getInstance()->setPopupNotify(false); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // set QUICK_V3_ROOT const char *QUICK_V3_ROOT = getenv("QUICK_V3_ROOT"); if (!QUICK_V3_ROOT || strlen(QUICK_V3_ROOT) == 0) { MessageBox("Please run \"setup_win.bat\", set Quick-Cocos2dx-Community root path.", "Quick-Cocos2dx-Community player error"); return 1; } _project.setQuickCocos2dxRootPath(QUICK_V3_ROOT); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() >= 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); } else { _project.resetToWelcome(); } } // set framework path if (!_project.isLoadPrecompiledFramework()) { FileUtils::getInstance()->addSearchPath(_project.getQuickCocos2dxRootPath() + "quick/"); } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // set window icon HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAYER)); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { SendMessage(_hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwndConsole, WM_SETICON, ICON_SMALL, (LPARAM)icon); ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setSearchRootPath(_project.getProjectDir().c_str()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; //if (dpi >= 120 && dpi < 144) //{ // screenScale = 1.25f; //} //else if (dpi >= 144 && dpi < 192) //{ // screenScale = 1.5f; //} //else if (dpi >= 192) //{ // screenScale = 2.0f; //} CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; GLView::setGLContextAttrs(glContextAttrs); //auto glview = GLView::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale, isResize, false, true); auto glview = GLViewImpl::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale); _hwnd = glview->getWin32Window(); SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // init player services initServices(); loadLuaConfig(); registerKeyboardEvent(); // register event handlers auto eventDispatcher = director->getEventDispatcher(); eventDispatcher->addCustomEventListener("APP.WINDOW_CLOSE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowClose, this)); eventDispatcher->addCustomEventListener("APP.WINDOW_RESIZE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowResize, this)); eventDispatcher->addCustomEventListener("APP.VIEW_SCALE", CC_CALLBACK_1(PlayerWin::onWindowScale, this)); // prepare _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)PlayerWin::windowProc); HWND hwnd = _hwnd; HWND hwndConsole = _hwndConsole; const ProjectConfig &project = _project; director->getScheduler()->schedule([hwnd, hwndConsole, project](float dt) { CC_UNUSED_PARAM(dt); ShowWindow(hwnd, SW_RESTORE); auto glview = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView()); GLFWwindow *window = glview->getWindow(); glfwShowWindow(window); }, this, 0.0f, 0, 0.001f, false, "SHOW_WINDOW_CALLBACK"); if (project.isAppMenu() && GetMenu(hwnd)) { // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); } ShowWindow(_hwnd, SW_MINIMIZE); // startup message loop return app->run(); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_mouseWheel(JNIEnv* env, jobject self, jint x, jint y) { Berkelium_Java_Env jEnv(env); getWindow(self)->mouseWheel(x, y); }
TextureOverviewDialog::~TextureOverviewDialog () { // Propagate shortcuts to the main window GlobalEventManager().disconnectDialogWindow(GTK_WINDOW(getWindow())); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_keyEvent(JNIEnv* env, jobject self, jboolean pressed, jint mods, jint vk_code, jint scancode) { Berkelium_Java_Env jEnv(env); getWindow(self)->keyEvent(pressed ? true : false, mods, vk_code, scancode); }
void EditListControl::clear() { SendMessageW(getWindow(), LVM_DELETEALLITEMS, 0, 0); }
JNIEXPORT void JNICALL Java_org_berkelium_java_impl_WindowImpl_resize(JNIEnv* env, jobject self, jint w, jint h) { Berkelium_Java_Env jEnv(env); getWindow(self)->resize(w, h); }
void IngameState::tick(float dt) { autolookTimer = std::max(autolookTimer - dt, 0.f); auto player = game->getPlayer(); if( player && player->isInputEnabled() ) { sf::Vector2f screenSize(getWindow().getSize()); sf::Vector2f screenCenter(screenSize / 2.f); sf::Vector2f mouseMove; if (game->hasFocus()) { sf::Vector2f mousePos(sf::Mouse::getPosition(getWindow())); sf::Vector2f deltaMouse = (mousePos - screenCenter); mouseMove = sf::Vector2f(deltaMouse.x / screenSize.x, deltaMouse.y / screenSize.y); sf::Mouse::setPosition(sf::Vector2i(screenCenter), getWindow()); if(deltaMouse.x != 0 || deltaMouse.y != 0) { autolookTimer = kAutoLookTime; if (!m_invertedY) { mouseMove.y = -mouseMove.y; } m_cameraAngles += glm::vec2(mouseMove.x, mouseMove.y); m_cameraAngles.y = glm::clamp(m_cameraAngles.y, kCameraPitchLimit, glm::pi<float>() - kCameraPitchLimit); } } float viewDistance = 4.f; switch( camMode ) { case IngameState::CAMERA_CLOSE: viewDistance = 2.f; break; case IngameState::CAMERA_NORMAL: viewDistance = 4.0f; break; case IngameState::CAMERA_FAR: viewDistance = 6.f; break; case IngameState::CAMERA_TOPDOWN: viewDistance = 15.f; break; default: viewDistance = 4.f; } auto target = getWorld()->pedestrianPool.find(getWorld()->state->cameraTarget); if( target == nullptr ) { target = player->getCharacter(); } glm::vec3 targetPosition = target->getPosition(); glm::vec3 lookTargetPosition = targetPosition; targetPosition += glm::vec3(0.f, 0.f, 1.f); lookTargetPosition += glm::vec3(0.f, 0.f, 0.5f); btCollisionObject* physTarget = player->getCharacter()->physObject; auto vehicle = ( target->type() == GameObject::Character ) ? static_cast<CharacterObject*>(target)->getCurrentVehicle() : nullptr; if( vehicle ) { auto model = vehicle->model; float maxDist = 0.f; for(auto& g : model->resource->geometries) { float partSize = glm::length(g->geometryBounds.center) + g->geometryBounds.radius; maxDist = std::max(partSize, maxDist); } viewDistance = viewDistance + maxDist; targetPosition = vehicle->getPosition(); lookTargetPosition = targetPosition; lookTargetPosition.z += (vehicle->info->handling.dimensions.z); targetPosition.z += (vehicle->info->handling.dimensions.z * 1.f); physTarget = vehicle->physBody; if (!m_vehicleFreeLook) { m_cameraAngles.y = kVehicleCameraPitch; } // Rotate the camera to the ideal angle if the player isn't moving it float velocity = vehicle->getVelocity(); if (autolookTimer <= 0.f && glm::abs(velocity) > kAutolookMinVelocity) { auto idealYaw = -glm::roll(vehicle->getRotation()) + glm::half_pi<float>(); const auto idealPitch = kVehicleCameraPitch; if (velocity < 0.f) { idealYaw = glm::mod(idealYaw - glm::pi<float>(), glm::pi<float>() * 2.f); } float currentYaw = glm::mod(m_cameraAngles.x, glm::pi<float>()*2); float currentPitch = m_cameraAngles.y; float deltaYaw = idealYaw - currentYaw; float deltaPitch = idealPitch - currentPitch; if (glm::abs(deltaYaw) > glm::pi<float>()) { deltaYaw -= glm::sign(deltaYaw) * glm::pi<float>()*2.f; } m_cameraAngles.x += glm::sign(deltaYaw) * std::min(kMaxRotationRate * dt, glm::abs(deltaYaw)); m_cameraAngles.y += glm::sign(deltaPitch) * std::min(kMaxRotationRate * dt, glm::abs(deltaPitch)); } } // Non-topdown camera can orbit if( camMode != IngameState::CAMERA_TOPDOWN ) { // Determine the "ideal" camera position for the current view angles auto yaw = glm::angleAxis(m_cameraAngles.x, glm::vec3(0.f, 0.f,-1.f)); auto pitch = glm::angleAxis(m_cameraAngles.y, glm::vec3(0.f, 1.f, 0.f)); auto cameraOffset = yaw * pitch * glm::vec3(0.f, 0.f, viewDistance); cameraPosition = targetPosition + cameraOffset; } else { cameraPosition = targetPosition + glm::vec3(0.f, 0.f, viewDistance); } glm::quat angle; auto camtotarget = targetPosition - cameraPosition; auto dir = glm::normalize(camtotarget); float correction = glm::length(camtotarget) - viewDistance; if( correction < 0.f ) { float innerDist = viewDistance * 0.1f; correction = glm::min(0.f, correction + innerDist); } cameraPosition += dir * 10.f * correction * dt; auto lookdir = glm::normalize(lookTargetPosition - cameraPosition); // Calculate the yaw to look at the target. float angleYaw = glm::atan(lookdir.y, lookdir.x); angle = glm::quat( glm::vec3(0.f, 0.f, angleYaw) ); // Update player with camera yaw if( player->isInputEnabled() ) { if (player->getCharacter()->getCurrentVehicle()) { player->setMoveDirection(_movement); } else { float length = glm::length(_movement); float movementAngle = angleYaw - M_PI/2.f; if (length > 0.1f) { glm::vec3 direction = glm::normalize(_movement); movementAngle += atan2(direction.y, direction.x); player->setMoveDirection(glm::vec3(1.f, 0.f, 0.f)); } else { player->setMoveDirection(glm::vec3(0.f)); } if (player->getCharacter()->canTurn()) { player->getCharacter()->rotation = glm::angleAxis(movementAngle, glm::vec3(0.f, 0.f, 1.f)); } } } else { player->setMoveDirection(glm::vec3(0.f)); } float len2d = glm::length(glm::vec2(lookdir)); float anglePitch = glm::atan(lookdir.z, len2d); angle *= glm::quat( glm::vec3(0.f, -anglePitch, 0.f) ); // Use rays to ensure target is visible from cameraPosition auto rayEnd = cameraPosition; auto rayStart = targetPosition; auto to = btVector3(rayEnd.x, rayEnd.y, rayEnd.z); auto from = btVector3(rayStart.x, rayStart.y, rayStart.z); ClosestNotMeRayResultCallback ray(physTarget, from, to); getWorld()->dynamicsWorld->rayTest(from, to, ray); if( ray.hasHit() && ray.m_closestHitFraction < 1.f ) { cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(), ray.m_hitPointWorld.z()); cameraPosition += glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(), ray.m_hitNormalWorld.z()) * 0.1f; } _look.position = cameraPosition; _look.rotation = angle; } }
void CtrlVideo::unsetLayout() { m_pLayout->getActiveVar().delObserver( this ); getWindow()->getVisibleVar().delObserver( this ); CtrlGeneric::unsetLayout(); }