[solved] mesh for squares

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
strale
Posts: 119
Joined: Wed Nov 23, 2005 1:58 pm
Location: Lambrugo Italy
Contact:

[solved] mesh for squares

Post by strale »

Hello

using the follow code i was expecting to obtain meshes in shape of a square instead i obtain a rectangle...
it sound queer as i used triangles with same base and hight.

Code: Select all

// Mesh Node
           SMeshBuffer * mb = new SMeshBuffer(); 
           
          mb->Vertices.push_back(video::S3DVertex(0,0,0,    0.0f,0.0f,0.0f, video::SColor(255,200,60,90), 0.0f, 0.0f));
          mb->Vertices.push_back(video::S3DVertex(0,10,0,   0.0f,0.0f,0.0f, video::SColor(255,200,160,190), 0.0f, 0.0f));
          mb->Vertices.push_back(video::S3DVertex(10,0,0,   0.0f,0.0f,0.0f, video::SColor(255,200,160,90), 0.0f, 0.0f));
          mb->Vertices.push_back(video::S3DVertex(10,10,0,  0.0f,0.0f,0.0f, video::SColor(255,0,60,190), 0.0f, 0.0f));

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

		   mb->Indices.push_back( 0);
		   mb->Indices.push_back(1);
		   mb->Indices.push_back(3);

	

           SMesh *Solid = new SMesh(); 
           Solid->addMeshBuffer(mb);
           Solid->recalculateBoundingBox();
            
           IMeshSceneNode * SolidNode = smgr->addMeshSceneNode(Solid);
           SolidNode->setMaterialFlag(EMF_LIGHTING, false);
           SolidNode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); 
// Mesh Node


the camera i have used is

Code: Select all

   // Camera
   f32 CamPosX = 0.0f,CamPosY = 0.0f,CamPosZ =-100.0f;

   cam = smgr->addCameraSceneNode();

   cam->setPosition(core::vector3df(CamPosX ,CamPosY ,CamPosZ));

   cam->setTarget(core::vector3df( 0,0,0));
I have check on the search to see if others have found the same problem but no one experienced this..

suposing the the square will have the vertex like:

0) : 0,0,0
1) : 0,10,0
2) : 10,0,0
3) : 10,10,0

with triangles indexed like this:
0,3,2
0,1,3

do i am mistaking?
could it be an effect of the camera?

Thanks
Cheers
Last edited by strale on Wed Oct 21, 2009 7:53 am, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The vertex data that you are providing seems correct. I'm guessing that the problem is with the camera aspect ratio not being consistent with the viewport dimensions. If your viewport is not 4:3, objects will look squished or squeezed. In that case you should call camera->setAspectRatio(1.f * w / h) where w and h are the width and height of the viewport.

Travis
strale
Posts: 119
Joined: Wed Nov 23, 2005 1:58 pm
Location: Lambrugo Italy
Contact:

Post by strale »

Thank you vitek
:D
Your post focused the problem
I belive it has been my fault and i realized just now that i did not post all the configuration
The irrlicht rendering (800 x 600 ) is ok the problem cam out as i rendered into a image of diffeent dimension (512 x 512):

Code: Select all

video::ITexture* rt = driver->addRenderTargetTexture(core::dimension2d<s32>(512,512), "RTT1");
	driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));
I belived the rendereing into a texture would keep the same proprotion but probably it can't work in this way.

i tired your solution to the problem
cam->setAspectRatio(1.0f * (512.0f/600.0f) ) ;
but i still have to find the correct parameters.

anyway the easyier solution seems to keep the device area equal to the rendering texture area.

Tahank you.
Post Reply