Hey guys, I'm having a bit of trouble with making this class for a 3d cube. I have simply made a few functions to build the infrastructures so far, so I have a purpose for most of the things in there, even if they aren't used yet.
I am strugling in a few different areas in which I will outline for you.
- How can I initialize a dynamic structure in a class. // haven't found much on it, not in classes
- how can I initialize a dynamic array in a class. //I don't want to specify the size of cubeNumber[amount] untill constructor.
- How can I use iterators for multidimensional vectors? // This just confuses me
Now I have never made a structure in a class before. Just how am I supposed to initialize it, int the private: area, or in the constructor?
here is the class
Code:
using namespace std;
class cubes
{
public:
// cube amount, defualt is 20
cubes(int input);
// add a cube, with a vector of it's vertices
void addCube(vector<vector<float>> input, int input2);
// get the vertices of a cube
vector<float> getVertices(int input); // input cube #
// shift the cube x amount of units in x, y, and z dirctions
void shiftCube(float input1, float input2, float input3, int input4);
private:
struct cubeIndex
{
// clockwise on top, then clockwise on bottom
vector<vector<float>> vertices; // there are 8 corners to a cube
// for future functions of class
vector<float> specs;
// lets make an array of structures so that we can have a struct for each cube
} cubeNumber[20]; // **** how do I make this dynamic? ******
// if cubeId is over bounds, will return error vector *comint soon*
vector<float> errorVector;
};
void cubes::addCube(vector<vector<float>> input, int input2)
{
cubeNumber[input2].vertices = input;
// make room for the specs, we will calculate them when get specs is called
// this way we don't have to worry about it when they call cubes::getSpecs(int cubeNumber)
cubeNumber[input2].specs.push_back(0);
cubeNumber[input2].specs.push_back(0);
}
void cubes::shiftCube(float input1, float input2, float input3, int input4)
{
/* ****** how would I use an iterator here, I know that it is supposed to help
contain memory leaks, and is simply a better method than using the variable in the
for statement ********* */
int b = 0;
int k = 0;
// lets shift all vertices
for(int i = 0, i <=8, i += 3)
{
// x
cubeNumber[input4].vertices[b][k] += input1;
// y
cubeNumber[input4].vertices[b][(k+1)] += input2;
// z
cubeNumber[input4].vertices[b][(k+2)] += input3;
b++;
k++;
}
}
Also if anyone could lead me to a good article on dynamic programming, that would be greatly appreciated.
Thanks for your time and effort,
Joe