Scaling a cube 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
Chris.Bailey
Posts: 9
Joined: Thu Aug 14, 2008 7:20 am

Scaling a cube node.

Post by Chris.Bailey »

I had asked this question in a previous thread but I somehow deleted it while trying to edit my post, so I will give it another go. I've noticed than when you increase the vertical scale of a cube it extends upward and downward. I would like to automatically adjust it so that the "bottom" of a vertically scaled node still meets up with the bottom of a smaller scale node. So I came up with a simple way of handling it. I take the scale of all the cube nodes, divide them in half and use the result as the y coordinate for drawing them as the following code shows. This works perfectly in my head and on paper(for me) but seems to do absolutely nothing in practice. =)

Code: Select all


struct sector
{
	sector() : height(1){}
	ISceneNode* cube;
	int height;
};

sector nMap[10][10];


int main() {
	nMap[5][3].height = 3;
	nMap[2][4].height = 3;
	nMap[3][3].height = 3;
	nMap[6][3].height = 3;
	nMap[6][2].height = 3;
	nMap[7][5].height = 3;
	nMap[5][4].height = 4;
	nMap[5][7].height = 3;
	nMap[3][9].height = 5;
	nMap[2][6].height = 3;

	// The primary Irrlicht device. Using OpenGL at 800x600 resolution.
	IrrlichtDevice* device = createDevice(EDT_OPENGL, core::dimension2d<s32>(800,600));

	// A pointer referencing the video device driver.
	IVideoDriver* video = device->getVideoDriver();

	// The primary scene manager for this app.
	ISceneManager* smgr = device->getSceneManager();
	ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
 	
 	for (int x=0; x<10; x++)
    	for (int y=0; y<10; y++) {
      		nMap[x][y].cube = smgr->addCubeSceneNode(10.0f, NULL, -1, core::vector3df(x*10,nMap[x][y].height/2,y*10));
      		nMap[x][y].cube->setScale(vector3df(1,nMap[x][y].height,1));
      		nMap[x][y].cube->getMaterial(0).setTexture(0,video->getTexture("square.bmp"));
      		nMap[x][y].cube->getMaterial(0).Lighting = false; 
  		} 

	// Main game loop.
	while(device->run() && device) {
		video->beginScene(true, true, video::SColor(255,0,0,255));
		smgr->drawAll();
		video->endScene();
	}
	
}

Any ideas?
Post Reply