# resizing a cube made from ofxVec3f vertexes

this is my first c++ and openFrameworks project. I have a cube class made from 8 vertexes, drawn in open gl and rotating in 3 dimensions. I want to be able to resize it while it is rotating. The following kind of works, but the cube shape distorts. does anyone have any ideas? the full code is available here: https://github.com/pepperminttiger/demiurge

void Cube::resizeCube(int changeInt)
{
for (int i = 0; i < NUM_VERTS; i++)
{
// move the points so that their center (ofGetW/2, ofGetH/2) is at 0,0,0
verts[i] -= cubeCenter;

if (verts[i].x>0)
verts[i].x = verts[i].x+changeInt;
if (verts[i].x<0)
verts[i].x = verts[i].x-changeInt;

if (verts[i].y>0)
verts[i].y = verts[i].y+changeInt;
if (verts[i].y<0)
verts[i].y = verts[i].y-changeInt;

if (verts[i].z>0)
verts[i].z = verts[i].z+changeInt;
if (verts[i].z<0)
verts[i].z = verts[i].z-changeInt;

// move them back
verts[i] += cubeCenter;
}
}

doh! i think i found my answer here: http://en.wikipedia.org/wiki/Scaling-(geometry

this seems to be working ok with a decimal rather than an integer:

void Cube::resizeCube(float changeFloat)
{
for (int i = 0; i < NUM_VERTS; i++)
{
// move the points so that their center (ofGetW/2, ofGetH/2) is at 0,0,0
verts[i] -= cubeCenter;

// transform the points
verts[i].x = verts[i].x*changeFloat;
verts[i].y = verts[i].y*changeFloat;
verts[i].z = verts[i].z*changeFloat;

verts[i] += cubeCenter;
}
}