Example #1
0
//  Define the geometry
void Init_Geometry(){

  // create a shpere wiht 64 longitudes and 64 latitudes
  // createSphere(8,4, 1, &vtx, &numVtx, &ind, &numInd);
  createSphere(64,32, 1, &vtx, &numVtx, &ind, &numInd);

  createSphere(64,32, 1, &vtx2, &numVtx2, &ind2, &numInd2);
  //createCylinder(64,100, 15, &vtx, &numVtx, &ind, &numInd);
  //createSurface(50,50, 20, 20, &vtx, &numVtx, &ind, &numInd);
  return;

}
Example #2
0
    template <typename PointT> bool
    PCLVisualizer::addSphere (const PointT &center, double radius, double r, double g, double b, const std::string &id, int viewport)
    {
      // Check to see if this ID entry already exists (has it been already added to the visualizer?)
      ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
      if (am_it != shape_actor_map_->end ())
      {
        PCL_WARN ("[addSphere] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
        return (false);
      }

      vtkSmartPointer<vtkDataSet> data = createSphere (center.getVector4fMap (), radius);

      // Create an Actor
      vtkSmartPointer<vtkLODActor> actor;
      createActorFromVTKDataSet (data, actor);
      actor->GetProperty ()->SetRepresentationToWireframe ();
  actor->GetProperty ()->SetInterpolationToGouraud ();
  actor->GetMapper ()->ScalarVisibilityOff ();
      actor->GetProperty ()->SetColor (r, g, b);
  addActorToRenderer (actor, viewport);

  // Save the pointer/ID pair to the global actor map
  (*shape_actor_map_)[id] = actor;
      return (true);
    }
/* called by the C++ code for initialization */
extern "C" void device_init (char* cfg)
{
  /* create scene */
  g_scene = rtcNewScene(g_device);
  rtcSetSceneFlags(g_scene,RTC_SCENE_FLAG_DYNAMIC | RTC_SCENE_FLAG_ROBUST);
  rtcSetSceneBuildQuality(g_scene,RTC_BUILD_QUALITY_LOW);

  /* create some triangulated spheres */
  for (int i=0; i<numSpheres; i++)
  {
    const float phi = i*2.0f*float(pi)/numSpheres;
    const float r = 2.0f*float(pi)/numSpheres;
    const Vec3fa p = 2.0f*Vec3fa(sin(phi),0.0f,-cos(phi));
    //RTCBuildQuality quality = i%3 == 0 ? RTC_BUILD_QUALITY_MEDIUM : i%3 == 1 ? RTC_BUILD_QUALITY_REFIT : RTC_BUILD_QUALITY_LOW;
    RTCBuildQuality quality = i%2 ? RTC_BUILD_QUALITY_REFIT : RTC_BUILD_QUALITY_LOW;
    //RTCBuildQuality quality = RTC_BUILD_QUALITY_REFIT;
    int id = createSphere(quality,p,r);
    position[id] = p;
    radius[id] = r;
    colors[id].x = (i%16+1)/17.0f;
    colors[id].y = (i%8+1)/9.0f;
    colors[id].z = (i%4+1)/5.0f;
  }

  /* add ground plane to scene */
  int id = addGroundPlane(g_scene);
  colors[id] = Vec3fa(1.0f,1.0f,1.0f);

  /* commit changes to scene */
  rtcCommitScene (g_scene);

  /* set start render mode */
  renderTile = renderTileStandard;
  key_pressed_handler = device_key_pressed_default;
}
Example #4
0
OpenGLWidget::OpenGLWidget(MainWindow* mainWindow)
    : QOpenGLWidget{mainWindow}
    , m_axisLegendScene{mainWindow->app()}
    , m_width{0}
    , m_height{0}
    , m_currentLocation{}
    , m_previousLocation{}
{
    this->setFocusPolicy(Qt::StrongFocus);

    m_contextMenu = new QMenu(this);

    QMenu* createMenu = m_contextMenu->addMenu("Create");
    createMenu->addAction(tr("Box"), this, SLOT(createBox()));
    createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder()));
    createMenu->addAction(tr("Cone"), this, SLOT(createCone()));
    createMenu->addAction(tr("Sphere"), this, SLOT(createSphere()));

    m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh()));

    QSurfaceFormat format = this->format();
    format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(32);
    format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);

    LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion);
    this->setFormat(format);
}
Example #5
0
void DeferredLight::rebuildGeometry(float radius)
{
	//Disable all 3 bits
	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_POINT);
	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_SPOTLIGHT);
	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_DIRECTIONAL);

	switch (mParentLight->getType())
	{
	case Ogre::Light::LT_DIRECTIONAL:
		createRectangle2D();
        ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_DIRECTIONAL);
		break;
	case Ogre::Light::LT_POINT:
		/// XXX some more intelligent expression for rings and segments
		createSphere(radius, 10, 10);
		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_POINT);
		break;
	case Ogre::Light::LT_SPOTLIGHT:
		Ogre::Real height = mParentLight->getAttenuationRange();
		Ogre::Radian coneRadiusAngle = mParentLight->getSpotlightOuterAngle() / 2;
        Ogre::Real rad = Ogre::Math::Tan(coneRadiusAngle) * height;
		createCone(rad, height, 20);
		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_SPOTLIGHT);
		break;
	}	
}
Example #6
0
Shape Shape::createShape(
	ShapeType type,
	float size /* = 1.0f */,
	float texturing /* = 2.0f */,
	int resolution /* = 16 */,
	float width /* = 0.0f */,
	float height /* = 0.0f */,
	float depth /* = 0.0f */)
{
	this->setSize(size);
	this->setResolution(resolution);

	switch (type)
	{
	case SPHERE:
		this->setVertices(createSphere(size, resolution, true));
		break;
	case PYRAMID:
		this->setVertices(createPyramid(size, texturing));
		break;
	case TETRAHEDRON:
		this->setVertices(createTetrahedron(size, texturing));
		break;
	case CUBOID:
		this->setVertices(createCuboid(size, width, height, depth, texturing));
		break;
	default:

		break;
	}

	this->setMesh(Mesh(this->m_vertices, this->m_vertices.size()));

	return *(this);
}
Example #7
0
void GeomUtils::createSphere(  const String& strName
                               , float radius
                               , int nRings, int nSegments
                               , bool bNormals
                               , bool bTexCoords)
{
    MeshPtr pSphere = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    SubMesh *pSphereVertex = pSphere->createSubMesh();
    pSphere->sharedVertexData = new VertexData();

    createSphere(pSphere->sharedVertexData, pSphereVertex->indexData
                 , radius
                 , nRings, nSegments
                 , bNormals // need normals
                 , bTexCoords // need texture co-ordinates
                );

    // Generate face list
    pSphereVertex->useSharedVertices = true;

    // the original code was missing this line:
    pSphere->_setBounds( AxisAlignedBox( Vector3(-radius, -radius, -radius), Vector3(radius, radius, radius) ), false );
    pSphere->_setBoundingSphereRadius(radius);
    // this line makes clear the mesh is loaded (avoids memory leaks)
    pSphere->load();
}
Example #8
0
void mousedrag(int x, int y) {
    if (reachObj != NULL) {
	mouseoldx = x; mouseoldy = y;
        createSphere(x, y);
    }
    glutPostRedisplay();
}
Example #9
0
/* called by the C++ code for initialization */
extern "C" void device_init (int8* cfg)
{
    /* initialize ray tracing core */
    rtcInit(cfg);

    /* create scene */
    g_scene = rtcNewScene(RTC_SCENE_DYNAMIC,RTC_INTERSECT1);

    /* create some triangulated spheres */
    for (int i=0; i<numSpheres; i++)
    {
        const float phi = i*2.0f*float(pi)/numSpheres;
        const float r = 2.0f*float(pi)/numSpheres;
        const Vec3f p = 2.0f*Vec3f(sin(phi),0.0f,-cos(phi));
        RTCGeometryFlags flags = i%2 ? RTC_GEOMETRY_DEFORMABLE : RTC_GEOMETRY_DYNAMIC;
        //RTCGeometryFlags flags = RTC_GEOMETRY_DEFORMABLE;
        int id = createSphere(flags,p,r);
        position[id] = p;
        radius[id] = r;
        colors[id].x = (i%16+1)/17.0f;
        colors[id].y = (i%8+1)/9.0f;
        colors[id].z = (i%4+1)/5.0f;
    }

    /* add ground plane to scene */
    int id = addGroundPlane(g_scene);
    colors[id] = Vec3f(1.0f,1.0f,1.0f);

    /* commit changes to scene */
    rtcCommit (g_scene);

    /* set start render mode */
    renderPixel = renderPixelStandard;
}
Example #10
0
bool SimpleShear::generate(std::string& message)
{
	scene = shared_ptr<Scene>(new Scene);
	createActors(scene);


// Box walls
	shared_ptr<Body> w1;	// The left one :
	createBox(w1,Vector3r(-thickness/2.0,(height)/2.0,0),Vector3r(thickness/2.0,5*(height/2.0+thickness),width/2.0));
	scene->bodies->insert(w1);


	shared_ptr<Body> w2;	// The lower one :
	createBox(w2,Vector3r(length/2.0,-thickness/2.0,0),Vector3r(length/2.0,thickness/2.0,width/2.0));
	YADE_PTR_CAST<FrictMat> (w2->material)->frictionAngle = sphereFrictionDeg * Mathr::PI/180.0; // so that we have phi(spheres-inferior wall)=phi(sphere-sphere)
	scene->bodies->insert(w2);

	shared_ptr<Body> w3;	// The right one
	createBox(w3,Vector3r(length+thickness/2.0,height/2.0,0),Vector3r(thickness/2.0,5*(height/2.0+thickness),width/2.0));
	scene->bodies->insert(w3);

	shared_ptr<Body> w4; // The upper one
	createBox(w4,Vector3r(length/2.0,height+thickness/2.0,0),Vector3r(length/2.0,thickness/2.0,width/2.0));
	YADE_PTR_CAST<FrictMat> (w4->material)->frictionAngle = sphereFrictionDeg * Mathr::PI/180.0; // so that we have phi(spheres-superior wall)=phi(sphere-sphere)
	scene->bodies->insert(w4);

// To close the front and the back of the box 
	shared_ptr<Body> w5;	// behind
	createBox(w5,Vector3r(length/2.0,height/2.0,-width/2.0-thickness/2.0),	Vector3r(2.5*length/2.0,height/2.0+thickness,thickness/2.0));
	scene->bodies->insert(w5);

	shared_ptr<Body> w6;	// the front
	createBox(w6,Vector3r(length/2.0,height/2.0,width/2.0+thickness/2.0),
	Vector3r(2.5*length/2.0,height/2.0+thickness,thickness/2.0));
	scene->bodies->insert(w6);


// the list which will contain the positions of centers and the radii of the created spheres
	vector<BasicSphere> sphere_list;

// to use the TriaxialTest method :
	string out=GenerateCloud(sphere_list,Vector3r(0,0,-width/2.0),Vector3r(length,height,width/2.0),1000,0.3,0.7);// tries to generate a sample of 1000 spheres, with a required porosity of 0.7
	cout << out << endl;

// to use a text file :
// 	std::pair<string,bool> res=ImportCloud(sphere_list,filename);
	
	vector<BasicSphere>::iterator it = sphere_list.begin();
	vector<BasicSphere>::iterator it_end = sphere_list.end();
	
	shared_ptr<Body> body;
	for (;it!=it_end; ++it)
	{
		createSphere(body,it->first,it->second);
		scene->bodies->insert(body);
	}
	
	return true;
}
Example #11
0
	void							buildMesh() {
		mMeshBuilt = true;
		cacheMesh();
		if (!mMesh) {
			ci::TriMesh			mesh;
			mesh = createSphere(mRadius, mXRes, mYRes);
			mMesh = ci::gl::VboMesh(mesh);
		}
	}
Example #12
0
	void							cacheMesh() {
		if (!mEngine) return;

		MeshCacheService&			s(mEngine->getService<ds::MeshCacheService>(ds::MESH_CACHE_SERVICE_NAME));
		std::stringstream			buf;
		// Currently getting a couple duplicates, should clip radius to some int value.
		buf << "sphere;r="<< mRadius << ";x=" << mXRes << ";y=" << mYRes;
		mMesh = s.get(buf.str(), [this]()->ci::TriMesh { ci::TriMesh t; t = createSphere(mRadius, mXRes, mYRes); return t;});
	}
Example #13
0
void readGeometry(scene_data* scene, const boost::property_tree::ptree& pt)
{
	boost::property_tree::ptree::const_iterator iter = pt.begin();
	for (; iter != pt.end(); ++iter)
	{
		std::string name = iter->first;
		geometry* geom;
		if (name == "cube")
			geom = createBox();
		else if (name == "tetrahedron")
			geom = createTetrahedron();
		else if (name == "pyramid")
			geom = createPyramid();
		else if (name == "disk")
		{
			int slices = iter->second.get_child("slices").get_value<int>();
			geom = createDisk(slices);
		}
		else if (name == "cylinder")
		{
			int slices = iter->second.get_child("slices").get_value<int>();
			int stacks = iter->second.get_child("stacks").get_value<int>();
			geom = createCylinder(stacks, slices);
		}
		else if (name == "sphere")
		{
			int slices = iter->second.get_child("slices").get_value<int>();
			int stacks = iter->second.get_child("stacks").get_value<int>();
			geom = createSphere(stacks, slices);
		}
		else if (name == "torus")
		{
			float radius = iter->second.get_child("radius").get_value<float>();
			int slices = iter->second.get_child("slices").get_value<int>();
			int stacks = iter->second.get_child("stacks").get_value<int>();
			geom = createTorus(radius, stacks, slices);
		}
		else if (name == "plane")
		{
			int width = iter->second.get_child("width").get_value<int>();
			int depth = iter->second.get_child("depth").get_value<int>();
			geom = createPlane(width, depth);
		}
		else if (name == "sierpinski")
		{
			int divisions = iter->second.get_child("divisions").get_value<int>();
			geom = createSierpinski(divisions);
		}
		else
		{
			std::cerr << "Error - Geometry type not recognised: " << name << std::endl;
			exit(EXIT_FAILURE);
		}
		scene->geometry[name] = geom;
	}
}
void createSphere(SrPoint3D* support, int numPoint ,SrSphere3D& sphere)
{
	switch(numPoint)
	{
	case 0:
		createSphere(sphere);
		break;
	case 1:
		createSphere(support[0],sphere);
		break;
	case 2:
		createSphere(support[0],support[1],sphere);
		break;
	case 3:
		createSphere(support[0],support[1],support[2],sphere);
		break;
	case 4:
		createSphere(support[0],support[1],support[2],support[3],sphere);
		break;
	}
}
Example #15
0
int main(int argc,const char *argv[])
{
    s32 ret,i;
    padInfo padinfo;
    padData paddata;
    rsxProgramConst *consts = rsxFragmentProgramGetConsts(fpo);

    initialize();
    ioPadInit(7);

    sphere = createSphere(3.0f,32,32);
    donut = createDonut(3.0f,1.5f,32,32);
    cube = createCube(5.0f);

    rsxConstOffsetTable *co_table = rsxFragmentProgramGetConstOffsetTable(fpo,consts[lightColor_id].index);
    u32 const_addr = (u32)((u64)fp_buffer + co_table->offset[0]);
    setup_shared_buffer(const_addr,(u32)(u64)mem_align(128,128),(u32)(u64)gcmGetLabelAddress(64));
    signal_spu_ppu();
    signal_spu_rsx();

    P = transpose(Matrix4::perspective(DEGTORAD(45.0f),aspect_ratio,1.0f,3000.0f));

    setRenderTarget(curr_fb);
    rsxFinish(context,0);

    ret = atexit(program_exit_callback);
    ret = sysUtilRegisterCallback(0,sysutil_exit_callback,NULL);

    delete cube;

    running = 1;
    while(running) {
        ret = sysUtilCheckCallback();

        ioPadGetInfo(&padinfo);
        for(i=0; i<MAX_PADS; i++) {
            if(padinfo.status[i]) {
                ioPadGetData(i, &paddata);

                if(paddata.BTN_CROSS) {
                    return 0;
                }
            }

        }

        drawFrame();
        flip();
    }

    return 0;
}
Example #16
0
bool createSphere(float	r,NxuGeometry &g,const NxMat34 *localPose,int stepsize,NxReal shrink,unsigned int maxV)
{

	unsigned int vcount;

	float	*points	=	createSphere(r,	stepsize,	vcount);

	bool ret = createHull(vcount,	points,		g,localPose, shrink, maxV);

	delete points;

	return ret;
}
Example #17
0
// Initializes OpenGL. Loads the vertex and fragment shaders, and creates the
// sphere mesh.
void glInit(void) 
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
	// Enable texture for the text fields.
	glEnable(GL_TEXTURE_2D);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	g_program = glCreateProgram();
	shaderAttachFromFile(g_program, GL_VERTEX_SHADER, "data/vertex.vp");
	shaderAttachFromFile(g_program, GL_FRAGMENT_SHADER, "data/fragment.fp");

	GLint result;
	glLinkProgram(g_program);
	glGetProgramiv(g_program, GL_LINK_STATUS, &result);
	if(result == GL_FALSE) {
		GLint length;
		char *log;

		// get the program info log
		glGetProgramiv(g_program, GL_INFO_LOG_LENGTH, &length);
		log = (char *)malloc(length);
		glGetProgramInfoLog(g_program, length, &result, log);

		// print an error message and the info log
		fprintf(stderr, "init(): Program linking failed: %s\n", log);
		free(log);

		// delete the program
		glDeleteProgram(g_program);
		g_program = 0;
	}

	// get uniform locations
	g_programCameraPositionLocation = glGetUniformLocation(g_program, "cameraPosition");
	g_programObjectPositionLocation = glGetUniformLocation(g_program, "objectPositions");
	g_programLightDirectionLocation = glGetUniformLocation(g_program, "lightDirection");
	g_programUserSphereLocation = glGetUniformLocation(g_program, "userSphere");
	
	g_lightDirection[0] = 1.0f;
	g_lightDirection[1] = 0.0f;
	g_lightDirection[2] = 0.0f;

	g_cameraPosition[0] = 0.0f;
	g_cameraPosition[1] = 0.0f;
	g_cameraPosition[2] = -zoom;

	sphereMesh = createSphere(12, 12);
}
Example #18
0
int main(int argc,const char *argv[])
{
	s32 ret,i;
	padInfo padinfo;
	padData paddata;
	void *host_addr = memalign(1024*1024,HOST_SIZE);

	printf("rsxtest started...\n");

	init_screen(host_addr,HOST_SIZE);
	ioPadInit(7);
	init_shader();
	init_texture();

	sphere = createSphere(3.0f,32,32);
	donut = createDonut(3.0f,1.5f,32,32);
	cube = createCube(5.0f);

	ret = atexit(program_exit_callback);
	ret = sysUtilRegisterCallback(0,sysutil_exit_callback,NULL);

	P = transpose(Matrix4::perspective(DEGTORAD(45.0f),aspect_ratio,1.0f,3000.0f));

	setTexture();
	setDrawEnv();
	setRenderTarget(curr_fb);

	running = 1;
	while(running) {
		ret = sysUtilCheckCallback();

		ioPadGetInfo(&padinfo);
		for(i=0; i<MAX_PADS; i++){
			if(padinfo.status[i]){
				ioPadGetData(i, &paddata);

				if(paddata.BTN_CROSS){
					return 0;
				}
			}

		}
		
		drawFrame();
		flip();
	}

	return 0;
}
Example #19
0
GLWidget::GLWidget(QWidget *parent) :
    QGLWidget(parent)
{
    upSphereCone = downSphereCone = cylinderVertices = diskVertices = sphereVertices = coneVertices = 0;
    cylinderSize = diskSize = sphereVerticesSize = sphereConeSize = coneSize = 0;

    createSphere(1.0f, 10, 10);
    createCone(0.5f, 0.5f, 6);
    createDisk(0.5f, 6);
    createCylinder(0.9f, 0.1f, 0.0f, 50);
    program = new QOpenGLShaderProgram(this);

    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::SampleBuffers | QGL::NoDeprecatedFunctions));
    modelView.setColumn(3, QVector4D(-0.5, -0.5, 0, 1));
}
Example #20
0
void initGeometry()
{
  // sphere for instancing

  float radius = 0.0025f;
  std::vector<float> Vertices;
  std::vector<float> Normals;  
  std::vector<unsigned int> Indices;
  
  Vertices.clear();
  Normals.clear();
  Indices.clear();
  createSphere(radius, Vertices, Indices, Normals);
  
  glGenVertexArrays(1, &vaoSphere);
  glBindVertexArray(vaoSphere);

  glGenBuffers(1, &vboSphereVertex);
  glBindBuffer(GL_ARRAY_BUFFER, vboSphereVertex);
  glBufferData(GL_ARRAY_BUFFER, sizeof(float)*Vertices.size(), Vertices.data(), 
	       GL_STATIC_DRAW);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

  glGenBuffers(1, &vboSphereNormal);
  glBindBuffer(GL_ARRAY_BUFFER, vboSphereNormal);
  glBufferData(GL_ARRAY_BUFFER, sizeof(float)*Normals.size(), Normals.data(), 
	       GL_STATIC_DRAW);
  glEnableVertexAttribArray(1);
  glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

  glGenBuffers(1, &vboSphereIndex);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboSphereIndex);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*Indices.size(), 
	       Indices.data(), GL_STATIC_DRAW);

  numIndicesSphere = Indices.size();

  glGenBuffers(1, &vboPositions);
  glBindBuffer(GL_ARRAY_BUFFER, vboPositions);

  glEnableVertexAttribArray(2);
  glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, (GLubyte*)NULL);
  glVertexAttribDivisor(2, 1);

  glBindVertexArray(0);
}
Example #21
0
int main()
{
	ogl.init();

	glutDisplayFunc(display);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);

	ogl.AddShader("triangles.vert", GL_VERTEX_SHADER);
	ogl.AddShader("triangles.frag", GL_FRAGMENT_SHADER);
	ogl.AddShader("triangles.geom", GL_GEOMETRY_SHADER);
	ogl.CompileProgram();
	
	auto triangles = createSphere(0.7, 100, 100);
	triangle = ogl.addVertexBuffer(GL_TRIANGLES, triangles);

	ogl.start();
}
Example #22
0
void main( int argc, char ** argv )
{
   Environment env(argc, argv);
   WALBERLA_UNUSED(env);
   walberla::mpi::MPIManager::instance()->useWorldComm();

   //init domain partitioning
   auto forest = blockforest::createBlockForest( AABB(0,0,0,20,20,20), // simulation domain
                                                 Vector3<uint_t>(2,2,2), // blocks in each direction
                                                 Vector3<bool>(false, false, false) // periodicity
                                                 );
   domain::BlockForestDomain domain(forest);

   //init data structures
   data::ParticleStorage ps(100);

   //initialize particle
   auto uid = createSphere(ps, domain);
   WALBERLA_LOG_DEVEL_ON_ROOT("uid: " << uid);

   //init kernels
   mpi::ReduceProperty    RP;
   mpi::SyncNextNeighbors SNN;

   //sync
   SNN(ps, domain);

   auto pIt = ps.find(uid);
   if (pIt != ps.end())
   {
      pIt->getForceRef() += Vec3(real_c(walberla::mpi::MPIManager::instance()->rank()));
   }

   RP.operator()<ForceTorqueNotification>(ps);

   if (walberla::mpi::MPIManager::instance()->rank() == 0)
   {
      WALBERLA_CHECK_FLOAT_EQUAL( pIt->getForce(), Vec3(real_t(28)) );
   } else
   {
      WALBERLA_CHECK_FLOAT_EQUAL( pIt->getForce(), Vec3(real_t(walberla::mpi::MPIManager::instance()->rank())) );
   }
}
Example #23
0
void DisplayWidget::mousePressEvent(QMouseEvent *event) {
    //get position of mouse press
    float x = (float)event->x();
    float y = (float)event->y();
    Vector2f v(x,y);

    //used to determine if current object should be deselected
    bool pressed = false;
    bool lastSelected = m_selected;

    //check if an existing sphere has been clicked
    for (uint i = 0; i < m_spheres.size(); i++) {
        Vector2f c = m_spheres[i]->getPosition();
        float r = m_spheres[i]->getRadius();
        if ((v-c).magnitude() <= r) {
            m_selected = true;
            pressed = true;
            m_selectedIndex = i;
            break;
        }
    }

    if (m_selected && !pressed) {
        //deselect current sphere
        m_selected = false;
    } else if (m_selected && event->button() & Qt::RightButton) {
        //delete selected sphere
        if (!lastSelected) {
            m_spheres.erase(m_spheres.begin() + m_selectedIndex);
            m_polygonizer.removeSurface(m_selectedIndex);
        }
        m_selected = false;
    } else if (!m_selected && event->button() & Qt::LeftButton) {
        //create and add random sphere to the scene
        ImplicitSphere *sphere = createSphere(v);
        m_spheres.push_back(sphere);
        m_polygonizer.addSurface(sphere);
    }

    emit sphereSelected(m_selected && !m_animate ? m_spheres[m_selectedIndex] : 0);
    repaint();
}
Example #24
0
/* called by the C++ code for initialization */
extern "C" void device_init (int8* cfg)
{
  /* initialize ray tracing core */
  rtcInit(cfg);

  /* set error handler */
  rtcSetErrorFunction(error_handler);

  /* create scene */
  g_scene = rtcNewScene(RTC_SCENE_DYNAMIC,RTC_INTERSECT1);

  /* create some triangulated spheres */
  for (int i=0; i<numSpheres; i++)
  {
    const float phi = i*2.0f*float(pi)/numSpheres;
    const float r = 2.0f*float(pi)/numSpheres;
    const Vec3fa p = 2.0f*Vec3fa(sin(phi),0.0f,-cos(phi));
    //RTCGeometryFlags flags = i%3 == 0 ? RTC_GEOMETRY_STATIC : i%3 == 1 ? RTC_GEOMETRY_DEFORMABLE : RTC_GEOMETRY_DYNAMIC;
    RTCGeometryFlags flags = i%2 ? RTC_GEOMETRY_DEFORMABLE : RTC_GEOMETRY_DYNAMIC;
    //RTCGeometryFlags flags = RTC_GEOMETRY_DEFORMABLE;
    int id = createSphere(flags,p,r);
    position[id] = p;
    radius[id] = r;
    colors[id].x = (i%16+1)/17.0f;
    colors[id].y = (i%8+1)/9.0f;
    colors[id].z = (i%4+1)/5.0f;
  }

  /* add ground plane to scene */
  int id = addGroundPlane(g_scene);
  colors[id] = Vec3fa(1.0f,1.0f,1.0f);

  /* commit changes to scene */
#if !defined(PARALLEL_COMMIT)
  rtcCommit (g_scene);
#else
  launch[ getNumHWThreads() ] parallelCommit(g_scene); 
#endif

  /* set start render mode */
  renderPixel = renderPixelStandard;
}
Example #25
0
osg::Node *create3DAxis()
{
    osg::PositionAttitudeTransform *xAxis = createArrow(osg::Vec4(1, 0, 0, 1));

    xAxis->setAttitude(osg::Quat(M_PI / 2.0, osg::Vec3(0, 1, 0)));

    osg::PositionAttitudeTransform *yAxis = createArrow(osg::Vec4(0, 1, 0, 1));
    yAxis->setAttitude(osg::Quat(-M_PI / 2.0, osg::Vec3(1, 0, 0)));

    osg::PositionAttitudeTransform *zAxis = createArrow(osg::Vec4(0, 0, 1, 1));

    osg::Node *center = createSphere(osg::Vec4(0.7, 0.7, .7, 1), 0.08);

    osg::Group *group = new osg::Group();
    group->addChild(xAxis);
    group->addChild(yAxis);
    group->addChild(zAxis);
    group->addChild(center);
    return group;
}
Example #26
0
void mouse(int button, int state, int x, int y) {
  if (button == GLUT_LEFT_BUTTON) {
        if (state == GLUT_UP) {
            reachObj = NULL;
        }
        else if (state == GLUT_DOWN) {
            mouseoldx = x; mouseoldy = y;
            createSphere(x, y);
        }
  }
  if (button == GLUT_RIGHT_BUTTON) {
        if (state == GLUT_UP) {
            reachObj = NULL;
	}
	else if (state == GLUT_DOWN) {
	    mouseoldx = x; mouseoldy = y;
            reachObj = NULL;
	}
  }
  glutPostRedisplay();
}
void smallestEnclosingSphere(SrPoint3D*	sp,int nsp,VertexList& vertexList,const VertexIterator& end,SrSphere3D& sphere)
{
	createSphere(sp, nsp,sphere);
	if( nsp==4 )
		return;
	VertexIterator iterator = vertexList.begin();
	for( ; end != iterator ; )
	{
		const SrPoint3D& p = *iterator;
		if( isOut(p,sphere) )
		{
			sp[ nsp ] = p;
			smallestEnclosingSphere( sp, nsp + 1 , vertexList , iterator , sphere);
			vertexList.splice(vertexList.begin(),vertexList,iterator++ );
		}
		else
		{
			iterator++;
		}
	}
}
	//---------------------------------------------------------------------
	bool PrefabFactory::createPrefab(Mesh* mesh)
	{
		const String& resourceName = mesh->getName();

		if(resourceName == "Prefab_Plane")
		{
			createPlane(mesh);
			return true;
		}
		else if(resourceName == "Prefab_Cube")
		{
			createCube(mesh);
			return true;
		}
		else if(resourceName == "Prefab_Sphere")
		{
			createSphere(mesh);
			return true;
		}
	
		return false;
	}
Example #29
0
/* called by the C++ code for initialization */
extern "C" void device_init (char* cfg)
{
  /* create new Embree device */
  g_device = rtcNewDevice(cfg);

  /* set error handler */
  rtcDeviceSetErrorFunction(g_device,error_handler);

  /* create scene */
  g_scene = rtcDeviceNewScene(g_device,RTC_SCENE_DYNAMIC | RTC_SCENE_ROBUST, RTC_INTERSECT1);

  /* create some triangulated spheres */
  for (int i=0; i<numSpheres; i++)
  {
    const float phi = i*2.0f*float(pi)/numSpheres;
    const float r = 2.0f*float(pi)/numSpheres;
    const Vec3fa p = 2.0f*Vec3fa(sin(phi),0.0f,-cos(phi));
    //RTCGeometryFlags flags = i%3 == 0 ? RTC_GEOMETRY_STATIC : i%3 == 1 ? RTC_GEOMETRY_DEFORMABLE : RTC_GEOMETRY_DYNAMIC;
    RTCGeometryFlags flags = i%2 ? RTC_GEOMETRY_DEFORMABLE : RTC_GEOMETRY_DYNAMIC;
    //RTCGeometryFlags flags = RTC_GEOMETRY_DEFORMABLE;
    int id = createSphere(flags,p,r);
    position[id] = p;
    radius[id] = r;
    colors[id].x = (i%16+1)/17.0f;
    colors[id].y = (i%8+1)/9.0f;
    colors[id].z = (i%4+1)/5.0f;
  }

  /* add ground plane to scene */
  int id = addGroundPlane(g_scene);
  colors[id] = Vec3fa(1.0f,1.0f,1.0f);

  /* commit changes to scene */
  rtcCommit (g_scene);

  /* set start render mode */
  renderPixel = renderPixelStandard;
  key_pressed_handler = device_key_pressed_default;
}
Example #30
0
bool createCapsule(float radius, float height, NxuGeometry &g,const NxMat34 *localPose,int axis, int stepsize,  NxReal shrink,unsigned int maxV)
{
	unsigned int vcount;

	float	*points	=	createSphere(radius, stepsize, vcount);

	float	spread = height	*	0.5f;

	for	(unsigned	int	i	=	0; i < vcount; i++)
	{
		float	*p = &points[i *3];

		if (p[2] < 0)
		{
			p[2] -=	spread;
		}
		else
		{
			p[2] +=	spread;
		}


		if (axis ==	1)
		{
			SwapYZ(p);
		}
		else if	(axis	== 0)
		{
			SwapXZ(p);
		}

	}

	bool ret = createHull(vcount,	points,	g,localPose, shrink, maxV);

	delete points;

	return ret;
}