Browse Source

neue collider, rumprobiererei mit defines

Sebastian 11 years ago
parent
commit
bff2ad312d
5 changed files with 26 additions and 16 deletions
  1. 0
    1
      emath.h
  2. 15
    8
      geotypes.cpp
  3. 5
    4
      geotypes.h
  4. 3
    1
      punkt2d.h
  5. 3
    2
      punkt3d.h

+ 0
- 1
emath.h View File

@@ -3,7 +3,6 @@
3 3
 
4 4
 #include <iostream>
5 5
 #include <cmath>
6
-#include <SDL_opengl.h>
7 6
 
8 7
 namespace segl {
9 8
 

+ 15
- 8
geotypes.cpp View File

@@ -21,7 +21,14 @@ bool Sphere::collision(const Sphere &s) const {
21 21
 }
22 22
 
23 23
 bool Sphere::collision(const Ray &r) const {
24
-	return true;
24
+	/*
25
+	// way more complex (i think), maybe usefull to calc the collpoints
26
+	const float bsum = r.dir.x + r.dir.y + r.dir.z;
27
+	float p = (2.0f*(r.pos*r.dir)-pos*r.dir) / bsum;
28
+	float q = (r.pos*r.pos-2.0f*r.pos*pos+pos*pos-radius*radius) / bsum;
29
+	return (p*p/4.0f-q >= 0.0f);
30
+	*/
31
+	return (r.dist(pos)<=radius);
25 32
 }
26 33
 
27 34
 bool Sphere::collision(const Box & b) const {
@@ -29,7 +36,7 @@ bool Sphere::collision(const Box & b) const {
29 36
 }
30 37
 
31 38
 bool Sphere::collision(const Plane &p) const {
32
-	return true;
39
+	return (p.dist(pos)<=radius);
33 40
 }
34 41
 
35 42
 bool Sphere::inSphere(Punkt3D p) const {
@@ -53,12 +60,12 @@ void Ray::set(Punkt3D _pos, Punkt3D _dir) {
53 60
 	dir = _dir;
54 61
 }
55 62
 
56
-Punkt3D Ray::get(float x) {
63
+Punkt3D Ray::get(float x) const {
57 64
 	return pos + dir*x;
58 65
 }
59 66
 
60 67
 // TODO: Heavy Testing
61
-bool Ray::onRay(Punkt3D p, int rnd) {
68
+bool Ray::onRay(Punkt3D p, int rnd) const {
62 69
 	float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
63 70
 	short fcount = 0;
64 71
 	bool g1=true, g2=true, g3=true;
@@ -105,14 +112,14 @@ bool Ray::onRay(Punkt3D p, int rnd) {
105 112
 	else if(g3)
106 113
 		return (r1 == r2);
107 114
 	else
108
-		return (r1 == r2 == r3);
115
+		return (r1 == r2 && r1 == r3);
109 116
 }
110 117
 
111
-float Ray::dist(Punkt3D p) {
118
+float Ray::dist(Punkt3D p) const {
112 119
 	return abs(p - get( getParam(p) ));
113 120
 }
114 121
 
115
-float Ray::getParam(Punkt3D p, bool onray) {
122
+float Ray::getParam(Punkt3D p, bool onray) const {
116 123
 	if(onray) {
117 124
 		if(!onRay(p))
118 125
 			return 0.0f;
@@ -193,7 +200,7 @@ bool Plane::collision(const Plane &p) const {
193 200
 }
194 201
 
195 202
 float Plane::dist(Punkt3D p) const {
196
-	
203
+		
197 204
 }
198 205
 
199 206
 } // namespace segl

+ 5
- 4
geotypes.h View File

@@ -5,6 +5,7 @@
5 5
 
6 6
 namespace segl {
7 7
 
8
+class Sphere;
8 9
 class Ray;
9 10
 class Box;
10 11
 class Plane;
@@ -38,10 +39,10 @@ class Ray {
38 39
 		Ray(Punkt3D _pos, Punkt3D _dir);
39 40
 		
40 41
 		void set(Punkt3D _pos, Punkt3D _dir);
41
-		Punkt3D get(float x);
42
-		bool onRay(Punkt3D p, int rnd=-1);
43
-		float dist(Punkt3D p);
44
-		float getParam(Punkt3D p, bool onray=false);
42
+		Punkt3D get(float x) const;
43
+		bool onRay(Punkt3D p, int rnd=-1) const;
44
+		float dist(Punkt3D p) const;
45
+		float getParam(Punkt3D p, bool onray=false) const;
45 46
 		
46 47
 		bool collision(const Sphere &s) const;
47 48
 		bool collision(const Ray &r) const;

+ 3
- 1
punkt2d.h View File

@@ -3,6 +3,7 @@
3 3
 
4 4
 #include <iostream>
5 5
 #include <cmath>
6
+#include <SDL_opengl.h>
6 7
 #include "emath.h"
7 8
 
8 9
 namespace segl {
@@ -53,12 +54,13 @@ class Punkt2D {
53 54
 
54 55
 } // namespace segl
55 56
 
57
+// #ifdef GLAPI
56 58
 void glTexCoord2f(segl::Punkt2D);
57 59
 float abs(segl::Punkt2D);
58 60
 
59 61
 // Fixed Headers
60 62
 void glTexCoordP2D(segl::Punkt2D p);
61
-
63
+// #endif /* GLAPI */
62 64
 
63 65
 
64 66
 #endif

+ 3
- 2
punkt3d.h View File

@@ -3,6 +3,7 @@
3 3
 
4 4
 #include <iostream>
5 5
 #include <cmath>
6
+#include <SDL_opengl.h>
6 7
 #include "emath.h"
7 8
 
8 9
 namespace segl {
@@ -62,7 +63,7 @@ class Punkt3D {
62 63
 float abs(const segl::Punkt3D&);
63 64
 
64 65
 // OpenGL-Functions for Punkt3D
65
-
66
+// #ifdef GLAPI
66 67
 void glVertex3f(const segl::Punkt3D&);
67 68
 void glTranslatef(const segl::Punkt3D&);
68 69
 void glNormal3f(const segl::Punkt3D&);
@@ -76,5 +77,5 @@ void glNormalP3D(const segl::Punkt3D&);
76 77
 
77 78
 void glRotateP3D(const float&, const segl::Punkt3D&);
78 79
 void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal);
79
-
80
+// #endif /* GLAPI */
80 81
 #endif

Loading…
Cancel
Save