how to place an object where the mouse points

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: how to place an object where the mouse points

Post by nespa »

Code: Select all

void SchootBlocks(){
//scene::ITriangleSelector* selector;// see down
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
irr::core::position2d<s32> mousePosition= device->getCursorControl()->getPosition();
//da modificare la texture blocco in base all blocco che si e selezionato
IAnimatedMesh *blocco=smgr->getMesh("../../media/blocco.3ds");
IAnimatedMeshSceneNode *blocconode=smgr->addAnimatedMeshSceneNode(blocco,smgr->getRootSceneNode());
blocconode->setMaterialFlag(video::EMF_LIGHTING,false);
 
ISceneNode *planenode;//    here :  create and position your planenode, horizontal;
/** here : create a triangle selector and link the selector to your planenode;
ITriangleSelector* selector;
selector = SceneManager->createTriangleSelector(planenode->getMesh(),planenode); 
planenode->setTriangleSelector(selector);
or:
IMeshManipulator* meshManipulator = SceneManager->getMeshManipulator();
ITriangleSelector* selector;
selector = SceneManager->createOctTreeTriangleSelector(planenode->getMesh(),planenode,meshManipulator->getPolyCount(planenode->getMesh()));
planenode->setTriangleSelector(selector);
 
**/
 
 
 
//planenode->setTriangleSelector(selector); //done 
selector->drop();
core::line3d<f32> ray;
ray.start = cam->getPosition();
ray.end = ray.start + (cam->getTarget() - ray.start).normalize() * 10000.0f;// can be longer
core::vector3df intersection;
core::triangle3df hitTriangle;
scene::ISceneNode * outNode =collMan->getSceneNodeAndCollisionPointFromRay(
ray,
intersection, // This will be the position of the collision
 
hitTriangle, // This will be the triangle hit in the collision
1<<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)
blocconode->setPosition(intersection);
}
 
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: how to place an object where the mouse points

Post by belva1234 »

ISceneNode has no member named getMesh...
Non funziona merda...
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: how to place an object where the mouse points

Post by nespa »

Code: Select all

IAnimatedMesh* planemesh = SceneManager->addHillPlaneMesh("myHill",
                        dimension2d<f32>(100,100),
                        dimension2d<u32>(2,2),0,0,
                        dimension2d<f32>(0,0),
                        dimension2d<f32>(5.0f,5.0f));
IAnimatedMeshSceneNode* planenode = smgr->addAnimatedMeshSceneNode(planemesh);
 
 

it was an example from a wrapper, addapt to your needs
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: how to place an object where the mouse points

Post by belva1234 »

omgggggggggggggggggggggg it workkkkkkkkkkkkkkkkkkk i loveeeeeeeeeeeeeeeeeeeeeeee youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
BUTTTTTTTTTTT
if i move the camera the cube disappear
Non funziona merda...
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: how to place an object where the mouse points

Post by nespa »

make to move only at mouse click


goodluck!
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: how to place an object where the mouse points

Post by belva1234 »

I' ve set an event receiver when you press the right button starts the funtion
Non funziona merda...
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: how to place an object where the mouse points

Post by nespa »

an advice : need to have a bird eye over the Irrlicht;
1'st, go to the Irrlicht SDK and parse the include folder; there will see alls the Irrlicht's objects and their metodes;
2'nd, go to the Irrlicht examples and parse them, one by one.
If You know c++ as You told earlier, will be very eassy to start make your application with Irrlicht;
Post Reply