Skip to main content
gamedev.net
🔒 Locked

Problem with oct

Started by Jezak 3 replies 400+ views
Original Post
Jezak
Jezak
I have small problem with rendering octtreesI created octtrees. I have following structures: struct Tri { D3DXVECTOR3 vec[3];//Triangle }; struct CNode { CNode *next; //next node CNode *back; //back node float size; //size a box int num; // amount triangle in node D3DXVECTOR3 center; //center of node Tri triangle[900];//traiangle }; Now how I can render world when i am for example in node 1?(I must render neighbour too).I use directx 9.0 BTW. I know , it's stupit question. [edited by - Jezak on February 1, 2004 9:52:08 AM]
Zahlman
Zahlman
quote:
Original post by Jezak
struct CNode
{
CNode *next; //next node
CNode *back; //back node



This looks to me like a double-linked list, not an octree.
quote:

float size; //size a box
int num; // amount triangle in node
D3DXVECTOR3 center; //center of node
Tri triangle[900];//traiangle
};



Try using a vector<tri> instead of a number and array storage. You''ll be happy you did eventually.

Since you have a "center" for each CNode, I assume your Tri coordinates are relative to that point.

quote:
Now how I can render world when i am for example in node 1?(I must render neighbour too).I use directx 9.0

BTW. I know , it''s stupit question.



Uh, just traverse the list and render each node:


void render() {
CNode curr = getFirstNode();
while (curr) {
for (int i = 0; i < curr->num; i++) {
CALL_SOME_D3DX_FUNCTION_TO_RENDER(curr->triangle[0] + curr->center, curr->triangle[1] + curr->center, curr->triangle[2] + curr->center);
}
curr = curr->next;
}}


Now, all those references to ''curr'' get annoying, so you probably want to make a member function of CNode instead. And since you have an internal linked list, you can use recursion:


void CNode::render() {
for (int i = 0; i < curr->num; i++) {
CALL_SOME_D3DX_FUNCTION_TO_RENDER(triangle[0] + center, triangle[1] + center, triangle[2] + center);
}
if (next) next->render();
}


Those additions are silly to do every time too (unless you want to move your space partitions around), so you probably want instead to do the adding when you add the triangles to the node, instead.

Oh, and with the member function you''ll want to be careful that you only call the render method on the first node from outside. It will do the traversal for you and if you start somewhere else in the list then it won''t render the items before it.
Jezak
Jezak
Okay but I don''t want redner all node!.I want render just node in that i am and neighbours node(so how it''s doing?). I have camera position and min,max range node.

I changed struct:
struct CNode
{
CNode *next[8]; //next node
CNode *back[8]; //back node
float size; //size a box
int num; // amount triangle in node
D3DXVECTOR3 center; //center of node
vector<tri> vec;
};

Now is it okay?
orbano
orbano
why do you have 8 parents?
When rendering (or doin any action in a tree, in this special case a kind of search tree) you should do something like this:
node=root;
node::render(node)
{
for "each children" if "condition1" is true then call child.render() else if "condition2" is true then do "something else";
};
where "condition1" is some kind of visibility condition (the condition, you set the ectree by)
"condition2" is true when you reached a leave
"something else" is the actual render code

i hope you get it

"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Jezak
Jezak
Okay ,thanks all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.