double GetVectorNorma1(CoordXYZ x){ double norma = 0.; for (int i = 0; i < 3; ++i){ norma += kva(x[i]); } return sqrt(norma); }
CoordXYZ SourceOfNoise::GetUDerivative(CoordXYZ &x0, double t){ CoordXYZ x(3); for (int i = 0; i < 3; ++i) x[i] = x0[i] - position_of_source[i]; x = ModifyPositionByFlow(x); CoordXYZ null(3); for (int i = 0; i < 3; ++i) null[i] = 0; double norma_x = GetVectorNorma1(x); if (!norma_x) return null; if(!intime(t-norma_x)) return null; CoordXYZ u_der(3); for (int i = 0; i < 3; ++i) u_der[i] = x[i] / kva(norma_x) * ( omega*cos(omega*(t-norma_x)) + 1./norma_x * sin(omega*(t-norma_x)) ); // for (int i = 0; i < 3; ++i) u_der[i] = 0.; return u_der; }
double CalcIntegralOfSmallTrg(CoordXYZ xtrg[3], double time, SourceOfNoise &source_of_noise, CoordXYZ &control_point) { // return 1; // PutTrgToWff(xtrg); double cell_square; CoordXYZ cell_normal(3), cell_mass_centre(3); if (GetCellParams(xtrg, cell_square, cell_normal,cell_mass_centre)){ // cout << " Error # 01 : norma_r=0" << endl; return 0; } CoordXYZ R(3); for (int i = 0; i < 3; ++i) R[i] = control_point[i] - cell_mass_centre[i]; double norma_R = GetVectorNorma1(R); if (!norma_R){ cout << " Error # 01 : norma_r=0" << endl; exit(1); } double t = ModifyTimeByPosition(R, time); CoordXYZ u_der = source_of_noise.GetUDerivative(cell_mass_centre, t); double rho_der = source_of_noise.GetRhoDerivative(cell_mass_centre, t); double rho = source_of_noise.GetRho(cell_mass_centre, t); // cout << norma_R << " " << rho << " " << rho_der << " " << u_der[0] << " ! " << u_der[1] << " " << u_der[2] << endl; // cout << cell_square << " ! " << cell_normal[0] << " " << cell_normal[1] << " " << cell_normal[2] << endl; double SUM = 0; for (int i = 0; i < 3; ++i) { SUM +=1./(4*PI)* ( u_der[i]/norma_R + R[i]/kva(norma_R)*(rho_der + rho/norma_R) ) *cell_normal[i] *cell_square; IntN[i]+=(cell_square*cell_normal[i]); } //cout << "!! IntN[" << i << "]=" << IntN[i] << "\t" << cell_square << "\t" << cell_normal[i] << endl; S_Surf+=cell_square; // cout << " cs " << cell_square*cell_normal[0] << " " << cell_square*cell_normal[1] << " " << cell_square*cell_normal[2] << endl; return SUM; }
void kexConsole::Draw(void) { bool bOverlay; float w; float h; rcolor color; w = (float)sysMain.VideoWidth(); if(cvarShowFPS.GetBool()) { color = RGBA(255, 255, 255, 255); renderBackend.consoleFont.DrawString(kva("fps: %i", client.fps), w - 64, 32, 1, false, (byte*)&color, (byte*)&color); } if(state == CON_STATE_UP && !cvarDisplayConsole.GetBool()) { return; } bOverlay = (state == CON_STATE_UP && cvarDisplayConsole.GetBool()); h = (float)sysMain.VideoHeight() * 0.6875f; renderBackend.SetState(GLSTATE_BLEND, true); if(!bOverlay) { cpuVertList.BindDrawPointers(); renderBackend.whiteTexture.Bind(); // draw tint overlay cpuVertList.AddVertex(0, 0, 0, 0, 0, 4, 8, 16, 192); cpuVertList.AddVertex(w, 0, 0, 0, 0, 4, 8, 16, 192); cpuVertList.AddVertex(0, h, 0, 0, 0, 4, 8, 16, 192); cpuVertList.AddVertex(w, h, 0, 0, 0, 4, 8, 16, 192); cpuVertList.AddTriangle(0, 1, 2); cpuVertList.AddTriangle(2, 1, 3); cpuVertList.DrawElementsNoShader(); // draw borders cpuVertList.AddVertex(0, h-17, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(w, h-17, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(0, h-16, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(w, h-16, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(0, h, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(w, h, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(0, h+1, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddVertex(w, h+1, 0, 0, 0, 0, 128, 255, 255); cpuVertList.AddTriangle(0, 1, 2); cpuVertList.AddTriangle(2, 1, 3); cpuVertList.AddTriangle(4, 5, 6); cpuVertList.AddTriangle(6, 5, 7); cpuVertList.DrawElementsNoShader(); color = RGBA(255, 255, 255, 255); renderBackend.consoleFont.DrawString("> ", 0, h-15, 1, false, (byte*)&color, (byte*)&color); if(bShowPrompt) { renderBackend.consoleFont.DrawString("_", 16 + renderBackend.consoleFont.StringWidth(typeStr, 1.0f, typeStrPos), h-15, 1, false, (byte*)&color, (byte*)&color); } if(strlen(typeStr) > 0) { renderBackend.consoleFont.DrawString(typeStr, 16, h-15, 1, false, (byte*)&color, (byte*)&color); } } if(scrollBackLines > 0) { float scy = h-34; for(int i = scrollBackLines-(scrollBackPos)-1; i >= 0; i--) { if(scy < 0) { break; } color = lineColor[i]; renderBackend.consoleFont.DrawString(scrollBackStr[i], 0, scy, 1, false, (byte*)&color, (byte*)&color); scy -= 16; } } renderBackend.SetState(GLSTATE_BLEND, false); }
double CalcIntegralOfSmallTrgBp(CoordXYZ xtrg[3], double time, BasePoints &bp, CoordXYZ &control_point) { double cell_square; CoordXYZ cell_normal(3), cell_mass_centre(3); if (GetCellParams(xtrg, cell_square, cell_normal,cell_mass_centre)){ return 0; } CoordXYZ R(3); for (int i = 0; i < 3; ++i) R[i] = control_point[i] - cell_mass_centre[i]; double norma_R = GetVectorNorma1(R); if (!norma_R){ cout << " Error 1 : norma_r=0" << endl; exit(1); } double SUM = 0; double t = ModifyTimeByPosition(R, time); CoordXYZ f(kbase); for(int i=0;i<kbase;i++) f[i]=0; // double rez[kbase]; // найдём отклик от каждой вершины // этот фрагмент следует вычислять для каждого узла пирамиды // и для каждой функции отдельно double rho=0, rho_der=0, u_der[3]; for(int nonZeroNode=0; nonZeroNode<4; nonZeroNode++) // по каждой вершине { f[nonZeroNode]=1; double rez=bp.GetVal(cell_mass_centre,ip,f); // величина отклика от вершины, без учета функциональной зависимости f[nonZeroNode]=0; for(int nonZeroFunc=0; nonZeroFunc<5; nonZeroFunc++) { /* Эти функции равны 0 или 1 в зависимости от nonZeroFunc CoordXYZ u_der = bp.GetUDerivative(cell_mass_centre, t); double rho_der = bp.GetRhoDerivative(cell_mass_centre, t); double rho = bp.GetRho(cell_mass_centre, t); */ switch(nonZeroFunc) { case 0: rho=1; rho_der=0; u_der[0]=0; u_der[1]=0; u_der[2]=0; break; case 1: rho=0; rho_der=1; u_der[0]=0; u_der[1]=0; u_der[2]=0; break; case 2: rho=0; rho_der=0; u_der[0]=1; u_der[1]=0; u_der[2]=0; break; case 3: rho=0; rho_der=0; u_der[0]=0; u_der[1]=1; u_der[2]=0; break; case 4: rho=0; rho_der=0; u_der[0]=0; u_der[1]=0; u_der[2]=1; break; } SUM=0.; for (int i = 0; i < 3; ++i) { SUM += 1./(4*PI)* ( u_der[i]/norma_R + R[i]/kva(norma_R)*(rho_der + rho/norma_R) ) *cell_normal[i] *cell_square; } int err=vrt.AddData(ip[nonZeroNode],nonZeroFunc,SUM*rez,t); if(err) exit(0); } } // Расчет инвариантов S_Surf+=cell_square; for (int i = 0; i < 3; ++i) IntN[i]+=(cell_square*cell_normal[i]); return SUM; }
double CalcIntegral(Surfaces &s, PointsXYZ &m){ //return; int ns=s.size(); // число треугольников CoordXYZ x[3]; for (int i = 0; i < 3; i++) x[i].resize(3); //============= init =================== vrt.Init(m.size(),p_DeltaT); CoordXYZ w(3); CoordXYZ control_point(3); CoordXYZ position_of_source(3); w[0] = 0; w[1] = 0; w[2] = 0; position_of_source[0] = e_x0; position_of_source[1] = e_y0; position_of_source[2] = e_z0; control_point[0] = p_control_x; control_point[1] = p_control_y; control_point[2] = p_control_z; double omega = p_omega; SourceOfNoise source_of_noise(omega, position_of_source,w);//,control_point); //========== end of init =============== double Sintegral; // for(double z=90.;z<100.;z+=(100.-90.)/200.) double T=0.; // for(;T<110.;T+=(110.-90.)/230.) { for (int i = 0; i < 3; ++i) IntN[i]=0; S_Surf=0.; // control_point[2]=z; Sintegral=0; for(int j=0;j<ns;j++) { int err; Sintegral+=CalcIntegralOfFullTrg(s[j],m,T,source_of_noise, control_point,err); if(err) { cout << " ERROR 3_ ret=" << err << " j= " << j << endl; return 0.; } } { static int ugu=0; if(!ugu) cout << " S_Surf=" << S_Surf << " (" << S_Surf/(4.*M_PI*kva(p_Rsphere)) << ") IntN " << IntN[0] << " " << IntN[1] << " " << IntN[2] << endl<< endl; ugu=1; } // cout << control_point[2] << " " << Sintegral << " " << source_of_noise.GetRho(control_point,T) << endl; if(!isbp) cout << T << "\t" << source_of_noise.GetRho(control_point,T) << " " << Sintegral << endl; } if(isbp) { vrt.PutData("koeff.txt"); // следует выполнить свёртку! int nk=150,ik; double dt=(p_T2-p_T1)/nk; for(ik=0,T=p_T1;ik<=nk;ik++,T+=dt) { Sintegral=vrt.Svertka(s,m,source_of_noise,T); cout << T << "\t" << source_of_noise.GetRho(control_point,T) << " " << Sintegral << endl; } } cout << endl; cout << " S_Surf=" << S_Surf << " (" << S_Surf/(4.*M_PI*kva(p_Rsphere)) << ") Int_N " << IntN[0] << " " << IntN[1] << " " << IntN[2] << endl; return Sintegral; }
void kexSystem::InitVideo(void) { int newwidth; int newheight; int p; uint32 flags = 0; bWindowed = cvarVidWindowed.GetBool(); videoWidth = cvarVidWidth.GetInt(); videoHeight = cvarVidHeight.GetInt(); videoRatio = (float)videoWidth / (float)videoHeight; if(CheckParam("-window")) { bWindowed = true; } if(CheckParam("-fullscreen")) { bWindowed = false; } newwidth = newheight = 0; p = CheckParam("-width"); if(p && p < argc - 1) { newwidth = atoi(argv[p+1]); } p = CheckParam("-height"); if(p && p < argc - 1) { newheight = atoi(argv[p+1]); } if(newwidth && newheight) { videoWidth = newwidth; videoHeight = newheight; } if(cvarVidDepthSize.GetInt() != 8 && cvarVidDepthSize.GetInt() != 16 && cvarVidDepthSize.GetInt() != 24) { cvarVidDepthSize.Set(24); } // TODO if(cvarVidStencilSize.GetInt() != 8/* && cvarVidStencilSize.GetInt() != 16 && cvarVidStencilSize.GetInt() != 24*/) { cvarVidStencilSize.Set(8); } if(cvarVidBuffSize.GetInt() != 8 && cvarVidBuffSize.GetInt() != 16 && cvarVidBuffSize.GetInt() != 24 && cvarVidBuffSize.GetInt() != 32) { cvarVidBuffSize.Set(32); } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, cvarVidBuffSize.GetInt()); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, cvarVidDepthSize.GetInt()); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, cvarVidStencilSize.GetInt()); SDL_GL_SetSwapInterval(cvarVidVSync.GetBool()); flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS; if(!bWindowed) flags |= SDL_WINDOW_FULLSCREEN; window = SDL_CreateWindow( kva("Kex Engine - Version Date: %s", __DATE__), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, sysMain.VideoWidth(), sysMain.VideoHeight(), flags); if(window == NULL) { common.Error("kexSystem::InitVideo: Failed to create window"); } if((glContext = SDL_GL_CreateContext(window)) == NULL) { common.Error("kexSystem::InitVideo: Failed to create opengl context"); } gameManager.SetTitle(); common.Printf("Video Initialized\n"); }