00001 /* 00002 Autor: $Author: kunkel $ State: $State: Exp $ 00003 Datum: $Date: 2005/05/30 12:35:25 $ 00004 Version: $Revision: 1.1 $ 00005 */ 00006 00012 #include "PhysikEngine.h" 00013 #include "Integrator.h" 00014 #include "Configuration.h" 00015 #include "ObjectManager.h" 00016 #include "CollisionsManager.h" 00017 #include "Opengl.h" 00018 00025 void PhysikEngine::simulateGravity(double time) { 00026 objectList * objects = ourObjectManager.getObjectList(); 00027 00028 // waehle aktuellen Integrator aus 00029 Integrator *integrator=ourConfiguration.integrator; 00030 00031 // hole die Integrator-interne Zeit 00032 double t=integrator->getTime(); 00033 00034 // uebergebe dem Integrator die Objektliste 00035 integrator->setObjects(objects); 00036 00037 // aktualisiere time 00038 time += t; 00039 00040 // starte Integration 00041 while(t<time-(1e-10)) { 00042 00043 // falls beim Integrieren Fehler auftritt, gebe entsprechende 00044 // Nachricht aus 00045 try { 00046 t=integrator->integrate(time-t); 00047 } catch (Integrator::Error Ierror) { 00048 Opengl::setAnimation(false); 00049 Ierror.print(); 00050 return; 00051 } 00052 00053 // falls Kollisionen stattgefunden haben, erzeuge 00054 // eine Kollisionsmanager und fuehre Kollisionen durch 00055 if(integrator->getCollisionslist()->empty() == false) { 00056 CollisionsManager CM(integrator->getCollisionslist(), 00057 objects); 00058 CM.collide(); 00059 } 00060 } 00061 } 00062 00063 /* Die folgende Ephemeriden-Funktion wurde aus datentechnischen 00064 Gruenden nie getestet/fertiggestellt, koennte aber als Geruest fuer 00065 ein ephemeridenbasiertes Koordinatensystem verwendet werden.*/ 00066 // Vector PhysikEngine::getPositionFromEphemeris(double acc, double a, double epsilon, double i, double Omega, double omega, double M,bool grad) 00067 // { 00068 // if(acc==0.0) acc=1e-12; 00069 // 00070 // if(grad) { 00071 // i=i/360*2*Pi; 00072 // Omega=Omega/360*2*Pi; 00073 // omega=omega/360*2*Pi; 00074 // M=M/360*2*Pi; 00075 // } 00076 // 00077 // double E = rtnewt(-10.0, 10.0, acc, M, epsilon); // Ränder evtl. noch verändern 00078 // if(E==0.0) return Vector(0.0,0.0,0.0); 00079 // 00080 // double ny = atan(sqrt((1.0+epsilon)/(1.0-epsilon))*tan(E/2)); 00081 // 00082 // Vector rorbit(cos(ny),sin(ny),0.0); 00083 // Vector rhelio(0.0,0.0,0.0); 00084 // Matrix D1i(1.0,0.0,0.0, 0.0,cos(i),-sin(i), 0.0,sin(i),cos(i)); 00085 // Matrix D3O(cos(Omega),-sin(Omega),0.0, sin(Omega),cos(Omega),0.0, 0.0,0.0,1); 00086 // Matrix D3o(cos(omega),-sin(omega),0.0, sin(omega),cos(omega),0.0, 0.0,0.0,1); 00087 // 00088 // rhelio = D3O*D1i*D3o*rorbit; 00089 // rhelio *= a*(1-epsilon*epsilon)/(1+epsilon*cos(ny)); 00090 // return rhelio; 00091 // } 00092 00093 // diese Funktiont wird fuer die Ephemeriden-Funktion unten benoetigt 00094 // double PhysikEngine::rtnewt(double x1, double x2, double xacc, double M, double epsilon) 00095 // /* Using the Newton-Raphson method, find the root of a function known to lie in the interval [x1, x2]. The root rtnewt will be refined until its accuracy is known within ±xacc. funcd is a user-supplied routine that returns both the function value and the first derivative of the function at the point x. */ 00096 // { 00097 // int j; 00098 // double df,dx,dx_abs,f,rtn; 00099 // rtn=0.5*(x1+x2); 00100 // for (j=1;j<=20;j++) { 00101 // f = M + epsilon*sin(rtn) - rtn; 00102 // df = epsilon*cos(rtn) - 1.0; 00103 // dx=f/df; 00104 // rtn -= dx; 00105 // if ((x1-rtn)*(rtn-x2) < 0.0) 00106 // Error("Jumped out of brackets in rtnewt"); 00107 // if (dx < 0) dx_abs=-dx; 00108 // else dx_abs=dx; 00109 // if (dx_abs < xacc) return rtn; 00110 // } 00111 // Error("maximum number of iterations exceeded in rtnewt"); 00112 // return 0.0; 00113 // } 00114 00115 00116