I've been trying to do collision tests on a tiles attached to the SceneManager. I just migrated the tiles from square tiles to isometric tiles. However the bounding boxes for these tiles still resemble the bounding boxes for square ones. I'm not exactly sure about this but even with TriangleSelectors on those individual TileNodes, I'm still unable tp pick them properly. The picking of the tiles is closer to picking the bounding boxes of the tiles then the triangles that make them up.
I'm thinking that getSceneNodeFromScreenCoordinatesBB tests the bounding boxes, but I'm not exactly sure. If this is the case is there anything I can do to pick the SceneNode from Coordinates and have them tested with the TriangleSelector's?
(TileNode.h)
Code: Select all
#pragma once
#include "precompiled.h"
class TileNode : public scene::ISceneNode
{
private:
static scene::SMeshBuffer Buffer;
static scene::SMesh Mesh;
video::SMaterial Material;
public:
TileNode(float size, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
~TileNode(void);
// Rendering Functions
void OnRegisterSceneNode();
void render();
// SceneNode Functions
const core::aabbox3d<f32>& getBoundingBox() const;
u32 getMaterialCount() const;
video::SMaterial& getMaterial(u32 num);
// TileNode Functions
void setTileSize(float size);
};
Code: Select all
#include "precompiled.h"
#include "TileNode.h"
scene::SMeshBuffer TileNode::Buffer;
scene::SMesh TileNode::Mesh;
TileNode::TileNode(float size, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
: scene::ISceneNode(parent, mgr, id)
{
// setup buffer
if(Buffer.Vertices.empty())
setTileSize(size);
// setup material
Material.Wireframe = false;
Material.Lighting = false;
Material.BackfaceCulling = false;
// setup triangle selector
scene::ITriangleSelector* triSel = SceneManager->createTriangleSelector(&Mesh, this);
this->setTriangleSelector(triSel);
triSel->drop();
}
TileNode::~TileNode(void)
{
}
void TileNode::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
}
void TileNode::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(Buffer.Vertices.const_pointer(), Buffer.Vertices.size(), Buffer.Indices.const_pointer(), Buffer.Indices.size() / 3);
}
const core::aabbox3d<f32>& TileNode::getBoundingBox() const
{
return Buffer.getBoundingBox();
}
u32 TileNode::getMaterialCount() const
{
return 1;
}
video::SMaterial& TileNode::getMaterial(u32 num)
{
return Material;
}
void TileNode::setTileSize(float size)
{
float half = size / 2;
Buffer.Vertices.clear();
Buffer.Indices.clear();
Buffer.Vertices.push_back(video::S3DVertex(0,half,0, 0,0,0,0xFFFFFFFF, 0,.5));
Buffer.Vertices.push_back(video::S3DVertex(half,0,0, 0,0,0,0xFFFFFFFF, .5,0));
Buffer.Vertices.push_back(video::S3DVertex(half,size,0, 0,0,0,0xFFFFFFFF, .5,1));
Buffer.Vertices.push_back(video::S3DVertex(size,half,0, 0,0,0,0xFFFFFFFF, 1,.5));
Buffer.Indices.push_back(0);
Buffer.Indices.push_back(1);
Buffer.Indices.push_back(2);
Buffer.Indices.push_back(2);
Buffer.Indices.push_back(1);
Buffer.Indices.push_back(3);
Buffer.recalculateBoundingBox();
Mesh.MeshBuffers.clear();
Mesh.addMeshBuffer(&Buffer);
Mesh.recalculateBoundingBox();
}
Code: Select all
for (y = 0; y < mapFile.GetHeight(); y++) {
fy = (y-10) * halfTileSize;
for (x = 0; x < mapFile.GetWidth(); x++) {
id = (y+1) * 100 + x;
if(y % 2) fx = (x-10) * tileSize;
else fx = (x-10) * tileSize + halfTileSize;
if (mapFile.GetMap(x, y)) {
cube = new TileNode(tileSize, GetScene()->getRootSceneNode(), GetScene(), id);
cube->setPosition(vector3df(fx, fy, 0));
cube->setMaterialTexture(0, m_driver->getTexture("Textures/tile32.png"));
} else {
cube = new TileNode(tileSize, GetScene()->getRootSceneNode(), GetScene(), id);
cube->setPosition(vector3df(fx, fy, 0));
cube->setMaterialTexture(0, m_driver->getTexture("Textures/tile32blue.png"));
}
cube->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
cube->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
cube->setMaterialFlag(EMF_TRILINEAR_FILTER, true);
cube->setMaterialFlag(EMF_BILINEAR_FILTER, true);
cube->setMaterialFlag(EMF_LIGHTING, false);
}
}