kleinere aenderungen

This commit is contained in:
seba 2008-09-29 15:51:17 +02:00
parent cf11ce691a
commit 9a8fbaf759
5 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,11 @@ Sphere::Sphere() {
radius = 1.0f; radius = 1.0f;
} }
void Sphere::set(Punkt3D _pos, float _radius) {
pos = _pos;
radius = _radius;
}
bool Sphere::collision(const Sphere &s) const { bool Sphere::collision(const Sphere &s) const {
return ((pos-s.pos)*(pos-s.pos))<((radius+s.radius)*(radius+s.radius)); return ((pos-s.pos)*(pos-s.pos))<((radius+s.radius)*(radius+s.radius));
} }

View File

@ -18,6 +18,8 @@ class Sphere {
Sphere(Punkt3D _pos, float radius); Sphere(Punkt3D _pos, float radius);
Sphere(); Sphere();
void set(Punkt3D _pos, float _radius);
bool collision(const Sphere &s) const; bool collision(const Sphere &s) const;
bool collision(const Ray &r) const; bool collision(const Ray &r) const;
bool collision(const Box & b) const; bool collision(const Box & b) const;

View File

@ -206,9 +206,10 @@ bool LoadOBJ::load(Model *m) {
v.clear(); 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; 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; i<m->meshdataanz; i++) { for(unsigned int i=0; i<m->meshdataanz; i++) {
m->boundingrad = std::max(m->boundingrad, abs(m->meshdata[i]));
minx = std::min(minx, m->meshdata[i].x); minx = std::min(minx, m->meshdata[i].x);
maxx = std::max(maxx, m->meshdata[i].x); maxx = std::max(maxx, m->meshdata[i].x);
miny = std::min(miny, m->meshdata[i].y); miny = std::min(miny, m->meshdata[i].y);

View File

@ -108,6 +108,8 @@ Model::Model() {
normdataanz = 0; normdataanz = 0;
loaded = false; loaded = false;
boundingrad = 0.0f;
backupmat.diffuse.set(1.0f, 1.0f, 1.0f); backupmat.diffuse.set(1.0f, 1.0f, 1.0f);
} }

View File

@ -85,7 +85,7 @@ class Model {
void render(); void render();
Quader getBoundingBox() { return boundingbox; } Quader getBoundingBox() { return boundingbox; }
float getBoundingRadius() { return boundingrad; } float getBoundingRad() { return boundingrad; }
const Punkt3D* getMeshData(unsigned int *meshanz); const Punkt3D* getMeshData(unsigned int *meshanz);
}; };