Browse Source

kleinere aenderungen

seba 11 years ago
parent
commit
9a8fbaf759
5 changed files with 12 additions and 2 deletions
  1. 5
    0
      geotypes.cpp
  2. 2
    0
      geotypes.h
  3. 2
    1
      model/loadobj.cpp
  4. 2
    0
      model/model.cpp
  5. 1
    1
      model/model.h

+ 5
- 0
geotypes.cpp View File

@@ -11,6 +11,11 @@ Sphere::Sphere() {
11 11
 	radius = 1.0f;
12 12
 }
13 13
 
14
+void Sphere::set(Punkt3D _pos, float _radius) {
15
+	pos = _pos;
16
+	radius = _radius;
17
+}
18
+
14 19
 bool Sphere::collision(const Sphere &s) const {
15 20
 	return ((pos-s.pos)*(pos-s.pos))<((radius+s.radius)*(radius+s.radius));
16 21
 }

+ 2
- 0
geotypes.h View File

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

+ 2
- 1
model/loadobj.cpp View File

@@ -206,9 +206,10 @@ bool LoadOBJ::load(Model *m) {
206 206
 		v.clear();
207 207
 	}
208 208
 	
209
-	// Calculate bounding box
209
+	// Calculate bounding box and rad for sphere
210 210
 	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;
211 211
 	for(unsigned int i=0; i<m->meshdataanz; i++) {
212
+		m->boundingrad = std::max(m->boundingrad, abs(m->meshdata[i]));
212 213
 		minx = std::min(minx, m->meshdata[i].x);
213 214
 		maxx = std::max(maxx, m->meshdata[i].x);
214 215
 		miny = std::min(miny, m->meshdata[i].y);

+ 2
- 0
model/model.cpp View File

@@ -108,6 +108,8 @@ Model::Model() {
108 108
 	normdataanz = 0;
109 109
 	loaded = false;
110 110
 	
111
+	boundingrad = 0.0f;
112
+	
111 113
 	backupmat.diffuse.set(1.0f, 1.0f, 1.0f);
112 114
 }
113 115
 

+ 1
- 1
model/model.h View File

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

Loading…
Cancel
Save