Activate point_is_on_surface() and calculate_normal()
This commit is contained in:
parent
6bb7689ac0
commit
86a9c74c1e
3 changed files with 17 additions and 16 deletions
|
@ -35,6 +35,7 @@ public:
|
||||||
Shape(Vector3 o);
|
Shape(Vector3 o);
|
||||||
|
|
||||||
virtual int does_intersect(const Ray &ray, float **t) const = 0;
|
virtual int does_intersect(const Ray &ray, float **t) const = 0;
|
||||||
|
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
||||||
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -128,25 +128,21 @@ Sphere::does_intersect(const Ray &ray, float **t)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sphere_point_lies_on_surface --
|
* Sphere::point_is_on_surface --
|
||||||
*
|
*
|
||||||
* Determine if a point lies on the given sphere.
|
* Determine if a point lies on the surface of this Sphere.
|
||||||
*/
|
*/
|
||||||
#if 0
|
bool
|
||||||
int
|
Sphere::point_is_on_surface(const Vector3 &p)
|
||||||
sphere_point_lies_on_surface(Object *obj, Vector3 p)
|
const
|
||||||
{
|
{
|
||||||
assert(obj != NULL && object_get_type(obj) == ObjectTypeSphere);
|
Vector3 o = get_origin();
|
||||||
|
float x = p.x - o.x;
|
||||||
|
float y = p.y - o.y;
|
||||||
|
float z = p.z - o.z;
|
||||||
|
|
||||||
Vector3 loc = object_get_location(obj);
|
return x*x + y*y + z*z == radius*radius;
|
||||||
float x = p.x - loc.x;
|
|
||||||
float y = p.y - loc.y;
|
|
||||||
float z = p.z - loc.z;
|
|
||||||
float r = object_sphere_get_radius(obj);
|
|
||||||
|
|
||||||
return (x * x) + (y * y) + (z * z) == (r * r);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -159,8 +155,11 @@ Vector3
|
||||||
Sphere::compute_normal(const Vector3 &p)
|
Sphere::compute_normal(const Vector3 &p)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
// TODO: Make sure the given point is actually on the surface of the sphere.
|
// Make sure the given point is actually on the surface of the sphere.
|
||||||
|
if (!point_is_on_surface(p)) {
|
||||||
// The fun thing about sphere is the normal to any point on the sphere is the point itself. Woo!
|
|
||||||
return Vector3::Zero;
|
return Vector3::Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The fun thing about sphere is the normal to any point on the sphere is the point itself. Woo!
|
||||||
|
return p - get_origin();
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
void set_radius(float r);
|
void set_radius(float r);
|
||||||
|
|
||||||
int does_intersect(const Ray &ray, float **t) const;
|
int does_intersect(const Ray &ray, float **t) const;
|
||||||
|
bool point_is_on_surface(const Vector3 &p) const;
|
||||||
Vector3 compute_normal(const Vector3 &p) const;
|
Vector3 compute_normal(const Vector3 &p) const;
|
||||||
private:
|
private:
|
||||||
float radius;
|
float radius;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue