bool CTextureFlatDX::Upload( spCImage _spImage ) { if( m_spImage == NULL ) m_spImage = _spImage; CImageFormat format = m_spImage->GetFormat(); if( m_Size.iWidth() != (int32)_spImage->GetWidth() || m_Size.iHeight() != (int32)_spImage->GetHeight() || m_Format != format.getFormatEnum() ) { // Stuff changed, nuke old texture. SAFE_RELEASE( m_pTextureDX9 ); } if( !m_pTextureDX9 ) { HRESULT hr = m_pDevice->CreateTexture( m_spImage->GetWidth(), m_spImage->GetHeight(), m_spImage->GetNumMipMaps(), 0, dxformats[ format.getFormatEnum() ], D3DPOOL_MANAGED, &m_pTextureDX9, NULL ); g_Log->Info( "%s texture created", format.GetDescription().c_str() ); m_Size = Base::Math::CRect( fp4(m_spImage->GetWidth()), fp4(m_spImage->GetHeight()) ); m_Format = format.getFormatEnum(); if( FAILED( hr ) ) { g_Log->Error( "Texture upload failed!" ); return( false ); } } // Copy texturedata. uint32 mipMapLevel = 0; uint8 *pSrc = m_spImage->GetData( 0 ); while( pSrc ) { D3DLOCKED_RECT rect; HRESULT hr = m_pTextureDX9->LockRect( mipMapLevel, &rect, NULL, 0 ); if( !FAILED(hr) ) { memcpy( rect.pBits, pSrc, m_spImage->getMipMappedSize( mipMapLevel, 1 ) ); m_pTextureDX9->UnlockRect( mipMapLevel ); } pSrc = m_spImage->GetData( ++mipMapLevel ); } m_bDirty = true; return true; }
spCShader CRendererDX::NewShader( const char *_pVertexShader, const char *_pFragmentShader ) { spCShader spShader = new CShaderDX( m_pDevice, fp4(m_spDisplay->Width()), fp4(m_spDisplay->Height()) ); if( !spShader->Build( _pVertexShader, _pFragmentShader ) ) return NULL; if( m_spActiveShader != NULL ) m_spActiveShader->Bind(); return spShader; }
Base::Math::CVector2 CRendererDX::GetTextExtent( spCBaseFont _spFont, const std::string &_text ) { ASSERT( _text != "" ); Base::Math::CVector2 result; if( _spFont == NULL ) return result; uint32 width = 0; uint32 height = 0; fp4 dispWidth = (fp4)m_spDisplay->Width(); fp4 dispHeight = (fp4)m_spDisplay->Height(); spCFontDX spDXFont = _spFont; ID3DXFont *pDXFont = spDXFont->GetDXFont(); ASSERT( pDXFont ); // Make a copy of `text' and extend it by `.'. size_t textLength = _text.length(); ASSERT( textLength < 2048 ); static char pTmp[ 2048 ]; strcpy( pTmp, (const char *)_text.c_str() ); pTmp[ textLength ] = '.'; pTmp[ textLength + 1 ] = '\0'; // Determine extents of `.'. RECT dotRect = { 0, 0, 0, 0 }; int32 h = pDXFont->DrawTextA( NULL, ".", -1, &dotRect, DT_LEFT | DT_NOCLIP | DT_CALCRECT, 0 ); int32 dotWidth = dotRect.right - dotRect.left; RECT rect = { 0, 0, 0, 0 }; h = pDXFont->DrawTextA( NULL, pTmp, -1, &rect, DT_LEFT | DT_NOCLIP | DT_CALCRECT, 0 ); width = rect.right - rect.left - dotWidth; height = rect.bottom - rect.top; result = Base::Math::CVector2( (fp4(width) / dispWidth), (fp4(height) / dispHeight) ); return( result ); }
static void test_standalone_funcs() { printf("\r\n********** Starting test_standalone_funcs **********\r\n"); const char *testmsg1 = "Test message 1"; const char *testmsg2 = "Test message 2"; const int testint1 = 13; const double testdouble = 100.0; // First call function pointers directly FunctionPointer1<void, const char*> fp1(sa_func_1); FunctionPointer1<void, int> fp2(sa_func_2); FunctionPointer0<void> fp3(sa_func_3); FunctionPointer3<void, int, const char*, double> fp4(sa_func_4); call_fp1("ptr to standalone func(char*)", fp1, testmsg1); call_fp1("ptr to standalone func(char*)", fp1, testmsg2); call_fp1("ptr to standalone func(int)", fp2, testint1); call_fp0("ptr to standalone func(void)", fp3); call_fp3("ptr to standalong func(int, const char*, double)", fp4, testint1, testmsg1, testdouble); }
void TestConstructor(void) { SCXCoreLib::SCXFilePath fp1; SCXCoreLib::SCXFilePath fp2(L"/some/path"); std::wstring sp = L"C:\\some/other\\path/"; SCXCoreLib::SCXFilePath fp3(sp); SCXCoreLib::SCXFilePath fp4(fp2); // Check that constructors create a path as expected. CPPUNIT_ASSERT(fp1.Get().compare(L"") == 0); #if defined(WIN32) CPPUNIT_ASSERT(fp2.Get() == L"\\some\\path"); CPPUNIT_ASSERT(fp3.Get() == L"C:\\some\\other\\path\\"); #else CPPUNIT_ASSERT(fp2.Get() == L"/some/path"); CPPUNIT_ASSERT(fp3.Get() == L"C:/some/other/path/"); #endif // Check that copy constructor creates identical content. CPPUNIT_ASSERT(fp2.Get() == fp4.Get()); }
static void test_array_of_events() { printf("\r\n********** Starting test_array_of_events **********\r\n"); const char* testmsg1 = "Test message 1"; const char* testmsg2 = "Test message 2"; const int testint = 13; VDerived derived(20, 100); MyArg arg("array", 5, 10); FunctionPointer1<void, const char*> fp1((VBase*)&derived, &VBase::print_virtual_str); FunctionPointer0<void> fp2(sa_func_3); FunctionPointer1<void, int> fp3(sa_func_2); FunctionPointer0<void> fp4(&derived, &VDerived::print_virtual_noargs); FunctionPointer1<void, MyArg> fp5(sa_ntc); Event events[] = {fp1.bind(testmsg1), fp1.bind(testmsg2), fp2.bind(), fp3.bind(testint), fp4.bind(), fp5.bind(arg)}; for (unsigned i = 0; i < sizeof(events)/sizeof(events[0]); i ++) { events[i].call(); } }
PyObject *_PY_fp4(PyObject *self, PyObject *args, PyObject *kwds) {int ok; PyObject *_lo; int _la1; int *_rv; char *kw_list[] = {"a1", NULL}; /* local variable initializations */ _la1 = 0; ok = PyArg_ParseTupleAndKeywords(args, kwds, "i:fp4_p", kw_list, &_la1); if (ok == FALSE) return(NULL); _rv = fp4(_la1); _lo = PY_build_object("fp4", G_INT_I, 0, &_rv, 0); return(_lo);}
void KisFixedPointMathsTest::testOperators() { KisFixedPoint fp1(1); KisFixedPoint fp2(2); KisFixedPoint fp3(qreal(2.5)); KisFixedPoint fp4(qreal(2.0)); QVERIFY(fp1 < fp2); QVERIFY(fp2 < fp3); QVERIFY(fp2 > fp1); QVERIFY(fp3 > fp2); QVERIFY(fp1 != fp2); QVERIFY(fp2 == fp4); QCOMPARE(fp1 + fp2, KisFixedPoint(3)); QCOMPARE(fp1 - fp2, KisFixedPoint(-1)); QCOMPARE(fp1 * fp2, KisFixedPoint(2)); QCOMPARE(fp2 * fp3, KisFixedPoint(5)); QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(0.5))); QCOMPARE(fp1 / fp3, KisFixedPoint(qreal(0.4))); QCOMPARE(fp2 / fp3, KisFixedPoint(qreal(0.8))); }
//一定要素用のBEM関数 void BEM_main_for_CONSTANT(mpsconfig *CON,vector<point2D> &NODE,vector<element2D> &ELEM,vector<mpsparticle> &PART,int fluid_number,double **F,vector<REGION> ®ion) { int node_num=int (NODE.size()); //節点数 int elemnum=int (ELEM.size()); //要素数 int region_num=(int)(region.size());//領域の数 int uk=0; //未知数 int count; cout<<"領域数="<<region_num<<endl; //未知数計算 for(int i=0;i<node_num;i++) { if(NODE[i].boundary_condition==BOTH) uk+=2; //BOTHは多媒質境界上の節点であり、ポテンシャル、法線微分の両方が未知であることを示す else uk++; //こちらは通常。DiricだろうとNeumnだろうと、片方は未知なので++; } cout<<"未知数="<<uk<<endl; int *Nid=new int [uk]; //i番目の未知数はi番目の計算点であることを示す int *bd_type=new int [uk]; int *BOTH_column=new int [node_num]; count=0; for(int i=0;i<elemnum;i++) { if(ELEM[i].boundary_condition==BOTH) { Nid[i]=i; //i番目の未知数はi番目の計算点であることを示す bd_type[i]=Neumn;//BOTHの場合、未知数はポテンシャル、法線微分の順に定義する。よってbd_typeはこのようにしておく Nid[elemnum+count]=i; bd_type[elemnum+count]=Diric; BOTH_column[i]=elemnum+count;//i番目の計算点がBOTHのとき、法線微分を表す未知数はBOTH_column[i]番目の未知数である。 count++; } else { Nid[i]=i; //i番目の未知数はi番目の計算点であることを示す bd_type[i]=ELEM[i].boundary_condition; BOTH_column[i]=-1; //BOTHでないならダミーとして−1を格納 } } int gauss_N=4; //ガウス積分における評価点数 //3,4,8 int NGS[32]; //たとえばGauss積分点が4のときはfor(int i=NGS[4];i<NGS[4]+4;i++) ep1[i]=~~~~という使いかたをする double ep1[32]; //ガウス積分における局所座標格納 double ep_ln[32]; //自然対数に関するガウス積分における局所座標格納 double w1[32]; //ガウス積分における重み格納 double w_ln[32]; //自然対数に関するガウス積分における重み格納 //ガウス積分の準備 set_gauss_parameter(NGS, ep1,w1,ep_ln,w_ln); //matrix作成 double **matrixC=new double*[uk]; for(int n=0;n<uk;n++) matrixC[n]=new double[uk]; double **matrixC2=new double*[uk]; for(int n=0;n<uk;n++) matrixC2[n]=new double[uk]; double **H=new double*[uk]; for(int n=0;n<uk;n++) H[n]=new double[uk]; double **G=new double*[uk]; for(int n=0;n<uk;n++) G[n]=new double[uk]; double *Bmatrix=new double[uk];//解行列 for(int n=0;n<uk;n++) { for(int m=0;m<uk;m++) { matrixC[n][m]=0; //初期化 matrixC2[n][m]=0; H[n][m]=0; G[n][m]=0; } Bmatrix[n]=0; } for(int ID=0;ID<1;ID++) //まずは第1領域のみ計算 { for(int n1=region[ID].start;n1<region[ID].end;n1++) { int n=n1; int n2=BOTH_column[n1]; double SR=0.5*ELEM[n1].L;//要素長さの半分 for(int m1=region[ID].start;m1<region[ID].end;m1++) { int m=m1; int m2=BOTH_column[m1]; int type=0;//type=0なら通常 1なら、その要素は節点nを含む特異積分 if(n1==m1) type=1; if(type==0) { double w; double ep; //評価点の局所座標 for(int i=NGS[gauss_N];i<NGS[gauss_N]+gauss_N;i++) { ep=ep1[i]; w=w1[i]; set_GHmatrix_for_constant(ELEM, ep, H, G, w, type,n, m,n1,m1); } if(m2!=-1) { G[n][m2]=G[n][m]; G[n][m]=0; } } } H[n][n]=PI; G[n][n]=2*SR*(1-log(SR)); if(n2!=-1) { G[n][n2]=G[n][n]; G[n][n]=0; } } } //法線ベクトルを反転 if(region_num>1) for(int i=0;i<elemnum;i++) for(int D=0;D<2;D++) ELEM[i].direct[D]*=-1.0; for(int ID=1;ID<region_num;ID++) //第2領域以降を計算 { for(int n1=region[ID].start;n1<region[ID].end;n1++) { int n=BOTH_column[n1]; //計算点n1の、法線微分の未知変数はBOTH_column[n1]番目の未知数 double SR=0.5*ELEM[n1].L;//要素長さの半分 for(int m1=region[ID].start;m1<region[ID].end;m1++) { int m=m1; int m2=BOTH_column[m1]; int type=0;//type=0なら通常 1なら、その要素は節点nを含む特異積分 if(n1==m1) type=1; if(type==0) { double w; double ep; //評価点の局所座標 for(int i=NGS[gauss_N];i<NGS[gauss_N]+gauss_N;i++) { ep=ep1[i]; w=w1[i]; set_GHmatrix_for_constant(ELEM, ep, H, G, w, type,n, m,n1,m1); } G[n][m2]=-G[n][m]/80; //G[n][m2]=-G[n][m]/1; G[n][m]=0; } } H[n][n1]=PI; G[n][n]=-2*SR*(1-log(SR)); } } //法線ベクトルを反転 if(region_num>1) for(int i=0;i<elemnum;i++) for(int D=0;D<2;D++) ELEM[i].direct[D]*=-1.0; //実際に解く係数行列作成 for(int n=0;n<elemnum;n++) { if(ELEM[n].boundary_condition==Diric) { for(int m=0;m<uk;m++) { matrixC[m][n]=-G[m][n]; matrixC2[m][n]=-H[m][n]; } } else if(ELEM[n].boundary_condition==Neumn) { for(int m=0;m<uk;m++) { matrixC[m][n]=H[m][n]; matrixC2[m][n]=G[m][n]; } } else if(ELEM[n].boundary_condition==BOTH) { int n2=BOTH_column[n]; for(int m=0;m<uk;m++) { matrixC[m][n2]=-G[m][n2]; if(H[m][n2]!=0) cout<<"H "<<m<<" "<<n2<<" "<<H[m][n2]<<endl; } for(int m=0;m<uk;m++) { matrixC[m][n]=H[m][n]; if(G[m][n]!=0) cout<<"G "<<m<<" "<<n<<" "<<G[m][n]<<endl; } } } //解行列作成 for(int n=0;n<uk;n++) { double val=0;//解行列の値 for(int m=0;m<uk;m++) { int elem=Nid[m]; //未知数nに対応する要素番号 int node=ELEM[elem].node[0]; //要素elemに対応するのはELEM[elem].node[0]に格納している if(bd_type[m]==Diric) val+=matrixC2[n][m]*NODE[node].potential; else if(bd_type[m]==Neumn) val+=matrixC2[n][m]*NODE[node].slop1; } Bmatrix[n]=val; } /////matrix作成完了 cout<<"行列作成完了 ガウスの消去法---"; gauss(matrixC,Bmatrix,uk);//答えはBmatrixに格納 cout<<"ok"<<endl; //答え格納 for(int n=0;n<uk;n++) { int elem=Nid[n]; //未知数nに対応する要素番号 int node=ELEM[elem].node[0]; if(bd_type[n]==Neumn) NODE[node].potential=Bmatrix[n]; else if(bd_type[n]==Diric) NODE[node].slop1=Bmatrix[n]; } //答え確認 ofstream fp3("V.dat"); ofstream fp4("slop.dat"); for(int n=0;n<elemnum;n++) { int node=ELEM[n].node[0]; fp3<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<NODE[node].potential<<endl; fp4<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<NODE[node].slop1<<endl; } fp3.close(); fp4.close(); ofstream fp5("F.dat"); double ep0=8.854e-12; double times=1e-3; double le=CON->get_distancebp(); for(int n=0;n<elemnum;n++) { if(ELEM[n].material==FLUID) { int node=ELEM[n].node[0];//対応する節点番号 int i=NODE[node].particle;//対応する粒子番号 double E=NODE[node].slop1; double Fs=0.5*ep0*E*E; //応力 double Fn=Fs*ELEM[n].L; //力[N] for(int D=0;D<2;D++) F[D][i]=-Fn*ELEM[n].direct[D]; fp5<<PART[i].r[A_X]<<" "<<PART[i].r[A_Y]<<" "<<F[A_X][i]*times/le<<" "<<F[A_Y][i]*times/le<<endl; //fp5<<NODE[node].r[A_X]<<" "<<NODE[node].r[A_Y]<<" "<<F[A_X][i]*times/le<<" "<<F[A_Y][i]*times/le<<endl; // fp5<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<Fs<<endl; } } fp5.close(); ////スムージング //smoothingF3D(CON,PART,fluid_number,F,t); if(CON->get_dir_for_P()==2 ||CON->get_dir_for_P()==3 ) { ofstream bb("electromagnetic_P.dat"); for(int i=0;i<fluid_number;i++) { double fs=0;//表面力 if(PART[i].surface==ON)//内部流体の場合はfs=0とする { double Fn=sqrt(F[A_X][i]*F[A_X][i]+F[A_Y][i]*F[A_Y][i]); fs=Fn/le; for(int D=0;D<3;D++) F[D][i]=0;//圧力デ゙ィリクレとして電磁力を使用するのでここでは初期化 } bb<<-fs<<endl; } bb.close(); } for(int n=0;n<node_num;n++) delete[] matrixC[n]; delete [] matrixC; for(int n=0;n<node_num;n++) delete[] matrixC2[n]; delete [] matrixC2; for(int n=0;n<node_num;n++) delete[] H[n]; delete [] H; for(int n=0;n<node_num;n++) delete[] G[n]; delete [] G; delete [] Bmatrix; delete [] Nid; delete [] bd_type; delete [] BOTH_column; }
void CRendererDX::DrawSoftQuad( const Base::Math::CRect &_rect, const Base::Math::CVector4 &_color, const fp4 _width ) { if( m_spSoftCorner == NULL ) { DisplayOutput::spCImage tmpImage = new DisplayOutput::CImage(); tmpImage->Create( 32, 32, DisplayOutput::eImage_RGBA8 ); for( uint32 y=0; y<32; y++) for( uint32 x=0; x<32; x++ ) { fp4 c = Base::Math::saturate(1.0f - powf( Base::Math::Sqrt( fp4(x*x + y*y) ) / 31.0f, 1.0f )); tmpImage->PutPixel( x, y, c, c, c, c ); } m_spSoftCorner = NewTextureFlat(); m_spSoftCorner->Upload( tmpImage ); } const fp4 w05 = (fp4)m_spDisplay->Width() * 0.5f; const fp4 h05 = (fp4)m_spDisplay->Height() * 0.5f; Base::Math::CRect r( lerpMacro( -w05, w05, _rect.m_X0 ), lerpMacro( -h05, h05, _rect.m_Y0 ), lerpMacro( -w05, w05, _rect.m_X1 ), lerpMacro( -h05, h05, _rect.m_Y1 ) ); DWORD rgba = D3DCOLOR_COLORVALUE( _color.m_X, _color.m_Y, _color.m_Z, _color.m_W ); struct Q { D3DXVECTOR3 vertex; uint32 color; D3DXVECTOR2 tc; Q( const fp4 _x, const fp4 _y, const fp4 _tx, const fp4 _ty, const uint32 _c ) { vertex = D3DXVECTOR3( _x, _y, 0 ); tc = D3DXVECTOR2( _tx, _ty ); color = _c; } }; fp4 x0 = r.m_X0; fp4 y0 = r.m_Y0; fp4 x1 = r.m_X1; fp4 y1 = r.m_Y1; fp4 x0bw = r.m_X0 + _width; fp4 y0bw = r.m_Y0 + _width; fp4 x1bw = r.m_X1 - _width; fp4 y1bw = r.m_Y1 - _width; m_pDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 ); Q border[] = { Q(x0, y0bw, 1, 0,rgba), Q(x0, y0 , 1, 1,rgba), Q(x0bw, y0bw, 0, 0,rgba), Q(x0bw, y0 , 0, 1,rgba), Q(x1bw, y0bw, 0, 0,rgba), Q(x1bw, y0 , 0, 1,rgba), Q(x1bw, y0 , 0, 1,rgba), Q(x1, y0 , 1, 1,rgba), Q(x1bw, y0bw, 0, 0,rgba), Q(x1, y0bw, 1, 0,rgba), Q(x1bw, y1bw, 0, 0,rgba), Q(x1, y1bw, 1, 0,rgba), Q(x1, y1bw, 1, 0,rgba), Q(x1, y1 , 1, 1,rgba), Q(x1bw, y1bw, 0, 0,rgba), Q(x1bw, y1 , 0, 1,rgba), Q(x0bw, y1bw, 0, 0,rgba), Q(x0bw, y1 , 0, 1,rgba), Q(x0bw, y1 , 0, 1,rgba), Q(x0, y1 , 1, 1,rgba), Q(x0bw, y1bw, 0, 0,rgba), Q(x0, y1bw, 1, 0,rgba), Q(x0bw, y0bw, 0, 0,rgba), Q(x0, y0bw, 1, 0,rgba), }; SetTexture( m_spSoftCorner, 0 ); Apply(); m_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); m_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); if(!SUCCEEDED(m_pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 22, border, sizeof(Q) ))) { g_Log->Error("DrawSoftQuad::DrawPrimitiveUP failed"); } // Center SetTexture( NULL, 0 ); Apply(); fp4 wu = _width / m_spDisplay->Width(); fp4 hu = _width / m_spDisplay->Height(); Base::Math::CRect r2( _rect.m_X0 + wu, _rect.m_Y0 + hu, _rect.m_X1 - wu, _rect.m_Y1 - hu ); DrawQuad( r2, _color ); }
void CRenderer::Orthographic( const uint32 _width, const uint32 _height ) { Base::Math::CMatrix4x4 proj; proj.OrthographicRH( fp4(_width), fp4(_height), -1, 1 ); SetTransform( proj, eProjection ); }