A plane node?

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
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

A plane node?

Post by ent1ty »

Hi,
so it's easy to add a cube or even sphere, but how do i add a simple plane? Basically, something like a billboard that doesn't rotate to the camera.
Thanks.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Code: Select all

scene::SMesh* createPlaneMesh(f32 width = 1.f, f32 height = 1.f)
{
   video::S3DVertex v0(0.f,0.f,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 0.f,1.f);

   video::S3DVertex v1(width,0.f,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 1.f,1.f);

   video::S3DVertex v2(width,height,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 1.f,0.f);

   video::S3DVertex v3(0.f,height,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 0.f,0.f);

   scene::CMeshBuffer<video::S3DVertex> *buffer =
      new scene::CMeshBuffer<video::S3DVertex>;

   buffer->Vertices.push_back(v0);
   buffer->Vertices.push_back(v1);
   buffer->Vertices.push_back(v2);
   buffer->Vertices.push_back(v3);

   buffer->Indices.push_back(0);
   buffer->Indices.push_back(1);
   buffer->Indices.push_back(2);

   buffer->Indices.push_back(0);
   buffer->Indices.push_back(2);
   buffer->Indices.push_back(3);

   buffer->recalculateBoundingBox();

   scene::SMesh *mesh = new scene::SMesh;
   mesh->addMeshBuffer(buffer);
   buffer->drop();
   mesh->recalculateBoundingBox();

   return mesh;
}

Code: Select all

scene::ISceneNode* createPlaneSceneNode(scene::ISceneManager* smgr,
   scene::ISceneNode *parent = NULL, s32 id = -1,
   core::vector3d<f32> position = core::vector3d<f32>(0.f,0.f,0.f),
   f32 width = 1.f, f32 height = 1.f)
{
   video::S3DVertex v0(0.f,0.f,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 0.f,1.f);

   video::S3DVertex v1(width,0.f,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 1.f,1.f);

   video::S3DVertex v2(width,height,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 1.f,0.f);

   video::S3DVertex v3(0.f,height,0.f, 0.f,0.f,1.f,
      video::SColor(255,255,255,255), 0.f,0.f);

   scene::CMeshBuffer<video::S3DVertex> *buffer =
      new scene::CMeshBuffer<video::S3DVertex>;

   buffer->Vertices.push_back(v0);
   buffer->Vertices.push_back(v1);
   buffer->Vertices.push_back(v2);
   buffer->Vertices.push_back(v3);

   buffer->Indices.push_back(0);
   buffer->Indices.push_back(1);
   buffer->Indices.push_back(2);

   buffer->Indices.push_back(0);
   buffer->Indices.push_back(2);
   buffer->Indices.push_back(3);

   buffer->recalculateBoundingBox();

   scene::SMesh *mesh = new scene::SMesh;
   mesh->addMeshBuffer(buffer);
   buffer->drop();
   mesh->recalculateBoundingBox();

   scene::ISceneNode *plane = smgr->addMeshSceneNode(mesh, parent, id);
   mesh->drop();
   plane->setPosition(position);

   return plane;
}
Last edited by arras on Mon Mar 22, 2010 2:32 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Irrlicht 1.7 also has its own createPlaneMesh function in geometry creator. Just add that mesh to a mesh scene node.
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Ah, nice, I was only looking in ISceneManager.
Thanks.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
vhson13
Posts: 10
Joined: Wed Mar 17, 2010 3:39 pm

Post by vhson13 »

I applied code above, but scene node does not render. I don't know why? Could you explain for me? Thanks everyone.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

vhson13 wrote:I applied code above, but scene node does not render. I don't know why? Could you explain for me? Thanks everyone.
It's hard to tell without code.
"Whoops..."
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Try turning off backface culling. There is chance, you look at plane from wrong side. It is facing along Z axis.

[EDIT:] ops, sorry, it was actually facing opposite way, along -Z axis. I just copy/pasted that code from one of my applications. Corrected. Now it should face along Z properly.
SG57
Posts: 66
Joined: Fri May 18, 2007 5:51 am

Post by SG57 »

You can also use the built-in hill plane mesh creator. Simply set the amount of tiles to (1,1) and each tile the size of the plane you want. You can even set the texture repeat rate this way so that saves you some hassle.

I used this as my floor and walls in my Light Cycle game, worked well.
vhson13
Posts: 10
Joined: Wed Mar 17, 2010 3:39 pm

Post by vhson13 »

I tried hill plane mesh, it's a good idea for me. I did as guide in tutorial about special FX using addMeshSceneNode instead of addWaterSurfaceSceneNode, and got ugly render, plane was not rendered well. I don't know why?

My purpose is creating a plane mesh and then changing color of some tiles when needed. How can I solve this problem below and move next step?

Image
Last edited by vhson13 on Thu Apr 01, 2010 4:23 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You cannot color separate tiles. The surrounding ones will be affected by such changes as well. It doesn't matter if you use textures or vertex colors, both will have an effect on the neighbors as well.
Post Reply