How to draw cylinder, again?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
rayn
Posts: 4
Joined: Mon Apr 07, 2008 6:44 pm

How to draw cylinder, again?

Post by rayn »

Hi, this is newbie question, but I can't get this working for 3 days already.

I need to implement scenenode that draws cylinder and I can't use any mesh file.
My cylinder actually should be N-sided prism with quite big N .
I took CustomSceneNode example and tried to make a prism, with it's base lying in xOy plane and it's sides being parallel to z axis.
So I made following changes:

Code: Select all

class CSampleSceneNode : public scene::ISceneNode
{

	core::aabbox3d<f32> Box;

	irr::core::array<irr::video::S3DVertex> vertex; 
   irr::core::array<unsigned short> index;
	video::SMaterial Material;
	irr::scene::SMeshBuffer mb;


public:
	CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
		: scene::ISceneNode(parent, mgr, id)
	{	
		int N=5, R=10, H=20;
		//N-number of sides
		//R-radius
		//H-height

		Material.Wireframe = false;
		Material.Lighting = false;
		float baseAngle = 2*core::PI64 / N;

		video::S3DVertex p1,p2;
		float a,b,angle;
		for( int i = 0; i <N+1; i++ )
		{
	       angle = baseAngle * (i+core::PI64/4);

			 a=R*cosf(angle);
			 b=R*sinf(angle);
				
			 p1= irr::video::S3DVertex (a,b,0,0,0,0,video::SColor(255,128,255,255), 0, 0);			 
			 vertex.push_back(p1);		 
			 p2= irr::video::S3DVertex (a,b,H,0,0,0,video::SColor(255,128,255,255), 0, 0);
			 vertex.push_back(p2);
				
		}
		for( int i = 0; i <2*(N+1); i+=1 )
			index.push_back(i);
	}
//...
//same as in example

	virtual void render()
	{
		
		video::IVideoDriver* driver = SceneManager->getVideoDriver();

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		
		driver->drawVertexPrimitiveList(vertex.const_pointer(),vertex.size(), index.const_pointer(), index.size(),video::EVT_STANDARD,scene::EPT_TRIANGLE_STRIP);
			}
//...
//rest same as in example
But that code doesn't work. What I get - are 3 connected planes with a lot of artifacts flying out of planes. It looks like I messed something in index array. But I did it according to TRIANGLE_STRIP definition. Where could be the problem? Could anybody help me, please?

And another question:
If I have the following mesh (thanks vitek for this example):

Code: Select all

  A------------B------------C 
  |          / |\           | 
  |  T1    /   |  \    T4   | 
  |      /     |    \       | 
  |    /       |      \     | 
  |  /   T2    |  T3    \   | 
  |/           |          \ | 
  F------------E------------D 
VertexBuffer = A, B, C, D, E, F 
and if I want to draw it using drawIndexedTriangleList, does it matter in what order I draw triangles?
Will I get different results using

Code: Select all

//                T1         T2         T3         T4 
IndexBuffer =  0, 1, 5,   4, 5, 1,   4, 1, 3,   2, 3, 1 
and

Code: Select all

//                T3       T2         T1           T4 
IndexBuffer =  4, 1, 3, 0, 1, 5,   4, 5, 1,      2, 3, 1 
or using whatever else index buffer if I keep 'winding order'?
Kriolyth
Posts: 26
Joined: Wed Mar 26, 2008 6:59 pm
Location: Moscow, Russia

Re: How to draw cylinder, again?

Post by Kriolyth »

rayn wrote:

Code: Select all

driver->drawVertexPrimitiveList(vertex.const_pointer(),vertex.size(), index.const_pointer(), index.size(),video::EVT_STANDARD,scene::EPT_TRIANGLE_STRIP);
TriangleCount is two less than index.size() in tri-strips, mind that.
Will I get different results using

Code: Select all

//                T1         T2         T3         T4 
IndexBuffer =  0, 1, 5,   4, 5, 1,   4, 1, 3,   2, 3, 1 
and

Code: Select all

//                T3       T2         T1           T4 
IndexBuffer =  4, 1, 3, 0, 1, 5,   4, 5, 1,      2, 3, 1 
or using whatever else index buffer if I keep 'winding order'?
Under most conditions it does not matter. However, if you have ZBuffering off or some fancy alpha blending, you'll get different results if the mesh overlaps itself.
The cake is a lie.
rayn
Posts: 4
Joined: Mon Apr 07, 2008 6:44 pm

Post by rayn »

Thanks, Kriolyth.
Now it works. I just miscounted number of indices
Post Reply