bool InteriorLMManager::loadBaseLightmaps(LM_HANDLE interiorHandle, LM_HANDLE instanceHandle) { AssertFatal(interiorHandle < mInteriors.size(), "InteriorLMManager::loadBaseLightmaps: invalid interior handle"); AssertFatal(instanceHandle < mInteriors[interiorHandle]->mInstances.size(), "InteriorLMManager::loadBaseLightmaps: invalid instance handle"); // must use a valid instance handle if(!instanceHandle) return(false); InteriorLMInfo * interiorInfo = mInteriors[interiorHandle]; if(!interiorInfo->mNumLightmaps) return(false); InstanceLMInfo * baseInstanceInfo = interiorInfo->mInstances[0]; // already loaded? (if any bitmap is present, then assumed that all will be) GFXTexHandle texture (baseInstanceInfo->mLightmapHandles[0]); if(texture.isValid() && texture.getBitmap()) return(true); InstanceLMInfo * instanceInfo = interiorInfo->mInstances[instanceHandle]; Resource<InteriorResource> & interiorRes = instanceInfo->mInstance->getResource(); if(!bool(interiorRes)) return(false); GBitmap *** pBitmaps = 0; if(!instanceInfo->mInstance->readLightmaps(&pBitmaps)) return(false); for(U32 i = 0; i < interiorRes->getNumDetailLevels(); i++) { Interior * interior = interiorRes->getDetailLevel(i); AssertFatal(interior, "InteriorLMManager::loadBaseLightmaps: invalid detail level in resource"); AssertFatal(interior->getLMHandle() != LM_HANDLE(-1), "InteriorLMManager::loadBaseLightmaps: interior not added to manager"); AssertFatal(interior->getLMHandle() < mInteriors.size(), "InteriorLMManager::loadBaseLightmaps: invalid interior"); InteriorLMInfo * interiorInfo = mInteriors[interior->getLMHandle()]; InstanceLMInfo * baseInstanceInfo = interiorInfo->mInstances[0]; for(U32 j = 0; j < interiorInfo->mNumLightmaps; j++) { AssertFatal(pBitmaps[i][j], "InteriorLMManager::loadBaseLightmaps: invalid bitmap"); if (baseInstanceInfo->mLightmapHandles[j]) { GFXTextureObject * texObj = baseInstanceInfo->mLightmapHandles[j]; texObj->mBitmap = pBitmaps[i][j]; } else baseInstanceInfo->mLightmapHandles[j].set( pBitmaps[i][j], &GFXDefaultPersistentProfile, false, String("Interior Lightmap Handle") ); } } delete [] pBitmaps; return(true); }
void Scene::performClick(S32 mouseX, S32 mouseY) { Point2I screenSize = window->getWindowSize(); //http://antongerdelan.net/opengl/raycasting.html //(x, y) are in device coordinates. We need to convert that to model coords //Device coords -> normalized device coords float x = (((F32)mouseX * 2.0f) / (F32)screenSize.x) - 1.0f; float y = 1.0f - (((F32)mouseY * 2.0f) / (F32)screenSize.y); float z = 1.0f; glm::vec3 ndc = glm::vec3(x, y, z); //Normalized device coords -> clip coordinates glm::vec4 clip = glm::vec4(ndc.x, ndc.y, -1.0f, 1.0f); //Clip coordinates -> eye coordinates glm::vec4 eye = glm::inverse(projectionMatrix) * clip; eye = glm::vec4(eye.x, eye.y, -1.0f, 0.0f); //Eye coordinates -> modelview coordinates glm::vec3 world = glm::vec3(glm::inverse(viewMatrix) * eye); RayF ray(cameraPosition.x, cameraPosition.y, cameraPosition.z, world.x, world.y, world.z); for (U32 i = 0; i < difCount; i ++) { DIF *dif = difs[i]; for (U32 j = 0; j < dif->numDetailLevels; j ++) { Interior *interior = dif->interior[j]; U32 surfaceNum = interior->rayCast(ray); if (surfaceNum != -1) { selection.hasSelection = true; selection.surfaceIndex = surfaceNum; selection.interior = interior; return; } } } selection.hasSelection = false; }
void CMyExcel::SetBackStyle(MyBackStyle BackStyle) { LPDISPATCH lpDisp=NULL; Interior Itor; lpDisp=MyRange.GetInterior(); Itor.AttachDispatch(lpDisp,TRUE); if(BackStyle.transparent==TRUE) Itor.SetColorIndex((_variant_t)(short)xlNone); else { Itor.SetColor((_variant_t)(long)BackStyle.Color); Itor.SetPattern((_variant_t)(short)BackStyle.Pattern); Itor.SetPatternColor((_variant_t)(long)BackStyle.PatternColor); } Itor.ReleaseDispatch(); }
void CXunJianDlg::OnOK() { try{ pList= (CListBox *)GetDlgItem(IDC_HOSTLIST); /*if( pList->GetTextLen(0)>15 || pList->GetTextLen(0)<7 ) { MessageBox("主机列表文件未加载,请重新选择!"); return; }*/ _GUID clsid; IUnknown *pUnk; IDispatch *pDisp; LPDISPATCH lpDisp; _Application app; Workbooks xj_books; _Workbook xj_book; Worksheets xj_sheets; _Worksheet xj_sheet; Range range; Range unionRange; Range cols; Font font; // COleVariant background; COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); ::CLSIDFromProgID(L"Excel.Application",&clsid); // from registry if(GetActiveObject(clsid, NULL,&pUnk) == S_OK) { VERIFY(pUnk->QueryInterface(IID_IDispatch,(void**) &pDisp) == S_OK); app.AttachDispatch(pDisp); pUnk->Release(); } else { if(!app.CreateDispatch("Excel.Application")) { MessageBox("Excel program not found"); app.Quit(); return; } } xj_books=app.GetWorkbooks(); xj_book= xj_books.Add(covOptional); xj_sheets= xj_book.GetSheets(); xj_sheet= xj_sheets.GetItem(COleVariant((short)1)); int i; Range item; range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); for(i= 0; i < 6; i++) { item.AttachDispatch(range.GetItem(COleVariant((long)1),COleVariant((long)i+1)).pdispVal); item.SetValue2(COleVariant(PROJ[i])); } //描绘第一行目录 //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); lpDisp=range.GetInterior(); Interior cellinterior; cellinterior.AttachDispatch(lpDisp); cellinterior.SetColor(COleVariant((long)0xc0c0c0)); //设置背景色为灰色 cellinterior.ReleaseDispatch(); //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); range.SetHorizontalAlignment(COleVariant((long)-4108)); //全部居中 Borders bord; bord=range.GetBorders(); bord.SetLineStyle(COleVariant((short)1)); //设置边框 //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); cols=range.GetEntireColumn(); cols.AutoFit(); //自动调整 /**************************表格初始绘画完成************************************/ long usedRowNum; //行计数 CString handleFile; CString hostFileName,hostip; bool error = false; CString infos,info; ExcelFile excelFile; ReadTxt xj_txt; xj_HostCount=pList->GetCount(); for(int n_host=0;n_host<xj_HostCount;n_host++) //主循环,一个文件一次循环。 { pList->GetText(n_host,hostFileName); hostip = hostFileName; handleFile = hostFileName + _T(" 正在处理..."); pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->SetCurSel(n_host); pList->UpdateWindow(); hostFileName = xj_FilePath + hostFileName; hostFileName += _T(".txt"); CStdioFile hostFile; if(!hostFile.Open(hostFileName,CFile::modeRead,0)) { //记录不存在文件名 handleFile.Replace("正在处理...","失败!"); error = true; pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->UpdateWindow(); continue; } usedRowNum = excelFile.GetRowCount(xj_sheet); range.AttachDispatch(xj_sheet.GetCells()); //info.Format( _T("%d"), n_host+1); info = xj_txt.ReadHostName(&hostFile,COMMAND[0],COMMAND[1]); //获取节点名称 range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(1)),COleVariant(info)); int portCount = 0; //端口数目,不包括7/1 CString nSend, nRecv; float n_Send,n_Recv; while(hostFile.ReadString(info)) if(info.Find( COMMAND[4]) > -1) break; while( hostFile.ReadString(info) && info.Find( "[local]" ) == -1 ) //端口号和流量 { if( info.Find( "/" ) == -1 || info.Find( "7/1" ) > -1 ) continue; info.Replace( "ethernet",""); info = _T("'") + info; infos = info; while( hostFile.ReadString(info) ) if( info.Find( "send bit rate" ) > -1 ) break; nSend = info.Mid( 60 ); hostFile.ReadString(info); nRecv = info.Mid( 60 ); nSend.Trim(); nRecv.Trim(); n_Send = (float)atof(nSend); n_Recv = (float)atof(nRecv); if( n_Send < 1000 && n_Recv < 1000 ) continue; portCount++; range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(2)),COleVariant(infos.Trim())); range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(4)),COleVariant((n_Send>n_Recv)?nSend:nRecv)); } hostFile.SeekToBegin(); infos = xj_txt.ReadLine(&hostFile,"ubscriber Address"); //历史在线最大用户数 if( infos == _T("") ) info = _T("0"); else { int token = 0; for(i = 0; i < 5 ; i++) info = infos.Tokenize(" ",token); } range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(6)),COleVariant(info.Trim())); hostFile.Close(); if(portCount > 1) { unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1))); unionRange.Merge(COleVariant((long)0)); //节点名称单元格合并 unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)6)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1))); unionRange.Merge(COleVariant((long)0)); //历史最大用户数合并 } unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)6))); unionRange.SetRowHeight(COleVariant(13.5)); bord = unionRange.GetBorders(); bord.SetLineStyle(COleVariant((short)1)); //设置边框 handleFile.Replace("正在处理...","已完成"); pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->UpdateWindow(); } CTime time; time = time.GetCurrentTime(); infos = time.Format("%Y%m%d%H%M%S"); //time.Format(); info = _T("巡检报表") + infos + _T(".xlsx"); info = xj_FilePath + info; info.Replace("\\\\","\\"); xj_book.SaveAs(COleVariant(info),covOptional,covOptional,covOptional,covOptional,covOptional,0,covOptional,covOptional,covOptional,covOptional,covOptional); if(error == true ) { MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n有文件打开错误,点击\"确定\"返回查看","有文件打开错误!",MB_OK|MB_ICONWARNING); app.Quit(); } else { if(MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n点击\"确定\"打开文件查看","生成报表完成",MB_OKCANCEL) == IDOK) { app.SetVisible(TRUE); app.SetUserControl(TRUE); } else app.Quit(); } } catch (CFileException* e) { e->ReportError(); e->Delete(); } //CDialog::OnOK(); }
void blInteriorProxy::addToShadowVolume(ShadowVolumeBSP * shadowVolume, LightInfo * light, S32 level) { if(light->getType() != LightInfo::Vector) return; ColorF ambient = light->getAmbient(); bool shadowedTree = true; InteriorInstance* interior = dynamic_cast<InteriorInstance*>(getObject()); if (!interior) return; Resource<InteriorResource> mInteriorRes = interior->getResource(); // check if just getting shadow detail if(level == SceneLighting::SHADOW_DETAIL) { shadowedTree = false; level = mInteriorRes->getNumDetailLevels() - 1; } Interior * detail = mInteriorRes->getDetailLevel(level); bool hasAlarm = detail->hasAlarmState(); // make sure surfaces do not get processed more than once BitVector surfaceProcessed; surfaceProcessed.setSize(detail->mSurfaces.size()); surfaceProcessed.clear(); ColorI color = light->getAmbient(); // go through the zones of the interior and grab outside visible surfaces for(U32 i = 0; i < detail->getNumZones(); i++) { Interior::Zone & zone = detail->mZones[i]; for(U32 j = 0; j < zone.surfaceCount; j++) { U32 surfaceIndex = detail->mZoneSurfaces[zone.surfaceStart + j]; // dont reprocess a surface if(surfaceProcessed.test(surfaceIndex)) continue; surfaceProcessed.set(surfaceIndex); Interior::Surface & surface = detail->mSurfaces[surfaceIndex]; // outside visible? if(!(surface.surfaceFlags & Interior::SurfaceOutsideVisible)) continue; // good surface? PlaneF plane = detail->getPlane(surface.planeIndex); if(Interior::planeIsFlipped(surface.planeIndex)) plane.neg(); // project the plane PlaneF projPlane; mTransformPlane(interior->getTransform(), interior->getScale(), plane, &projPlane); // fill with ambient? (need to do here, because surface will not be // added to the SVBSP tree) F32 dot = mDot(projPlane, light->getDirection()); if(dot > -gParellelVectorThresh)// && !(GFX->getPixelShaderVersion() > 0.0) ) { if(shadowedTree) { // alarm lighting GFXTexHandle normHandle = gInteriorLMManager.duplicateBaseLightmap(detail->getLMHandle(), interior->getLMHandle(), detail->getNormalLMapIndex(surfaceIndex)); GFXTexHandle alarmHandle; GBitmap * normLightmap = normHandle->getBitmap(); GBitmap * alarmLightmap = 0; // check if they share the lightmap if(hasAlarm) { if(detail->getNormalLMapIndex(surfaceIndex) != detail->getAlarmLMapIndex(surfaceIndex)) { alarmHandle = gInteriorLMManager.duplicateBaseLightmap(detail->getLMHandle(), interior->getLMHandle(), detail->getAlarmLMapIndex(surfaceIndex)); alarmLightmap = alarmHandle->getBitmap(); } } // // Support for interior light map border sizes. // U32 xlen, ylen, xoff, yoff; U32 lmborder = detail->getLightMapBorderSize(); xlen = surface.mapSizeX + (lmborder * 2); ylen = surface.mapSizeY + (lmborder * 2); xoff = surface.mapOffsetX - lmborder; yoff = surface.mapOffsetY - lmborder; // attemp to light normal and alarm lighting for(U32 c = 0; c < 2; c++) { GBitmap * lightmap = (c == 0) ? normLightmap : alarmLightmap; if(!lightmap) continue; // fill it for(U32 y = 0; y < ylen; y++) { for(U32 x = 0; x < xlen; x++) { ColorI outColor(255, 0, 0, 255); #ifndef SET_COLORS ColorI lmColor(0, 0, 0, 255); lightmap->getColor(xoff + x, yoff + y, lmColor); U32 _r = static_cast<U32>( color.red ) + static_cast<U32>( lmColor.red ); U32 _g = static_cast<U32>( color.green ) + static_cast<U32>( lmColor.green ); U32 _b = static_cast<U32>( color.blue ) + static_cast<U32>( lmColor.blue ); outColor.red = mClamp(_r, 0, 255); outColor.green = mClamp(_g, 0, 255); outColor.blue = mClamp(_b, 0, 255); #endif lightmap->setColor(xoff + x, yoff + y, outColor); } } } } continue; } ShadowVolumeBSP::SVPoly * poly = buildInteriorPoly(shadowVolume, detail, surfaceIndex, light, shadowedTree); // insert it into the SVBSP tree shadowVolume->insertPoly(poly); } } }