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
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
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
Code: Select all
// T3 T2 T1 T4
IndexBuffer = 4, 1, 3, 0, 1, 5, 4, 5, 1, 2, 3, 1