PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llline.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 80 lines | 27 code | 15 blank | 38 comment | 0 complexity | 8dd7483cf06775bb2d539837efbe9eda MD5 | raw file
 1// llline.h
 2/**
 3 * @file llline.cpp
 4 * @author Andrew Meadows
 5 * @brief Simple line for computing nearest approach between two infinite lines
 6 *
 7 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
 8 * Second Life Viewer Source Code
 9 * Copyright (C) 2010, Linden Research, Inc.
10 * 
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License only.
15 * 
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 * 
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 * 
25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
26 * $/LicenseInfo$
27 */
28
29#ifndef LL_LINE_H
30#define LL_LINE_H
31
32#include <iostream>
33#include "stdtypes.h"
34#include "v3math.h"
35
36const F32 DEFAULT_INTERSECTION_ERROR = 0.000001f;
37
38class LLLine
39{
40public:
41	LLLine();
42	LLLine( const LLVector3& first_point, const LLVector3& second_point );
43	virtual ~LLLine() {};
44
45	void setPointDirection( const LLVector3& first_point, const LLVector3& second_point );
46	void setPoints( const LLVector3& first_point, const LLVector3& second_point );
47
48	bool intersects( const LLVector3& point, F32 radius = DEFAULT_INTERSECTION_ERROR ) const;
49
50	// returns the point on this line that is closest to some_point
51	LLVector3 nearestApproach( const LLVector3& some_point ) const;
52
53	// returns the point on this line that is closest to other_line
54	LLVector3 nearestApproach( const LLLine& other_line ) const;
55
56	friend std::ostream& operator<<( std::ostream& output_stream, const LLLine& line );
57
58	// returns 'true' if this line intersects the plane
59	// on success stores the intersection point in 'result'
60	bool intersectsPlane( LLVector3& result, const LLLine& plane ) const;
61
62	// returns 'true' if planes intersect, and stores the result 
63	// the second and third arguments are treated as planes
64	// where mPoint is on the plane and mDirection is the normal
65	// result.mPoint will be the intersection line's closest approach 
66	// to first_plane.mPoint
67	static bool getIntersectionBetweenTwoPlanes( LLLine& result, const LLLine& first_plane, const LLLine& second_plane );
68
69	const LLVector3& getPoint() const { return mPoint; }
70	const LLVector3& getDirection() const { return mDirection; }
71
72protected:
73	// these are protected because some code assumes that the normal is 
74	// always correct and properly normalized.
75	LLVector3 mPoint;
76	LLVector3 mDirection;
77};
78
79
80#endif