parenting troubles(Now with screens)

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
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

parenting troubles(Now with screens)

Post by Xenxe »

no this does not have to do with real HUMAN CHILDREN!!!

ok i put the pistol in front of the camera i can see it WHEN IT IS NOT PARENTED but when it is I cant see it.

my assumption is that the pistol is automatically put at the cameras center when i parented it so can i move with it but can i set its position while its parented? so i can see it


ok here is my code

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif


int main()
{
	


	IrrlichtDevice *device =
		createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480), 16, false);
		
	
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	
	device->getFileSystem()->addZipFileArchive("../media/map-20kdm2.pk3");

	
	scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
	scene::ISceneNode* q3node = 0;

	scene::IAnimatedMesh* pistol = smgr->getMesh("../media/pistol.3ds");
	scene::ISceneNode* pistolnode = 0;

	if (q3levelmesh)
		q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));

	if (pistol)
		pistolnode = smgr->addOctTreeSceneNode(pistol->getMesh(0));



	

	scene::ITriangleSelector* selector = 0;
	pistolnode->setPosition(core::vector3df(5,17,10));
	if (q3node)
	{		
		q3node->setPosition(core::vector3df(-1350,-140,-1410));

		selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
		q3node->setTriangleSelector(selector);
	}


	
	scene::ICameraSceneNode* camera = 
		smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
	camera->setPosition(core::vector3df(0,50,0));

	if (selector)
	{
		scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
			selector, camera, core::vector3df(30,50,30),
			core::vector3df(0,-3,0), 
			core::vector3df(0,50,0));
		selector->drop();
		camera->addAnimator(anim);
		anim->drop();
	}

	
	

	device->getCursorControl()->setVisible(false);

	scene::ISceneNode* selectedSceneNode = 0;
	scene::ISceneNode* lastSelectedSceneNode = 0;

	pistolnode->setParent(camera);
	
	int lastFPS = -1;

	while(device->run())
	if (device->isWindowActive())
	{
	
		driver->beginScene(true, true, 0);

		smgr->drawAll();
	
		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
		  core::stringw str = L"test[";
		  str += driver->getName();
		  str += "] FPS:";
		  str += fps;

		  device->setWindowCaption(str.c_str());
		  lastFPS = fps;
		}
	}

	device->drop();
	
	return 0;
}

Last edited by Xenxe on Sat Feb 02, 2008 2:35 am, edited 1 time in total.
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Yes, when parenting the child's position is relative to its parent.
You should set the pistol's position few units in front (Z axis) of the camera and that should do it.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

how?
you see i have already put it in front of the camera im sure of it ill upload a screenshot when i can right now im having photobucket probs

here
Image
this is me with out pistolnode->setParent(camera)

the black thing is my pistol (This is only a test this is not the actual pistol model that im goin to put in the game)

ps im sorry for low bandwidth users for the unbearibly large picture

now with the parent
Image
PISTOLS GONE!!!

so how do i move the pistol in front of me while its parented
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

this is just so people will look at it again
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Try to

Code: Select all

camera->setNearValue(0.01f);
(it may helps)

P.S.: also try to move pistol node more away from the camera until you can see it. than step-by-step decrease the distance.
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

that is for clipping distance witch i beleive is how far away till i start clipping polys from veiw so the FPS is bigger

and this does not help with my parenting issues
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

First, don't add the pistol as octreenode. Those should be used for large static geometry (like your level). A normal node will do.

Then, did you try to set the position after you added the pistol to the camera? Because currently you set the position relativ to it's old parent (though I'm not really sure here, as maybe it won't be updated yet). Well, just try setting it later.

And then I guess it's too close, the near-clipping plane will probably clip it (edit: someone mentioned it already, but I guess you only know about the far-clipping plane. There's another one clipping objects which are close-up).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

yes i tried positioning after parenting before i even posted this i at least try to solve my problems before i post them!!!
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Your code as posted seems to work fine. Try replacing pistol.3ds with (e.g.) faerie.md2 from the sample media, and you should see it working.

From that, I'd suggest that perhaps the issue is with your pistol model itself; the geometry may be offset in model space to the extent that it's outside the camera's frustum.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

dontworry about this i solved it
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

maybe i'm late, but this:

Code: Select all

scene::ICameraSceneNode *cam = irrScene->addCameraSceneNodeFPS();

	scene::ISceneNode *gun = irrScene->addCubeSceneNode(10, cam);
	gun->setScale(vector3df(0.5,0.5,1.0));
	gun->setPosition(vector3df(8,-5,15));

	irrScene->addCubeSceneNode(100);
Produces this:
Image

p.s.: simple and working.
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

hmmm ill try that your way is nicer
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
Post Reply