addChild Problem

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
reetu.raj
Posts: 17
Joined: Wed Aug 27, 2008 5:11 pm
Location: Orlando
Contact:

addChild Problem

Post by reetu.raj »

I am making a card game which has columns like solitaire(Image attached). So I have 10 parents node in a array of 10 called ISceneNode* thenode[10].
Now I am trying to set new child cards to them but it gives me problem, meaning it sets first child row at the right position but they rest of children row are at wrong position.

I am finding the last child in the children list of parent node thenode[j]
by doing

Code: Select all

last_node->setPosition(vector3df(node_pos_x,node_pos_y,node_pos_z));
parent_node=thenode[i];
list_node=(ISceneNode*)(*parent_node->getChildren().getLast());
and then adding the child to that last node by doing

Code: Select all

list_node->addChild(last_node);
Problem 1 :: Now as I am setting last_node as childnode of list_node not the parent node so the coordinates must be wrt to list_node but that doesnt work so, I had to set coordinates of new node (called last_node) wrt the parent node (thenode[j]) ... as written in the code below . so instead of setting node_pos_z= -11(setting wrt list_node).... I had to set it like node_pos_z= -((11*cards_per_col)+50);(setting wrt parent node called thenode[j]). If I set node_pos_z= -11, it makes the new child cards just overlap each other instead of keeping them proper distance.

Whys that happening ?? :((

Problem 2 ::First time this fucntion set_new_row(int level) is called, it sets the new child card at right distance from last child of that particular column but when I call this function second time or third time , it messes up the distance .
I havent been able to figure out either :(( , Please help me .
Image
Thanks a lot !

Code: Select all

void set_new_row(int level)
{
	ISceneNode* last_node;	
	ISceneNode* parent_node;	
	ISceneNode* list_node;	
	int node_pos_x=0;
	int	node_pos_y=0;
	int	node_pos_z=0;
	ITexture* halfchild_texture = driver->getTexture("media_jpg/b1pt.jpg");
	ITexture* fullchild_texture;
	
	int ran_num;
	char buffer[30];
	char *texture_name=new char[20];
	
	

	for(int i=0;i<10;i++)
	{
		
		ran_num=non_rep_rand_num();
		texture_name=texture_file(texture_name,ran_num,level);
		sprintf_s(buffer,30,"media_jpg/%s",texture_name);
		fullchild_texture = driver->getTexture(buffer);
		node_pos_x=0;
		node_pos_y=cards_per_col[i];
		node_pos_z=-((11*cards_per_col[i])+50);
		printf("node_pos_z==\n",node_pos_z);
		last_node=smgr->addMeshSceneNode(full_cards_mesh);
		last_node->setMaterialFlag(EMF_LIGHTING, false);
		last_node->setMaterialTexture(0,fullchild_texture);
		last_node->setPosition(vector3df(node_pos_x,node_pos_y,node_pos_z));
		parent_node=thenode[i];
		list_node=(ISceneNode*)(*parent_node->getChildren().getLast());
		list_node->addChild(last_node);
		cards_per_col[i]=cards_per_col[i]+1;
	}
			
			
	return;
}
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Sorry, life's too short to try and decipher this problem. I'll happily debug a compilable, runnable app with all required resources though.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
reetu.raj
Posts: 17
Joined: Wed Aug 27, 2008 5:11 pm
Location: Orlando
Contact:

Post by reetu.raj »

lol :D
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I don't know exactly what the problem is, but it seems that a simple (and obvious) solution to the card placement issue would be to use the scene graph to your advantage.

When you put a card onto a stack, parent the new card to the topmost card on the stack. Every card could then use the same offset from parent, so when moving cards to other stacks you wouldn't need to modify the positions of each card, only the one that is actually being moved. All of the child cards will move with the parent.

To make that all a little simpler, you might want to make your thenode array point to the top elements of the stacks instead of the bottom ones.

Travis
reetu.raj
Posts: 17
Joined: Wed Aug 27, 2008 5:11 pm
Location: Orlando
Contact:

Post by reetu.raj »

Solved it :D
Now using list of ISceneNode and there was minor mistake in formula for z coordinate in my code.
Post Reply