[DEV] add Ray camera ray (not ended)

This commit is contained in:
Edouard DUPIN 2014-11-11 23:09:41 +01:00
parent 790c8f6cdb
commit 13c661d29f
7 changed files with 129 additions and 0 deletions

26
ege/Ray.cpp Normal file
View File

@ -0,0 +1,26 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ege/Ray.h>
#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();
}

67
ege/Ray.h Normal file
View File

@ -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 <etk/math/Vector3D.h>
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

View File

@ -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));
}

View File

@ -14,6 +14,8 @@
#include <etk/math/Vector3D.h>
#include <etk/math/Vector2D.h>
#include <etk/math/Matrix4.h>
#include <ege/Ray.h>
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);
};
};

View File

@ -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;
}

View File

@ -75,6 +75,8 @@ namespace ege {
};
protected:
virtual vec3 getViewVector() const;
public:
virtual ege::Ray getRayFromScreen(const vec2& _offset);
};
};
};

View File

@ -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.*','')