Problem with SceneNodes not displaying except at (0,0,0)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Granthus
Posts: 16
Joined: Mon Jan 22, 2007 8:04 am
Location: Australia
Contact:

Problem with SceneNodes not displaying except at (0,0,0)

Post by Granthus »

I will apologies up front if this is the wrong forum, and/or that this I fear will be a lengthy post.

Problem:
The code below performs the task is was designed for perfectly - except that when I use coordinates other than 0,0,0 origin, suddenly my planets stop displaying. I have double checked my output logs and the planets are there, and simply by unparenting them from the star they appear as expected.

Now while I have stepped the code countless times, double checked my data structures, verified the engines belief that the planets are there I cant get them to render - and I suspect it may be something rather simple I have overlooked :\

Offending Code:

Code: Select all

void T_Core::buildScene(core::vector3df secCoords, int sysNum)
{
	bool specSector;
	int numSystems;
	int cnt;
	T_Sector Sector = T_Galaxy::T_Galaxy().genSectorTmp(secCoords);
	T_System sSystem;
	T_Star sStar;
	T_Planet sPlanet;

	specSector = ( secCoords == core::vector3df(0,0,0) && sysNum == 0 ) ? true : false; 

	numSystems = (specSector) ? 1 : Sector.getSystemCount();
	//numSystems = 1;

	WriteLog("[-] =========================================");
	WriteLog("[?] Intro Sector Name: '%s'",Sector.getName());

	for (cnt = 0; cnt < numSystems; cnt++)
	{
		sSystem = Sector.getSystem(cnt);

		WriteLog("[?] System Name: '%s'", sSystem.getName());

		sStar = sSystem.getStar();

		// Lets try to create it
		WriteLog("[*] INIT System Draw");
		WriteLog("[-] -----------------------------------------");

		core::vector3df starPos;
		video::SColorf starCol;
		f32 lightRad;

		starPos = sStar.getCoords();
		starCol = sStar.color;
		lightRad = sStar.lightRadius;
		
		WriteLog("[-] -----------------------------------------");
		WriteLog("[*] CREATE STAR NODE (%s)", sStar.getName());
		WriteLog("[*] StarLightRadius (%f)", lightRad);

		// Generate STAR SceneNode
		scene::ISceneNode* ISNStar =	smgr->addLightSceneNode(0, starPos,	starCol, lightRad, TSYS_ID_STAR+cnt);

		WriteLog("[+] StarPos %d,%d,%d", (int)ISNStar->getPosition().X,(int)ISNStar->getPosition().Y,(int)ISNStar->getPosition().Z);

		//light2->setPosition(core::vector3df(0,0,0));
		scene::ISceneNode* bill;
		f32	starSize = (f32)sStar.getSize();
		WriteLog("[*] StarSize (%f)", starSize);
		// attach billboard to light
		bill = smgr->addBillboardSceneNode(ISNStar, core::dimension2d<f32>(starSize, starSize));
		bill->setMaterialFlag(video::EMF_LIGHTING, false);
		bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
		bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
		bill->setMaterialTexture(0, driver->getTexture("data/textures/particlewhite.bmp"));
		// add particle system
		scene::IParticleSystemSceneNode* ps = smgr->addParticleSystemSceneNode(false, ISNStar);
		// create and set emitter
		scene::IParticleEmitter* em = ps->createBoxEmitter(	core::aabbox3d<f32>(-3,0,-3,3,1,3),	core::vector3df(0.0f,0.0f,0.0f), 20,50, video::SColor(0,255,255,255), video::SColor(0,255,255,255),400,1100);
		em->setMinStartSize(core::dimension2d<f32>(20.0f, 30.0f));
		em->setMaxStartSize(core::dimension2d<f32>(20.0f, 30.0f));

		ps->setEmitter(em);
		em->drop();

		// create and set affector
		scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();
		ps->addAffector(paf);
		paf->drop();

		// adjust some material settings
		ps->setMaterialFlag(video::EMF_LIGHTING, false);
		ps->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
		ps->setMaterialTexture(0, driver->getTexture("data/textures/particle.bmp"));
		ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);

		ISNStar->setVisible(true);

		// ##[ Now Generate planets ]########################################
		if ( cnt == sysNum )
		{
			int j;
			int iCnt = sSystem.getPlanetCnt();

			systemCoords = sStar.getCoords();

			WriteLog("[*] Planet Node Count (%d)", iCnt);
			for (j = 0; j < iCnt; j++)
			{
				sPlanet = sSystem.getPlanet(j);
				WriteLog("[-] -----------------------------------------");
				WriteLog("[*] CREATE PLANET NODE ( %d: '%s' )", j, sPlanet.getName() );
				f32 scaleValue;
				f32 radiusValue;
				f32 speedValue;
				core::vector3df Pcoords;
				core::vector3df rotateValue;
				core::vector3df directValue;

				Pcoords = sStar.getCoords();
				scaleValue = (f32)(sPlanet.getSize()) / 15.0f; //
				radiusValue = sPlanet.radius;
				speedValue = sPlanet.speed / 2000.0f;
				rotateValue = sPlanet.rotation;
				directValue = sPlanet.direction;

				WriteLog("[*] Planet ScaleValue (%f)", scaleValue);
				WriteLog("[*] Planet RadiusValue (%f)", radiusValue);
				WriteLog("[*] Planet SpeedValue (%f)", speedValue);


				WriteLog("[ ] Load 'earth.x' Model (Planet)");
				scene::IAnimatedMesh * mesh;
				if ( radiusValue <= 150 )
				{
					WriteLog("    >> Load Earth RED  (%f)", radiusValue);
					mesh = smgr->getMesh("data/models/earthred.x");
				}
				else if ( radiusValue > 150 && radiusValue <= 220 )
				{
					WriteLog("    >> Load Earth NORM (%f)", radiusValue);
					mesh = smgr->getMesh("data/models/earth.x");
				}
				else
				{
					WriteLog("    >> Load Earth DEAD (%f)", radiusValue);
					mesh = smgr->getMesh("data/models/earthdead.x");
				}

				if (mesh)
				{
					//perform various task with the mesh manipulator
					scene::IMeshManipulator *manipulator = smgr->getMeshManipulator();

					// create mesh copy with tangent informations from original earth.x mesh
					scene::IMesh* tangentSphereMesh = manipulator->createMeshWithTangents(mesh->getMesh(0));

					// scale the mesh by factor 5
					core::matrix4 m;
					m.setScale ( core::vector3df(scaleValue,scaleValue,scaleValue) );
	//				m.setScale ( core::vector3df(8,8,8) );
					manipulator->transformMesh( tangentSphereMesh, m );

					scene::ISceneNode *sphere = smgr->addMeshSceneNode(tangentSphereMesh, ISNStar, ((cnt*10)+TSYS_ID_PLANET)+j);//
					//sphere->setMaterialFlag(video::EMF_LIGHTING, true);

	#ifdef _CREATOR
			core::vector3df bbcheck = sphere->getBoundingBox().getExtent();
			sphere->setDebugDataVisible(scene::EDS_BBOX);
			WriteLog("@@@ Planet getExtent() %f, %f, %f", bbcheck.X, bbcheck.Y, bbcheck.Z);
	#endif

						video::ITexture* earthNormalMap = driver->getTexture("data/textures/earthbump.bmp");
						driver->makeNormalMapTexture(earthNormalMap, 10.0f);
						sphere->setMaterialTexture(1, earthNormalMap);

						// adjust material settings
						sphere->setMaterialFlag(video::EMF_FOG_ENABLE, true);
						sphere->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
					// add rotation animator
					scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(rotateValue);
					sphere->addAnimator(anim);
					anim->drop();
					scene::ISceneNodeAnimator* anim2 = smgr->createFlyCircleAnimator(Pcoords, radiusValue, speedValue, directValue);
	//				scene::ISceneNodeAnimator* anim2 = smgr->createFlyCircleAnimator(core::vector3df(0,0,0), 125.0f, 0.00003f, core::vector3df(-0.1f, 0.9f, 0.f));
					sphere->addAnimator(anim2);
					anim2->drop();

					// To be sure
					//sphere->setVisible(true);

					// drop mesh because we created it with a create.. call.
					tangentSphereMesh->drop();

					//WriteLog("        - Update Absolute Position");
					//sphere->updateAbsolutePosition();
				} // END Valid Mesh
			} // END For Loop (numPlanets)
		} // END (cnt == sysNum)
	} // END For Loop (numSystems)
}

This function is called in 2 locations within the project. First time it sets a random solar system set at origin - eg.

Code: Select all

buildScene(core::vector3df(0,0,0), 0);
The second call sets a specific system based on the coords.

Code: Select all

buildScene(core::vector3df(196,164,7), 0);
Results:

Scene(1) - First Call
Image

Scene(2) - Second Call
Image

Scene(2) - Second Call - NOT parent to Star
Image

I am clearing any previous scenes using

Code: Select all

	camera = smgr->getActiveCamera();
	if (camera)
	{
		smgr->setActiveCamera(0);
		camera->remove();
		camera = 0;
	}
	smgr->getRootSceneNode()->removeAll();
prior to calling buildScene and the only things created after are a skydome and camera.

*EDIT* Sample Data - Scene(1)

Code: Select all

[-] =========================================
[?] Intro Sector Name: 'AA-0000.00'
[?] System Name: 'Ackda'
[*] INIT System Draw
[-] -----------------------------------------
[-] -----------------------------------------
[*] CREATE STAR NODE (Ho)
[*] StarLightRadius (1600.000000)
[+] StarPos 0,0,0
[*] StarSize (110.000000)
[*] Planet Node Count (4)
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 0: 'Andmasen' )
[*] Planet ScaleValue (5.333333)
[*] Planet RadiusValue (234.000000)
[*] Planet SpeedValue (0.000034)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth DEAD (234.000000)
@@@ Planet getExtent() 10.666667, 10.666667, 10.666667
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 1: 'Canfomi' )
[*] Planet ScaleValue (5.333333)
[*] Planet RadiusValue (158.000000)
[*] Planet SpeedValue (0.000035)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth NORM (158.000000)
@@@ Planet getExtent() 10.666667, 10.666667, 10.666667
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 2: 'Laio' )
[*] Planet ScaleValue (6.666667)
[*] Planet RadiusValue (295.000000)
[*] Planet SpeedValue (0.000038)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth DEAD (295.000000)
@@@ Planet getExtent() 13.333333, 13.333333, 13.333333
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 3: 'Soex' )
[*] Planet ScaleValue (7.333333)
[*] Planet RadiusValue (356.000000)
[*] Planet SpeedValue (0.000047)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth DEAD (356.000000)
@@@ Planet getExtent() 14.666667, 14.666667, 14.666667
Sample Data - Scene(2)

Code: Select all

[-] =========================================
[?] Intro Sector Name: 'TQ-0604.07'
[?] System Name: 'Negre'
[*] INIT System Draw
[-] -----------------------------------------
[-] -----------------------------------------
[*] CREATE STAR NODE (Hecan)
[*] StarLightRadius (1000.000000)
[+] StarPos 12955,11295,8246
[*] StarSize (150.000000)
[*] Planet Node Count (3)
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 0: 'Ackwa' )
[*] Planet ScaleValue (7.333333)
[*] Planet RadiusValue (224.000000)
[*] Planet SpeedValue (0.000028)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth DEAD (224.000000)
@@@ Planet getExtent() 14.666667, 14.666667, 14.666667
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 1: 'Nearmi' )
[*] Planet ScaleValue (5.333333)
[*] Planet RadiusValue (178.000000)
[*] Planet SpeedValue (0.000031)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth NORM (178.000000)
@@@ Planet getExtent() 10.666667, 10.666667, 10.666667
[-] -----------------------------------------
[*] CREATE PLANET NODE ( 2: 'Masioan' )
[*] Planet ScaleValue (8.000000)
[*] Planet RadiusValue (122.000000)
[*] Planet SpeedValue (0.000026)
[ ] Load 'earth.x' Model (Planet)
    >> Load Earth RED  (122.000000)
@@@ Planet getExtent() 16.000000, 16.000000, 16.000000
*phew*
Any suggestions as to what I have overlooked which causes the undesirable output would be much appreciated.

G
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I guess it's a culling problem...
e.g. if the star is the parent and get's out of sight it will be culled and all it's children, too !!! ;)
maybe disable culling for testing this...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Granthus
Posts: 16
Joined: Mon Jan 22, 2007 8:04 am
Location: Australia
Contact:

Post by Granthus »

Thanks for the reply Acki

While I am unable to test this now (Im at work) I am puzzled as to what could cause the culling to be a problem.

I say this because aside from the planets themselves, nothing else in the 'system' scene moves. ie planets orbit star, camera and star are stationary and are core::vector3df(300,0,0) apart.

I will however give this a try when back at my dev box.

G
Granthus
Posts: 16
Joined: Mon Jan 22, 2007 8:04 am
Location: Australia
Contact:

Post by Granthus »

Well I believe I have found the cause of my problem.

Line in Question:

Code: Select all

scene::ISceneNodeAnimator* anim2 = smgr->createFlyCircleAnimator(Pcoords, radiusValue, speedValue, directValue); 
In particular Pcoords. When my scene was at origin, this worked fine. I was however forgetting that the 'center' was relative coords to its parent :\

Thus I ended up with a star at 12955,11295,8246 and my planets orbiting some location (12955,11295,8246) away from the star (parent).

I have my Planets orbiting their parent star correctly .. now if only I can find why they arnt using the light from the star *sigh*

G
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Post by wITTus »

This is why you should include a lot of ready to use debug code. You can still delete it afterwards.

Code: Select all

#define IRR_VEC3DF_OUT(V) cerr << "\033[36m" << #V; cerr << "(\033[32m"<<V.X<<"f,"<<V.Y<<"f,"<<V.Z<<"f\033[0m)"<<endl;
\033[36m are color codes for the linux console. You can leave them out when developing for Windows.
Generated Documentation for BlindSide's irrNetLite.
"When I heard birds chirping, I knew I didn't have much time left before my mind would go." - clinko
Post Reply