Page 1 of 1

Does the irrlicht offer a method to create a cylinder??

Posted: Sun Dec 21, 2008 4:26 pm
by lizhigang34
I am a novice of irrlicht!! :)

Posted: Sun Dec 21, 2008 9:31 pm
by hybrid
So why do you think you can ask advanced stuff then :roll:
Moved, and denied...

Posted: Sun Dec 21, 2008 10:40 pm
by Acki
hybrid wrote:So why do you think you can ask advanced stuff then :roll:
even the greatest noob can ask the most advanced stuff, what he can make out of it is another think... :lol:

well, there is no function for this...
but you can create one on your own... ;)
a good starting point for such probably is the custom scene node tutorial (#03)...

Posted: Mon Dec 22, 2008 1:05 am
by lizhigang34
Thanks for your reply!
I just feel accidental..
There is a method addSphereSceneNode() in class ISceneManager for create a sphere , another method addCubeSceneNode() for create a cube..
but,there is no similar method addCylinderSceneNode()..
My English is poor!! and I am a novice of 3D program.

I am a Chinese.. :)
谢谢大家的回复,
我只是感到有点意外而已.
在类ISceneManager有函数addSphereSceneNode()能创建一个球,函数addCubeSceneNode() 创建一个立方体..却没有类似的函数addCylinderSceneNode().
我的英语很差,而且我刚学3D程序设计.

Posted: Mon Dec 22, 2008 3:50 am
by vitek
It isn't difficult to create a cylinder. You just have to figure out a little bit of math and have a good understanding of how a mesh buffer describes a series of triangles (i.e., you need to know how a vertex and index buffer work).

I wrote this code some time back, but I believe it works correctly...

Code: Select all

scene::SMeshBuffer*
createCylinderMeshBuffer(u32 faces, f32 radius, f32 height, video::SColor color)
{
  if (faces < 3)
    faces = 3;
  else if (65534 < faces)
    faces = 65534;

  scene::SMeshBuffer* mb =
    new scene::SMeshBuffer;
  if (!mb)
    return 0;

  video::S3DVertex vertex;
  vertex.Color = color;

  u32 n, m = 0; 
  for (n = 0; n <= faces; ++n) 
  { 
    const f32 x = (core::PI * 2.f) * n / faces; 

    const f32 dx = sinf(x); 
    const f32 dz = cosf(x); 

    vertex.Pos.set    (dx * radius, height, dz * radius); 
    vertex.Normal.set (dx, 0, dz); 
    vertex.TCoords.set(1.f * n / faces, 0.f); 

    mb->Vertices.push_back(vertex);

    vertex.Pos.Y     = 0; 
    vertex.TCoords.Y = 1.f; 

    mb->Vertices.push_back(vertex);
  }

  for (u32 n = 0; n < 2 * faces; ++n)
  {
      mb->Indices.push_back(n);

      if (n & 1) {
        mb->Indices.push_back(n+2);
        mb->Indices.push_back(n+1);
      }
      else
      {
        mb->Indices.push_back(n+1);
        mb->Indices.push_back(n+2);
      }
  }

  mb->BoundingBox.reset (-radius, 0, -radius);
  mb->BoundingBox.addInternalPoint(radius, height, radius);

  return mb;
}

scene::SMesh*
createCylinderMesh(u32 faces, f32 radius, f32 height, video::SColor color)
{
  scene::SMeshBuffer* mb = createCylinderMeshBuffer(faces, radius, height, color);
  if (!mb)
    return 0;

  scene::SMesh* mesh = new scene::SMesh;
    mesh->addMeshBuffer(mb);
  mb->drop();

  mesh->recalculateBoundingBox();

  return mesh;
}
You would use it like...

Code: Select all

scene::IMesh* cylinder = createCylinderMesh(6, 10, 10, video::SColor(255, 255, 0, 0));
// make sure cylinder got created

scene::IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
Travis

Posted: Mon Dec 22, 2008 4:34 am
by vitek
I just noticed that there is code for creating a cylinder in CGeometryCreator.cpp. Unfortunately it isn't exposed to the user, so if you want to use it, you need to copy/paste it into your project.

Travis

Posted: Mon Dec 22, 2008 6:01 am
by lizhigang34
That means I cannot use it like sphere scene node.

Maybe, I need to read the code Tutorial 3.CustomSceneNode. :lol:

Posted: Mon Dec 22, 2008 6:57 am
by vitek
I don't understand your complaint. You want to call smgr->addCylinderSceneNode() and can't? So modify your copy of the source. FYI, there is no sphere scene node. It is just a IMeshSceneNode with a mesh that happens to be a sphere.

That said, you could just use an mesh editor and make the cylinder. Then everything works as it should and you don't have to modify the source.

Travis

Posted: Tue Dec 23, 2008 3:42 pm
by Jiang
lizhigang34 wrote:Thanks for your reply!
I just feel accidental..
There is a method addSphereSceneNode() in class ISceneManager for create a sphere , another method addCubeSceneNode() for create a cube..
but,there is no similar method addCylinderSceneNode()..
My English is poor!! and I am a novice of 3D program.

I am a Chinese.. :)
谢谢大家的回复,
我只是感到有点意外而已.
在类ISceneManager有函数addSphereSceneNode()能创建一个球,函数addCubeSceneNode() 创建一个立方体..却没有类似的函数addCylinderSceneNode().
我的英语很差,而且我刚学3D程序设计.

I think you can use irrlicht's Arrow mesh to simulate the cylinder.

Code: Select all


	ISceneNode * cylinder= m_pSceneManager->addMeshSceneNode(
		m_pSceneManager->addArrowMesh("arrow",
		SColor(255, 255, 0, 0), SColor(255, 0, 255, 0),
		4,8,1.f,

                0.99f,               // 1. arrow's cylinder length
                0.01f,               // 2. arrow cone's roof 

                0.5f
		), robotRoot);
	cylinder->setMaterialFlag(video::EMF_LIGHTING, false);
	cylinder->setScale(vector3df(50, 1000, 50));  // 3. scale it


Please tune the 1, 2, 3 parts, and maybe it fits your need. :-)
If you really need the exact cylinder, find how irrlicht creates the arrow mesh. Should not be too difficult in my mind.

Actually we share the same feeling but irrlicth has nothing to do with glu interface and you will find more differences between irrlicht and Opengl/Glu. Nothing strange.

HTH,

Jiang

cylinders, planes, easy of use = ?

Posted: Tue Aug 18, 2009 12:10 am
by koscianski
I have the same 'complain' about Irrlicht. Let's think about it.

Knowing that the method to create a cylindrical mesh (or a plane) is ready and implemented inside the engine, it makes no sense at all not to expose it. Take a look:

1) it is faster to create programatically instead of loading a file. If users are asking for it, maybe they do not want to model the mesh externally, right?

2) it is reasonable to think that cylinders and planes have more usefulness than arrows. However, Irrlicht have "addArrow" and no "addCylinder". If the point here is "arrows are difficult to model" ..., well, in that case Irrlicht should have addCastle, addGun, etc. Programatically creating geometry is indeed useful and important. Klasker's tree generator is one example. A labyrinth would be another one. Ah, ok, we model a maze in Blender and point the exit with arrows with the API.. = do'h!

3) the code (cylinder) is ready and (hopefully) optimized. Now, where is the "easy of use" if we get as answer "model your mesh"?! :shock:

4) copy and paste = duplicate code. Sorry, that's absurd.

5) simplicity and easyness of use does not mean a little API. That's not a good reasoning line, as games get more and more rich. Irrlicht is in serious need of DX10 and shadows, falling behind Ogre and other tools. But it also need 'simple' tools. API's are growing.
These additions (addCylinderNode, addPlaneNode) are not even additions - in truth it means to unlock resources that are kept hidden inside the engine. Not even necessary to implement!

Help me here. I understand nothing.

Posted: Tue Aug 18, 2009 12:14 pm
by wITTus
Well, you could do something like:

Code: Select all

IMesh* Mesh = SceneManager->getGeometryCreator()->createCylinderMesh();
SceneManager->addMeshSceneNode(Mesh);
or write a quick patch for the engine itself. In my opinion, these simple Manager->addSphere() functions (and others which simply use CGeometryCreator) are redundant and could be removed.

About the code

Posted: Tue May 03, 2011 7:33 pm
by thanvilk
vitek wrote:It isn't difficult to create a cylinder. You just have to figure out a little bit of math and have a good understanding of how a mesh buffer describes a series of triangles (i.e., you need to know how a vertex and index buffer work).

I wrote this code some time back, but I believe it works correctly...

Code: Select all

scene::SMeshBuffer*
createCylinderMeshBuffer(u32 faces, f32 radius, f32 height, video::SColor color)
{
  if (faces < 3)
    faces = 3;
  else if (65534 < faces)
    faces = 65534;

  scene::SMeshBuffer* mb =
    new scene::SMeshBuffer;
  if (!mb)
    return 0;

  video::S3DVertex vertex;
  vertex.Color = color;

  u32 n, m = 0; 
  for (n = 0; n <= faces; ++n) 
  { 
    const f32 x = (core::PI * 2.f) * n / faces; 

    const f32 dx = sinf(x); 
    const f32 dz = cosf(x); 

    vertex.Pos.set    (dx * radius, height, dz * radius); 
    vertex.Normal.set (dx, 0, dz); 
    vertex.TCoords.set(1.f * n / faces, 0.f); 

    mb->Vertices.push_back(vertex);

    vertex.Pos.Y     = 0; 
    vertex.TCoords.Y = 1.f; 

    mb->Vertices.push_back(vertex);
  }

  for (u32 n = 0; n < 2 * faces; ++n)
  {
      mb->Indices.push_back(n);

      if (n & 1) {
        mb->Indices.push_back(n+2);
        mb->Indices.push_back(n+1);
      }
      else
      {
        mb->Indices.push_back(n+1);
        mb->Indices.push_back(n+2);
      }
  }

  mb->BoundingBox.reset (-radius, 0, -radius);
  mb->BoundingBox.addInternalPoint(radius, height, radius);

  return mb;
}

scene::SMesh*
createCylinderMesh(u32 faces, f32 radius, f32 height, video::SColor color)
{
  scene::SMeshBuffer* mb = createCylinderMeshBuffer(faces, radius, height, color);
  if (!mb)
    return 0;

  scene::SMesh* mesh = new scene::SMesh;
    mesh->addMeshBuffer(mb);
  mb->drop();

  mesh->recalculateBoundingBox();

  return mesh;
}
You would use it like...

Code: Select all

scene::IMesh* cylinder = createCylinderMesh(6, 10, 10, video::SColor(255, 255, 0, 0));
// make sure cylinder got created

scene::IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
Travis
I used this code compiled well with our any error but not showing any thing on the irrlicht device window... !
what is the problem ??
i also used IGeometryCreater method of createCylinderMesh but it is also compiling well but not showing any thing...

Please suggest me if any new solution for creating cylinder...bcoz both above methods are not working...
if anywhere i am wrong then please correct me.. as i used you code as it is but all is fail !

Re: Does the irrlicht offer a method to create a cylinder??

Posted: Fri Jan 04, 2013 6:21 pm
by cirosantilli
how to turn the cylinder inside out, so that it can be seen and do collision detection if the camera is inside it?

the cylinder woks for me with:

Code: Select all

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

Code: Select all

mesh = smgr->getGeometryCreator()->createCylinderMesh(
    .1f,    //radius
    1.,     //length
    50,     //tesselation
    SColor(),              //color
    false,                 //closeTop
    0.f                    //oblique
);
node = smgr->addMeshSceneNode(
    mesh,
    0,     //ISceneNode * parent
    -1,    //s32 id
    vector3df(0, -HEIGHT, 0),            //const core::vector3df & position
    vector3df(0, 0, 0),                  //const core::vector3df & rotation
    vector3df(1.0f, 2.*HEIGHT, 1.0f)     //const core::vector3df & scale
);
node->getMaterial(0).AmbientColor.set(0,0,0,255);
node->getMaterial(0).DiffuseColor.set(0,0,0,255);
node->getMaterial(0).Lighting = true;
 

Re: Does the irrlicht offer a method to create a cylinder??

Posted: Fri Jan 04, 2013 6:42 pm
by smso
cirosantilli wrote:how to turn the cylinder inside out, so that it can be seen and do collision detection if the camera is inside it?
Try disabling back culling (and disabling material lighting if there is not any light).

Regards,
smso