~mir-team/mir/in-process-egl+input-conglomeration

« back to all changes in this revision

Viewing changes to 3rd_party/glm/glm/gtx/closest_point.inl

Merged trunk and fixed issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
///////////////////////////////////////////////////////////////////////////////////////////////////
2
 
// OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
3
 
///////////////////////////////////////////////////////////////////////////////////////////////////
4
 
// Created : 2005-12-30
5
 
// Updated : 2008-10-05
6
 
// Licence : This source is under MIT License
7
 
// File    : glm/gtx/closest_point.inl
8
 
///////////////////////////////////////////////////////////////////////////////////////////////////
9
 
 
10
 
#ifndef glm_gtx_closest_point
11
 
#define glm_gtx_closest_point
12
 
 
13
 
namespace glm
14
 
{
15
 
        template <typename valType> 
16
 
        GLM_FUNC_QUALIFIER detail::tvec3<valType> closestPointOnLine
17
 
        (
18
 
                detail::tvec3<valType> const & point, 
19
 
                detail::tvec3<valType> const & a, 
20
 
                detail::tvec3<valType> const & b
21
 
        )
22
 
        {
23
 
                valType LineLength = distance(a, b);
24
 
                detail::tvec3<valType> Vector = point - a;
25
 
                detail::tvec3<valType> LineDirection = (b - a) / LineLength;
26
 
 
27
 
                // Project Vector to LineDirection to get the distance of point from a
28
 
                valType Distance = dot(Vector, LineDirection);
29
 
 
30
 
                if(Distance <= valType(0)) return a;
31
 
                if(Distance >= LineLength) return b;
32
 
                return a + LineDirection * Distance;
33
 
        }
34
 
}//namespace glm
35
 
 
36
 
#endif//glm_gtx_closest_point