void PARTICLE::clearParameters() {
  _position = VEC3D();
  _velocity = VEC3D();
  _acceleration = VEC3D();
  _density = 0.0;
  _pressure = 0.0;


}
void kinematicConstraint::setCoordinates()
{
	spi = loc - (i ? i->getPosition() : VEC3D(0, 0, 0));
	spj = loc - (j ? j->getPosition() : VEC3D(0, 0, 0));
	spi = i ? i->toLocal(spi) : VEC3D(0, 0, 0);
	spj = j ? j->toLocal(spj) : VEC3D(0, 0, 0);
	switch (type){
	case REVOLUTE:
		nconst = 5;
		(i && j) ? maxnnz += 46 : maxnnz += 23;
		break;
	}
}
Exemple #3
0
bool vcylinder::define()
{
	glList = glGenLists(1);
	glNewList(glList, GL_COMPILE);
	glShadeModel(GL_FLAT);
	float angle = (float)(15 * (M_PI / 180));
	int iter = (int)(360 / 15);

	float h_len = length * 0.5f;
	VEC3F to = VEC3F(pb[0] - origin[0], pb[1] - origin[1], pb[2] - origin[2]);
	VEC3F u = to / to.length();
	double th = M_PI * 0.5;
	double ap = acos(u.z);
	double xi = asin(-u.y);

	if (ap > M_PI)
		ap = ap - M_PI;

	ang[0] = 180 * xi / M_PI;
	ang[1] = 180 * th / M_PI;
	ang[2] = 180 * ap / M_PI;

	EPD ep;
	ep.setFromEuler(xi, th, ap);

	glPushMatrix();
	glBegin(GL_TRIANGLE_FAN);
	{
		VEC3D p = VEC3D( 0.f, length * 0.5f, 0.f );
		glColor3f(0.0f, 0.f, 1.f);
	//	VEC3F p2_ = ep.A() * VEC3F(p2[0], p2[1], p2[2]);
		//glVertex3f(p2[0], p2[1], p2[2]);
		//p = ep.A() * p;
		glVertex3f(p.x, p.y, p.z);
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			glColor3f(i % 2, 0.f, i % 2 + 1.f);
			VEC3D q(sin(rad)*topRadius, length * 0.5, cos(rad) * topRadius);
			//q = ep.A() * q;
			glVertex3f(/*origin[0] + */(float)q.x, /*origin[1] + */(float)q.y, /*origin[2] + */(float)q.z);	
		}
	}
	glEnd();
	glPopMatrix();
	glBegin(GL_TRIANGLE_FAN);
	{
		VEC3D p = VEC3D(0.f, -length * 0.5f, 0.f);
		//float p[3] = { 0.f, -length * 0.5f, 0.f };
		glColor3f(0.f, 0.f, 1.f);
		//glVertex3f(p1[0], p1[1], p1[2]);
		//p = ep.A() * p;
		glVertex3f(p.x, p.y, p.z);
		//glVertex3f(p[0], p[1], p[2]);
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			glColor3f(i % 2, 0.0f, i % 2 + 1.0f);
			VEC3D q(sin(-rad)*baseRadius, -length * 0.5, cos(-rad) * baseRadius);
			//q = ep.A() * q;
			glVertex3f(/*origin[0] + */q.x, /*origin[1] + */q.y, /*origin[2] +*/ q.z);
		}
	}
	glEnd();
	glBegin(GL_QUAD_STRIP);
	{
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			VEC3D q1(sin(rad) * topRadius, length * 0.5, cos(rad) * topRadius);
			VEC3D q2(sin(rad) * baseRadius, -length * 0.5, cos(rad) * baseRadius);
			//q1 = ep.A() * q1;
			//q2 = ep.A() * q2;
			glVertex3f(/*origin[0] + */q2.x, /*origin[1] + */q2.y, /*origin[2] + */q2.z);
			glVertex3f(/*origin[0] + */q1.x, /*origin[1] + */q1.y, /*origin[2] + */q1.z);
		}
	}
	glEnd();
	glEndList();


	return true;
}
bool fluid_detection::initGrid()
{
	cells = 0;
// 	VEC3D fMax = sph->particle(0)->position();
// 	VEC3D fMin = fMax;
// 	if (sph->getPeriodicDirection() == PERI_X)
// 	{
// 		for (unsigned int i = 0; i < sph->nParticleByType(FLUID); i++)
// 		{
// 			VEC3D p = sph->particle(i)->position();
// 			if (fMax <= p)
// 				fMax = p;
// 			if (fMin >= p)
// 				fMin = p;
// 		}		
// 	}
	gMin = gMin - VEC3D(gcSize);
	gMax = gMax + VEC3D(gcSize);
	gSize = gMax - gMin;

	gcCount.x = static_cast<int>(ceil(gSize.x / gcSize));
	gcCount.y = static_cast<int>(ceil(gSize.y / gcSize));
	cells = gcCount.x * gcCount.y;
	if (sph->dimension() == DIM3){
		gcCount.z = static_cast<int>(ceil(gSize.z / gcSize));
		cells *= gcCount.z;
	}

	if (!gcCount.x || !gcCount.y){
		std::cout << "You need to correctly set simulation boundaries" << std::endl;
		return false;
	}

	cellCount_1 = gcCount - VEC3I(1);
	cSize_inv = 1.0 / gcSize;

	size_t np = sph->nParticle();
	if (sph->getPeriodicParticles())
	{
		np += sph->getPeriodicParticles()->nParticle();
	}
	hashes = new VEC2UI[np];
	cell_id = new size_t[np];		memset(cell_id, 0, sizeof(size_t)*np);
	cell_start = new size_t[cells];	memset(cell_start, 0, sizeof(size_t)*cells);

// 	if (sph->getPeriodicDirection() == PERI_X)
// 	{
// 		VEC3I _cmax = cellPos(fMax);
// 		peri_maxCI.x = _cmax.x;
// 		VEC3I _cmin = cellPos(fMin);
// 		peri_minCI.x = _cmin.x;
// 	}
	
// 	if (sph->Device() == GPU){
// 		checkCudaErrors(cudaMalloc((void**)&d_hashes, sizeof(int2) * np));
// 		checkCudaErrors(cudaMalloc((void**)&d_cell_id, sizeof(uint) * np));
// 		checkCudaErrors(cudaMalloc((void**)&d_cell_start, sizeof(uint) * cells));
// 	}

	return true;
}