diff --git a/ege/Ray.cpp b/ege/Ray.cpp new file mode 100644 index 0000000..6d6e996 --- /dev/null +++ b/ege/Ray.cpp @@ -0,0 +1,26 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ +#include + +#undef __class__ +#define __class__ "Ray" + +ege::Ray::Ray(const vec3& _origin, const vec3& _direction) : + m_origin(_origin), + m_direction(_direction) { + m_direction.safeNormalize(); +} + +void ege::Ray::setOrigin(const vec3& _origin) { + m_origin = _origin; +} + +void ege::Ray::setDirection(const vec3& _direction) { + m_direction = _direction; + m_direction.safeNormalize(); +} diff --git a/ege/Ray.h b/ege/Ray.h new file mode 100644 index 0000000..d52e1a4 --- /dev/null +++ b/ege/Ray.h @@ -0,0 +1,67 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EGE_RAY_H__ +#define __EGE_RAY_H__ + +#include + +namespace ege { + class Ray { + public: + /** + * @brief Contructor + * @param _origin The ray's origin. + * @param _direction The ray's direction. + */ + Ray(const vec3& _origin=vec3(0,0,0), const vec3& _direction=vec3(0,0,1)); + /** + * @brief Destructor. + */ + ~Ray() {}; + private: + vec3 m_origin; //!< The ray origin position. + public: + /** + * @brief Set the ray's origin. + * @param[in] _origin The new origin. + */ + void setOrigin(const vec3& _origin); + /** + * @brief Gets the ray's origin. + * @return The ray's origin. + */ + const vec3& getOrigin() const { + return m_origin; + } + private: + vec3 m_direction; //!< The ray direction vector. + public: + /** + * @brief Sets the ray's direction. + * @param[in] _direction The new direction vector. + */ + void setDirection(const vec3& _direction); + /** + * @brief Gets the ray's direction. + * @return The ray's direction. + */ + const vec3& getDirection() const { + return m_direction; + } + public: + /** + * @brief Sets this ray to the specified values. + * @param[in] _origin The ray's origin. + * @param[in] _direction The ray's direction. + */ + void set(const vec3& _origin, const vec3& _direction); + }; +} + +#endif diff --git a/ege/camera/Camera.cpp b/ege/camera/Camera.cpp index 265c00a..79e6cbb 100644 --- a/ege/camera/Camera.cpp +++ b/ege/camera/Camera.cpp @@ -66,3 +66,14 @@ void ege::Camera::configureOpenGL() { ewol::openGL::setMatrix(getMatrixProjection()); } + +ege::Ray ege::Camera::getRayFromScreen(const vec2& _offset) { + ege::Ray out; + return out; +} + +ege::Ray ege::Camera::getRayFromScreenPosition(const vec2& _position, const vec2& _size) { + vec2 half = _size * 0.5f; + return getRayFromScreen(_position/half - vec2(1,1)); +} + diff --git a/ege/camera/Camera.h b/ege/camera/Camera.h index 8cba304..b42f982 100644 --- a/ege/camera/Camera.h +++ b/ege/camera/Camera.h @@ -14,6 +14,8 @@ #include #include #include +#include + namespace ege { class Camera { @@ -143,6 +145,20 @@ namespace ege { float getZNear() { return m_zNear; } + public: + /** + * Get ray from the camera with the screen offset. + * @param[in] _offset Offset in the screen [-1..1] + * @return the ray requested. + */ + virtual ege::Ray getRayFromScreen(const vec2& _offset); + /** + * Get ray from the camera with the screen offset. + * @param[in] _position positin the screen + * @param[in] _size size of the screen + * @return the ray requested. + */ + ege::Ray getRayFromScreenPosition(const vec2& _position, const vec2& _size); }; }; diff --git a/ege/camera/View.cpp b/ege/camera/View.cpp index 551abd1..308d998 100644 --- a/ege/camera/View.cpp +++ b/ege/camera/View.cpp @@ -66,3 +66,9 @@ vec3 ege::camera::View::getViewVector() const { return m_eye-m_target; } + +ege::Ray ege::camera::View::getRayFromScreen(const vec2& _offset) { + ege::Ray out(m_eye, getViewVector()); + // TODO : Use offset... + return out; +} diff --git a/ege/camera/View.h b/ege/camera/View.h index 93973ba..c0876a6 100644 --- a/ege/camera/View.h +++ b/ege/camera/View.h @@ -75,6 +75,8 @@ namespace ege { }; protected: virtual vec3 getViewVector() const; + public: + virtual ege::Ray getRayFromScreen(const vec2& _offset); }; }; }; diff --git a/lutin_ege.py b/lutin_ege.py index e08c66c..0ecf818 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -43,6 +43,7 @@ def create(target): 'ege/physicsShape/PhysicsConvexHull.cpp', 'ege/physicsShape/PhysicsCylinder.cpp', 'ege/physicsShape/PhysicsSphere.cpp', + 'ege/Ray.cpp', ]) myModule.copy_folder('data/ParticuleMesh.*','')