• Advertisement

Archived

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

What this code does?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
% 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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement