#### Archived

This topic is now archived and is closed to further replies.

# What this code does?

This topic is 5331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Can anyone explain the following code? This is from the book, "Programming Role Playing Games with DirectX", ch-12->CNodeTreeMesh::SortNode() I could not understand what this code is doing. So, if someone could help... XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f); ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f); YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f); Thanks

##### Share on other sites
% is a mod operation (i think)
? is like an if statment:
(i < 4) ? i = 0 : i = 100;
means if i is less than 4, then set i = 0, else set i = 100.

##### Share on other sites
so in your equation, if the test evaluates to true set XOFF = -1 * (size/ 4), if test evaluates to false set XOFF = 1 * (size/4).

##### Share on other sites
Looks like it might be setting the vertex positions for a cube. It''s hard to say without context.

I like pie.

##### Share on other sites
I know about the % and ? operators and how they work. Infact, i wanted to know the logic behind this code. That''s why i put reference to the book. This code is part of a fuction SortNode() while implementing Octree/Quadtree that splits the node into child nodes. But i could not understand how splitting is done through this code. That''s what i was trying to ask...

##### Share on other sites
Well, it''s a programmatic way of getting the x y z subcubes coordinates.

Each i iteration is one of the 8 subcubes. This is going to return the center point of each cube.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011473
• ### Who's Online (See full list)

There are no registered users currently online

×