code of tile
Code: Select all
class HexTile : public scene::ISceneNode
{
aabbox3d<f32> Box;
S3DVertex Vertices[8];
SMaterial Material;
public:
terrainType ttype;
HexTile(ISceneNode* parent, ISceneManager* smgr, s32 id);
virtual void OnRegisterSceneNode();
virtual void render();
virtual const aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount() const;
virtual SMaterial& getMaterial(u32 i);
void setTexture(ITexture*);
void setTerrainType(terrainType);
};
HexTile::HexTile(ISceneNode* parent, ISceneManager* smgr, s32 id)
: ISceneNode(parent, smgr, id)
{
ttype = terrainType::grass;
/////////////////////////////////////////////////
Material.Wireframe = false;
Material.Lighting = false;
Material.setTexture(0, getTexture(ttype));
SColor color = SColor(255, 255, 255, 255);
// vertices of hexagons
for (int i = 0; i < 7; i++)
Vertices[i+1] = S3DVertex(hexVertices[2*i], 0.0f, hexVertices[2 * i + 1], 0, 0, 0, color, texture_uv[2 * i], texture_uv[2 * i + 1]);
Box.reset(Vertices[0].Pos);
for (s32 i = 1; i < 7; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
void HexTile::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
void HexTile::render()
{
u16 indices[] = { 0, 1, 2, /**/ 0, 2, 3, /**/ 0, 3, 4, /**/ 0, 4, 5, /**/ 0, 5, 6, /**/ 0, 6, 7 };
IVideoDriver* driver = smgr->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawVertexPrimitiveList(&Vertices[0], 3, &indices[0], 6, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
}
const aabbox3d<f32>& HexTile::getBoundingBox() const
{
return Box;
}
u32 HexTile::getMaterialCount() const
{
return 1;
}
SMaterial& HexTile::getMaterial(u32 i)
{
return Material;
}
void HexTile::setTexture(ITexture* tex)
{
Material.setTexture(0, tex);
}
void HexTile::setTerrainType(terrainType ttype)
{
this->ttype = ttype;
setTexture(getTexture(ttype));
}
Code: Select all
position2d < s32 > mousePos = device->getCursorControl()->getPosition();
cout << "mouse position: " << mousePos.X << ", " << mousePos.Y<<" - ";
core::line3d<f32> ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(mousePos, cam);
core::vector3df intersection;
core::triangle3df hitTriangle;
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
if (collMan != nullptr)
cout << "collman ok - ";
scene::ISceneNode* selectedSceneNode =
collMan->getSceneNodeAndCollisionPointFromRay(
ray,
intersection, // This will be the position of the collision
hitTriangle);// , // This will be the triangle hit in the collision
//0, // This ensures that only nodes that we have set up to be pickable are considered
//0); // Check the entire scene (this is actually the implicit default)
if (selectedSceneNode != nullptr)
cout << " | " << selectedSceneNode->getPosition().X << ", " << selectedSceneNode->getPosition().Y << endl;
else
cout << " node is null\n";