problems with AnimatedMeshSceneNode and HillPlaneMesh

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
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

problems with AnimatedMeshSceneNode and HillPlaneMesh

Post by Ulf »

Is there something wrong with this code?
I can't get the hillplanemesh to draw on the screen.

Code: Select all

irr::scene::IAnimatedMesh* bgMesh = 
	scene->addHillPlaneMesh( "background", irr::core::dimension2df(1024,512), irr::core::dimension2du(1,1) );
if ( bgMesh )
{
	irr::scene::ISceneNode* bgNode = scene->addAnimatedMeshSceneNode( bgMesh );

	bgNode->setMaterialTexture( 0, driver->getTexture("../Irrlicht/media/skydome2.jpg") );
	bgNode->setMaterialFlag( irr::video::EMF_LIGHTING, false );
	bgNode->setMaterialType( irr::video::EMT_SOLID );
}
What have I missed?

I set up an ortho projection as follows

Code: Select all

irr::scene::ICameraSceneNode* camera = scene->addCameraSceneNode();
scene->setActiveCamera( camera );

//! setup the projection matrix
irr::core::matrix4 projMatrix;
projMatrix.buildProjectionMatrixOrthoLH(640.f, 480.f, -1000.f, 1000.f);
camera->setProjectionMatrix(projMatrix);

//! setup the view matrix
camera->setTarget(irr::core::vector3df(0,0,0));
camera->setPosition(irr::core::vector3df(0,0,-1000));
camera->updateAbsolutePosition();
I set the active camera correctly. The following billboard works

Code: Select all

billNode = scene->addBillboardSceneNode( 0, irr::core::dimension2df(50, 50) );
billNode->setMaterialFlag( irr::video::EMF_LIGHTING, false );
billNode->setMaterialType( irr::video::EMT_TRANSPARENT_ADD_COLOR );
billNode->setMaterialTexture( 0, driver->getTexture("../Irrlicht/media/particlewhite.bmp") );
I finally decided to start using the 3D to create my 2D games/game engine. Start from scratch. I gotta say, it was crazy going the other way plus making my own physics system. Besides all the 2D problems, when I got to collision response I realised that I am making things impossible *tearing my hair out* :roll:
I decided to start using better and available options. But it was a great learning experience. A good warm-up.

So, I am trying to create a 2D background with an IAnimatedMeshSceneNode and IAnimatedMesh.
I thought I would create it and not add it to the scene manager. Then I'll call draw on the background scene node manually, then call scene->drawAll() to ensure the background gets drawn first.

Does this sound sensible and viable?

I could use a billboard for my 2D game objects. Is that the ideal way to do it?
Or would it be more efficient if I used a mesh and mesh scene node because I will be setting up the camera as ortho projection so I actually don't need the billboard (billboard set's the projection on every draw call).
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

I found the problem. I had to rotate the node by 270 degrees on the x axis. But this still leaves me a bit confused as I have set up the projection as ortho.

Is a plane mesh geometry flat on the z-axis and spanning the x and y axis? Or is it flat on the y axis?
I thought the first.

Code: Select all

irr::scene::IAnimatedMesh* bgMesh = 
   scene->addHillPlaneMesh( "background", irr::core::dimension2df(1024,512), irr::core::dimension2du(1,1) ); 
if ( bgMesh ) 
{ 
   irr::scene::ISceneNode* bgNode = scene->addMeshSceneNode( bgMesh ); //! changed from addAnimatedMeshSceneNode()

   bgNode->setMaterialTexture( 0, driver->getTexture("../Irrlicht/media/skydome2.jpg") ); 
   bgNode->setMaterialFlag( irr::video::EMF_LIGHTING, false ); 
   bgNode->setMaterialType( irr::video::EMT_SOLID ); 
}
bgNode->setRotation( irr::core::vector3df(270.f,0,0) );

Code: Select all

irr::core::matrix4 projMatrix;
projMatrix.buildProjectionMatrixOrthoLH(640.f, 480.f, 1.f, 3000.f);
camera->setProjectionMatrix(projMatrix);

camera->setPosition( irr::core::vector3df(0,0,-1000) );
camera->updateAbsolutePosition();
I tested using a plane mesh scene node compared to a billboard by creating 192 of each. I rotated the mesh's 270 degrees. The performance was equal.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Post Reply