Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. BoundingSphere::BoundingSphere(ObjMesh* mesh, char name[]){
  2.     float mx = 0.0;
  3.     float my = 0.0;
  4.     float mz = 0.0;
  5.     float mr = 0.0;
  6.     this->r = 0.0;
  7.     int vertices = mesh->m_iNumberOfVertices;
  8.     for (int vi = 0; vi < vertices; vi++){
  9.         mx += mesh->m_aVertexArray[vi].x;
  10.         my += mesh->m_aVertexArray[vi].y;
  11.         mz += mesh->m_aVertexArray[vi].z;
  12.     }
  13.     mx = mx / vertices;
  14.     my = my / vertices;
  15.     mz = mz / vertices;
  16.  
  17.     for (int vi = 0; vi < vertices; vi++){
  18.         mr = sqrt(pow((mx - mesh->m_aVertexArray[vi].x), 2) + pow((my - mesh->m_aVertexArray[vi].y), 2) + pow((mz - mesh->m_aVertexArray[vi].z), 2));
  19.         if (mr > this->r){
  20.             this->r = mr;
  21.         }
  22.     }
  23.     this->iPos.x = mx;
  24.     this->iPos.y = my;
  25.     this->iPos.z = mz;
  26.     strcpy(this->name, name);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement