I searched alot on the forums on this issue, and found alot of posts about it, but still cant get it to work. Clicking on a node and getting it to move an so on is easy with "getSceneNodeAndCollisionPointFromRay". Problem is i cant access a custom nodes properties : / Maybe im doing it totally wrong..
Edit: Problem is that the references to the Item gets random values only.
The node class. The Item class inherits the 2ISceneNode" class
Code: Select all
#include "Stone.h"
#include <irrlicht.h>
#include "Main.h"
using namespace irr;
using namespace video;
using namespace scene;
Stone::Stone(ISceneNode* parent, ISceneManager* irrScene, s32 id)
: Item(parent, irrScene, id)
{
setWeight(1);
setType(IT_COMPONENT);
setName(L"Stone");
setDescription(L"A big stone");
}
Stone::~Stone(void)
{
}
void Stone::Create(ISceneManager* irrScene, IVideoDriver * irrVideo, f32 xPos, f32 yPos, f32 zPos)
{
ITriangleSelector* meshSelector = 0;
IMesh * mesh = irrScene->getMesh("T:/Game project/Files/Models/Stone.ms3d");
ISceneNode* stone = irrScene->addMeshSceneNode(mesh,0, MT_ITEM, vector3df(xPos, yPos, zPos),
vector3df(0,100,0),vector3df(9.0F,9.0F,9.0F));
stone->setMaterialFlag(EMF_LIGHTING, false);
meshSelector = irrScene->createTriangleSelector(mesh,stone);
stone->setTriangleSelector(meshSelector);
meshSelector->drop();
}Code: Select all
Item::Item(ISceneNode* parent, ISceneManager* irrScene, s32 id)
Code: Select all
void EventReceiver::EventLeftUp(void)
{
leftButtonDown = false;
vector3df intersection;
triangle3df hitTriangle;
line3d<f32> ray;
ray.start = camera->getPosition();
ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 300.0f;
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, // Check all
0); // Check the entire scene (this is actually the implicit default)
if(selectedSceneNode)
{
if(selectedSceneNode->getID() == MT_TREE)
{
//selectedSceneNode->setRotation(vector3df(90,90,0));
//((Tree*)selectedSceneNode)->setCut(true);
chatList->addItem(stringw(((Tree*)selectedSceneNode)->getHp()).c_str());
}
else if(selectedSceneNode->getID() == MT_ITEM)
{
myPlayer->AddItem((Item*)selectedSceneNode);
}Code: Select all
bool Player::AddItem(Item * newItem)
{
if(invCounter < 99)
{
char temp[5];
char temp3[40] = "Total weight: ";
inventory->Append(newItem);
invTree->addRow(invCounter);
invTree->setCellText(invCounter,0,newItem->getName());
sprintf(temp, "%.1f", newItem->getWeight());
invTree->setCellText(invCounter,1,temp);
totalWeight += inventory->Look(invCounter)->getWeight();
invCounter++;
sprintf(temp, "%.1f", totalWeight);
strcat(temp3, temp);
strcat(temp3, "kg / 100kg");
weightText->setText(stringw(temp3).c_str());
return true;
}
else
return false;
}