Original Post
I'm writing a structure that hold a box (SBox), it is made up of a vector of planes (SPlane) and each plane is made out of a vector of corners(v_Corners) were each corner has x,y and z values. I wanted to make a constructer that initiates all the verticies (planes,corners,verticies) by a center point (x,y,z) a width (w), height (h), and a depth (d). I did this: But for some reason all of the 6 sides got the same corners and vertices as the front side? Why would this be? Thanks.
struct SPlane{
vector<CVector3> v_Corners;
int ID;
};
struct SBox{
vector<SPlane> v_Sides;
int ID;
SBox(vector<SPlane> s, int i){v_Sides = s; ID = i;}
SBox(float x, float y, float z, float w, float d, float h, int i);
//for debugging only
void DrawBox();
};
SBox :: SBox(float x, float y, float z, float w, float d, float h, int i)
{
SPlane temp_plane;
CVector3 temp_corner;
ID = i;
//front side
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
//right side
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
//back side
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
//left side
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
//top side
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y + h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
//bottom side
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z + d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x + w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
temp_corner.x = x - w; temp_corner.y = y - h; temp_corner.z = z - d;
temp_plane.v_Corners.push_back(temp_corner);
v_Sides.push_back(temp_plane);
}