Page 1 of 1

Scale node to desired Size

Posted: Mon Jul 19, 2010 9:43 am
by raveneyex
Hey everyone!

This is just a little code I made to scale a node to an specified size.
It takes as parameters a pointer to an ISceneNode and your desired size (specified in X, Y, Z UNITS) and then calculates the needed factor and scales the Node.

Code: Select all

void scaleMesh(scene::ISceneNode* mesh, 
f32 desiredX = 40, 
f32 desiredY = 40, 
f32 desiredZ = 40)
{
	core::vector3d<f32> * edges = new core::vector3d<f32>[8]; 
	core::aabbox3d<f32> boundingbox = 
            mesh->getTransformedBoundingBox(); 
	boundingbox.getEdges(edges);
	
	f32 height = edges[1].Y - edges[0].Y; 
	//std::cout<<"height: "<<height<<std::endl;

	f32 width = edges[5].X - edges[1].X;
	//std::cout<<"width: "<<width<<std::endl;

	f32 depth = edges[2].Z - edges[0].Z;
	//std::cout<<"depth: "<<depth<<std::endl;

	f32 factorX = desiredX/width;
	f32 factorY = desiredY/height;
	f32 factorZ = desiredZ/depth;
	core::vector3d<f32> factorEscalate(factorX,factorY,factorZ);
	mesh->setScale(factorEscalate);
}
Hope someone finds it useful!

Scale Node

Posted: Thu Jul 29, 2010 10:41 am
by raveneyex
Hey everyone,

This is a revised version of my last code to scale a Node.
On the previous code, the scaled node won't keep the proportions and thus would look like crap!
So, here's a new version that DOES keeps the proportions of the mesh.

Code: Select all

void scaleNode(scene::ISceneNode* mesh, f32 desiredX)
{
	core::vector3dfextent=
            mesh->getTransformedBoundingBox().getExtent();
	f32 factor = desiredX/extent.X;
	core::vector3d<f32> factorEscalate(factor,factor,factor);
	mesh->setScale(factorEscalate);
}
Hope anyone finds this useful.