Browse Source

Updated geotypes, sphereintersection still broken

Sebastian 11 years ago
parent
commit
801a164446
2 changed files with 23 additions and 15 deletions
  1. 16
    8
      geotypes.cpp
  2. 7
    7
      geotypes.h

+ 16
- 8
geotypes.cpp View File

@@ -43,7 +43,7 @@ bool Sphere::collision(const Sphere &s) const {
43 43
 }
44 44
 
45 45
 bool Sphere::collision(const Ray &r) const {
46
-	return true;
46
+	return (r.dist(pos) <= radius);
47 47
 }
48 48
 
49 49
 bool Sphere::collision(const Box & b) const {
@@ -66,26 +66,26 @@ Ray::Ray() {
66 66
 	dir.set(0.0f, 1.0f, 0.0f);
67 67
 }
68 68
 
69
-Ray::Ray(Punkt3D _pos, Punkt3D _dir) {
69
+Ray::Ray(const Punkt3D &_pos, const Punkt3D &_dir) {
70 70
 	set(_pos, _dir);
71 71
 }
72 72
 
73
-void Ray::set(Punkt3D _pos, Punkt3D _dir) {
73
+void Ray::set(const Punkt3D &_pos, const Punkt3D &_dir) {
74 74
 	pos = _pos;
75 75
 	dir = _dir;
76 76
 }
77 77
 
78
-void Ray::setFromPoints(Punkt3D a, Punkt3D b) {
78
+void Ray::setFromPoints(const Punkt3D &a, const Punkt3D &b) {
79 79
 	pos = a;
80 80
 	dir = b - a;
81 81
 }
82 82
 
83
-Punkt3D Ray::get(float x) {
83
+Punkt3D Ray::get(float x) const {
84 84
 	return pos + dir*x;
85 85
 }
86 86
 
87 87
 // TODO: Heavy Testing
88
-bool Ray::onRay(Punkt3D p, int rnd) {
88
+bool Ray::onRay(Punkt3D p, int rnd) const {
89 89
 	float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
90 90
 	short fcount = 0;
91 91
 	bool g1=true, g2=true, g3=true;
@@ -135,11 +135,19 @@ bool Ray::onRay(Punkt3D p, int rnd) {
135 135
 		return ((r1 == r2) == r3);
136 136
 }
137 137
 
138
-float Ray::dist(Punkt3D p) {
138
+float Ray::dist(Punkt3D p) const {
139 139
 	return abs(p - get( getParam(p) ));
140 140
 }
141 141
 
142
-float Ray::getParam(Punkt3D p, bool onray) {
142
+int getIntersectionParam(const std::Ray &ray, float *param1, float *param2) {
143
+
144
+}
145
+
146
+int getIntersectionParam(const std::Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b) {
147
+
148
+}
149
+
150
+float Ray::getParam(Punkt3D p, bool onray) const {
143 151
 	if(onray) {
144 152
 		if(!onRay(p))
145 153
 			return 0.0f;

+ 7
- 7
geotypes.h View File

@@ -57,14 +57,14 @@ class Ray {
57 57
 		Punkt3D dir;
58 58
 		
59 59
 		Ray();
60
-		Ray(Punkt3D _pos, Punkt3D _dir);
60
+		Ray(const Punkt3D &_pos, const Punkt3D &_dir);
61 61
 		
62
-		void set(Punkt3D _pos, Punkt3D _dir);
63
-		void setFromPoints(Punkt3D a, Punkt3D b);
64
-		Punkt3D get(float x);
65
-		bool onRay(Punkt3D p, int rnd=-1);
66
-		float dist(Punkt3D p);
67
-		float getParam(Punkt3D p, bool onray=false);
62
+		void set(const Punkt3D &_pos, const Punkt3D &_dir);
63
+		void setFromPoints(const Punkt3D &a, const Punkt3D &b);
64
+		Punkt3D get(float x) const;
65
+		bool onRay(Punkt3D p, int rnd=-1) const;
66
+		float dist(Punkt3D p) const;
67
+		float getParam(Punkt3D p, bool onray=false) const;
68 68
 		
69 69
 		bool collision(const Sphere &s) const;
70 70
 		bool collision(const Ray &r) const;

Loading…
Cancel
Save