diff --git a/geotypes.cpp b/geotypes.cpp index f26e289..84f8d5f 100644 --- a/geotypes.cpp +++ b/geotypes.cpp @@ -11,6 +11,11 @@ Sphere::Sphere() { radius = 1.0f; } +void Sphere::set(Punkt3D _pos, float _radius) { + pos = _pos; + radius = _radius; +} + bool Sphere::collision(const Sphere &s) const { return ((pos-s.pos)*(pos-s.pos))<((radius+s.radius)*(radius+s.radius)); } diff --git a/geotypes.h b/geotypes.h index c4be645..7deb7c4 100644 --- a/geotypes.h +++ b/geotypes.h @@ -18,6 +18,8 @@ class Sphere { Sphere(Punkt3D _pos, float radius); Sphere(); + void set(Punkt3D _pos, float _radius); + bool collision(const Sphere &s) const; bool collision(const Ray &r) const; bool collision(const Box & b) const; diff --git a/model/loadobj.cpp b/model/loadobj.cpp index 2a91068..269ef7f 100644 --- a/model/loadobj.cpp +++ b/model/loadobj.cpp @@ -206,9 +206,10 @@ bool LoadOBJ::load(Model *m) { v.clear(); } - // Calculate bounding box + // Calculate bounding box and rad for sphere float minx=m->meshdata[0].x, maxx=m->meshdata[0].x, miny=m->meshdata[0].y, maxy=m->meshdata[0].y, minz=m->meshdata[0].z, maxz=m->meshdata[0].z; for(unsigned int i=0; imeshdataanz; i++) { + m->boundingrad = std::max(m->boundingrad, abs(m->meshdata[i])); minx = std::min(minx, m->meshdata[i].x); maxx = std::max(maxx, m->meshdata[i].x); miny = std::min(miny, m->meshdata[i].y); diff --git a/model/model.cpp b/model/model.cpp index ebb51d5..ddad10d 100644 --- a/model/model.cpp +++ b/model/model.cpp @@ -108,6 +108,8 @@ Model::Model() { normdataanz = 0; loaded = false; + boundingrad = 0.0f; + backupmat.diffuse.set(1.0f, 1.0f, 1.0f); } diff --git a/model/model.h b/model/model.h index 34769ad..7c88ee6 100644 --- a/model/model.h +++ b/model/model.h @@ -85,7 +85,7 @@ class Model { void render(); Quader getBoundingBox() { return boundingbox; } - float getBoundingRadius() { return boundingrad; } + float getBoundingRad() { return boundingrad; } const Punkt3D* getMeshData(unsigned int *meshanz); };