[fixed]may be it is a bug

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
wuallen
Posts: 67
Joined: Thu Jan 25, 2007 3:07 am
Location: Shanghai

[fixed]may be it is a bug

Post by wuallen »

dwarf = addAnimatedMeshSceneNode( meshOfdwarf );
weapon = addAnimatedMeshSceneNode( meshOfweapon );

dwaf->addChild(weapon);

engine will call render() of dwarf once, but render() of weapon many times.

I found this with irrlicht 1.4.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Please post your actual code. I'm not interested in guessing whether the bug is in Irrlicht or your usage of it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
wuallen
Posts: 67
Joined: Thu Jan 25, 2007 3:07 am
Location: Shanghai

Post by wuallen »

two many code to post.

Code: Select all


#include "mi_CGame.h"

using namespace irr;


int LEFT_MOUSE = 0;
int RIGHT_MOUSE = 1;

bool Keys[KEY_KEY_CODES_COUNT];
f32 MouseX;
f32 MouseY;
f32 MouseXold;
f32 MouseYold;
f32 MouseXspeed;
f32 MouseYspeed;
bool MouseKeyDown[3];
bool MouseKeyPress[3];

scene::IAnimatedMeshSceneNode* Weapon;
scene::IAnimatedMesh* Mesh_pistol;

core::array<CDwarf*> List_dwarf;

void reset_camera(scene::ICameraSceneNode* camera, core::vector3df& target)
{
	camera->setTarget(core::vector3df(target.X, target.Y+10, target.Z));
	camera->setPosition(core::vector3df(target.X, target.Y*8+10, target.Z+180));
}

core::vector3df get_move_matrix(const core::matrix4 &relativematrix, core::vector3df movevector)
{
	core::matrix4 tmpmatrix;
	tmpmatrix.setTranslation(movevector);
	return (relativematrix*tmpmatrix).getTranslation();
}

void set_relative_transformation(core::matrix4 matrix, scene::ISceneNode* node)
{
	node->setPosition(matrix.getTranslation());
	node->setRotation(matrix.getRotationDegrees());
	node->setScale(matrix.getScale());
}

void CGame::updateAll()
{
	Driver->beginScene(true, true, video::SColor(0,200,200,200));


	// update drawing
	if ((m_first_load_driver--) > 0)
	{
		m_lastTime = Timer->getRealTime();
	}
	
	s32 newtime = Timer->getRealTime();
	f32 deltaspeed = ((f32)(newtime - m_lastTime))*(60.0f/1000.0f);
	m_lastTime = newtime;


	CDwarf::updateAll(deltaspeed);

	Smgr->drawAll();
	
	Driver->endScene();
}


CGame::~CGame()
{ 
	// to do
	// ...
}
	
int CGame::setup()
{
	List_dwarf.reallocate(5);
	



	CDwarf* dwarf = new CDwarf();
	dwarf->m_isPlayer = true;
//	dwarf->attach(Weapon, "weapon2");
	dwarf->setup();

	
	List_dwarf.push_back(dwarf);

	return 0;
}

int CDwarf::attach(scene::IAnimatedMeshSceneNode* node, const c8* jointname)
{
	scene::ISceneNode* joint = m_node->getJointNode(jointname);
	if (joint == NULL)
		return -1;
	joint->addChild(node);
	m_attachNodeList.push_back(node);
	m_attachJointList.push_back(joint);
	return 0;
}

CDwarf::CDwarf()
	:	m_isPlayer(0),
		m_node(NULL),
		m_animation(0),
		m_node_animfeet(NULL),
		m_move_forward(0),
		m_move_sideways(0),
		m_move_shoot(0),
		m_move_yaw(0),
		m_move_pitch(0),
		m_yawReset(0),
		m_yaw(0),
		m_pitch(0),
		m_shootTimer(0),
		m_reloadTimer(0),
		m_gun_ammo(0),
		m_lastWalkFrame(0),
		m_ai_timer(0)
{}


int CDwarf::setup()
{
	m_attachNodeList.reallocate(5);
	m_attachJointList.reallocate(5);

	/* test 
	m_node = Smgr->addAnimatedMeshSceneNode(Mesh_dwarf);
	m_node->addShadowVolumeSceneNode(-1, true, 100.0f);
	Smgr->setShadowColor(video::SColor(150, 0, 0, 0));
	m_node->setPosition(core::vector3df(0, 60, -30));

	m_node->setLoopMode(true);
	m_node->setTransitionTime(0);
	m_node->setFrameLoop(368, 368+2);
	m_node->setAnimationSpeed(5); 
	/*/

	/*
	m_node_animfeet = Smgr->addAnimatedMeshSceneNode(Mesh_dwarf);
	m_node_animfeet->setVisible(false);
	m_node_animfeet->animateJoints(false);

	m_node_animfeet->setLoopMode(true);
	m_node_animfeet->setFrameLoop(292, 325);
	m_node_animfeet->setAnimationSpeed(5);
*/
	m_feetAnimation = -100;


/*
	s32 tmp;

	m_feetJointID.reallocate(8);
	
	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("lhip");
	if (tmp == -1) mi_debug("dwarf no lhip\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("lknee");
	if (tmp == -1) mi_debug("dwarf no lknee\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("lankle");
	if (tmp == -1) mi_debug("dwarf no lankle\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("ltoe");
	if (tmp == -1) mi_debug("dwarf no ltoe\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("rhip");
	if (tmp == -1) mi_debug("dwarf no rhip\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("rknee");
	if (tmp == -1) mi_debug("dwarf no rknee\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("rankle");
	if (tmp == -1) mi_debug("dwarf no rankle\n");
	m_feetJointID.push_back(tmp);

	tmp = reinterpret_cast<scene::ISkinnedMesh*>(Mesh_dwarf)->getJointNumber("rtoe");
	if (tmp == -1) mi_debug("dwarf no rtoe\n");
	m_feetJointID.push_back(tmp);
*/



	m_node = Smgr->addAnimatedMeshSceneNode(Mesh_dwarf);
	m_node->addShadowVolumeSceneNode(-1, true, 100.0f);
	Smgr->setShadowColor(video::SColor(150, 0, 0, 0));
	m_node->setPosition(core::vector3df(0, 60, -30));
	m_node->setName("dwarf");

	
	scene::ISceneNode* hand = m_node->getJointNode("weapon2");


	Mesh_pistol = Smgr->getMesh(MEDIA_PATH"dwarf/pistol.b3d");
	//Weapon = Smgr->addAnimatedMeshSceneNode(Mesh_pistol, hand);
	Weapon = Smgr->addAnimatedMeshSceneNode(Mesh_pistol);
	Weapon->setScale(core::vector3df(1.5, 1.5, 1.5));
	Weapon->setFrameLoop(1, 1);
	Weapon->setAnimationSpeed(4);
	//Weapon->setJointMode(scene::EJUOR_CONTROL);
	//Weapon->setPosition(core::vector3df(0, 30, -30));
	Weapon->setName("weapon");

	hand->addChild(Weapon);
	m_attachNodeList.push_back(Weapon);
	m_attachJointList.push_back(hand);



	//m_joint_gunEnd = Weapon->getJointNode("end");

	
	//Weapon->setParent(hand); 
 	//Weapon->setPosition(core::vector3df(0,0,0)); 
	// attach child
	
	m_joint_head = m_node->getJointNode("head");
	m_joint_spine2 = m_node->getJointNode("spine2");
	m_joint_spine3 = m_node->getJointNode("Joint75");

	m_node->setLoopMode(true);
	m_node->setTransitionTime(2);
	m_node->setFrameLoop(ANIM_DWARF_WALK);
	m_node->setAnimationSpeed(1);
	//m_node->setFrameLoop(ANIM_DWARF_HOLD_GUN);
	//m_node->setAnimationSpeed(1);
	
	m_animation = -100;

	m_lastWalkFrame = -1;
	m_gun_ammo = 6;
	//*/

	return 0;
}

void CDwarf::getUserInput(f32 deltaStep)
{
	// reset 
	m_move_forward = 0;
	m_move_sideways = 0;
	m_move_pitch = 0;
	m_move_yaw = 0;
	m_move_shoot = false;

	if (Keys[KEY_UP])
		m_move_forward = 1;
	else if (Keys[KEY_DOWN])
		m_move_forward = -1;

	if (Keys[KEY_LEFT])
		m_move_sideways= 1;
	else if (Keys[KEY_RIGHT])
		m_move_sideways = -1;	

	m_move_yaw = MouseXspeed*40;

	if (m_move_yaw > 1)
		m_move_yaw = 1;
	else if (m_move_yaw < -1)
		m_move_yaw = -1;

	if (MouseKeyDown[LEFT_MOUSE])
		m_move_shoot = true;
}

void CDwarf::getAIInput(f32 deltaStep)
{
	// reset 
	m_move_forward = 0;
	m_move_sideways = 0;
	m_move_pitch = 0;
	m_move_yaw = 0;
	m_move_shoot = false;

	// to do 
//	m_ai_timer += deltaStep;

	
}


void CDwarf::update(f32 deltaStep)
{
	
	if (m_isPlayer)
	{
		getUserInput(deltaStep);
	}
	else
	{
		// to do
		// getAIInput(deltaStep);
	}

	core::vector3df tmpposvector(0,0,0);
	core::vector3df tmprotvector(0,0,0);

	if (m_shootTimer > 0)
	{
		m_shootTimer -= deltaStep;
		if (m_shootTimer < 0)
			m_shootTimer = 0;
	}

	if (m_shootAnimTimer > 0)
	{
		m_shootAnimTimer -= 0.05f*deltaStep;
		if (m_shootAnimTimer < 0)
			m_shootAnimTimer = 0;
	}

	if (m_reloadTimer > 0)
	{
		m_reloadTimer -= deltaStep;
		if (m_reloadTimer < 0)
			m_reloadTimer = 0;
	}

	if (m_move_shoot)
	{
		// to do
		//
		//if (m_shootTimer==0 && m_reloadTimer==0)
		//{
		//	m_shootTimer = 30;
		//	m_shootAnimTimer = 1;
		//}
	}

	if (m_animation!=0 && m_reloadTimer==0)
	{
		m_animation = 0;
		m_node->setLoopMode(true);
		m_node->setTransitionTime(0);
		m_node->setFrameLoop(ANIM_DWARF_HOLD_GUN);
		m_node->setAnimationSpeed(1);
	}

	if (m_move_forward == 1)
	{
		tmpposvector += core::vector3df(0,0,(SPEED_DWARF_WALK/10.0f)*deltaStep);
		m_yawReset = m_yaw;

		if (m_feetAnimation != 1)
		{
			m_feetAnimation = 1;

			//m_node_animfeet->setTransitionTime(0.2f);
			//m_node_animfeet->setAnimationSpeed(15*100);
			//m_node_animfeet->setFrameLoop(ANIM_DWARF_WALK);
			//m_node->setTransitionTime(2.0f);
			m_node->setAnimationSpeed(SPEED_DWARF_WALK);
			m_node->setFrameLoop(ANIM_DWARF_WALK);
		}
	}
	else if (m_move_forward == -1)
	{
		tmpposvector += core::vector3df(0,0,-(SPEED_DWARF_WALK/10.0f)*deltaStep);
		m_yawReset = m_yaw;

		if (m_feetAnimation != -1)
		{
			m_feetAnimation = -1;

			//m_node->setTransitionTime(0.2f);
			m_node->setAnimationSpeed(-SPEED_DWARF_WALK_BACK);
			m_node->setFrameLoop(ANIM_DWARF_WALK);
		}
	}
	else
	{
		if (m_feetAnimation != 0 
			&& m_feetAnimation != 3 
			&& m_feetAnimation != 4 
			&& m_feetAnimation != 8
			&& m_feetAnimation != 9)
		{
			m_feetAnimation = 0;
			//m_node->setTransitionTime(2.0f);
			m_node->setFrameLoop(ANIM_DWARF_IDLE);
			m_node->setAnimationSpeed(5);
		}
	}

	// to do
	if (m_move_sideways == 1)
	{
		tmprotvector += core::vector3df(0, -7.0f*deltaStep, 0);
	}
	else if (m_move_sideways == -1)
	{
		tmprotvector += core::vector3df(0, 7.0f*deltaStep, 0);
	}
	else
	{

	}

	tmpposvector = get_move_matrix(m_node->getRelativeTransformation(), tmpposvector) - m_node->getPosition();

	core::triangle3df triout;
	bool outfalling;

	core::vector3df target = Smgr->getSceneCollisionManager()->getCollisionResultPosition(
		MapTriangleSelector, 					// selector
		m_node->getPosition(), 					// ellipseoid position
		core::vector3df(14, 3, 14), 			// ellipseoid radius
		tmpposvector, 							// ellipseoid direction and speed
		triout, 								// collision happen triangle
		outfalling,								// tell if falling
		0.0005f,								// sliding speed
		core::vector3df(0,-0.6f*deltaStep,0));	// gravity

	m_node->setPosition(target);

	// rotation
	core::vector3df tmprotvector2 = m_node->getRotation();

	tmprotvector2 += tmprotvector;

	m_node->setRotation(tmprotvector2 );

	m_node->animateJoints(true);
}
I only add two scene node, and use addChild(). I put some debug information in render() function, and I see dwarf node call render() once, and weapon node call render() many times.

but if I don't use addChild(), dwarf call render() once, and weapon node once too.
Baz
Posts: 11
Joined: Fri Jul 04, 2008 12:03 pm

Post by Baz »

hi!
i found this bug too.
addChild doesn't add just one child.

i make my model with this:

Code: Select all

		char path[256] = {0};

		sprintf(path,"%s\\lower.b3d",mdl);
		lower = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));

		jUpper = lower->getJointNode("torso");

		sprintf(path,"%s\\upper.b3d",mdl);
		upper = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path),jUpper);

		jHead = upper->getJointNode("head");
		sprintf(path,"%s\\head.b3d",mdl);
		head = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path),jHead);
you see, i attach upper to lower, and head to upper.
with attaching it's 32549 triangles.
without attaching, it's 3061 triangles (that's the correct)

i made my own "parenting"

Code: Select all

void Model::UpdateJoints()
{
	head->setPosition(jHead->getAbsolutePosition());
	upper->setPosition(jUpper->getAbsolutePosition());

	vector3df vrot = jUpper->getRotation();
	CMatrix4<f32> m = jUpper->getAbsoluteTransformation();
	m.transformVect(vrot);
	upper->setRotation(m.getRotationDegrees());

	vrot = jHead->getRotation();
	m = jHead->getAbsoluteTransformation();
	m.transformVect(vrot);
	head->setRotation(m.getRotationDegrees());
}
the creating is same as before, but without setting the parent.
and it's working (3061 triangles)
i don't think my source is correct, so please correct this bug :P
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The multiple renders were already addressed in a different thread...
Baz
Posts: 11
Joined: Fri Jul 04, 2008 12:03 pm

Post by Baz »

really? and where? xD
i searched for "multiple renders" but didn't found anything.
is there a solution?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Here (and possibly elsewhere) and yes, probably.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply