int main(int argc, char **argv) { int sockfd, newfd; struct sockaddr_in sin, cli; int clilen; fd_set allfds, fds; /* ビットマスク */ int fd, fd_min, fd_max; create_game(&g); if ( (sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) /* ソケット */ error("cannot create socket"); bzero((char *)&sin, sizeof(sin)); /* sin に 0 をつめる */ sin.sin_family = PF_INET; /* Internet ドメイン */ sin.sin_addr.s_addr = htonl(INADDR_ANY); /* アドレスは何でもOK */ sin.sin_port = htons(SERVER_PORT); /* ポートは SERVER_PORT */ if ( bind(sockfd, (struct sockaddr *)&sin, sizeof(sin)) < 0 ) error("cannot bind"); if ( listen(sockfd, 5) < 0 ) error("cannot listen"); FD_ZERO(&allfds); /* すべてゼロにクリア */ FD_SET(sockfd, &allfds); /* sockfdのところに1を立てる */ fd_min = sockfd; fd_max = sockfd; search_min_max(allfds, &fd_min, &fd_max); printf("min %d max %d\n", fd_min, fd_max); while ( 1 ) { fds = allfds; /* fdsはselectにより変化するかも */ if ( select(FD_SETSIZE, &fds, NULL, NULL, NULL) < 0 ) error("cannot select"); for ( fd = 0; fd < FD_SETSIZE; fd++ ) /* ファイル記述子を順に調査 */ if ( FD_ISSET(fd, &fds) ) { /* ビットが立っていた */ update_min_max(fd, &fd_min, &fd_max); if ( fd == sockfd ) { /* 入力受付用ファイル記述子の場合 */ clilen = sizeof(cli); /* 接続を受け入れる準備 */ if ( (newfd = accept(sockfd, (struct sockaddr *)&cli, &clilen)) < 0 ) error("cannot accept"); if (battle[0] == 0 ){ battle[0] = newfd; write(newfd, "0", 6); } else if(battle[0] != 0) { battle[1] = newfd; write(newfd, "1", 6); } else if (battle[1] != 0) { } update_min_max(newfd, &fd_min, &fd_max); printf("Accetpted new connection: fd = %d\n", newfd); FD_SET(newfd, &allfds); /* selectによる調査対象に加える */ } else if ( service(fd, &g) == 0 ) { /* クライアントからの要求処理 */ printf("Closed connection: fd = %d\n", fd); if ( shutdown(fd, SHUT_RDWR) < 0 ) /* これ以上の送受信を禁止 */ error("cannot shutdown"); FD_CLR(fd, &allfds); /* selectによる調査対象から外す */ close(fd); search_min_max(allfds, &fd_min, &fd_max); } } } return 0; }
//virtual bool LLViewerOctreeGroup::boundObjects(BOOL empty, LLVector4a& minOut, LLVector4a& maxOut) { const OctreeNode* node = mOctreeNode; if (node->isEmpty()) { //don't do anything if there are no objects if (empty && mOctreeNode->getParent()) { //only root is allowed to be empty OCT_ERRS << "Empty leaf found in octree." << LL_ENDL; } return false; } LLVector4a& newMin = mObjectExtents[0]; LLVector4a& newMax = mObjectExtents[1]; if (hasState(OBJECT_DIRTY)) { //calculate new bounding box clearState(OBJECT_DIRTY); //initialize bounding box to first element OctreeNode::const_element_iter i = node->getDataBegin(); LLViewerOctreeEntry* entry = *i; const LLVector4a* minMax = entry->getSpatialExtents(); newMin = minMax[0]; newMax = minMax[1]; for (++i; i != node->getDataEnd(); ++i) { entry = *i; minMax = entry->getSpatialExtents(); update_min_max(newMin, newMax, minMax[0]); update_min_max(newMin, newMax, minMax[1]); } mObjectBounds[0].setAdd(newMin, newMax); mObjectBounds[0].mul(0.5f); mObjectBounds[1].setSub(newMax, newMin); mObjectBounds[1].mul(0.5f); } if (empty) { minOut = newMin; maxOut = newMax; } else { minOut.setMin(minOut, newMin); maxOut.setMax(maxOut, newMax); } return TRUE; }
LLVector3 LLModel::getTransformedCenter(const LLMatrix4& mat) { LLVector3 ret; if (!mVolumeFaces.empty()) { LLMatrix4a m; m.loadu(mat); LLVector4a minv,maxv; LLVector4a t; m.affineTransform(mVolumeFaces[0].mPositions[0], t); minv = maxv = t; for (S32 i = 0; i < (S32)mVolumeFaces.size(); ++i) { LLVolumeFace& face = mVolumeFaces[i]; for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { m.affineTransform(face.mPositions[j],t); update_min_max(minv, maxv, t); } } minv.add(maxv); minv.mul(0.5f); ret.set(minv.getF32ptr()); } return ret; }
inline void quadsquare::MakeSpecialTri( int a, int b, int c, int terrain) { /* terrain should be -1 */ if ( VertexTerrains[a] != VertexTerrains[b] && VertexTerrains[a] != VertexTerrains[c] && VertexTerrains[b] != VertexTerrains[c] ) { VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a]; update_min_max( VertexIndices[a] ); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b]; update_min_max( VertexIndices[b] ); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c]; update_min_max( VertexIndices[c] ); } }
inline void quadsquare::MakeTri( int a, int b, int c, int terrain ) { if ( ( VertexTerrains[a] == terrain || VertexTerrains[b] == terrain || VertexTerrains[c] == terrain ) ) { VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a]; setalphaval(a); update_min_max( VertexIndices[a] ); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b]; setalphaval(b); update_min_max( VertexIndices[b] ); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c]; setalphaval(c); update_min_max( VertexIndices[c] ); } }
//------------------------------------------------------------------------------ void GeoDat::usun(wektor3d wsp) { it = geoMap.find(wsp); if (it != geoMap.end()) { geoMap.erase(it); update_min_max(); } }
// Combine two rigging info states. // - isRiggedTo if either of the source infos are rigged to // - box is union of the two sources void LLJointRiggingInfo::merge(const LLJointRiggingInfo& other) { if (other.mIsRiggedTo) { if (mIsRiggedTo) { // Combine existing boxes update_min_max(mRiggedExtents[0], mRiggedExtents[1], other.mRiggedExtents[0]); update_min_max(mRiggedExtents[0], mRiggedExtents[1], other.mRiggedExtents[1]); } else { // Initialize box mIsRiggedTo = true; mRiggedExtents[0] = other.mRiggedExtents[0]; mRiggedExtents[1] = other.mRiggedExtents[1]; } } }
//make the parent bounding box to include this child void LLVOCacheEntry::updateParentBoundingInfo(const LLVOCacheEntry* child) { const LLVector4a* child_exts = child->getSpatialExtents(); LLVector4a newMin, newMax; newMin = child_exts[0]; newMax = child_exts[1]; //move to regional space. { const LLVector4a& parent_pos = getPositionGroup(); newMin.add(parent_pos); newMax.add(parent_pos); } //update parent's bbox(min, max) const LLVector4a* parent_exts = getSpatialExtents(); update_min_max(newMin, newMax, parent_exts[0]); update_min_max(newMin, newMax, parent_exts[1]); for(S32 i = 0; i < 4; i++) { llclamp(newMin[i], 0.f, 256.f); llclamp(newMax[i], 0.f, 256.f); } setSpatialExtents(newMin, newMax); //update parent's bbox center LLVector4a center; center.setAdd(newMin, newMax); center.mul(0.5f); setPositionGroup(center); //update parent's bbox size vector LLVector4a size; size.setSub(newMax, newMin); size.mul(0.5f); setBinRadius(llmin(size.getLength3().getF32() * 4.f, 256.f)); }
int AssimpScene::uncompress_vertex(aiMesh *mesh, float* arr, int arr_size, int arr_index) { for (int i = 0; i < mesh->mNumVertices; i++) { aiVector3D vert = mesh->mVertices[i]; //std::cout << "ARR SIZE " << arr_size << " , " << "I USED " << arr_index+3 << std::endl; if (arr_index + 3 > arr_size) { std::cout << mesh->mNumVertices << " ARR SIZE " << arr_size << " , " << "I USED " << arr_index + 3 << std::endl; throw std::invalid_argument("AssimpScene::uncompress_vertex:: array size too small"); } update_min_max(sceneMin, sceneMax, vert); arr[arr_index] = vert.x; arr[arr_index + 1] = vert.y; arr[arr_index + 2] = vert.z; arr_index += 3; } return arr_index; }
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->setPercent(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); const LLVector3* ext = vf.mExtents; 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(); glh::matrix4f mat; if (!is_hud) { mat = glh_get_current_projection() * glh_get_current_modelview(); } else { glh::matrix4f proj, modelview; if (get_hud_matrices(proj, modelview)) mat = proj * modelview; } LLVector3 min = LLVector3(1,1,1); LLVector3 max = LLVector3(-1,-1,-1); for(; vert_it != vert_end; ++vert_it) { // project silhouette vertices into screen space glh::vec3f screen_vert = glh::vec3f(vert_it->mV); mat.mult_matrix_vec(screen_vert); // add to screenspace bounding box update_min_max(min, max, LLVector3(screen_vert.v)); } // convert screenspace bbox to pixels (in screen coords) LLRect window_rect = gViewerWindow->getWorldViewRectScaled(); LLCoordGL screen_min; screen_min.mX = llround((F32)window_rect.getWidth() * (min.mV[VX] + 1.f) * 0.5f); screen_min.mY = llround((F32)window_rect.getHeight() * (min.mV[VY] + 1.f) * 0.5f); LLCoordGL screen_max; screen_max.mX = llround((F32)window_rect.getWidth() * (max.mV[VX] + 1.f) * 0.5f); screen_max.mY = llround((F32)window_rect.getHeight() * (max.mV[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); } } }
//static LLSD LLModel::writeModel( std::ostream& ostr, LLModel* physics, LLModel* high, LLModel* medium, LLModel* low, LLModel* impostor, const LLModel::Decomposition& decomp, BOOL upload_skin, BOOL upload_joints, BOOL nowrite, BOOL as_slm, int submodel_id) { LLSD mdl; LLModel* model[] = { impostor, low, medium, high, physics }; bool skinning = upload_skin && high && !high->mSkinWeights.empty(); if (skinning) { //write skinning block mdl["skin"] = high->mSkinInfo.asLLSD(upload_joints); } if (!decomp.mBaseHull.empty() || !decomp.mHull.empty()) { mdl["physics_convex"] = decomp.asLLSD(); if (!decomp.mHull.empty() && !as_slm) { //convex decomposition exists, physics mesh will not be used (unless this is an slm file) model[LLModel::LOD_PHYSICS] = NULL; } } else if (submodel_id) { const LLModel::Decomposition fake_decomp; mdl["secondary"] = true; mdl["submodel_id"] = submodel_id; mdl["physics_convex"] = fake_decomp.asLLSD(); model[LLModel::LOD_PHYSICS] = NULL; } if (as_slm) { //save material list names for (U32 i = 0; i < high->mMaterialList.size(); ++i) { mdl["material_list"][i] = high->mMaterialList[i]; } } for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx) { if (model[idx] && (model[idx]->getNumVolumeFaces() > 0) && model[idx]->getVolumeFace(0).mPositions != NULL) { LLVector3 min_pos = LLVector3(model[idx]->getVolumeFace(0).mPositions[0].getF32ptr()); LLVector3 max_pos = min_pos; //find position domain for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i) { //for each face const LLVolumeFace& face = model[idx]->getVolumeFace(i); for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { update_min_max(min_pos, max_pos, face.mPositions[j].getF32ptr()); } } LLVector3 pos_range = max_pos - min_pos; for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i) { //for each face const LLVolumeFace& face = model[idx]->getVolumeFace(i); if (face.mNumVertices < 3) { //don't export an empty face mdl[model_names[idx]][i]["NoGeometry"] = true; continue; } LLSD::Binary verts(face.mNumVertices*3*2); LLSD::Binary tc(face.mNumVertices*2*2); LLSD::Binary normals(face.mNumVertices*3*2); LLSD::Binary indices(face.mNumIndices*2); U32 vert_idx = 0; U32 norm_idx = 0; U32 tc_idx = 0; LLVector2* ftc = (LLVector2*) face.mTexCoords; LLVector2 min_tc; LLVector2 max_tc; if (ftc) { min_tc = ftc[0]; max_tc = min_tc; //get texture coordinate domain for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { update_min_max(min_tc, max_tc, ftc[j]); } } LLVector2 tc_range = max_tc - min_tc; for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { //for each vert F32* pos = face.mPositions[j].getF32ptr(); //position for (U32 k = 0; k < 3; ++k) { //for each component //convert to 16-bit normalized across domain U16 val = (U16) (((pos[k]-min_pos.mV[k])/pos_range.mV[k])*65535); U8* buff = (U8*) &val; //write to binary buffer verts[vert_idx++] = buff[0]; verts[vert_idx++] = buff[1]; } if (face.mNormals) { //normals F32* norm = face.mNormals[j].getF32ptr(); for (U32 k = 0; k < 3; ++k) { //for each component //convert to 16-bit normalized U16 val = (U16) ((norm[k]+1.f)*0.5f*65535); U8* buff = (U8*) &val; //write to binary buffer normals[norm_idx++] = buff[0]; normals[norm_idx++] = buff[1]; } } //texcoord if (face.mTexCoords) { F32* src_tc = (F32*) face.mTexCoords[j].mV; for (U32 k = 0; k < 2; ++k) { //for each component //convert to 16-bit normalized U16 val = (U16) ((src_tc[k]-min_tc.mV[k])/tc_range.mV[k]*65535); U8* buff = (U8*) &val; //write to binary buffer tc[tc_idx++] = buff[0]; tc[tc_idx++] = buff[1]; } } } U32 idx_idx = 0; for (U32 j = 0; j < (U32)face.mNumIndices; ++j) { U8* buff = (U8*) &(face.mIndices[j]); indices[idx_idx++] = buff[0]; indices[idx_idx++] = buff[1]; } //write out face data mdl[model_names[idx]][i]["PositionDomain"]["Min"] = min_pos.getValue(); mdl[model_names[idx]][i]["PositionDomain"]["Max"] = max_pos.getValue(); mdl[model_names[idx]][i]["Position"] = verts; if (face.mNormals) { mdl[model_names[idx]][i]["Normal"] = normals; } if (face.mTexCoords) { mdl[model_names[idx]][i]["TexCoord0Domain"]["Min"] = min_tc.getValue(); mdl[model_names[idx]][i]["TexCoord0Domain"]["Max"] = max_tc.getValue(); mdl[model_names[idx]][i]["TexCoord0"] = tc; } mdl[model_names[idx]][i]["TriangleList"] = indices; if (skinning) { //write out skin weights //each influence list entry is up to 4 24-bit values // first 8 bits is bone index // last 16 bits is bone influence weight // a bone index of 0xFF signifies no more influences for this vertex std::stringstream ostr; for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { LLVector3 pos(face.mPositions[j].getF32ptr()); weight_list& weights = high->getJointInfluences(pos); S32 count = 0; for (weight_list::iterator iter = weights.begin(); iter != weights.end(); ++iter) { if (iter->mJointIdx < 255 && iter->mJointIdx >= 0) { U8 idx = (U8) iter->mJointIdx; ostr.write((const char*) &idx, 1); U16 influence = (U16) (iter->mWeight*65535); ostr.write((const char*) &influence, 2); ++count; } } U8 end_list = 0xFF; if (count < 4) { ostr.write((const char*) &end_list, 1); } } //copy ostr to binary buffer std::string data = ostr.str(); const U8* buff = (U8*) data.data(); U32 bytes = data.size(); LLSD::Binary w(bytes); for (U32 j = 0; j < bytes; ++j) { w[j] = buff[j]; } mdl[model_names[idx]][i]["Weights"] = w; } } } } return writeModelToStream(ostr, mdl, nowrite, as_slm); }
// Shrink the model to fit // on a 1x1x1 cube centered at the origin. // The positions and extents // multiplied by mNormalizedScale // and offset by mNormalizedTranslation // to be the "original" extents and position. // Also, the positions will fit // within the unit cube. void LLModel::normalizeVolumeFaces() { // ensure we don't have too many faces if (mVolumeFaces.size() > LL_SCULPT_MESH_MAX_FACES) mVolumeFaces.resize(LL_SCULPT_MESH_MAX_FACES); if (!mVolumeFaces.empty()) { LLVector4a min, max; // For all of the volume faces // in the model, loop over // them and see what the extents // of the volume along each axis. min = mVolumeFaces[0].mExtents[0]; max = mVolumeFaces[0].mExtents[1]; for (U32 i = 1; i < mVolumeFaces.size(); ++i) { LLVolumeFace& face = mVolumeFaces[i]; update_min_max(min, max, face.mExtents[0]); update_min_max(min, max, face.mExtents[1]); if (face.mTexCoords) { LLVector2& min_tc = face.mTexCoordExtents[0]; LLVector2& max_tc = face.mTexCoordExtents[1]; min_tc = face.mTexCoords[0]; max_tc = face.mTexCoords[0]; for (U32 j = 1; j < (U32)face.mNumVertices; ++j) { update_min_max(min_tc, max_tc, face.mTexCoords[j]); } } else { face.mTexCoordExtents[0].set(0,0); face.mTexCoordExtents[1].set(1,1); } } // Now that we have the extents of the model // we can compute the offset needed to center // the model at the origin. // Compute center of the model // and make it negative to get translation // needed to center at origin. LLVector4a trans; trans.setAdd(min, max); trans.mul(-0.5f); // Compute the total size along all // axes of the model. LLVector4a size; size.setSub(max, min); // Prevent division by zero. F32 x = size[0]; F32 y = size[1]; F32 z = size[2]; F32 w = size[3]; if (fabs(x)<F_APPROXIMATELY_ZERO) { x = 1.0; } if (fabs(y)<F_APPROXIMATELY_ZERO) { y = 1.0; } if (fabs(z)<F_APPROXIMATELY_ZERO) { z = 1.0; } size.set(x,y,z,w); // Compute scale as reciprocal of size LLVector4a scale; scale.splat(1.f); scale.div(size); LLVector4a inv_scale(1.f); inv_scale.div(scale); for (U32 i = 0; i < mVolumeFaces.size(); ++i) { LLVolumeFace& face = mVolumeFaces[i]; // We shrink the extents so // that they fall within // the unit cube. face.mExtents[0].add(trans); face.mExtents[0].mul(scale); face.mExtents[1].add(trans); face.mExtents[1].mul(scale); // For all the positions, we scale // the positions to fit within the unit cube. LLVector4a* pos = (LLVector4a*) face.mPositions; LLVector4a* norm = (LLVector4a*) face.mNormals; for (U32 j = 0; j < (U32)face.mNumVertices; ++j) { pos[j].add(trans); pos[j].mul(scale); if (norm && !norm[j].equals3(LLVector4a::getZero())) { norm[j].mul(inv_scale); norm[j].normalize3(); } } } // mNormalizedScale is the scale at which // we would need to multiply the model // by to get the original size of the // model instead of the normalized size. LLVector4a normalized_scale; normalized_scale.splat(1.f); normalized_scale.div(scale); mNormalizedScale.set(normalized_scale.getF32ptr()); mNormalizedTranslation.set(trans.getF32ptr()); mNormalizedTranslation *= -1.f; } }
LLSD LLModel::Decomposition::asLLSD() const { LLSD ret; if (mBaseHull.empty() && mHull.empty()) { //nothing to write return ret; } //write decomposition block // ["physics_convex"]["HullList"] -- list of 8 bit integers, each entry represents a hull with specified number of points // ["physics_convex"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points // ["physics_convex"]["BoundingVerts"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape //get minimum and maximum LLVector3 min; if (mHull.empty()) { min = mBaseHull[0]; } else { min = mHull[0][0]; } LLVector3 max = min; LLSD::Binary hulls(mHull.size()); U32 total = 0; for (U32 i = 0; i < mHull.size(); ++i) { U32 size = mHull[i].size(); total += size; hulls[i] = (U8) (size); for (U32 j = 0; j < mHull[i].size(); ++j) { update_min_max(min, max, mHull[i][j]); } } for (U32 i = 0; i < mBaseHull.size(); ++i) { update_min_max(min, max, mBaseHull[i]); } ret["Min"] = min.getValue(); ret["Max"] = max.getValue(); LLVector3 range = max-min; if (!hulls.empty()) { ret["HullList"] = hulls; } if (total > 0) { LLSD::Binary p(total*3*2); U32 vert_idx = 0; for (U32 i = 0; i < mHull.size(); ++i) { std::set<U64> valid; llassert(!mHull[i].empty()); for (U32 j = 0; j < mHull[i].size(); ++j) { U64 test = 0; const F32* src = mHull[i][j].mV; for (U32 k = 0; k < 3; k++) { //convert to 16-bit normalized across domain U16 val = (U16) (((src[k]-min.mV[k])/range.mV[k])*65535); if(valid.size() < 3) { switch (k) { case 0: test = test | (U64) val; break; case 1: test = test | ((U64) val << 16); break; case 2: test = test | ((U64) val << 32); break; }; valid.insert(test); } U8* buff = (U8*) &val; //write to binary buffer p[vert_idx++] = buff[0]; p[vert_idx++] = buff[1]; //makes sure we haven't run off the end of the array llassert(vert_idx <= p.size()); } } //must have at least 3 unique points llassert(valid.size() > 2); } ret["Positions"] = p; } //llassert(!mBaseHull.empty()); if (!mBaseHull.empty()) { LLSD::Binary p(mBaseHull.size()*3*2); U32 vert_idx = 0; for (U32 j = 0; j < mBaseHull.size(); ++j) { const F32* v = mBaseHull[j].mV; for (U32 k = 0; k < 3; k++) { //convert to 16-bit normalized across domain U16 val = (U16) (((v[k]-min.mV[k])/range.mV[k])*65535); U8* buff = (U8*) &val; //write to binary buffer p[vert_idx++] = buff[0]; p[vert_idx++] = buff[1]; if (vert_idx > p.size()) { LL_ERRS() << "Index out of bounds" << LL_ENDL; } } } ret["BoundingVerts"] = p; } return ret; }
void Task_SmartPHTApp(void) { message_t msg; adc_voltages_t *v; sensor_data_t *c; byte_t comRecvByte; if (knl_mailbox_pend(&taskMailbox, &msg) == RV_OK) { switch (msg.MsgId) { case MSG_ID_SYS_VOLTAGE_UPDATE: v = (adc_voltages_t*) msg.Param0; //tiny_printf("SYS: Vbat=%dmV, Vcc=%dmV, Vdd=%dmV, Vtft=%dmV\n", v->vbat, v->vcc, v->vdd, v->vtft); // if(v->vdd < 3000) // tty_output("SYS: system voltage is low!\n"); // if(v->vbat < 3300) // tty_output("SYS: BATTERY LOW! replace or battery can be damaged\n"); break; case MSG_ID_SYS_BATTERY_STAT: // if(msg.Param0 == BAT_CHARGE_COMPLETE) // tty_output("SYS: battery charge complete.\n"); // if(msg.Param0 == BAT_CHARGING) // tty_output("SYS: charging...\n"); // if(msg.Param0 == BAT_SHUTDOWN) // tty_output("SYS: charger shtdn.\n"); // break; break; case MSG_ID_USB_STATE_CHANGED: handle_usb_change(msg.Param0); break; case MSG_ID_SENSOR_UPDATE: c = (sensor_data_t*) msg.Param0; filter(&dashboardData.pressure, c->compensated.hp_pressure); filter(&dashboardData.humidity, c->compensated.sht_humidity); filter(&dashboardData.temperature, c->compensated.sht_temperature); update_min_max(&dashboardData.pressure); update_min_max(&dashboardData.humidity); update_min_max(&dashboardData.temperature); check_alarms(); // update waveforms wfrm_put_sample(&wfrmPressure, dashboardData.pressure.val); wfrm_put_sample(&wfrmHumidity, dashboardData.humidity.val); wfrm_put_sample(&wfrmTemperature, dashboardData.temperature.val); // Write to file write_samples_to_file(c, (rtc_time_t*) msg.Param1); gui_invalidate(&dashb); gui_invalidate(&lineplot); break; case MSG_ID_MEDIA_DETECTED: //tty_output("SDCARD: inserted."); //if(msg.Param0) tty_output(" Card is write protected!"); //tty_output("\n"); sd_register(); f_close(&samplesFile); // Mount filesystem f_mount(0, &filesystem); // Try open file; sampleFileIsOpen = try_open_file(); // Change statusbar toolbar_set_status(&statusbar, STATUS_SDCARD_PRESENT); break; case MSG_ID_MEDIA_DISAPPEARED: //tty_output("SDCARD: removed\n"); // Dismount file system f_mount(0, NULL); // Change statusbar toolbar_clear_status(&statusbar, STATUS_SDCARD_PRESENT); break; case MSG_ID_WDG_PRESSED: handle_button_press_event(msg.Param0); break; case MSG_ID_WDG_DELAYED_OP: handle_delayed_operation_event(msg.Param0); break; case MSG_ID_WDG_CHECKED: handle_button_checked_event(msg.Param0); break; case MSG_ID_WDG_INVALIDATE: // GUI needs to be redrawn gui_draw(); break; case MSG_ID_LPM_REQUEST: enter_sleep_mode(); break; case MSG_ID_TOUCH_EVENT: // // Draw cursor // if(msg.Param0 == TOUCH_EVENT_PANEL_PRESSED) // { // uint16_t i, j; // i = msg.Param1; // j = msg.Param2; // // if(i < 12) i = 12; // else if(i > 467) i = 467; // if(j < 12) j = 12; // else if(j > 260) j = 260; // // gfx_set_color(COLOR_WHITE); // gfx_draw_circle(i, j , 10); // } if(!darkenScreen) { set_brightness(lightenBrightness); } darkenScreen = bTrue; // no break, gui must get this msg too default: gui_msg(&msg); break; } } // COMMAND PARSER if(usb_device_state == CONFIGURED_STATE) if (poll_getc_cdc(&comRecvByte)) { putc_cdc(comRecvByte); // echo CDC_Flush_In_Now(); cmd_parse_char(comRecvByte); } }
void LLPanelMediaHUD::updateShape() { const S32 MIN_HUD_WIDTH=200; const S32 MIN_HUD_HEIGHT=120; LLPluginClassMedia* media_plugin = NULL; if(mMediaImpl.notNull() && mMediaImpl->hasMedia()) { media_plugin = mMediaImpl->getMediaPlugin(); } // Early out for no media plugin if(media_plugin == NULL) { setVisible(FALSE); return; } LLParcel *parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); bool can_navigate = parcel->getMediaAllowNavigate(); // LLObjectSelectionHandle selection = LLViewerMediaFocus::getInstance()->getSelection(); LLSelectNode* nodep = mMediaFocus ? LLSelectMgr::getInstance()->getSelection()->getFirstNode() : LLSelectMgr::getInstance()->getHoverNode(); if(! nodep) { return; } setVisible(FALSE); LLViewerObject* objectp = nodep->getObject(); if (objectp) { // Set the state of the buttons LLButton* back_btn = getChild<LLButton>("back"); LLButton* fwd_btn = getChild<LLButton>("fwd"); LLButton* reload_btn = getChild<LLButton>("reload"); LLButton* play_btn = getChild<LLButton>("play"); LLButton* pause_btn = getChild<LLButton>("pause"); LLButton* stop_btn = getChild<LLButton>("stop"); LLButton* media_stop_btn = getChild<LLButton>("media_stop"); LLButton* home_btn = getChild<LLButton>("home"); LLButton* close_btn = getChild<LLButton>("close"); LLButton* open_btn = getChild<LLButton>("new_window"); LLPanel* media_focused_panel = getChild<LLPanel>("media_focused_controls"); LLPanel* media_hover_panel = getChild<LLPanel>("media_hover_controls"); back_btn->setVisible(true); fwd_btn->setVisible(true); reload_btn->setVisible(true); stop_btn->setVisible(false); home_btn->setVisible(true); close_btn->setVisible(true); open_btn->setVisible(true); if(mMediaFocus) { back_btn->setEnabled(mMediaImpl->canNavigateBack() && can_navigate); fwd_btn->setEnabled(mMediaImpl->canNavigateForward() && can_navigate); stop_btn->setEnabled(can_navigate); home_btn->setEnabled(can_navigate); LLPluginClassMediaOwner::EMediaStatus result = media_plugin->getStatus(); if(media_plugin->pluginSupportsMediaTime()) { reload_btn->setEnabled(FALSE); reload_btn->setVisible(FALSE); media_stop_btn->setVisible(TRUE); home_btn->setVisible(FALSE); back_btn->setEnabled(TRUE); fwd_btn->setEnabled(TRUE); switch(result) { case LLPluginClassMediaOwner::MEDIA_PLAYING: play_btn->setEnabled(FALSE); play_btn->setVisible(FALSE); pause_btn->setEnabled(TRUE); pause_btn->setVisible(TRUE); media_stop_btn->setEnabled(TRUE); break; case LLPluginClassMediaOwner::MEDIA_PAUSED: default: pause_btn->setEnabled(FALSE); pause_btn->setVisible(FALSE); play_btn->setEnabled(TRUE); play_btn->setVisible(TRUE); media_stop_btn->setEnabled(FALSE); break; } } else { play_btn->setVisible(FALSE); pause_btn->setVisible(FALSE); media_stop_btn->setVisible(FALSE); if(result == LLPluginClassMediaOwner::MEDIA_LOADING) { reload_btn->setEnabled(FALSE); reload_btn->setVisible(FALSE); stop_btn->setEnabled(TRUE); stop_btn->setVisible(TRUE); } else { reload_btn->setEnabled(TRUE); reload_btn->setVisible(TRUE); stop_btn->setEnabled(FALSE); stop_btn->setVisible(FALSE); } } } media_focused_panel->setVisible(mMediaFocus); media_hover_panel->setVisible(!mMediaFocus); if(media_plugin == NULL) // Handle Scrolling switch (mScrollState) { case SCROLL_UP: media_plugin->scrollEvent(0, -1, MASK_NONE); break; case SCROLL_DOWN: media_plugin->scrollEvent(0, 1, MASK_NONE); break; case SCROLL_LEFT: mMediaImpl->handleKeyHere(KEY_LEFT, MASK_NONE); break; case SCROLL_RIGHT: mMediaImpl->handleKeyHere(KEY_RIGHT, MASK_NONE); break; case SCROLL_NONE: default: break; } LLBBox screen_bbox; setVisible(TRUE); glh::matrix4f mat = glh_get_current_projection()*glh_get_current_modelview(); 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(nodep->getLastSelectedTE()); const LLVector3* ext = vf.mExtents; 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(); LLVector3 min = LLVector3(1,1,1); LLVector3 max = LLVector3(-1,-1,-1); for(; vert_it != vert_end; ++vert_it) { // project silhouette vertices into screen space glh::vec3f screen_vert = glh::vec3f(vert_it->mV); mat.mult_matrix_vec(screen_vert); // add to screenspace bounding box update_min_max(min, max, LLVector3(screen_vert.v)); } LLCoordGL screen_min; screen_min.mX = llround((F32)gViewerWindow->getWindowWidth() * (min.mV[VX] + 1.f) * 0.5f); screen_min.mY = llround((F32)gViewerWindow->getWindowHeight() * (min.mV[VY] + 1.f) * 0.5f); LLCoordGL screen_max; screen_max.mX = llround((F32)gViewerWindow->getWindowWidth() * (max.mV[VX] + 1.f) * 0.5f); screen_max.mY = llround((F32)gViewerWindow->getWindowHeight() * (max.mV[VY] + 1.f) * 0.5f); // grow panel so that screenspace bounding box fits inside "media_region" element of HUD LLRect media_hud_rect; getParent()->screenRectToLocal(LLRect(screen_min.mX, screen_max.mY, screen_max.mX, screen_min.mY), &media_hud_rect); LLView* media_region = getChild<LLView>("media_region"); media_hud_rect.mLeft -= media_region->getRect().mLeft; media_hud_rect.mBottom -= media_region->getRect().mBottom; media_hud_rect.mTop += getRect().getHeight() - media_region->getRect().mTop; media_hud_rect.mRight += getRect().getWidth() - media_region->getRect().mRight; LLRect old_hud_rect = media_hud_rect; // keep all parts of HUD on-screen media_hud_rect.intersectWith(getParent()->getLocalRect()); // If we had to clip the rect, don't display the border childSetVisible("bg_image", false); // clamp to minimum size, keeping centered media_hud_rect.setCenterAndSize(media_hud_rect.getCenterX(), media_hud_rect.getCenterY(), llmax(MIN_HUD_WIDTH, media_hud_rect.getWidth()), llmax(MIN_HUD_HEIGHT, media_hud_rect.getHeight())); userSetShape(media_hud_rect); // 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) { mMouseMoveTimer.start(); mLastCursorPos = cursor_pos_window; } // Mouse has been stationary, but not for long enough to fade the UI if(mMouseMoveTimer.getElapsedTimeF32() < mMouseInactiveTime) { // If we have started fading, reset the alpha values if(mFadeTimer.getStarted()) { F32 alpha = 1.0f; setAlpha(alpha); mFadeTimer.stop(); } } // If we need to start fading the UI (and we have not already started) else if(! mFadeTimer.getStarted()) { mFadeTimer.reset(); mFadeTimer.start(); } } }