I managed to get what I wanted, but I'm wondering if it's the best way.
I'm trying to make a program that will read a 3D object info, and so far I have:
class Vertex
- has x, y, z values
class Triangle
- has the address of 3 Vertexes
class Model
- has Vertex* vertexes = new Vertex[int], which I will only know during runtime
- has Triangle* triangles = new Triangle[int], which I will only know during runtime
The reason is that I'm going to use triangles to draw, and each must have 3 vertexes' info to be properly show.
The drawing code will loop through each triangle, and draw all of their 3 vertexes.
The vertexes (array), however, are subjected to change from other factors such as Model position and effects, but this wasn't being reflected before - because the values I had in each Triangle was copied.
I managed to get around with:
1 2 3 4 5 6 7 8 9 10 11
|
Triangle** ptrTriangles; //Creating an array of pointers?
ptrTriangles = &triangles; //Setting it to reference the original triangle array
ptrTriangles[0]->SetVertexes(&vertexes[0], &vertexes[1], &vertexes[2]); //Setting the first 3 vertexes to ptrTriangle, which will be triangles
vertexes[0]->X; //Returns 1
ptrTriangles[0]->GetVertex(0)->X; //Returns 1
vertexes[0]->X = 10;
triangles[0]->GetVertex(0)->X; //Returns 10!
ptrTriangles[0]->GetVertex(0)->X; //Also returns 10
|
Is there a better way for this? Maybe without needing the second array of pointers?
Isn't my original "triangles" an array of pointers already?