Here is an example. It's a simple wall oder quad scene node I am using at my current project.
Code: Select all
class SceneNodeWall : public scene::ISceneNode
{
private:
video::S3DVertex2TCoords Vertices[4];
video::SMaterial Material;
core::aabbox3d<f32> Box;
public:
SceneNodeWall(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, Ambersun::byte X, Ambersun::byte Y, Ambersun::byte Width, Ambersun::AmberDirection Direction)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = true;
Material.MaterialType = video::EMT_SOLID;
Vertices[0] = video::S3DVertex2TCoords(0.0f, 0.0f, 64.0f, 0.0f,0.0f,1.0f, video::SColor(255,255,255,255), 0.0f,0.0f, 0.0f,0.0f);
Vertices[1] = video::S3DVertex2TCoords(Width * -64.0f, 0.0f, 64.0f, 0.0f,0.0f,1.0f, video::SColor(255,255,255,255), 1.0f,0.0f, 1.0f,0.0f);
Vertices[2] = video::S3DVertex2TCoords(Width * -64.0f, -128.0f, 64.0f, 0.0f,0.0f,1.0f, video::SColor(255,255,255,255), 1.0f,1.0f, 1.0f,1.0f);
Vertices[3] = video::S3DVertex2TCoords(0.0f, -128.0f, 64.0f, 0.0f,0.0f,1.0f, video::SColor(255,255,255,255), 0.0f,1.0f, 0.0f,1.0f);
setAutomaticCulling(scene::EAC_FRUSTUM_BOX);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
float PosX = X * (-64.0f);
float PosY = 0.0f;
float PosZ = Y * (64.0f);
switch(Direction)
{
case Ambersun::AmberDown:
default:
setPosition(core::vector3d<float>(PosX,PosY,PosZ));
break;
case Ambersun::AmberUp:
setRotation(core::vector3d<float>(180.0f, 0.0f, 180.0f));
setPosition(core::vector3d<float>(PosX - 64.0f, PosY, PosZ + 64.0f));
break;
case Ambersun::AmberRight:
setRotation(core::vector3d<float>(180.0f, 270.0f, 180.0f));
setPosition(core::vector3d<float>(PosX, PosY, PosZ + 64.0f));
break;
case Ambersun::AmberLeft:
setRotation(core::vector3d<float>(180.0f, 90.0f, 180.0f));
setPosition(core::vector3d<float>(PosX - 64.0f, PosY, PosZ));
break;
}
setVisible(true);
}
virtual void OnRegisterSceneNode()
{
if(IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[] = { 0,1,2, 2,3,0};
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 2);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(u32 i)
{
return Material;
}
void setMaterialTexture(video::ITexture* Texture)
{
Material.TextureLayer[0].Texture = Texture;
}
void setLightmapTexture(video::ITexture* Texture)
{
Material.MaterialType = video::EMT_LIGHTMAP;
Material.TextureLayer[1].Texture = Texture;
Material.TextureLayer[1].TextureWrap = video::ETC_CLAMP;
}
};
The important code is inside the constructor where the vertices get their infos.