int ARLambda::factorize( const Matrix<double>& Q, Matrix<double>& L, Vector<double>& D) { // TODO: CHECK UNEXPECTED INPUT // L:nxn Z:nxn 0<=(i,j)<n const int n = static_cast<int>(Q.rows()); Matrix<double> QC(Q); L.resize(n, n, 0.0); D.resize(n, 0.0); for(int i = n-1; i >= 0; i--) { D(i) = QC(i,i); if( D(i) <= 0.0 ) return -1; double temp = std::sqrt(D(i)); for(int j=0; j<=i; j++) L(i,j) = QC(i,j)/temp; for(int j=0; j<=i-1; j++) { for(int k=0; k<=j; k++) QC(j,k) -= L(i,k) * L(i,j); } for(int j=0; j<=i; j++) L(i,j) /= L(i,i); } return 0; } // End of method 'ARLambda::factorize()'
static int Qs(q_g_mul_p_)(lua_State *L) { mClifford *m = qlua_checkClifford(L, 1); Qs(mSeqDirProp) *f = Qs(qlua_checkSeqDirProp)(L, 2, -1); Qs(mSeqDirProp) *mf = Qs(qlua_newSeqDirProp)(L, QC(f)); Qs(mSeqDirProp) *r = Qs(qlua_newZeroSeqDirProp)(L, QC(f)); int i; for (i = 0; i < 16; i++) { switch (m->g[i].t) { case qG_z: continue; case qG_p: Qx(QLA_D,_P_eq_gamma_times_P)(QNC(QC(f)) mf->ptr, f->ptr, i); Qx(QLA_D,_P_peq_P)(QNC(QC(f)) r->ptr, mf->ptr); break; case qG_m: Qx(QLA_D,_P_eq_gamma_times_P)(QNC(QC(f)) mf->ptr, f->ptr, i); Qx(QLA_D,_P_meq_P)(QNC(QC(f)) r->ptr, mf->ptr); break; case qG_r: Qx(QLA_D,_P_eq_gamma_times_P)(QNC(QC(f)) mf->ptr, f->ptr, i); Qx(QLA_D,_P_peq_r_times_P)(QNC(QC(f)) r->ptr, &m->g[i].r, mf->ptr); break; case qG_c: Qx(QLA_D,_P_eq_gamma_times_P)(QNC(QC(f)) mf->ptr, f->ptr, i); Qx(QLA_D,_P_peq_c_times_P)(QNC(QC(f)) r->ptr, &m->g[i].c, mf->ptr); break; } } return 1; }
static int Qs(q_g_mul_D_)(lua_State *L) { mClifford *m = qlua_checkClifford(L, 1); Qs(mLatDirFerm) *f = Qs(qlua_checkLatDirFerm)(L, 2, NULL, -1); mLattice *S = qlua_ObjLattice(L, 2); int Sidx = lua_gettop(L); Qs(mLatDirFerm) *mf = Qs(qlua_newLatDirFerm)(L, Sidx, QC(f)); Qs(mLatDirFerm) *r = Qs(qlua_newZeroLatDirFerm)(L, Sidx, QC(f)); int i; CALL_QDP(L); for (i = 0; i < 16; i++) { switch (m->g[i].t) { case qG_z: continue; case qG_p: Qx(QDP_D,_D_eq_gamma_times_D)(mf->ptr, f->ptr, i, *S->qss); Qx(QDP_D,_D_peq_D)(r->ptr, mf->ptr, *S->qss); break; case qG_m: Qx(QDP_D,_D_eq_gamma_times_D)(mf->ptr, f->ptr, i, *S->qss); Qx(QDP_D,_D_meq_D)(r->ptr, mf->ptr, *S->qss); break; case qG_r: Qx(QDP_D,_D_eq_gamma_times_D)(mf->ptr, f->ptr, i, *S->qss); Qx(QDP_D,_D_peq_r_times_D)(r->ptr, &m->g[i].r, mf->ptr, *S->qss); break; case qG_c: Qx(QDP_D,_D_eq_gamma_times_D)(mf->ptr, f->ptr, i, *S->qss); Qx(QDP_D,_D_peq_c_times_D)(r->ptr, &m->g[i].c, mf->ptr, *S->qss); break; } } return 1; }
static QualType getTypeWithAttribute(ASTContext &C, QualType T, Qualifiers::AS AS) { auto Split = T.split(); if(Split.second.hasAttributeSpec(AS)) return T; QualifierCollector QC(Split.second); QC.addAttributeSpecs(AS); return C.getTypeWithQualifers(T, QC); }
static int Qs(q_M_fmt)(lua_State *L) { char fmt[72]; Qs(mLatColMat) *b = Qs(qlua_checkLatColMat)(L, 1, NULL, -1); sprintf(fmt, "QDP:ColorMatrix%d(%p)", QC(b), b->ptr); lua_pushstring(L, fmt); return 1; }
void xrMU_Model::export_geometry () { // Declarator VDeclarator D; D.set (decl); // RT-check, BOX, low-point, frac-size Fbox BB; BB.invalidate (); for (v_vertices_it vit=m_vertices.begin(); vit!=m_vertices.end(); vit++) BB.modify ((*vit)->P); Fvector frac_low; float frac_Ysize; BB.getcenter (frac_low); frac_low.y = BB.min.y; frac_Ysize = BB.max.y - BB.min.y; // Begin building for (v_subdivs_it it=m_subdivs.begin(); it!=m_subdivs.end(); it++) { // Vertices { g_VB.Begin (D); vecOGF_V& verts = it->ogf->vertices; for (u32 v_it=0; v_it<verts.size(); v_it++) { OGF_Vertex& oV = verts[v_it]; // Position g_VB.Add (&oV.P,3*sizeof(float)); // Normal { base_color_c oV_c; oV.Color._get(oV_c); Fvector N = oV.N; N.add (1.f); N.mul (.5f*255.f); s32 nx = iFloor(N.x); clamp(nx,0,255); s32 ny = iFloor(N.y); clamp(ny,0,255); s32 nz = iFloor(N.z); clamp(nz,0,255); s32 cc = iFloor(oV_c.hemi*255.f); clamp(cc,0,255); u32 uN = color_rgba(nx,ny,nz,cc); g_VB.Add (&uN,4); } // Tangent { u32 uT = color_rgba(oV.T.x,oV.T.y,oV.T.z,0); g_VB.Add (&uT,4); } // Binormal { u32 uB = color_rgba(oV.B.x,oV.B.y,oV.B.z,0); g_VB.Add (&uB,4); } // TC s16 tu,tv,frac,dummy; tu = QC(oV.UV.begin()->x); tv = QC(oV.UV.begin()->y); g_VB.Add (&tu,2); g_VB.Add (&tv,2); // frac float f1 = (oV.P.y - frac_low.y) /frac_Ysize; float f2 = oV.P.distance_to(frac_low)/frac_Ysize; frac = QC((f1+f2)/2.f); dummy = 0; g_VB.Add (&frac, 2); g_VB.Add (&dummy,2); } g_VB.End (&it->vb_id,&it->vb_start); } // Indices g_IB.Register (LPWORD(&*it->ogf->faces.begin()),LPWORD(&*it->ogf->faces.end()),&it->ib_id,&it->ib_start); // SW if (it->ogf->progressive_test()) g_SWI.Register (&it->sw_id,&it->ogf->m_SWI); } }
void CDetailManager::hw_Load_Geom() { // Analyze batch-size hw_BatchSize = (u32(HW.Caps.geometry.dwRegisters)-c_hdr)/c_size; clamp (hw_BatchSize,(u32)0,(u32)64); Msg ("* [DETAILS] VertexConsts(%d), Batch(%d)",u32(HW.Caps.geometry.dwRegisters),hw_BatchSize); // Pre-process objects u32 dwVerts = 0; u32 dwIndices = 0; for (u32 o=0; o<objects.size(); o++) { const CDetail& D = *objects[o]; dwVerts += D.number_vertices*hw_BatchSize; dwIndices += D.number_indices*hw_BatchSize; } u32 vSize = sizeof(vertHW); Msg("* [DETAILS] %d v(%d), %d p",dwVerts,vSize,dwIndices/3); #if !defined(USE_DX10) && !defined(USE_DX11) // Determine POOL & USAGE u32 dwUsage = D3DUSAGE_WRITEONLY; // Create VB/IB R_CHK (HW.pDevice->CreateVertexBuffer (dwVerts*vSize,dwUsage,0,D3DPOOL_MANAGED,&hw_VB,0)); HW.stats_manager.increment_stats_vb (hw_VB); R_CHK (HW.pDevice->CreateIndexBuffer (dwIndices*2,dwUsage,D3DFMT_INDEX16,D3DPOOL_MANAGED,&hw_IB,0)); HW.stats_manager.increment_stats_ib (hw_IB); #endif // USE_DX10 Msg("* [DETAILS] Batch(%d), VB(%dK), IB(%dK)",hw_BatchSize,(dwVerts*vSize)/1024, (dwIndices*2)/1024); // Fill VB { vertHW* pV; #if defined(USE_DX10) || defined(USE_DX11) vertHW* pVOriginal; pVOriginal = xr_alloc<vertHW>(dwVerts); pV = pVOriginal; #else // USE_DX10 R_CHK (hw_VB->Lock(0,0,(void**)&pV,0)); #endif // USE_DX10 for (o=0; o<objects.size(); o++) { const CDetail& D = *objects[o]; for (u32 batch=0; batch<hw_BatchSize; batch++) { u32 mid = batch*c_size; for (u32 v=0; v<D.number_vertices; v++) { const Fvector& vP = D.vertices[v].P; pV->x = vP.x; pV->y = vP.y; pV->z = vP.z; pV->u = QC(D.vertices[v].u); pV->v = QC(D.vertices[v].v); pV->t = QC(vP.y/(D.bv_bb.max.y-D.bv_bb.min.y)); pV->mid = short(mid); pV++; } } } #if defined(USE_DX10) || defined(USE_DX11) R_CHK(dx10BufferUtils::CreateVertexBuffer(&hw_VB, pVOriginal, dwVerts*vSize)); HW.stats_manager.increment_stats_vb ( hw_VB); xr_free(pVOriginal); #else // USE_DX10 R_CHK (hw_VB->Unlock()); #endif // USE_DX10 } // Fill IB { u16* pI; #if defined(USE_DX10) || defined(USE_DX11) u16* pIOriginal; pIOriginal = xr_alloc<u16>(dwIndices); pI = pIOriginal; #else // USE_DX10 R_CHK (hw_IB->Lock(0,0,(void**)(&pI),0)); #endif // USE_DX10 for (o=0; o<objects.size(); o++) { const CDetail& D = *objects[o]; u16 offset = 0; for (u32 batch=0; batch<hw_BatchSize; batch++) { for (u32 i=0; i<u32(D.number_indices); i++) *pI++ = u16(u16(D.indices[i]) + u16(offset)); offset = u16(offset+u16(D.number_vertices)); } } #if defined(USE_DX10) || defined(USE_DX11) R_CHK(dx10BufferUtils::CreateIndexBuffer(&hw_IB, pIOriginal, dwIndices*2)); HW.stats_manager.increment_stats_ib (hw_IB); xr_free(pIOriginal); #else // USE_DX10 R_CHK (hw_IB->Unlock()); #endif // USE_DX10 } // Declare geometry hw_Geom.create (dwDecl, hw_VB, hw_IB); }
void CDetailManager::hw_Load () { // Analyze batch-size hw_BatchSize = (u32(HW.Caps.geometry.dwRegisters)-c_hdr)/c_size; clamp (hw_BatchSize,(u32)0,(u32)64); Msg ("* [DETAILS] VertexConsts(%d), Batch(%d)",u32(HW.Caps.geometry.dwRegisters),hw_BatchSize); // Pre-process objects u32 dwVerts = 0; u32 dwIndices = 0; for (u32 o=0; o<objects.size(); o++) { CDetail& D = *objects[o]; dwVerts += D.number_vertices*hw_BatchSize; dwIndices += D.number_indices*hw_BatchSize; } u32 vSize = sizeof(vertHW); Msg("* [DETAILS] %d v(%d), %d p",dwVerts,vSize,dwIndices/3); // Determine POOL & USAGE u32 dwUsage = D3DUSAGE_WRITEONLY; // Create VB/IB R_CHK (HW.pDevice->CreateVertexBuffer(dwVerts*vSize,dwUsage,0,D3DPOOL_MANAGED,&hw_VB,0)); R_CHK (HW.pDevice->CreateIndexBuffer(dwIndices*2,dwUsage,D3DFMT_INDEX16,D3DPOOL_MANAGED,&hw_IB,0)); Msg("* [DETAILS] Batch(%d), VB(%dK), IB(%dK)",hw_BatchSize,(dwVerts*vSize)/1024, (dwIndices*2)/1024); // Fill VB { vertHW* pV; R_CHK (hw_VB->Lock(0,0,(void**)&pV,0)); for (o=0; o<objects.size(); o++) { CDetail& D = *objects[o]; for (u32 batch=0; batch<hw_BatchSize; batch++) { u32 mid = batch*c_size; for (u32 v=0; v<D.number_vertices; v++) { Fvector& vP = D.vertices[v].P; pV->x = vP.x; pV->y = vP.y; pV->z = vP.z; pV->u = QC(D.vertices[v].u); pV->v = QC(D.vertices[v].v); pV->t = QC(vP.y/(D.bv_bb.max.y-D.bv_bb.min.y)); pV->mid = short(mid); pV++; } } } R_CHK (hw_VB->Unlock()); } // Fill IB { u16* pI; R_CHK (hw_IB->Lock(0,0,(void**)(&pI),0)); for (o=0; o<objects.size(); o++) { CDetail& D = *objects[o]; u16 offset = 0; for (u32 batch=0; batch<hw_BatchSize; batch++) { for (u32 i=0; i<u32(D.number_indices); i++) *pI++ = u16(u16(D.indices[i]) + u16(offset)); offset = u16(offset+u16(D.number_vertices)); } } R_CHK (hw_IB->Unlock()); } // Create shader to access constant storage ref_shader S; S.create("details\\set"); R_constant_table& T0 = *(S->E[0]->passes[0]->constants); R_constant_table& T1 = *(S->E[1]->passes[0]->constants); hwc_consts = T0.get("consts"); hwc_wave = T0.get("wave"); hwc_wind = T0.get("dir2D"); hwc_array = T0.get("array"); hwc_s_consts = T1.get("consts"); hwc_s_xform = T1.get("xform"); hwc_s_array = T1.get("array"); // Declare geometry hw_Geom.create (dwDecl, hw_VB, hw_IB); }