Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BoundingSphere::BoundingSphere(ObjMesh* mesh, char name[]){
- float mx = 0.0;
- float my = 0.0;
- float mz = 0.0;
- float mr = 0.0;
- this->r = 0.0;
- int vertices = mesh->m_iNumberOfVertices;
- for (int vi = 0; vi < vertices; vi++){
- mx += mesh->m_aVertexArray[vi].x;
- my += mesh->m_aVertexArray[vi].y;
- mz += mesh->m_aVertexArray[vi].z;
- }
- mx = mx / vertices;
- my = my / vertices;
- mz = mz / vertices;
- for (int vi = 0; vi < vertices; vi++){
- 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));
- if (mr > this->r){
- this->r = mr;
- }
- }
- this->iPos.x = mx;
- this->iPos.y = my;
- this->iPos.z = mz;
- strcpy(this->name, name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement