Page 1 of 1

Collision detection

Posted: Mon Jul 05, 2004 11:45 am
by joy
Just the next wonderful amazing post to the topic collision detection :wink:

After having some other stuff done I decided to try the collision detection again which I had already problems with (topic: http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2895). Anyway it still doesn't work. I tried to reduce the code as far as possible (using saigumis orthographic tutorial) and even don't use the orthographic view anymore.
That's left :

#include <irrlicht.h>
int main(){
irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_DIRECTX8, irr::core::dimension2d<irr::s32>(512, 384), 16, false, false, 0);
device->getFileSystem()->addZipFileArchive("lb.zip",true,true);
device->getFileSystem()->addZipFileArchive("Release/lb.zip",true,true);
device->getFileSystem()->addZipFileArchive("lb.zip",true,true);

device->setWindowCaption(L"Orthogonal Demo");

irr::video::IVideoDriver* driver = device->getVideoDriver();
irr::scene::ISceneManager* smgr = device->getSceneManager();

irr::scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0,irr::core::vector3df(0.0f, 0.0f, 1.0f),irr::core::vector3df(0,0,0));

irr::scene::ISceneNode* marker = smgr->addAnimatedMeshSceneNode(smgr->getMesh("tile_3.ms3d"),0,-1,irr::core::vector3df(1.0f,0.0f,-1.0f),irr::core::vector3df(0.0f,0.0f,0.0f));
marker->setMaterialTexture(0, driver->getTexture("dummy.bmp"));
marker->setMaterialFlag(irr::video::EMF_LIGHTING, false);

irr::core::position2d<irr::s32> cursorPos = device->getCursorControl()->getPosition();
irr::scene::ISceneCollisionManager* pSCollMan = device->getSceneManager()->getSceneCollisionManager();
irr::scene::ISceneNode* selectedNode = pSCollMan->getSceneNodeFromScreenCoordinatesBB(cursorPos,1);

if (selectedNode != NULL)
{
int i=1;
}


while(device->run()) {
driver->beginScene(true, true, irr::video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
}

device->drop();
return 0;
}


The red section is what I added. The problem is that it doesn't matter where my mousepointer is; it always finds a scenenode. May be someone could try it himself and say if he has the same problem. Or maybe the error is obvious, then I would be glad for any suggestions.

Thank you in advance.

Posted: Tue Jul 06, 2004 2:50 am
by thesmileman
When you make your call to "getSceneNodeFromScreenCoordinatesBB()" you are outside of the main loop so therefore the engine is only going to check at initilization. Move that code into the main loop and it will check dynamically.

What is happening is that Irrlicht is checking right after you load the model to the middle of the screen and your mouse would be there because it has just been created and not moved. You never change this result because there is not code in the main loop.

Posted: Tue Jul 06, 2004 9:25 am
by joy
Do you mean like this? :

Code: Select all

while(device->run()) {
        irr::core::position2d<irr::s32> cursorPos = device->getCursorControl()->getPosition(); 
        irr::scene::ISceneCollisionManager* pSCollMan = device->getSceneManager()->getSceneCollisionManager();
        irr::scene::ISceneNode* selectedNode = pSCollMan->getSceneNodeFromScreenCoordinatesBB(cursorPos,1);
        
        if (selectedNode != NULL)
        {
            int i=1;
        }
   
		driver->beginScene(true, true, irr::video::SColor(0,100,100,100));
		smgr->drawAll();
		driver->endScene();
	}
the same thing. It finds the object even if the mouse pointer is not on the object. Try it yourself...

Is this a bug in the getSceneNodeFromScreenCoordinatesBB function?

Posted: Wed Jul 07, 2004 10:26 am
by joy
Anyone?

Posted: Thu Jul 08, 2004 11:45 am
by warui
Works fine for me. Can you send me lb.zip or put it on a webpage or something like that ? Maybe problem is with the mesh.

And try to change rendering device to OpenGL, because it's what i'm using.

Posted: Thu Jul 08, 2004 11:48 am
by warui
my email: waru before @ and ravcio.retsat1.net after.

Posted: Thu Jul 08, 2004 12:54 pm
by joy
Thank you so much for your offer, I will send you some of my meshes (they are most of the cases .obj). With opengl the problem is getting better , but it is not gone. in that example there is a point under the real mesh, where it finds also the mesh. Besides that point it works fine with that mesh.

Thank you again, that is so nice of you!!!! :D :D :D

sorry about that lb.zip, I have never worked with that besides with the one saigumi uses in his tutorial orthogonal, because normally I just use single meshes to create 3D buttons. But I will send xou the lb.zip too.

Posted: Sat Jul 10, 2004 6:12 pm
by i2k
joy wrote:Do you mean like this? :

Code: Select all

while(device->run()) {
        irr::core::position2d<irr::s32> cursorPos = device->getCursorControl()->getPosition(); 
        irr::scene::ISceneCollisionManager* pSCollMan = device->getSceneManager()->getSceneCollisionManager();
        irr::scene::ISceneNode* selectedNode = pSCollMan->getSceneNodeFromScreenCoordinatesBB(cursorPos,1);
        
        if (selectedNode != NULL)
        {
            int i=1;
        }
   
		driver->beginScene(true, true, irr::video::SColor(0,100,100,100));
		smgr->drawAll();
		driver->endScene();
	}
the same thing. It finds the object even if the mouse pointer is not on the object. Try it yourself...

Is this a bug in the getSceneNodeFromScreenCoordinatesBB function?
has written the code, but beside me problems, than is further
found object, that he does not stand out.

See on this: Download

Posted: Mon Jul 12, 2004 8:56 am
by joy
Hi, thank you for answering, but I didn't understand your command very good *sorry* :oops:
When I press on Download I come to a Russian page which I don't understand. Did you mean, that I should download http://www.compilers.narod.ru/i2k.Cult.zip to see how you solved the problem?

Thank you

Posted: Mon Jul 12, 2004 9:14 pm
by i2k
joy wrote:Hi, thank you for answering, but I didn't understand your command very good *sorry* :oops:
When I press on Download I come to a Russian page which I don't understand. Did you mean, that I should download http://www.compilers.narod.ru/i2k.Cult.zip to see how you solved the problem?

Thank you
Hi.

Sorry, download from hear:
Click Hear

Posted: Tue Jul 13, 2004 7:52 am
by joy
Thank you for posting your meshes. I inserted them into the code above and they were drawn fine! -BUT the collision detection still won't work right .

I am very confused. As it works with you guys and my code is not wrong I have no idea why my collision detection won't work! :cry: :cry:

I additionally see that the collision detection works worse using different renderer. With the software renderer and openGL it works ok (I mean about 80% right) and with DirectX not at all (about 99% of the cases wrong). I seems that it has to do with something like that but probably not with the code (but I am not sure at all, it is very very odd and very enoying, because I need this feature!!!)

Posted: Tue Jul 13, 2004 8:44 am
by joy
By the way I tried your main.exe and it worked fine... could you give me your code so that I can build my own one with just your code?

Posted: Tue Jul 13, 2004 5:26 pm
by Guest
joy wrote:By the way I tried your main.exe and it worked fine... could you give me your code so that I can build my own one with just your code?
Give me you're mail or isq and We Agree about this.
(If I all it is correct has translated)
My mail : i2k@yandex.ru
My isq : 349581313

Posted: Wed Jul 14, 2004 7:24 am
by joy
send you a mail today :)

Are there any specific project setting I have to set, so that it would work?