예제 #1
0
 void System::addBall(int nn, float4 center, float radius, bool scaled, float4 color, float mass)
 {
     float scale = 1.0f;
     vector<float4> sphere = addSphere(nn, center, radius, spacing, scale);
     float4 velo(0, 0, 0, 0);
     pushParticles(sphere,velo,color, mass);
 }
예제 #2
0
PhysicsWidget::PhysicsWidget() 
	: QWidget(0)
{

	physicsLbl = new QLabel("Physics:");
	physicsLbl->setFixedHeight(28);
	addBoxBtn = new QPushButton("Add Box");
	addSphereBtn = new QPushButton("Add Sphere");
	addCylinderBtn = new QPushButton("Add Cylinder");

	QVBoxLayout *mainLayout = new QVBoxLayout;

	mainLayout->addWidget(physicsLbl);
	mainLayout->addWidget(addBoxBtn);
	mainLayout->addWidget(addSphereBtn);
	mainLayout->addWidget(addCylinderBtn);

	setLayout(mainLayout);
	layout()->setContentsMargins(5,0,0,0);

	connect(addBoxBtn, SIGNAL(clicked()),this, SLOT(addBox()));
	connect(addSphereBtn, SIGNAL(clicked()),this, SLOT(addSphere()));
	connect(addCylinderBtn, SIGNAL(clicked()),this, SLOT(addCylinder()));

	setFixedHeight(sizeHint().height());
	setFixedWidth(150);
}
예제 #3
0
파일: motion.cpp 프로젝트: Ezio47/OSGEarth
Motion::Motion(GraphicsView* view, QWidget* parent)
	: m_pOSGView(view), QWidget(parent)
{
	ui.setupUi(this);

	addSphere();

	connect(ui.radioButton, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_2, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_3, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_4, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_5, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_6, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_7, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_8, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_9, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_10, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_11, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_12, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_13, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_14, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_15, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_16, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_17, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_18, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_19, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_20, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_21, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_22, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_23, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_24, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_25, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_26, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
	connect(ui.radioButton_27, SIGNAL(pressed()), this, SLOT(slotRadioChanged()));
}
bool SceneParser::addElement(struct basicxmlnode * elementNode, Scene * scene){
	if (!elementNode) {
		std::cout << "SceneParser::addElement: empty element node \n";
		return false;
	}

	// find out element type
	if (std::string(elementNode->tag) == "Plane") {
		return addPlane(elementNode, scene);
	}
  else if (std::string(elementNode->tag) == "CirclePlane") {
		return addCirclePlane(elementNode, scene);
	}
	else if (std::string(elementNode->tag) == "Sphere") {
		return addSphere(elementNode, scene);
	}
	else if (std::string(elementNode->tag) == "Triangle") {
		return addTriangle(elementNode, scene);
	}
	else if (std::string(elementNode->tag) == "Quadric") {
		return addQuadric(elementNode, scene);
	}
	else if (std::string(elementNode->tag) == "Torus") {
		return addTorus(elementNode, scene);
	}
	else if (std::string(elementNode->tag) == "TriangleMesh") {
		return addTriangleMesh(elementNode, scene);
	}
	else {
		std::cout << "SceneParser::addElement: do not know how to generate \"" << elementNode->tag << "\"\n";
		return false;
	}
}
예제 #5
0
void Clouds::addCloud(int numberOfSpheres)
{
	glm::vec3 offset(0);
	for (size_t i = 0; i < numberOfSpheres; i++)
	{
		addSphere(offset);
	}
}
예제 #6
0
 void createBulge(Vec3f nucleusP){
   bulgeScale = Vec3f(0.035, 0.035, 0.035);
   bulgePosition = (ending - nucleusP) * 0.6f + nucleusP;
   mesh.primitive(Graphics::TRIANGLES); 
   addSphere(bulgeMesh);
   for (int i = 0; i < bulgeMesh.vertices().size(); i++){
     bulgeMesh.color(Color(HSV(0.7, 0.5, 1.0), 0.6));
   }
   bulgeMesh.generateNormals();
 }
예제 #7
0
void PovrayMaker::addRadial(double r, double phi,double theta, double c)
{
	double x1=r*cos(phi)*sin(theta);
	double y1=r*sin(phi)*sin(theta);
	double z1=r*cos(theta);
//	addCone(0,0,0,0,x1, y1, z1, scale*0.025, c);
	addSphere(x1, y1, z1, scale*0.075, c);

	checkBorder(x1,y1,z1);
}
예제 #8
0
int PhysicsWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: addBox(); break;
        case 1: addSphere(); break;
        case 2: addCylinder(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
예제 #9
0
파일: NGLScene.cpp 프로젝트: NCCA/NGL6Demos
void NGLScene::keyPressEvent(QKeyEvent *_event)
{
  // this method is called every time the main window recives a key event.
  // we then switch on the key value and set the camera in the NGLScene
  switch (_event->key())
  {
  // escape key to quite
  case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break;
  // turn on wirframe rendering
  case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break;
  // turn off wire frame
  case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break;
  // show full screen
  case Qt::Key_F : showFullScreen(); break;
  // show windowed
  case Qt::Key_N : showNormal(); break;
  case Qt::Key_Space : m_car->reset(); break;
  case Qt::Key_X : stepAnimation(); break;
  case Qt::Key_1 : addCube(); break;
  case Qt::Key_2 : addSphere(); break;
  case Qt::Key_3 : addCapsule(); break;
  case Qt::Key_4 : addCylinder(); break;
  case Qt::Key_5 : addCone(); break;
  case Qt::Key_6 : addMesh(TEAPOT); break;
  case Qt::Key_7 : addMesh(APPLE); break;
/*  case Qt::Key_Left : m_physics->addImpulse(ngl::Vec3(-5,0.0f,0.0f)); break;
  case Qt::Key_Right : m_physics->addImpulse(ngl::Vec3(5.0f,0.0f,0.0f)); break;
  case Qt::Key_Up : m_physics->addImpulse(ngl::Vec3(0.0f,5.0f,0.0f)); break;
  case Qt::Key_Down : m_physics->addImpulse(ngl::Vec3(0.0f,-5.0f,0.0f)); break;
*/
  case Qt::Key_Left : m_car->left(); break;
  case Qt::Key_Right : m_car->right(); break;
  case Qt::Key_Up : m_car->accelerate(); break;
  case Qt::Key_Down : m_car->stop(); break;


  case Qt::Key_B : toggleBBox(); break;
  case Qt::Key_R : toggleRandomPlace(); break;
  case Qt::Key_0 : resetSim();  break;

  default : break;
  }
  // finally update the GLWindow and re-draw
  //if (isExposed())
    renderNow();
}
예제 #10
0
void VoxelField::setSpheres( float phase )
{
	setAllValues( -0.5f );
	float x = 0.3 * getSizeX() * sin(phase*0.1) + 0.5 * getSizeX();
	float y = 0.3 * getSizeY() * cos(phase*0.2) + 0.5 * getSizeY();
	float z = 0.3 * getSizeZ() * sin(1+phase*0.15) + 0.5 * getSizeZ();
	float rad = getSizeX() / 3;
	addSphere( x, y, z, rad );
	addSphere( y, z, x, rad );
	addSphere( z, x, y, rad );

	addSphere( z, y, x, rad );
	addSphere( y, x, z, rad );
	addSphere( x, z, y, rad );
}
예제 #11
0
void idle(void)
{
    if ((idleCounter++ > idleDelay) && (demoMode==false))
    {
        demoMode = true;
        printf("Entering demo mode\n");
    }

    if (demoMode)
    {
        camera_rot[1] += 0.1f;

        if (demoCounter++ > 1000)
        {
            ballr = 10 + (rand() % 10);
            addSphere();
            demoCounter = 0;
        }
    }

    glutPostRedisplay();
}
예제 #12
0
Renderer::Renderer(CubemapSource* cubemapSource)
    :
    al::OmniApp("AlloPlayer", false, 2048), resizeCtx(nullptr), cubemapSource(cubemapSource),
    cubemap(nullptr), newCubemap(false)
{
    nav().smooth(0.8);
    
    // set up cube
    cube.color(1,1,1,1);
    cube.primitive(al::Graphics::TRIANGLES);
    addCube(cube);
    for (int i = 0; i < cube.vertices().size(); ++i) {
        float f = (float)i / cube.vertices().size();
        cube.color(al::Color(al::HSV(f, 1 - f, 1), 1));
    }
    cube.generateNormals();
    
    // set up sphere
    sphere.primitive(al::Graphics::TRIANGLES);
    addSphere(sphere, 1.0, 32, 32);
    for (int i = 0; i < sphere.vertices().size(); ++i) {
        float f = (float)i / sphere.vertices().size();
        sphere.color(al::Color(al::HSV(f, 1 - f, 1), 1));
    }
    sphere.generateNormals();
    
    // set up light
    light.ambient(al::Color(0.4, 0.4, 0.4, 1.0));
    light.pos(5, 5, 5);
    
    
    
    std::function<void (CubemapSource*, StereoCubemap*)> callback = boost::bind(&Renderer::onNextCubemap,
                                                                                this,
                                                                                _1,
                                                                                _2);
    cubemapSource->setOnNextCubemap(callback);
}
예제 #13
0
// Helper function to loop through different modes
//*****************************************************************************
void ResetSim(int iOption)
{
    if((iOption < 1) || (iOption > 4))return;
    switch (iOption)
    {
        case 1:
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;
        case 2:
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;
        case 3:
            addSphere();
            break;
        case 4:
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = fShootVelocity;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr * 2.0f);
            }
            break;
    }
}
예제 #14
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key)
    {
        case ' ':
            bPause = !bPause;
            break;

        case 13:
            psystem->update(timestep);

            if (renderer)
            {
                renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
            }

            break;

        case '\033':
        case 'q':
            // cudaDeviceReset causes the driver to clean up all state. While
            // not mandatory in normal operation, it is good practice.  It is also
            // needed to ensure correct operation when the application is being
            // profiled. Calling cudaDeviceReset causes all profile data to be
            // flushed before the application exits
            cudaDeviceReset();
            exit(EXIT_SUCCESS);
            break;

        case 'v':
            mode = M_VIEW;
            break;

        case 'm':
            mode = M_MOVE;
            break;

        case 'p':
            displayMode = (ParticleRenderer::DisplayMode)
                          ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;

        case 'd':
            psystem->dumpGrid();
            break;

        case 'u':
            psystem->dumpParticles(0, numParticles-1);
            break;

        case 'r':
            displayEnabled = !displayEnabled;
            break;

        case '1':
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;

        case '2':
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;

        case '3':
            addSphere();
            break;

        case '4':
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = -0.05f;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
            }
            break;

        case 'w':
            wireframe = !wireframe;
            break;

        case 'h':
            displaySliders = !displaySliders;
            break;
    }

    demoMode = false;
    idleCounter = 0;
    glutPostRedisplay();
}
예제 #15
0
void wiBULLET::registerObject(Object* object){
	if(object->rigidBody && rigidBodyPhysicsEnabled){
		//XMVECTOR s,r,t;
		//XMMatrixDecompose(&s,&r,&t,XMLoadFloat4x4(&object->world));
		XMFLOAT3 S,T;
		XMFLOAT4 R;
		//XMStoreFloat3(&S,s);
		//XMStoreFloat4(&R,r);
		//XMStoreFloat3(&T,t);
		object->applyTransform();
		object->attachTo(object->GetRoot());

		S = object->scale;
		T = object->translation;
		R = object->rotation;

		if(!object->collisionShape.compare("BOX")){
			addBox(
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("SPHERE")){
			addSphere(
				S.x,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("CAPSULE")){
			addCapsule(
				S.x,S.y,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("CONVEX_HULL")){
			addConvexHull(
				object->mesh->vertices,
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("MESH")){
			addTriangleMesh(
				object->mesh->vertices,object->mesh->indices,
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
	}

	if(object->mesh->softBody && softBodyPhysicsEnabled){
		XMFLOAT3 s,t;
		XMFLOAT4 r;
		if(object->mesh->hasArmature()){
			s=object->mesh->armature->scale;
			r=object->mesh->armature->rotation;
			t=object->mesh->armature->translation;
		}
		else{
			s=object->scale;
			r=object->rotation;
			t=object->translation;
		}
		addSoftBodyTriangleMesh(
			object->mesh
			,s,r,t
			,object->mass,object->mesh->friction,object->restitution,object->damping
		);
		object->physicsObjectI=++registeredObjects;
	}
}
예제 #16
0
void CollisionMap::compileSphereMap(float nominal_rad)
{
	vector < Mesh * >::iterator meshes_i;
	vector < Face * >::iterator faces_i;
	vector < XYZ * >::iterator points_i;
	
	cvrIndex faceNum = 0;
//	unsigned int numDivs;
	bool bb_init = false;

	Logger::log("Compiling sphere map for collision mesh nominal radius %f\n\n",nominal_rad);
	
	collision_box bbox;
	bbox.xmin = bbox.xmax = bbox.ymin = bbox.ymax = bbox.zmin = bbox.zmax = 0;
	
	for (meshes_i = meshes.begin(); meshes_i != meshes.end(); meshes_i++)
	{
		for (faces_i = (*meshes_i)->faces.begin(); faces_i != (*meshes_i)->faces.end(); faces_i++)
		{
			// Find center of face (point average, triangles only)
			Vector centerpoint = Vector(0,0,0);
			
			if ((*faces_i)->points.size() == 0) continue;
			
			for (points_i = (*faces_i)->points.begin(); points_i != (*faces_i)->points.end(); points_i++)
			{
				if (!bb_init)
				{
					bbox.xmin = (**points_i).x;
					bbox.xmax = (**points_i).x;
					bbox.ymin = (**points_i).y;
					bbox.ymax = (**points_i).y;
					bbox.zmin = (**points_i).z;
					bbox.zmax = (**points_i).z;
					bb_init = true;
				}
				centerpoint += (XYZ)(**points_i);
				
				// calculate bounding regions
				bbox.xmin = (bbox.xmin < (**points_i).x) ? bbox.xmin : (**points_i).x;
				bbox.ymin = (bbox.ymin < (**points_i).y) ? bbox.ymin : (**points_i).y;
				bbox.zmin = (bbox.zmin < (**points_i).z) ? bbox.zmin : (**points_i).z;

				bbox.xmax = (bbox.xmax > (**points_i).x) ? bbox.xmax : (**points_i).x;
				bbox.ymax = (bbox.ymax > (**points_i).y) ? bbox.ymax : (**points_i).y;
				bbox.zmax = (bbox.zmax > (**points_i).z) ? bbox.zmax : (**points_i).z;
			}
			
			centerpoint /= (cvrFloat)(*faces_i)->points.size();
			
			// face bounding sphere radius
			Vector rad;
			
			rad=XYZ(0,0,0);
			
			// Determine maximum extent (radius) of any rotated position of this face from it's centerpoint
			for (points_i = (*faces_i)->points.begin(); points_i != (*faces_i)->points.end(); points_i++)
			{
				Vector dist;
				
				dist = *(*points_i);
				dist -= centerpoint;

				if (dist.magnitude() > rad.magnitude()) rad = dist;
			}
			
			
			// check for thin triangles that aren't going to have enough surface area
//			double rfail = 0;
//			Vector rtest[3];
//			
//			rtest[0] = *(*faces_i).points[0];
//			rtest[1] = *(*faces_i).points[1];
//			rtest[2] = *(*faces_i).points[2];
//
//			rtest[0] -= *(*faces_i).points[2];
//			rtest[1] -= *(*faces_i).points[0];
//			rtest[2] -= *(*faces_i).points[1];
//			
//			if (rtest[0].magnitude() < nominal_rad) rfail = rtest[0].magnitude();
//			if (rtest[1].magnitude() < nominal_rad) rfail = rtest[1].magnitude();
//			if (rtest[2].magnitude() < nominal_rad) rfail = rtest[2].magnitude();
			
			// if the face is smaller than the nominal rad just add it as-is
			if (rad.magnitude() <= nominal_rad*2.0)
			{
				addSphere(centerpoint,rad.magnitude(),faceNum); //rad.magnitude()
				continue;
			};

						
//			addSphere(centerpoint,rad.magnitude(),faceNum); //rad.magnitude()
//			addSphere(*(*faces_i).points[0],nominal_rad,faceNum); //rad.magnitude()
//			addSphere(*(*faces_i).points[1],nominal_rad,faceNum); //rad.magnitude()
//			addSphere(*(*faces_i).points[2],nominal_rad,faceNum); //rad.magnitude()
			
			
			// create a 'grid' on the current face (two vectors on the plane 90 deg from each other)
			// and 'scatter' the spheres across the surface at the nominal radius within the surface range
			
			Vector norm;
			Vector lv,bv,cp,rp,gv[2];
			
			(*faces_i)->calcNormal(norm);
			norm.makeUnit();
			
			lv = centerpoint;
//			lv -= *(*faces_i).points[0];
			
			rp = *(*faces_i)->points[1];
			rp -= *(*faces_i)->points[0];
			rp /= 2.0f;
			rp += *(*faces_i)->points[0];
			lv -= rp;
			
			gv[0] = lv;
			gv[1] = Vector::crossProduct(gv[0],norm);

			gv[0].makeUnit();
			gv[1].makeUnit();

			float i,j;
			float r;
			
			r = rad.magnitude();
						
			for (i = -r; i <= r; i+= nominal_rad)
			{	
				for (j = -r; j <= r; j+= nominal_rad)
				{
					cp = centerpoint;
					
					lv = gv[0];
					lv *= i;

					bv = gv[1];
					bv *= j;
					
					cp += lv;
					cp += bv;
					
					// check if this sphere's centerpoint falls within the face, add it if it does
					if ((*faces_i)->onTriangle(cp)) addSphere(cp,nominal_rad,faceNum);
				}
				
			}
			

			faceNum++;
		}
	}
	
	Logger::log("Generated bounding box.\n");

//	collision_box *bbox_ptr = new collision_box;
	
//	*bbox_ptr = bbox;
	
//	bboxes.push_back(bbox_ptr);
	
	
	collision_sphere *tmp;
	unsigned int currentSphereSet = activeSphereSet;
	unsigned int t;

	activeSphereSet++;

	if (spheres.size()-1 < activeSphereSet)
	{
	 vector<collision_sphere*> *tmpVect = new vector<collision_sphere*>;
	 spheres.push_back(tmpVect);
	}

	
	unsigned int xdivs, ydivs, zdivs;
	cvrFloat block_size;
	
	block_size=1.0f;
	
	xdivs = (int)floor(fabs(bbox.xmax - bbox.xmin)/block_size);
	ydivs = (int)floor(fabs(bbox.ymax - bbox.ymin)/block_size);
	zdivs = (int)floor(fabs(bbox.zmax - bbox.zmin)/block_size);
	
	if (xdivs < 1) xdivs = 1;
	if (ydivs < 1) ydivs = 1;
	if (zdivs < 1) zdivs = 1;

	cvrIndex i,j,k,l;

	map<int, map<int, map<int, vector<int>, ltulong>, ltulong>, ltulong> quant_map;

	cvrFloat xs,ys,zs;
	
	xs = (fabs(bbox.xmax - bbox.xmin) / ((cvrFloat) xdivs) );
	ys = (fabs(bbox.ymax - bbox.ymin) / ((cvrFloat) ydivs) );
	zs = (fabs(bbox.zmax - bbox.zmin) / ((cvrFloat) zdivs) );
	
	for (t = 0; t < spheres[currentSphereSet]->size(); t++)
	{
		tmp = (*spheres[currentSphereSet])[t];		
		
//		if (tmp->radius > 2.0*sqrt(xs*xs + ys*ys + zs*zs)) 
//		{
//			(*spheres[activeSphereSet]).push_back(tmp);
//			
//			continue;
//		}
		
		i = (unsigned int)floor((tmp->center.x-bbox.xmin) / xs);
		j = (unsigned int)floor((tmp->center.y-bbox.ymin) / ys);
		k = (unsigned int)floor((tmp->center.z-bbox.zmin) / zs);
		
		i = (i < 0)?0:i;
		j = (j < 0)?0:j;
		k = (k < 0)?0:k;

		i = (i > xdivs-1)?(xdivs-1):i;
		j = (j > ydivs-1)?(ydivs-1):j;
		k = (k > zdivs-1)?(zdivs-1):k;

//		if (i < 0 | j < 0 | k < 0 | i > STEP_DIVS-1 | j > STEP_DIVS-1 | k > STEP_DIVS-1) 
//		{ 
//			(*spheres[activeSphereSet]).push_back(tmp);
//	
//			printf("skipped? %d,%d,%d xyz: %f,%f,%f\n",i,j,k,tmp->center.x,tmp->center.y,tmp->center.z); 
//			
//			continue; 
//		};

//		printf("Sorted point into sector i,j,k: %d, %d, %d\n",i,j,k);
		
		quant_map[i][j][k].push_back(t);
	}
	
	for (i = 0; i < xdivs; i++)
	{
		for (j = 0; j < ydivs; j++)
		{
			for (k = 0; k < zdivs; k++)
			{
				unsigned int numPts = quant_map[i][j][k].size();
				
				if (numPts)
				{
					Vector quant_center;
					Vector sect_center;
					Vector half_sect;
					
					Vector quant_rad;
					cvrFloat dquant_rad;
					cvrFloat max_rad;
					
					collision_box *bb_sect;
					

					quant_center = XYZ(0,0,0);
					sect_center = XYZ(bbox.xmin+((cvrFloat)i)*xs,bbox.ymin+((cvrFloat)j)*ys,bbox.zmin+((cvrFloat)k)*zs);

					bb_sect = new collision_box;
					
					bb_sect->xmin = sect_center.x;
					bb_sect->ymin = sect_center.y;
					bb_sect->zmin = sect_center.z;

					bb_sect->xmax = sect_center.x+xs;
					bb_sect->ymax = sect_center.y+ys;
					bb_sect->zmax = sect_center.z+zs;
					
					bboxes.push_back(bb_sect);

					half_sect = XYZ(xs/2.0f,ys/2.0f,zs/2.0f);
					sect_center += half_sect;
					
					max_rad = 0.0f;


					for (l = 0; l < numPts; l++)
					{
						tmp = (*spheres[currentSphereSet])[(quant_map[i][j][k])[l]];
						quant_center += tmp->center;
					}

					quant_center /= (cvrFloat)numPts;
					
					//printf("Sector i,j,k: %d, %d, %d\n",i,j,k);
					for (l = 0; l < numPts; l++)
					{
						tmp = (*spheres[currentSphereSet])[(quant_map[i][j][k])[l]];
						
					//	printf("Found sphere: %d\n",(*quant_map[i][j][k])[l]);

						quant_rad = quant_center;
						quant_rad -= tmp->center;
						
						dquant_rad = quant_rad.magnitude();
						
						if (dquant_rad > max_rad) max_rad = dquant_rad;
					}
					
										
					addSphere(quant_center,max_rad,tmp->face);
				}
			}
		}
	}
	
	
	if (spheres.size()) 
	{
		Logger::log("Generated %d spheres.\n",(*spheres[activeSphereSet]).size());
	}
	else
	{
		Logger::log("No spheres generated.");
	}
//	processSpheres(nominal_rad);
};
예제 #17
0
bool SphereLoader::load(const char *filename)
{
    std::string fname = filename;
    if (!sofa::helper::system::DataRepository.findFile(fname)) return false;

	char cmd[64];
	FILE* file;
	
	static const char* SPH_FORMAT = "sph 1.0";
	
	if ((file = fopen(fname.c_str(), "r")) == NULL)
	{
		std::cout << "ERROR: cannot read file '" << filename << "'. Exiting..." << std::endl;
		return false;
	}
// 	std::cout << "Loading model'" << filename << "'" << std::endl;
	
	int totalNumSpheres=0;
	
	// Check first line 
	if (fgets(cmd, 7, file) == NULL || !strcmp(cmd,SPH_FORMAT))
	{
		fclose(file);
		return false;
	}
	skipToEOL(file);

	while (fscanf(file, "%s", cmd) != EOF)
	{
		if (!strcmp(cmd,"nums"))
		{
		  if (fscanf(file, "%d", &totalNumSpheres) == EOF)
		    std::cerr << "Error: SphereLoader: fscanf function has encountered an error." << std::endl;
			setNumSpheres(totalNumSpheres);
		}
		else if (!strcmp(cmd,"sphe"))
		{
			int index;
			double cx=0,cy=0,cz=0,r=1;
			if (fscanf(file, "%d %lf %lf %lf %lf\n",
				   &index, &cx, &cy, &cz, &r) == EOF)
			  std::cerr << "Error: SphereLoader: fscanf function has encountered an error." << std::endl;
			addSphere((SReal)cx,(SReal)cy,(SReal)cz,(SReal)r);
			++totalNumSpheres;
		}
		else if (cmd[0]=='#')
		{
			skipToEOL(file);
		}
		else			// it's an unknown keyword
		{
			printf("%s: Unknown Sphere keyword: %s\n", filename, cmd);
			skipToEOL(file);
		}
	}
// 	printf("Model contains %d spheres\n", totalNumSpheres);

	(void) fclose(file);
	
	return true;
}
예제 #18
0
void CollisionMap::processSpheres(float nominal_rad)
{
	int sSet = activeSphereSet;
	unsigned int i,j;
	collision_sphere *tmp;


	bool bProcNeeded = false;

	for (i = 0; i < spheres[sSet]->size(); i++)
	{
		tmp = (*spheres[sSet])[i];

		if (tmp->radius > nominal_rad)
		{
			bProcNeeded = true;
			break;
		}
	}
	
	if (!bProcNeeded) return;


	activeSphereSet++;
	
	if (spheres.size()-1 < activeSphereSet)
	{
	 vector<collision_sphere*> *tmpVect = new vector<collision_sphere*>;
	 spheres.push_back(tmpVect);
	}
	
	
	for (i = 0; i < spheres[sSet]->size(); i++)
	{
		tmp = (*spheres[sSet])[i];

		if (tmp->radius > nominal_rad)
		{
			cvrFloat q_rad = tmp->radius/2.0f;
//			cvrFloat pdist;
			
			XYZ tmpPoint;
			
			XYZ subSphereOfs[15] = 
			{
				XYZ(0,0,0),
				XYZ(q_rad,0,0),
				XYZ(-q_rad,0,0),
				XYZ(0,q_rad,0),
				XYZ(0,-q_rad,0),
				XYZ(0,0,q_rad),
				XYZ(0,0,-q_rad),
				XYZ(-q_rad,-q_rad,-q_rad),
				XYZ(-q_rad,-q_rad,q_rad),
				XYZ(q_rad,-q_rad,-q_rad),
				XYZ(q_rad,-q_rad,q_rad),
				XYZ(-q_rad,q_rad,-q_rad),
				XYZ(-q_rad,q_rad,q_rad),
				XYZ(-q_rad,q_rad,-q_rad),
				XYZ(q_rad,q_rad,q_rad)
			};
			

			for (j = 0; j < 15; j++)
			{
				tmpPoint = tmp->center;
				tmpPoint += subSphereOfs[j];

				if (tmp->face >= 0)
				{
					float dist = meshes[0]->faces[tmp->face]->planeDistanceTo(tmpPoint);
					
					if (dist < q_rad && dist >= 0)
					{
						addSphere(tmpPoint,q_rad,tmp->face);
					}
					// else discard
				}

			}
		}
		else
		{
			(*spheres[activeSphereSet]).push_back(tmp);
		}

	}

	Logger::log("Generated %d sub spheres.\n",(*spheres[activeSphereSet]).size());

	processSpheres(nominal_rad);
}
예제 #19
0
    template <typename PointT> bool
PCLVisualizer::addSphere (const PointT &center, double radius, const std::string &id, int viewport)
{
  return (addSphere (center, radius, 0.5, 0.5, 0.5, id, viewport));
}
예제 #20
0
int main(int argc, char * argv[] ) {
  world theworld = worldMalloc();
  double angle1, angle2;
  double radius1, radius2;
  double s,c,s1,s2,c1,c2,w,h,x,y,z,pct,r,g,b;
  const double pi = 3.14159265;
  int nspheres = 128;
  int nloops = 3;
  int nspirals = 2;
  double floops = (double)nloops + 1.0/(double)nspirals;
  int i;
  sphere mySphere;

  // tilt ring by pi/6:
  s = sin(pi/6.0);
  c = cos(pi/6.0);

  // build world:
  assign(theworld->backgroundColor, 0.5, 0.75, 1.0);
  assign(theworld->eye, 0.0, 0.0, 150.0);
  assign(theworld->light, 1.0, 1.0, 1.0);
  normalize(theworld->light);
  
  // make ring:
  radius1 = 500.0;
  radius2 = 100.0;
  for (i = 0; i < nspheres; i++) {
    angle1 = 2.0*pi*(double)nspirals*(double)i/(double)nspheres;
    angle2 = floops * angle1;
    s1 = sin(angle1);
    s2 = sin(angle2);
    c1 = cos(angle1);
    c2 = cos(angle2);
    w = radius1 + c2*radius2;
    h = s2*radius2;
    x = c1*w;
    y = h;
    z = s1*w;
    pct = 6.0*(double)i/(double)nspheres;
    if ((0.0 <= pct) && (pct < 1.0)) {
      r =  1.0; g = pct; b = 0.0;
    } else if ((1.0 <= pct && pct < 2.0)) {
      pct = pct - 1.0;
      r =  1.0-pct; g = 1.0; b = 0.0;
    } else if ((2.0 <= pct) && (pct < 3.0)) {
      pct = pct - 2.0;
      r =  0.0; g = 1.0; b = pct;
    } else if ((3.0 <= pct) && (pct < 4.0)) {
      pct = pct - 3.0;
      r =  0.0; g = 1.0-pct; b = 1.0;
    } else if ((4.0 <= pct) && (pct < 5.0)) {
      pct = pct - 4.0;
      r =  pct; g = 0.0; b = 1.0;
    } else {
      pct = pct - 5.0;
      r =  1.0; g = 0.0; b = 1.0-pct;
    }
    
    mySphere = makeSphere(x, c*y-s*z, s*y+c*z - 2000.0,
			  60.0,
			  r, g, b);
    addSphere(theworld, mySphere);
  }

  tracer("images/ring.ppm", 6, theworld);
  return 0;
}
예제 #21
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key)
    {
        case ' ':
            bPause = !bPause;
            break;

        case 13:
            psystem->update(timestep);

            if (renderer)
            {
                renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
            }

            break;

        case '\033':
        case 'q':
            #if defined(__APPLE__) || defined(MACOSX)
                exit(EXIT_SUCCESS);
            #else
                glutDestroyWindow(glutGetWindow());
                return;
            #endif
        case 'v':
            mode = M_VIEW;
            break;

        case 'm':
            mode = M_MOVE;
            break;

        case 'p':
            displayMode = (ParticleRenderer::DisplayMode)
                          ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;

        case 'd':
            psystem->dumpGrid();
            break;

        case 'u':
            psystem->dumpParticles(0, numParticles-1);
            break;

        case 'r':
            displayEnabled = !displayEnabled;
            break;

        case '1':
            psystem->reset(ParticleSystem::CONFIG_GRID);
            break;

        case '2':
            psystem->reset(ParticleSystem::CONFIG_RANDOM);
            break;

        case '3':
            addSphere();
            break;

        case '4':
            {
                // shoot ball from camera
                float pr = psystem->getParticleRadius();
                float vel[4], velw[4], pos[4], posw[4];
                vel[0] = 0.0f;
                vel[1] = 0.0f;
                vel[2] = -0.05f;
                vel[3] = 0.0f;
                ixform(vel, velw, modelView);

                pos[0] = 0.0f;
                pos[1] = 0.0f;
                pos[2] = -2.5f;
                pos[3] = 1.0;
                ixformPoint(pos, posw, modelView);
                posw[3] = 0.0f;

                psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
            }
            break;

        case 'w':
            wireframe = !wireframe;
            break;

        case 'h':
            displaySliders = !displaySliders;
            break;
    }

    demoMode = false;
    idleCounter = 0;
    glutPostRedisplay();
}
예제 #22
0
void PovrayMaker::addSphere(double *vec, double r, double c)
{
	addSphere(vec[0], vec[1],vec[2], r, c);
}