directx - How to compute bounding box/sphere across multiple meshes (C#) -


I load several mesions from .x files in various Aries variables. Now I want to calculate the bound area (which is being displayed) Please guide me how it can be achieved. Can VertexBuffers be attached in a variable and that borderline page can be calculated using it? (If yes, then how are they, buffer is added) Otherwise what would you suggest !? Thankx

It's surprisingly easy to do this:

First of all, The average of all your corners gives you the position of the center.

It has been done in C ++ (sorry my C # is very wild but it should give you an idea):

  D3DXVECTOR3 avgPos; Const rcpNum = 1.0f / (float) numVerts; // divide it here, as the partition is more aggressive than the polygon int count = 0; Whereas (calculation & amp; lt; numVerts) {// instead of adding everything and then dividing by the number (which can be overflow / /) I am dividing the number as I go along with the result is. AvgPos.x + = vert [count] .pos.x * rcpNum; AvgPos.y + = vert [count] .pos.y * rcpNum; AvgPos.z + = vert [count] .pos.z * rcpNum; Count ++; }  

Now you need to go through every part and it works that the topmost point from the center point is far away.

Something like (C ++):

  float maxSqDist = 0.0f; Int count = 0; While (count & lt; numVerts) {D3DXVECTOR3 diff = avgPos - vert [count] .pos; // Note: We can also use the length of the square because sqrt is very expensive and // maximum square length will also be the maximum length and still we have to do only one type of CTRTR :) const float sqDist = D3DXVec3LengthSq (difference) ; If (sqDist> maxSqDist) {maxSqDist = sqDist; } Calculate ++; Const Float Radius = sqrtf (maxSqDist);  

And now you have your center position (AGPOS) and your radius and, thus, all the information that you need to define a border area.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -