Hi
If this is possible could you help me please
If i wanted to select an object that is in the 3d world how would i go about finding the coordinates of the mouse in the 3d world so i could select the object that is closest to the mouse
Cheers
DGEN XP
re. Finding the mouse coordinates in the 3d world
The mouse coordinates cannot be converted simply to a 3D position (because there is one dimension more). Instead, the mouse position can give you a ray that start from the camera position and goes 'inside' your screen. With that ray, you'll have to check for the collisions with other object.
Take a look at the function getRayFromScreenCoordinates from the ISceneCollisionManager. You can then use getCollisionPoint to check the collision with a triangle selector (constructed from a scene node).
Take a look at the function getRayFromScreenCoordinates from the ISceneCollisionManager. You can then use getCollisionPoint to check the collision with a triangle selector (constructed from a scene node).
Hi
Thank you for your quick reply
I have read the api and i am assuming that where pos is on the command i will need to place the x and y co-ordinates on the mouse position.
getRayFromScreenCoordinates ( core::position2d< s32 > pos, IsceneNode * camera = 0)
would i need to place the command in the while loop and now would i go by using this in my app
any further questions please post here.
Thank you for your quick reply
I have read the api and i am assuming that where pos is on the command i will need to place the x and y co-ordinates on the mouse position.
getRayFromScreenCoordinates ( core::position2d< s32 > pos, IsceneNode * camera = 0)
would i need to place the command in the while loop and now would i go by using this in my app
any further questions please post here.
What do you want to do exactly ? Select a node when you click on it probably (that seems the most logical to me) ?
Then, why don't you simply check when you click with the mouse ? Don't need to calculate this all the time in a loop.
Then, why don't you simply check when you click with the mouse ? Don't need to calculate this all the time in a loop.
I don't get you. Could you be more specific ?where pos is on the command i will need to place the x and y co-ordinates on the mouse position.
To simply select an object in a 3d world, you dont need to know a virtual 3d cord for your mouse, you just need to use a pick command on the 2d cords where your mouse is at. (If thats what you want to do, read on)
ISceneNode* selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(curs->getPosition());
were curs is your irrlicht cursor and smgr is your scene manager.
and thats all you have to do, to pick individual nodes, no fancy code
”Ì0D
Hope that helps!
ISceneNode* selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(curs->getPosition());
were curs is your irrlicht cursor and smgr is your scene manager.
and thats all you have to do, to pick individual nodes, no fancy code
”Ì0D
Hope that helps!
Hi Thank you again for your reply.
ok my software creates an array that contains all of the floor tiles that are in my scene i will paste the code following to this. i would like to be able to select nodes that are in the array by clicking on them in order to do this i thought that you may need to also store all of the coordinates of each tile in an array as well
the below equation is not exactly what i am going to do it is just a brief description of what i want it to do
MPOS.X < Tile(i).X + 512 ( X = MPOS.X - Tile(i).X - X +Tile(i).x )
Below is the code that defines and places the tiles
in the previous post by rambus how would i go about using it for my code
please ask if you have any more questions
cheers
DGENXP
ok my software creates an array that contains all of the floor tiles that are in my scene i will paste the code following to this. i would like to be able to select nodes that are in the array by clicking on them in order to do this i thought that you may need to also store all of the coordinates of each tile in an array as well
the below equation is not exactly what i am going to do it is just a brief description of what i want it to do
MPOS.X < Tile(i).X + 512 ( X = MPOS.X - Tile(i).X - X +Tile(i).x )
Below is the code that defines and places the tiles
Code: Select all
for (int Boxes = -Ammountofblocks*Ammountofblocks*1024*3; Boxes < 1024*Ammountofblocks*Ammountofblocks; Boxes+=1024)
{
nodes.push_back(smgr->addAnimatedMeshSceneNode(mesh));
}
// Initialise the created nodes
for (size_t i = 0; i < nodes.size(); ++i)
{
if (AblocksLine >= Ammountofblocks*1024) {Ablocksdown += 1024;AblocksLine =-Ammountofblocks*1024;}
nodes[i]->setMaterialFlag(EMF_LIGHTING, true);
nodes[i]->setMaterialTexture( 0, driver->getTexture("Objects/Floor10.jpg") );
nodes[i]->setPosition(vector3df(AblocksLine,0,Ablocksdown));
nodes[i]->setMaterialFlag(EMF_FOG_ENABLE,true);
AblocksLine +=1024;
//nodes[i]->setDebugDataVisible(true);
Tempy[i]=Ablocksdown ;
Tempx[i]=AblocksLine-1024;
}
please ask if you have any more questions
cheers
DGENXP
hi,
i want to get a the point on a node from my mouse cursor position. i did like explained above and wrote this code:
but it says
greets,
halan
i want to get a the point on a node from my mouse cursor position. i did like explained above and wrote this code:
Code: Select all
line3d<f32> line = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(device->getCursorControl->getPosition(), pCamera);but isnt everything in my code a pointer?206 C:\Dokumente und Einstellungen\Kai\Eigene Dateien\age of war\Editor\main.cpp invalid use of member (did you forget the `&' ?)
206 C:\Dokumente und Einstellungen\Kai\Eigene Dateien\age of war\Editor\main.cpp base operand of `->' is not a pointer
greets,
halan
My Blog: http://www.freakybytes.org
getCursorControl is a function. You need to put parens after it so the compiler knows you are trying to call the function...
Code: Select all
device->getCursorControl()->getPosition();