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)
}
Code: Select all
buildScene(core::vector3df(0,0,0), 0);
Code: Select all
buildScene(core::vector3df(196,164,7), 0);
Scene(1) - First Call
Scene(2) - Second Call
Scene(2) - Second Call - NOT parent to Star
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();
*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
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
Any suggestions as to what I have overlooked which causes the undesirable output would be much appreciated.
G