JNR
laLine3.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 #ifndef M_LINE3_H
31 #define M_LINE3_H
32 
34 
35 
37 //
39 
40 class laLine3
41 {
42 public:
43  laPoint3 origin;
44  laPoint3 vector;
45 
46  laLine3(void) {}
47  laLine3(laPoint3 &a, laPoint3 &b){
48  build_2pt(a,b);
49  }
50 
52 
53 
55  inline void build_2pt(laPoint3 &a, laPoint3 &b){
56  origin = a; vector = b-a;
57  }
58 
60  inline void build_vec(laPoint3 &a, laPoint3 &v){
61  origin = a; vector = v;
62  }
64 
65 
67 
68  inline double lenght() const{
69  return vector.lenght();
70  }
71 
73  inline double lenght_sq() const{
74  return vector.lenght_sq();
75  }
77 
79 
80 
82  inline laPoint3 end() const{ return origin + vector; };
83 
85  inline void at(double k, laPoint3 *ppt) const{
86  *ppt = origin + vector*k;
87  }
88 
90  inline laPoint3 at(double k) const{
91  return origin + vector*k;
92  }
94 
96  // TODO: Not Tested (NT)
97  laPoint3 intersection(laLine3 &l, double &pk1);
98 
100  // TODO: Not Tested (NT)
101  laPoint3 intersection(class laPlane3 &pn, double *pk=NULL);
102 
104  void draw(class laRenderer* r, laPoint3 pos);
105 };
107 #endif
laPoint3 intersection(laLine3 &l, double &pk1)
Find point of intersection (or nearest point) to another laLine3.
Definition: laLine3.cpp:48
3D line segment
Definition: laLine3.h:40
laPoint3 vector
Vector ( not normalized, so k = [0;1] traces the whole line segment )
Definition: laLine3.h:44
laPoint3 end() const
Get endpoint.
Definition: laLine3.h:82
void build_2pt(laPoint3 &a, laPoint3 &b)
Build from two end-points.
Definition: laLine3.h:55
laPoint3 origin
Point of origin.
Definition: laLine3.h:43
void draw(class laRenderer *r, laPoint3 pos)
Draw the line ( primarily for debug purposes )
Definition: laLine3.cpp:123
void build_vec(laPoint3 &a, laPoint3 &v)
Build from an end-poind and vector.
Definition: laLine3.h:60
double lenght_sq() const
Squared root of segment lenght.
Definition: laLine3.h:73
void at(double k, laPoint3 *ppt) const
Get point at 1/k lenght (returns in user-specified pointer)
Definition: laLine3.h:85
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
3D plane
Definition: laPlane3.h:39