Exemplo n.º 1
0
kernel void interact(global float *one, global float *two, const uint work_size)
{
	const int size = get_global_size(0);
	const int pos = get_global_id(0);
	int i, s;
	
	const float dt = 0.00001; // time step
	const float in = 1e1;     // interaction magnitude
	const float rm = 0.2;     // equillibrium distance
	const float el = 1e6;     // boundaries elasticity
	const float em = 1e-4;    // emission coefficient
	const float ms = 100.0;    // maximal speed
	
	global float *src = one;
	global float *dst = two;
	global float *tmp;
	
	Particle p;
	if(pos < work_size)
		p = loadParticle(pos,src);
	
	for(s = 0; s < 200; ++s)
	{
		barrier(CLK_GLOBAL_MEM_FENCE);
		
		if(pos >= work_size)
			continue;
		
		float3 acc = (float3)(0.0);
		float3 frc;
		/* We use Lennard-Jones potential */
		for(i = 0; i < work_size; ++i)
		{
			if(i == pos) 
				continue;
			Particle p2 = loadParticle(i, src);
			float3 r = p2.pos - p.pos;
			float l2 = dot(r,r)/(rm*rm);
			if(l2 < 0.6)
				continue;
			float l4 = l2*l2;
			float l6 = l2*l4;
			float l8 = l4*l4;
			frc = r*in*12.0*(1.0 - 1.0/l6)/(l8*rm*rm);
			acc += frc*(1.0 - em*dot(frc, p.vel - p2.vel));
		}
		
		/* Boundaries */
		frc = el*convert_float3(isgreater(fabs(p.pos), (float3)(1.0)))*(fabs(p.pos) - (float3)(1.0))*sign(p.pos);
		acc += frc*(1.0 - em*dot(frc, p.vel));
		
		p.vel += dt*acc;
		float spd = length(p.vel);
		if(spd > ms)
			p.vel *= ms/spd;
		p.pos += dt*p.vel;
		
		storeParticle(&p,pos,dst);
		
		tmp = src;
		src = dst;
		dst = tmp;
	}
}
Exemplo n.º 2
0
void CocosEditor::createAction()
{
	newProjAct = new QAction(QIcon(":/images/new.png"), tr("&New project"), this);
	newProjAct->setShortcuts(QKeySequence::New);
	newProjAct->setStatusTip(tr("Create a new file"));
	connect(newProjAct, SIGNAL(triggered()), this, SLOT(newProject()));
	 


	//! [19]
	loadModelAct = new QAction(QIcon(":/images/open.png"), tr("load &Model..."), this);
	loadModelAct->setStatusTip(tr("Open an existing file"));
	connect(loadModelAct, SIGNAL(triggered()), this, SLOT(loadModel()));
	//! [18] //! [19]

	saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save project"), this);
	saveAct->setShortcuts(QKeySequence::Save);
	saveAct->setStatusTip(tr("Save the document to disk"));
	connect(saveAct, SIGNAL(triggered()), this, SLOT(saveProject()));
	saveAsAct = new QAction(tr("Save &As..."), this);
	saveAsAct->setShortcuts(QKeySequence::SaveAs);
	saveAsAct->setStatusTip(tr("Save the document under a new name"));
	connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));


	undoAct = new QAction(QIcon(":/images/undo.png"), tr("&undo"),this);
	undoAct->setShortcut(QKeySequence::Undo);
	//connect(undoAct, SIGNAL(triggered()), UIDoucument::getInstance(), SLOT(undo()));

	redoAct = new QAction(QIcon(":/images/redo.png"), tr("&redo"), this);
	redoAct->setShortcut(QKeySequence::Redo);
	//connect(redoAct, SIGNAL(triggered()), UIDoucument::getInstance(), SLOT(redo()));

	restoreFromBak = new QAction(QIcon(":/images/bak.png"), tr("&restore"), this);
	restoreFromBak->setShortcut(QKeySequence::Replace);
	//connect(restoreFromBak, SIGNAL(triggered()), UIDoucument::getInstance(), SLOT(resetAnimationFromBackFile()));

	//! [20]
	exitAct = new QAction(tr("E&xit"), this);
	exitAct->setShortcuts(QKeySequence::Quit);
	//! [20]
	exitAct->setStatusTip(tr("Exit the application"));
	connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

	openProjAct = new QAction(tr("&Open project"), this);
	openProjAct->setShortcuts(QKeySequence::Open);
	connect(openProjAct, SIGNAL(triggered()), this, SLOT(openProject()));

	loadParticleAct = new QAction(tr("load &Particle"),this);
	connect(loadParticleAct, SIGNAL(triggered()), this, SLOT(loadParticle()));

	//! [21]

// 	aboutAct = new QAction(tr("&About"), this);
// 	aboutAct->setStatusTip(tr("Show the application's About box"));
// 	connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

	//! [22]
	

	aboutQtAct = new QAction(tr("About &Qt"), this);
	aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
	connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
	//! [22]

	//! [23]

}