-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
231 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#define SPICA_DISK_EXPORT | ||
#include "disk.h" | ||
|
||
namespace spica { | ||
|
||
Disk::Disk() | ||
: _center() | ||
, _normal() | ||
, _radius(0.0) | ||
{ | ||
} | ||
|
||
Disk::Disk(const Vector3& center, const Vector3& normal, double radius) | ||
: _center(center) | ||
, _normal(normal) | ||
, _radius(radius) | ||
{ | ||
} | ||
|
||
Disk::Disk(const Disk& disk) | ||
: _center() | ||
, _normal() | ||
, _radius() | ||
{ | ||
operator=(disk); | ||
} | ||
|
||
Disk::~Disk() | ||
{ | ||
} | ||
|
||
Disk& Disk::operator=(const Disk& disk) { | ||
this->_center = disk._center; | ||
this->_normal = disk._normal; | ||
this->_radius = disk._radius; | ||
return *this; | ||
} | ||
|
||
bool Disk::intersect(const Ray& ray, double* tHit) const { | ||
*tHit = (_center - ray.origin()).dot(ray.direction()); | ||
Vector3 posHit = ray.origin() + (*tHit) * ray.direction(); | ||
return (posHit - _center).norm() < _radius; | ||
} | ||
|
||
} // namepspace spica | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef _SPICA_DISK_H_ | ||
#define _SPICA_DISK_H_ | ||
|
||
#if defined(_WIN32) || defined(__WIN32__) | ||
#ifdef SPICA_DISK_EXPORT | ||
#define SPICA_DISK_DLL __declspec(dllexport) | ||
#else | ||
#define SPICA_DISK_DLL __declspec(dllimport) | ||
#endif | ||
#else | ||
#define SPICA_DISK_DLL | ||
#endif | ||
|
||
#include "../renderer/ray.h" | ||
#include "../utils/vector3.h" | ||
|
||
namespace spica { | ||
|
||
class Disk { | ||
private: | ||
Vector3 _center; | ||
Vector3 _normal; | ||
double _radius; | ||
|
||
public: | ||
Disk(); | ||
Disk(const Vector3& center, const Vector3& normal, double radius); | ||
Disk(const Disk& disk); | ||
~Disk(); | ||
|
||
Disk& operator=(const Disk& disk); | ||
|
||
bool intersect(const Ray& ray, double* tHit) const; | ||
|
||
inline Vector3 center() const { return _center; } | ||
inline Vector3 normal() const { return _normal; } | ||
inline double radius() const { return _radius; } | ||
|
||
}; | ||
|
||
} // namespace spica | ||
|
||
#endif // _SPICA_DISK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef _SPICA_GEOMETRY_H_ | ||
#define _SPICA_GEOMETRY_H_ | ||
|
||
#include "bbox.h" | ||
#include "triangle.h" | ||
#include "quad.h" | ||
#include "disk.h" | ||
|
||
#endif // _SPICA_GEOMETRY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#define SPICA_QUAD_EXPORT | ||
#include "quad.h" | ||
|
||
namespace spica { | ||
|
||
Quad::Quad() | ||
: _t0() | ||
, _t1() | ||
{ | ||
} | ||
|
||
Quad::Quad(const Vector3& v0, const Vector3& v1, const Vector3& v2, const Vector3& v3) | ||
: _t0(v0, v1, v2) | ||
, _t1(v2, v3, v0) | ||
{ | ||
} | ||
|
||
Quad::Quad(const Quad& quad) | ||
: _t0() | ||
, _t1() | ||
{ | ||
operator=(quad); | ||
} | ||
|
||
Quad::~Quad() | ||
{ | ||
} | ||
|
||
Quad& Quad::operator=(const Quad& quad) { | ||
this->_t0 = quad._t0; | ||
this->_t1 = quad._t1; | ||
return *this; | ||
} | ||
|
||
bool Quad::intersect(const Ray& ray, double* tHit) const { | ||
if (_t0.intersect(ray, tHit)) { | ||
return true; | ||
} | ||
|
||
if (_t1.intersect(ray, tHit)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace spica |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef _SPICA_QUAD_H_ | ||
#define _SPICA_QUAD_H_ | ||
|
||
#if defined(_WIN32) || defined(__WIN32__) | ||
#ifdef SPICA_QUAD_EXPORT | ||
#define SPICA_QUAD_DLL __declspec(dllexport) | ||
#else | ||
#define SPICA_QUAD_DLL __declspec(dllimport) | ||
#endif | ||
#else | ||
#define SPICA_QUAD_DLL | ||
#endif | ||
|
||
#include "../utils/vector3.h" | ||
#include "triangle.h" | ||
|
||
namespace spica { | ||
|
||
class SPICA_QUAD_DLL Quad { | ||
private: | ||
Triangle _t0; | ||
Triangle _t1; | ||
|
||
public: | ||
Quad(); | ||
Quad(const Vector3& v0, const Vector3& v1, const Vector3& v2, const Vector3& v3); | ||
Quad(const Quad& quad); | ||
~Quad(); | ||
|
||
Quad& operator=(const Quad& quad); | ||
|
||
bool intersect(const Ray& ray, double* tHit) const; | ||
|
||
inline Vector3 p0() const { return _t0.p0(); } | ||
inline Vector3 p1() const { return _t0.p1(); } | ||
inline Vector3 p2() const { return _t0.p2(); } | ||
inline Vector3 p3() const { return _t1.p1(); } | ||
}; | ||
|
||
} // namespace spica | ||
|
||
#endif // _SPICA_QUAD_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters