Page 1 of 1

RPG game, mouse coordinates movement

Posted: Fri Feb 13, 2004 3:05 pm
by WromthraX
Hi, me and my friend are at the begining of an RPG game development with Irrlicht engine.

The game has an isometric-like 3d view with a camera that will move along side player.

I have lodead a mesh, with octtree that is sort of a map and i need help with next question:

How can I get the position on a mesh or in "space" where mouse is when left button is clicked? I would use that coordinates (x,y,z) to move the player there.

I have looked and found a function that returns 2d coordinates of mouse positoon but i cannot use it for 3d space.

If someone could write that piece of code or tell me how to do it. :roll:

Thanx in advance!

Posted: Fri Feb 13, 2004 3:34 pm
by keless
in iscenemanager->getcollisionmanager() you can then call something like getSceneNodeFromRay or something-- this will cast a ray into the scene and return a scene node if you pierce its bounding box.

from there, you can take the same ray, and do a test on a triangle selection based on the actual mesh of the model (not just it's bounding box), this will give you the individual triangle.

Posted: Fri Feb 13, 2004 5:38 pm
by WromthraX
Yes, but i don't have enough skill yet to write that on my own.. :(

What do i have to add for that to work, i just need to get the coordinates into a variable, i'll figure out the movement myself.

When someone clicks on "floor" scene node i want to get the position of click (the place where mouse has clicked in 3d space x,y,z coordinates) on that scene node and use it later to move "man" scene node there.

Will anyone do it, please?

Here is this simple code which i use for testing.

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

IrrlichtDevice* device = 0;

int main()
{

    device = createDevice(DT_OPENGL, dimension2d<s32>(800, 600), 32, false, false, 0);
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    
    IAnimatedMeshSceneNode* man = smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/man.3ds")); 
        man->setPosition(vector3df(0,0,0));

    IAnimatedMesh* floormesh = smgr->getMesh("data/floor.3ds");
    ISceneNode* floor = 0;
        if (floormesh)
            floor = smgr->addOctTreeSceneNode(floormesh->getMesh(0));
        if (floor)
            floor->setPosition(vector3df(0,0,0));

    smgr->addCameraSceneNode(0, vector3df(0,150,-150), vector3df(0,0,0));
 
    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,0,0,0));
        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();
    }

    device->drop();
	
    return 0;
}

Posted: Fri Feb 13, 2004 9:42 pm
by keless
no one will do it for you.

if you arent willing to learn to do the first thing, you'll never be able to do the second thing-- you may as well not pretend to be programming at all.

go practice more until you do have the skill, and come back.

sorry if that sounds to harsh.

Posted: Sat Feb 14, 2004 1:56 am
by DarkWhoppy
keless sounds harsh at times. But most of the time.. he's right. :lol:

Posted: Sat Feb 14, 2004 12:59 pm
by WromthraX
Ok, you are kind a right...

I've practiced :D and i figure out how to do collision detection and pick triangles with ray etc.. but..

How do I make the ray go thru the point where mouse clicked, and how to get position of the triangle i get couse ->GetPosition or .GetPosition doesn't work...

..or i already have the position in outColisionPoint in this function:

Code: Select all

virtual bool irr::scene::ISceneCollisionManager::getCollisionPoint  (  const core::line3d< f32 > &    ray,  
  ITriangleSelector *    selector,  
  core::vector3df &    outCollisionPoint,  
  core::triangle3df &    outTriangle 
 )  [pure virtual] 
...so i dont need to use the triangles i think, but again how to make ray go where i want it to...


Sorry if I'm asking too much, just direct me into the right direction :)

Bye.

Posted: Sat Feb 14, 2004 7:04 pm
by keless

Posted: Sat Feb 14, 2004 7:13 pm
by WromthraX
I found somethig about that function here in the forum but I was not able to find it in the help file a got with irrlich, maybe I have older version or something.

Thanks keless!