Exemplo n.º 1
0
	CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
		: scene::ISceneNode(parent, mgr, id)
	{
		Descriptor = mgr->getVideoDriver()->getVertexDescriptor(0);

		VertexBuffer = new scene::CVertexBuffer<video::S3DVertex>();
		IndexBuffer = new scene::CIndexBuffer(video::EIT_16BIT);
		MeshBuffer = new scene::CMeshBuffer<video::S3DVertex>(Descriptor);

		Material.Wireframe = false;
		Material.Lighting = false;

		video::S3DVertex Vertices[4];

		Vertices[0] = video::S3DVertex(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1);
		Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1);
		Vertices[2] = video::S3DVertex(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0);
		Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0);

		for (s32 i = 0; i<4; ++i)
			VertexBuffer->addVertex(&Vertices[i]);
			
	/*
	Indices into the 'Vertices' array. A triangle needs 3 vertices 
	so you have to pass the 3 corresponding indices for each triangle to 
	tell which of the vertices should be used for it.
	*/

		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(1);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(1);
		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(1);

	/*
	Append Vertex and Index buffers to the Mesh buffer.
	*/

		MeshBuffer->setVertexBuffer(VertexBuffer, 0);
		MeshBuffer->setIndexBuffer(IndexBuffer);

	/*
	The Irrlicht Engine needs to know the bounding box of a scene node.
	It will use it for automatic culling and other things. Hence, we
	need to create a bounding box from the 4 vertices we use.
	If you do not want the engine to use the box for automatic culling,
	and/or don't want to create the box, you could also call
	irr::scene::ISceneNode::setAutomaticCulling() with irr::scene::EAC_OFF.
	*/
		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<4; ++i)
			Box.addInternalPoint(Vertices[i].Pos);
	}
Exemplo n.º 2
0
	CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id)
		: ISceneNode(parent, mgr, id)
	{
		Descriptor = mgr->getVideoDriver()->getVertexDescriptor(0);

		VertexBuffer = new scene::CVertexBuffer<S3DVertex>();
		IndexBuffer = new scene::CIndexBuffer(video::EIT_16BIT);

		Material.Wireframe = false;
		Material.Lighting = false;

		S3DVertex Vertices[4];

		Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);
		Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);
		Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);
		Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);

		for (s32 i = 0; i<4; ++i)
			VertexBuffer->addVertex(&Vertices[i]);

		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(1);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(1);
		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(3);
		IndexBuffer->addIndex(2);
		IndexBuffer->addIndex(0);
		IndexBuffer->addIndex(1);

		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<4; ++i)
			Box.addInternalPoint(Vertices[i].Pos);

	}