[DEV] add Ray camera ray (not ended)
This commit is contained in:
parent
790c8f6cdb
commit
13c661d29f
26
ege/Ray.cpp
Normal file
26
ege/Ray.cpp
Normal 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
67
ege/Ray.h
Normal 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
|
@ -66,3 +66,14 @@ void ege::Camera::configureOpenGL() {
|
|||||||
ewol::openGL::setMatrix(getMatrixProjection());
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <etk/math/Vector3D.h>
|
#include <etk/math/Vector3D.h>
|
||||||
#include <etk/math/Vector2D.h>
|
#include <etk/math/Vector2D.h>
|
||||||
#include <etk/math/Matrix4.h>
|
#include <etk/math/Matrix4.h>
|
||||||
|
#include <ege/Ray.h>
|
||||||
|
|
||||||
|
|
||||||
namespace ege {
|
namespace ege {
|
||||||
class Camera {
|
class Camera {
|
||||||
@ -143,6 +145,20 @@ namespace ege {
|
|||||||
float getZNear() {
|
float getZNear() {
|
||||||
return m_zNear;
|
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);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,3 +66,9 @@ vec3 ege::camera::View::getViewVector() const {
|
|||||||
return m_eye-m_target;
|
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;
|
||||||
|
}
|
||||||
|
@ -75,6 +75,8 @@ namespace ege {
|
|||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
virtual vec3 getViewVector() const;
|
virtual vec3 getViewVector() const;
|
||||||
|
public:
|
||||||
|
virtual ege::Ray getRayFromScreen(const vec2& _offset);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -43,6 +43,7 @@ def create(target):
|
|||||||
'ege/physicsShape/PhysicsConvexHull.cpp',
|
'ege/physicsShape/PhysicsConvexHull.cpp',
|
||||||
'ege/physicsShape/PhysicsCylinder.cpp',
|
'ege/physicsShape/PhysicsCylinder.cpp',
|
||||||
'ege/physicsShape/PhysicsSphere.cpp',
|
'ege/physicsShape/PhysicsSphere.cpp',
|
||||||
|
'ege/Ray.cpp',
|
||||||
])
|
])
|
||||||
|
|
||||||
myModule.copy_folder('data/ParticuleMesh.*','')
|
myModule.copy_folder('data/ParticuleMesh.*','')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user