RPG game, mouse coordinates movement

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.
Post Reply
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

RPG game, mouse coordinates movement

Post 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!
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post 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.
a screen cap is worth 0x100000 DWORDS
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

Post 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;
}
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post 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.
a screen cap is worth 0x100000 DWORDS
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

keless sounds harsh at times. But most of the time.. he's right. :lol:
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

Post 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.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

a screen cap is worth 0x100000 DWORDS
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

Post 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!
Post Reply