i have done a bit of revising and i cant get past a list of errors pointing to the 5 lines towards the end of the sort function:
temp.node[nodeLevel].numVertex++; temp.node[nodeLevel].vertices.resize(temp.node[nodeLevel].numVertex); temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].x = vertices[x].x; temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].y = vertices[x].y; temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].z = vertices[x].z;
here are the errors im getting:
--------------------Configuration: Box Physics - Win32 Release--------------------Compiling...main.cppE:\Adam\Software\Visual C++\Box Physics\Octree.h(101) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(102) : error C2228: left of '.vertices' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(102) : error C2228: left of '.resize' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(102) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(103) : error C2228: left of '.vertices' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(103) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(103) : error C2228: left of '.x' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(103) : error C2109: subscript requires array or pointer typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(103) : error C2228: left of '.x' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(104) : error C2228: left of '.vertices' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(104) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(104) : error C2228: left of '.y' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(104) : error C2109: subscript requires array or pointer typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(104) : error C2228: left of '.y' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(105) : error C2228: left of '.vertices' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(105) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(105) : error C2228: left of '.z' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(105) : error C2109: subscript requires array or pointer typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(105) : error C2228: left of '.z' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(109) : error C2228: left of '.numVertex' must have class/struct/union typeE:\Adam\Software\Visual C++\Box Physics\Octree.h(112) : error C2664: 'Sort' : cannot convert parameter 1 from 'struct _node *' to 'struct _node' No constructor could take the source type, or constructor overload resolution was ambiguousE:\Adam\Software\Visual C++\Box Physics\main.cpp(219) : error C2664: 'Sort' : cannot convert parameter 1 from 'struct _node *' to 'struct _node' No constructor could take the source type, or constructor overload resolution was ambiguousError executing cl.exe.Box Physics.exe - 22 error(s), 0 warning(s)
here is the entire file
const int MAX_VERTEX = 100;struct float3{ float x, y, z; float d; void mag();};void float3::mag(){ d=sqrt((x*x)+(y*y)+(z*z));}struct _node{ float3 center; bool isFull; int level; int numVertex; vector<float3> vertices; _node *node[8];};struct _cube{ float3 upperlim; float3 lowerlim; float3 center; //center of root cube float width; //width of root cube int numVertex; vector<float3> vertices; bool isFull; _node *node[8]; _cube(); void Load(vector<float> array); void Draw();};_cube::_cube(){ isFull = false; numVertex = 0; upperlim.x = upperlim.y = upperlim.z = 0; lowerlim.x = lowerlim.y = lowerlim.z = 0;}void Sort(_node temp){ int nodeLevel; if(temp.numVertex > MAX_VERTEX) { for(int x=0; x<temp.numVertex; x++) { nodeLevel = 8; if(temp.vertices[x].x < temp.center.x) if(temp.vertices[x].y < temp.center.y) if(temp.vertices[x].z < temp.center.z) { nodeLevel = 0; } else { nodeLevel = 1; } else if(temp.vertices[x].z < temp.center.z) { nodeLevel = 2; } else { nodeLevel = 3; } else if(temp.vertices[x].y < temp.center.y) if(temp.vertices[x].z < temp.center.z) { nodeLevel = 4; } else { nodeLevel = 5; } else if(temp.vertices[x].z < temp.center.z) { nodeLevel = 6; } else { nodeLevel = 7; } temp.node[nodeLevel].numVertex++; temp.node[nodeLevel].vertices.resize(temp.node[nodeLevel].numVertex); temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].x = vertices[x].x; temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].y = vertices[x].y; temp.node[nodeLevel].vertices[temp.node[nodeLevel].numVertex-1].z = vertices[x].z; } for(x=0; x<8; x++) { if(temp.node[x].numVertex > MAX_VERTEX) { temp.isFull = true; Sort(temp.node[x]); } } }}void _cube::Load(vector<float> array){ numVertex = array.size()/3; vertices.resize(numVertex); for(int x=0; x<numVertex; x++) { vertices[x].x = array[3*x]; vertices[x].y = array[3*x+1]; vertices[x].z = array[3*x+2]; } for(x=0; x<numVertex; x++) vertices[x].mag(); for(x=0; x<numVertex; x++) { if(lowerlim.x > vertices[x].x) lowerlim.x = vertices[x].x; if(lowerlim.y > vertices[x].y) lowerlim.y = vertices[x].y; if(lowerlim.z > vertices[x].z) lowerlim.z = vertices[x].z; if(upperlim.x < vertices[x].x) upperlim.x = vertices[x].x; if(upperlim.y < vertices[x].y) upperlim.y = vertices[x].y; if(upperlim.z < vertices[x].z) upperlim.z = vertices[x].z; } float xlen = upperlim.x - lowerlim.x; float ylen = upperlim.y - lowerlim.y; float zlen = upperlim.z - lowerlim.z; if(xlen>ylen) if(xlen>zlen) width=xlen; else width=zlen; else if(ylen>zlen) width=ylen; else width=zlen; center.x = (upperlim.x + lowerlim.x) / 2; center.y = (upperlim.y + lowerlim.y) / 2; center.z = (upperlim.z + lowerlim.z) / 2; //Sort();}void _cube::Draw(){ float w = width/2; glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPointSize(15); glColor3f(1, 0, 0); glBegin(GL_POINTS); glVertex3f(center.x, center.y, center.z); glEnd(); glColor4f(1, 1, 0, 1); glLineWidth(1); glBegin(GL_LINE_LOOP); glVertex3f(center.x-w, center.y-w, center.z-w);//lowerlim.x, lowerlim.y, lowerlim.z); glVertex3f(center.x+w, center.y-w, center.z-w);//upperlim.x, lowerlim.y, lowerlim.z); glVertex3f(center.x+w, center.y+w, center.z-w);//upperlim.x, upperlim.y, lowerlim.z); glVertex3f(center.x-w, center.y+w, center.z-w);//lowerlim.x, upperlim.y, lowerlim.z); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(center.x-w, center.y-w, center.z+w);//lowerlim.x, lowerlim.y, upperlim.z); glVertex3f(center.x+w, center.y-w, center.z+w);//upperlim.x, lowerlim.y, upperlim.z); glVertex3f(center.x+w, center.y+w, center.z+w);//upperlim.x, upperlim.y, upperlim.z); glVertex3f(center.x-w, center.y+w, center.z+w);//lowerlim.x, upperlim.y, upperlim.z); glEnd(); glBegin(GL_LINES); glVertex3f(center.x-w, center.y-w, center.z-w); glVertex3f(center.x-w, center.y-w, center.z+w); glVertex3f(center.x+w, center.y-w, center.z-w); glVertex3f(center.x+w, center.y-w, center.z+w); glVertex3f(center.x-w, center.y+w, center.z-w); glVertex3f(center.x-w, center.y+w, center.z+w); glVertex3f(center.x+w, center.y+w, center.z-w); glVertex3f(center.x+w, center.y+w, center.z+w); glEnd(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D);}
keep in mind this is just a test to get the tree up and running so ive spared myself alot of the math involving polygons and im just using points right now.
as always optimization tips are very much appreciated!