예제 #1
0
파일: mygl.cpp 프로젝트: codemodo/renderer
void MyGL::SceneLoadDialog()
{
    QString filepath = QFileDialog::getOpenFileName(0, QString("Load Scene"), QString("../scene_files"), tr("*.xml"));
    if(filepath.length() == 0)
    {
        return;
    }

    QFile file(filepath);
    int i = filepath.length() - 1;
    while(QString::compare(filepath.at(i), QChar('/')) != 0)
    {
        i--;
    }
    QStringRef local_path = filepath.leftRef(i+1);
    //Reset all of our objects
    scene.Clear();
    integrator = Integrator();
    intersection_engine = IntersectionEngine();
    //Load new objects based on the XML file chosen.
    xml_reader.LoadSceneFromFile(file, local_path, scene, integrator);
    integrator.scene = &scene;
    integrator.intersection_engine = &intersection_engine;
    intersection_engine.scene = &scene;



    update();
    //intersection_engine.BuildBvhTree();
}
예제 #2
0
void AssignmentFour::RungeKuttaStreamline()
{
	Vector4f color = makeVector4f(1, 0, 1, 1);
	
	vector<Vector2f> path = Integrator(RKStep, &AssignmentFour::RK4, XStart, YStart);
	DrawStreamline(path, color);
}
예제 #3
0
int main(void)
{
    FILE *f;

    int i;
    int iteration;

    double x[2];
    double xx[2];
    double t, dt;

    dt = 0.05;
    iteration=1000;

    x[0] = 1.0; // q
    x[1] = 0.0; // p

    f = fopen("trajectory_symp2.dat","w");

    for (i=0; i<iteration; i++) {
        t = i*dt;
        fprintf(f,"%lf %lf %lf %le\n", t, x[0], x[1], Hamiltonian(t,x[0],x[1]));
        Integrator(Symplectic2, t,dt,x,xx);

        x[0] = xx[0];
        x[1] = xx[1];
    }
    fclose(f);
    return 0;
}
예제 #4
0
void AssignmentFour::SeedingStreamLines()
{
	viewer->clear();

	if (DrawField) {
		DrawVectorFieldHelper();
	}

	Vector4f color = makeVector4f(0.8f, 0.2f, 0.0f, 0.40f);
	float32 minX = Field.boundMin()[0]; 
	float32 maxX = Field.boundMax()[0];
	float32 minY = Field.boundMin()[1]; 
	float32 maxY = Field.boundMax()[1];
	
	if (GridSeed) {
		float32 dx = (maxX - minX) / GridPointsX;
		float32 dy = (maxY - minY) / GridPointsY;
		float32 x = minX; 

		for (int ix = 0; ix < GridPointsX; ++ix) {
			float32 y = minY;
			for (int iy = 0; iy < GridPointsY; ++iy) {
				vector<Vector2f> path = Integrator(RKStep, &AssignmentFour::RK4, x, y);
				DrawStreamline(path, color);				

				y += dy;
			}
			x += dx;
		}
	}
	else {
		int n = NumStreamLines;

		for (int i = 0; i < n; ++i) {
			float32 x = randomFloat(minX, maxX);
			float32 y = randomFloat(minY, maxY);

			vector<Vector2f> path = Integrator(RKStep, &AssignmentFour::RK4, x, y);
			DrawStreamline(path, color);
		}
	}

	viewer->refresh();
}
예제 #5
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetVerticalSync(true);
	//ofSetFrameRate(120);
	ofHideCursor();
	oscIn.setup(12345);
	oscOut.setup("surya.local", 12346);
    fftMax =0;
    scale =100;
    ofEnableSmoothing();
    for(int i=0;i<10;i++){
        line.addVertex(100,0);
        line.addVertex(-100,0);
        line.addVertex(0,-100);
    }
    ofEnableSmoothing();
    saveFrame =false;
    
    iRadius = Integrator(200,.2f,.2f);
    a = Integrator(1,.2f,.2f);
    b = Integrator(1,.2f,.2f);
    m =  Integrator(2,.2f,.2f);
    n1 = Integrator(20,.2f,.2f);
    n2 = Integrator(1,.2f,.2f);
    n3 = Integrator(1,.2f,.2f);
    
    stkWeight = Integrator(22,.2f,.2f);
    
    //    iRadius_ =200;
    //    a_ = 1;
    //    b_ = 1;
    //    m_ = 2;
    //    n1_ =20;
    //    n2_ = 1;
    //    n3_ = 1;
    
    iRadius_ =170;
    a_ = 0.24;
    b_ = 0.34;
    m_ = 11.92;
    n1_ =12.81;
    n2_ = -2.71;
    n3_ = 2.46;
    
    stkWeight_ = 3.5;
    
    cam.enableMouseInput();
    
    
    setupGUI();
    setupShaper();
}
예제 #6
0
void AssignmentFour::EulerStreamline()
{
	Vector4f color = makeVector4f(1, 1, 0, 1);

	output << "Calculating integration points...";
	vector<Vector2f> path = Integrator(EulerStep, &AssignmentFour::Euler, XStart, YStart);
	output << "done\n";

	output << "Drawing stream line...";
	DrawStreamline(path, color);
	output << "done\n";
}
예제 #7
0
void AssignmentFour::DistributionSeed() {
	viewer->clear();

	if (DrawField) {
		DrawVectorFieldHelper();
	}

	Vector4f color = makeVector4f(0.8f, 0.2f, 0.0f, 0.40f);

	vector<Vector2f> points = magnitudeDistribution(NumStreamLines);

	for (size_t i = 0; i < points.size(); ++i) {
		float32 x = points[i][0];
		float32 y = points[i][1];
		vector<Vector2f> path = Integrator(RKStep, &AssignmentFour::RK4, x, y);
		DrawStreamline(path, color);

		output << "x: " << x << "\ty:" << y << "\n";
	}

	//viewer->refresh();
}
예제 #8
0
void MyGL::SceneLoadDialog()
{
    QString filepath = QFileDialog::getOpenFileName(0, QString("Load Scene"), QString("../scene_files"), tr("*.xml"));
    if(filepath.length() == 0)
    {
        return;
    }

    QFile file(filepath);
    int i = filepath.length() - 1;
    while(QString::compare(filepath.at(i), QChar('/')) != 0)
    {
        i--;
    }
    QStringRef local_path = filepath.leftRef(i+1);
    //Reset all of our objects
    scene.Clear();
    integrator = Integrator();

    //delete existing bvh tree
    clearTree(this->intersection_engine.BVHrootNode);
    delete this->intersection_engine.BVHrootNode;

    intersection_engine = IntersectionEngine();

    //Load new objects based on the XML file chosen.
    xml_reader.LoadSceneFromFile(file, local_path, scene, integrator);
    integrator.scene = &scene;
    integrator.intersection_engine = &intersection_engine;
    intersection_engine.scene = &scene;

    //create new tree with this new set of geometry!
    this->intersection_engine.BVHrootNode = new BVHnode();
    this->intersection_engine.BVHrootNode = createBVHtree(this->intersection_engine.BVHrootNode, this->scene.objects, 0);

    update();
}
예제 #9
0
int main(int argc, char* argv[]) {
    int nsteps;
    Box box = Box(20.0);
    Particles particles = Particles(400, 400, box);
    Potential potential = Potential();
    Integrator integrator = Integrator(0.0005);

    std::ofstream file;
    file.open("dump.lammpstrj");
    Dump dump = Dump(100, &file);

    std::ofstream file2;
    file2.open("thermo.out");
    Thermo thermo = Thermo(100, &file2);
    
    if (argc != 2) {
	std::cerr << "usage: " << argv[0] << " nsteps" << std::endl;
	exit(1);
    }
    nsteps = atoi(argv[1]);
    std::cout << "Initializing system..." << std::endl;
    System sys = System(&box, &particles, &potential, &integrator, &dump, &thermo);
    sys.run(nsteps);
}
Settings PhotonMapper(int sampleCount)
{
	return Settings(Integrator("photonmapper", sampleCount > 32, sampleCount < 1),
					Sampler("ldsampler", sampleCount));
}
Settings PathTracer(int sampleCount)
{
	return Settings(Integrator("path", sampleCount > 32, sampleCount < 1),
					Sampler("ldsampler", sampleCount));
}
Settings DirectIllumination(int sampleCount)
{
	return Settings(Integrator("direct", sampleCount > 64, sampleCount < 1, "<integer name=\"bsdfSamples\" value=\"8\"/><integer name=\"luminaireSamples\" value=\"8\"/>"),
					Sampler("ldsampler", sampleCount));
}
char* Player::update(char *input)
{
	//p is a char pointer to a mSendBuff which is the data that will be sent to the other players, it maps the Input data

	char *p=mSendBuff;
	
	//Get Xinput State
	XInputGetState(0,&gXInputState);

	if(eUserType==USERTYPE_SERVER)
	{

		if(eCarState==CARSTATE_COLLIDED)
		{
			if(eCollisionType==COLLISIONTYPE_MUD)
			{
				decAcceleration(0.2);
				p[4]='1';
				eCarState=CARSTATE_MOVINGREVERSE;
			}
	
			if(eCollisionType==COLLISIONTYPE_OIL)
			{
				decAcceleration(0.2);
				if(mPosition.x<(SCREEN_WIDTH/2))
					yaw(-5,-0.3);
				else
					yaw(5,0.3);
			
				eCarState=CARSTATE_MOVINGREVERSE;
				p[4]='2';
			}
		

			if(eCollisionType==COLLISIONTYPE_PEDESTRIAN)
			{
				deaccelerate(15);
				eCarState=CARSTATE_MOVINGREVERSE;
				p[4]='3';
			}
		
			if(eCollisionType==COLLISIONTYPE_ROADBLOCK || eCollisionType==COLLISIONTYPE_NPCCAR)
			{
				mCurrentVelocity=0;
				mCurrentBVelocity=0;
				deaccelerate(50);
				eCarState=CARSTATE_STOP;
				p[4]='4';
			}
			
				eCollisionType=COLLISIONTYPE_NONE;
		}
		else
		{
			p[4]='0';
		}

		if(hge->Input_GetKeyState(HGEK_UP) || gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_A && eCollisionType!=COLLISIONTYPE_ROADBLOCK)
		{
			accelerate(1);
			eCarState=CARSTATE_MOVING;
			p[0]='6';
		}
		else
		{
			p[0]='0';
			damp(1);
		}

		if(hge->Input_GetKeyState(HGEK_DOWN)||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_X)
		{
			deaccelerate(1);
			eCarState=CARSTATE_MOVING;
			p[1]='7';
		}
		else
		{
			p[1]='0';
			Bdamp(1);
		}

		if(hge->Input_GetKeyState(HGEK_LEFT) ||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_DPAD_LEFT&& (eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(-5,-0.3);
			p[2]='8';
		}
		else
		{
			p[2]='0';
			RLdamp();
		}

		if(hge->Input_GetKeyState(HGEK_RIGHT)||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_DPAD_RIGHT && (eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(5,0.3);
			p[3]='9';
		}
		else
		{
			RRdamp();
			p[3]='0';
		}
		/*char c[256];
		sprintf(c,"send : %s \n",mSendBuff);
		OutputDebugString(c);*/

		sprintf(SpeedString,"Speed : %d ",(int)mCurrentVelocity);
		//OutputDebugString(SpeedString);
		Integrator();
		
		p[5]='\0';
	}
		else if(eUserType==USERTYPE_CLIENT)
	{
			if(input[4]=='1')
			{
				//MUD COLLISION
				decAcceleration(0.2);
				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='2')
			{
				//OIL COLLISION
				decAcceleration(0.2);
				if(mPosition.x<(SCREEN_WIDTH/2))
					yaw(-5,-0.3);
				else
					yaw(5,0.3);

				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='3')
			{
				//PEDESTRIAN COLLISION
				deaccelerate(15);
				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='4')
			{
				//NPC CAR COLLISION
				mCurrentVelocity=0;
				mCurrentBVelocity=0;
				deaccelerate(50);
				eCarState=CARSTATE_STOP;
			}
		
		if(input[0]=='6' || hge->Input_GetKeyState(HGEK_W))
		{
			accelerate(1);
			eCarState=CARSTATE_MOVING;
		}
		else
		{
			damp(1);
		}

		if(input[1]=='7')
		{
			deaccelerate(1);
			eCarState=CARSTATE_MOVING;
		}
		else
		{
			Bdamp(1);
		}

		if(input[2]=='8'&&(eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(-5,-0.3);
		}
		else
		{
			RLdamp();
		}

		if(input[3]=='9'&& (eCarState==CARSTATE_MOVING|| eCarState==CARSTATE_DAMPING))
		{
			yaw(5,0.3);
		}
		else
		{
			RRdamp();
		} 

		Integrator();

	}
	return p;
}
void TwoDofController::setup(double _ke, double _tc, double _dt, unsigned int _range) {
  ke = _ke; tc = _tc; dt = _dt;
  integrator = Integrator(_dt, _range);
}
void TwoDofController::setup() {
  ke = 0; tc = 0; dt = 0;
  integrator = Integrator(0, 0);
}
void DirectMultipleShootingInternal::init() {
  // Initialize the base classes
  OCPSolverInternal::init();

  // Create an integrator instance
  std::string integrator_name = getOption("integrator");
  integrator_ = Integrator(integrator_name, ffcn_, Function());
  if (hasSetOption("integrator_options")) {
    integrator_.setOption(getOption("integrator_options"));
  }

  // Set t0 and tf
  integrator_.setOption("t0", 0);
  integrator_.setOption("tf", tf_/nk_);
  integrator_.init();

  // Path constraints present?
  bool path_constraints = nh_>0;

  // Count the total number of NLP variables
  int NV = np_ + // global parameters
           nx_*(nk_+1) + // local state
           nu_*nk_; // local control

  // Declare variable vector for the NLP
  // The structure is as follows:
  // np x 1  (parameters)
  // ------
  // nx x 1  (states at time i=0)
  // nu x 1  (controls in interval i=0)
  // ------
  // nx x 1  (states at time i=1)
  // nu x 1  (controls in interval i=1)
  // ------
  // .....
  // ------
  // nx x 1  (states at time i=nk)

  MX V = MX::sym("V", NV);

  // Global parameters
  MX P = V(Slice(0, np_));

  // offset in the variable vector
  int v_offset=np_;

  // Disretized variables for each shooting node
  vector<MX> X(nk_+1), U(nk_);
  for (int k=0; k<=nk_; ++k) { // interior nodes
    // Local state
    X[k] = V[Slice(v_offset, v_offset+nx_)];
    v_offset += nx_;

    // Variables below do not appear at the end point
    if (k==nk_) break;

    // Local control
    U[k] = V[Slice(v_offset, v_offset+nu_)];
    v_offset += nu_;
  }

  // Make sure that the size of the variable vector is consistent with the
  // number of variables that we have referenced
  casadi_assert(v_offset==NV);

  // Input to the parallel integrator evaluation
  vector<vector<MX> > int_in(nk_);
  for (int k=0; k<nk_; ++k) {
    int_in[k].resize(INTEGRATOR_NUM_IN);
    int_in[k][INTEGRATOR_P] = vertcat(P, U[k]);
    int_in[k][INTEGRATOR_X0] = X[k];
  }

  // Input to the parallel function evaluation
  vector<vector<MX> > fcn_in(nk_);
  for (int k=0; k<nk_; ++k) {
    fcn_in[k].resize(DAE_NUM_IN);
    fcn_in[k][DAE_T] = (k*tf_)/nk_;
    fcn_in[k][DAE_P] = vertcat(P, U.at(k));
    fcn_in[k][DAE_X] = X[k];
  }

  // Options for the parallelizer
  Dictionary paropt;

  // Transmit parallelization mode
  if (hasSetOption("parallelization"))
    paropt["parallelization"] = getOption("parallelization");

  // Evaluate function in parallel
  vector<vector<MX> > pI_out = integrator_.callParallel(int_in, paropt);

  // Evaluate path constraints in parallel
  vector<vector<MX> > pC_out;
  if (path_constraints)
    pC_out = cfcn_.callParallel(fcn_in, paropt);

  //Constraint function
  vector<MX> gg(2*nk_);

  // Collect the outputs
  for (int k=0; k<nk_; ++k) {
    //append continuity constraints
    gg[2*k] = pI_out[k][INTEGRATOR_XF] - X[k+1];

    // append the path constraints
    if (path_constraints)
      gg[2*k+1] = pC_out[k][0];
  }

  // Terminal constraints
  MX g = vertcat(gg);

  // Objective function
  MX f;
  if (mfcn_.getNumInputs()==1) {
    f = mfcn_(X.back()).front();
  } else {
    vector<MX> mfcn_argin(MAYER_NUM_IN);
    mfcn_argin[MAYER_X] = X.back();
    mfcn_argin[MAYER_P] = P;
    f = mfcn_.call(mfcn_argin).front();
  }

  // NLP
  nlp_ = MXFunction(nlpIn("x", V), nlpOut("f", f, "g", g));
  nlp_.setOption("ad_mode", "forward");
  nlp_.init();

  // Get the NLP creator function
  std::string nlp_solver_name = getOption("nlp_solver");

  // Allocate an NLP solver
  nlp_solver_ = NlpSolver(nlp_solver_name, nlp_);

  // Pass user options
  if (hasSetOption("nlp_solver_options")) {
    const Dictionary& nlp_solver_options = getOption("nlp_solver_options");
    nlp_solver_.setOption(nlp_solver_options);
  }

  // Initialize the solver
  nlp_solver_.init();
}