Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Richter BelmontThe BoundingSphere
#1
You may have notice that the TPolygonGeometry and TSkinPolygonGeometry node of your scene files, contain a TNode.BoundingSphere parameter.
Like you can see by the name of this parameter, people should be able to use it on any kind of TNode.
These TNode.BoundingSphere take a Spheref() with 4 float as value:
The first three number being a 3d coordinate(the center point of the sphere) and the last one a radius(the radius of the sphere): Spheref( X, Y, Z, Radius)
Code:
TNode.BoundingSphere Spheref( 0.7, 12, 2, 0.88 );//EXAMPLE



Ok, but what is the purpose of all this?
Well, the game use this to know when it should "render" a mesh and when it shouldn't:
If the BoundingSphere is within the camera view, the game will render the object and not if not.

There is also an another parameter that can go with the TNode.BoundingSphere Spheref() one.
I don't know what it do, so I only write it to let people know it exist.
You can let the game use the default value by not writing it in your file.
TNode.BoundingMode TNode.BoundingModeEnum and use .BoundingDynamic, .BoundingStatic or .BoundingStaticSubtree.


Code:
TNode.BoundingMode TNode.BoundingModeEnum.BoundingDynamic;//EXAMPLE




Many people have encountered situations where objects was randomly disappearing.
The cause of this being bad BoundingSphere (bad origin and/or size).
A "fixe" that SHOULD NEVER HAVE BEEN ADVISED is born: drastically increasing the size of the sphere(radius)
[i]What is so bad about increasing the size of the bounding sphere?[/i]
Remember what I said: [i]the game use this to know when it should "render" a mesh...[/i]
If the sphere is too big, the game will render the object...
EVEN IF IT IS NOT IN THE CAMERA VIEW!
This can seem to be not that bad for a single object, but think about a room.
Imagine what happen when all the object of a given room use huge bounding sphere and end up being rendered at all time (even when you can't see them).
The answer = a huge amount of unnecessary work is given to the GPU, which result in high fps drop.

To make thing right, the center point of your bounding sphere should be in the center of your mesh and the sphere should be just big enough to envelop the whole mesh.(try to get the minimal possible size).

[i]How to calculate the BoundingSphere?[/i]
To get the center point, you need to get the average of all the x, y and z valuer of all the vertex of your mesh.
So you will sum all the vertex X value of your mesh and divide the total by the number of vertex your mesh have, then repeat for Y and Z.

Code:
SPolygonGeometry.VertexArray Array_Vector3f [ (1, 1, -1), (1, -1, -1), (-1, -1, -1), (-1, 1, -1), (1, 1, 1), (1, -1, 1), (-1, -1, 1), (-1, 1, 1), (0, 0, 2.69)];[/i][/color]
[color=#000000][i]The mesh contain 9 vertex[/i][/color]

[color=#000000][i]X = 1+1-1-1+1+1-1-1+0 = 0[/i][/color]
[color=#000000][i]X = 0/9 = 0[/i][/color]
[color=#000000][i]X = 0[/i][/color]

[color=#000000][i]Y = 1-1-1+1+1-1-1+1+0 = 0[/i][/color]
[color=#000000][i]Y = 0/9[/i][/color]
[color=#000000][i]Y = 0[/i][/color]

[color=#000000][i]Z = -1-1-1-1+1+1+1+1+2.69 = 2.69[/i][/color]
[color=#000000][i]Z = 2.69/9[/i][/color]
[color=#000000][i]Z = 0.2989[/i][/color]

[i][color=#000000]Sphere Center Point = (0, 0, 0.2989)


Once you have the center point.
For each vertex, you will calculate the distance between the given vertex and the sphere center point and use the highest distance value receive as your radius.


Code:
Distance = sqrt( ((meshVerticesX-CenterX)*(meshVerticesX-CenterX)) + ((meshVerticesY-CenterY)*(meshVerticesY-CenterY)) + ((meshVerticesZ-CenterZ)*(meshVerticesZ-CenterZ)) )[/i][/color]
[color=#000000][i]sqrt mean "square root".[/i][/color]
[color=#000000][i]So calculating the distance value for the first vertex of my exemple (1, 1, -1) will look like this:[/i][/color]
[color=#000000][i]Distance = sqrt( ((1-0)*(1-0)) + ((1-0)*(1-0)) + ((-1-0.2989)*(-1-0.2989)) )[/i][/color]
[color=#000000][i]Distance = 1.92019[/i][/color]
[color=#000000][i]In my exemple, the highest distance value will come from the last vertex (0, 0, 2.69) with a distance of 2.39115[/i][/color]
[color=#000000][i]Radius = 2.39115[/i][/color]
[i][color=#000000]TNode.BoundingSphere Spheref( 0, 0, 0.2989, 2.39115);



Download 

[To see links please log-in or register here]

[To see links please log-in or register here]

Reply




Users browsing this thread: 1 Guest(s)
Copyright: Roy's website was started on September 3, 2013. We been on-line over 10 years and going strong.
WARNING: ADULT CONTENT: You must be 18 years of age or older to view this website.