NGL  6.5
The NCCA Graphics Library
PathCamera.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "PathCamera.h"
18 #include "NGLStream.h"
19 #include <memory>
20 //--------------------------------------------------------------------------------------------------------------------
23 //----------------------------------------------------------------------------------------------------------------------
24 
25 
26 namespace ngl
27 {
28 
29 //----------------------------------------------------------------------------------------------------------------------
30 PathCamera::PathCamera( const Vec3 &_up, const BezierCurve &_eyePath,const BezierCurve &_lookPath, Real _step) noexcept
31 {
32  m_dir=CAMFWD;
33  m_eyeCurvePoint=0.0;
34  m_lookCurvePoint=0.0;
35  m_eyePath=_eyePath;
36  m_lookPath=_lookPath;
37  m_step=_step;
38  m_up=_up;
39 }
40 
41 //----------------------------------------------------------------------------------------------------------------------
42 PathCamera::PathCamera(const Vec3 &_up, const Vec3 *_eyePoints,int _nEyePoints, const Vec3 *_lookPoints, int _nLookPoints,Real _step) noexcept
43 {
44  m_dir=CAMFWD;
45  m_eyeCurvePoint=0.0;
46  m_lookCurvePoint=0.0;
47  for(int i=0; i<_nEyePoints; ++i)
48  {
49  m_eyePath.addPoint(_eyePoints[i]);
50  }
51  m_eyePath.createKnots();
52 
53  for(int i=0; i<_nLookPoints; ++i)
54  {
55  m_lookPath.addPoint(_lookPoints[i]);
56  }
57  m_lookPath.createKnots();
58  m_step=_step;
59  m_up=_up;
60 }
61 
62 
63 
64 //----------------------------------------------------------------------------------------------------------------------
65 PathCamera::PathCamera(const Vec4 &_up, const std::string &_fName, Real _step) noexcept
66 {
67  m_dir=CAMFWD;
68 
69  std::ifstream FileIn;
70  FileIn.open(_fName.c_str(),std::ios::in);
71 
72  if (!FileIn.is_open())
73  {
74  std::cout <<"File : "<<_fName<<" Not found Exiting "<<std::endl;
75  exit(EXIT_FAILURE);
76  }
77  unsigned int nEye,nLook;
78  FileIn >> nEye>>nLook;
79 
80  std::unique_ptr<Vec4 []> eyePoints( new Vec4[nEye]);
81  std::unique_ptr<Vec4 []> lookPoints( new Vec4[nLook]);
82 
83  for(unsigned int i=0; i<nEye; ++i)
84  {
85  FileIn >> eyePoints[i];
86  }
87  for(unsigned int i=0; i<nLook; ++i)
88  {
89  FileIn>> lookPoints[i];
90  }
91  FileIn.close();
92 
93  m_eyeCurvePoint=0.0;
94  m_lookCurvePoint=0.0;
95  for(unsigned int i=0; i<nEye; ++i)
96  {
97  m_eyePath.addPoint(eyePoints[i].toVec3());
98  }
99  m_eyePath.createKnots();
100 
101  for(unsigned int i=0; i<nLook; ++i)
102  {
103  m_lookPath.addPoint(lookPoints[i].toVec3());
104  }
105  m_lookPath.createKnots();
106 
107  m_step=_step;
108  m_up=_up;
109 
110 }
111 
112 //----------------------------------------------------------------------------------------------------------------------
113 void PathCamera::loadPath( const std::string &_fName) noexcept
114 {
115  m_dir=CAMFWD;
116  m_eyeCurvePoint=0.0;
117  m_lookCurvePoint=0.0;
118 
119  std::ifstream FileIn;
120  FileIn.open(_fName.c_str(),std::ios::in);
121 
122  if (!FileIn.is_open())
123  {
124  std::cout <<"File : "<<_fName<<" Not found Exiting "<<std::endl;
125  exit(EXIT_FAILURE);
126  }
128  /*
129  Vector eyePoint;
130  Vector lookPoint;
131 
132  for(int i=0; i<4; i++)
133  {
134  FileIn >> eyePoint;
135  EyePath->SetCP(i,eyePoint);
136  }
137  for(int i=0; i<4; i++)
138  {
139  FileIn>> lookPoint;
140  LookPath->SetCP(i,lookPoint);
141  }
142  */
143  FileIn.close();
144 
145 
146 }
147 
148 
149 //----------------------------------------------------------------------------------------------------------------------
151 {
152 
153 }
154 
155 //----------------------------------------------------------------------------------------------------------------------
156 void PathCamera::update() noexcept
157 {
160  std::cout <<ept<<lpt<<std::endl;
161  m_eye.set(ept);
162  m_look.set(lpt);
163  m_n=m_eye-m_look;
164  m_u.set(m_up.cross(m_n));
165  m_v.set(m_n.cross(m_u));
167 
168  setViewMatrix();
169 
171  if(m_eyeCurvePoint>1.0)
172  {
173  m_eyeCurvePoint=0.0;
174  }
176  if(m_lookCurvePoint>1.0)
177  {
178  m_lookCurvePoint=0.0;
179  }
180 }
181 
182 //----------------------------------------------------------------------------------------------------------------------
184 {
187 
188  m_eye.set(ept);
189  m_look.set(lpt);
190  m_n=m_eye-m_look;
191  m_u=m_up.cross(m_n);
192  m_v=m_n.cross(m_u);
194 
195  setViewMatrix();
196  if(m_dir==CAMFWD)
197  {
199  if(m_eyeCurvePoint>=1.0)
200  {
201  m_dir=CAMBWD;
202  }
203 
205  if(m_lookCurvePoint>=1.0)
206  {
207  m_dir=CAMBWD;
208  }
209  } // end if fwd
210 
211  else
212  {
215  {
216  m_dir=CAMFWD;
217  }
220  {
221  m_dir=CAMFWD;
222  }
223  }// end else
224 
225 }
226 
227 //----------------------------------------------------------------------------------------------------------------------
228 void PathCamera::drawPaths()const noexcept
229 {
231 }
232 
233 void PathCamera::createCurvesForDrawing(int _lod ) noexcept
234 {
235  // now we set the level of detail for the curve
236  m_eyePath.setLOD(_lod);
237  m_lookPath.setLOD(_lod);
238 }
239 
240 
241 
242 } // end namespace ngll
243 //----------------------------------------------------------------------------------------------------------------------
244 
~PathCamera() noexcept
dtor
Definition: PathCamera.cpp:150
Real m_step
the step for each update of the camera, the higher the number the smoother the movement ...
Definition: PathCamera.h:130
Generic Bezier Curve Class allowing the user to generate basic curves using a number of different con...
Definition: BezierCurve.h:45
Vec4 & normalize() noexcept
Normalize the vector using .
Definition: Vec4.cpp:99
camera going forward
Definition: PathCamera.h:119
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
Vec4 m_v
vector for the Camera local cord frame
Definition: Camera.h:311
void updateLooped() noexcept
update the camera by incrementing the step value and re-calculating the tx matrix if the camera is at...
Definition: PathCamera.cpp:183
Vec4 m_look
where the camera is looking to, used with Eye to calculate the Vector m_n
Definition: Camera.h:323
void setViewMatrix() noexcept
method to set the modelview matrix values for the current camera, this method load the matrix Modelvi...
Definition: Camera.cpp:95
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
Real m_lookCurvePoint
the look path of the camera&#39;s current position value
Definition: PathCamera.h:105
GLuint in
Definition: glew.h:11550
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
Vec3 getPointOnCurve(Real _value) const noexcept
get a point on the curve in the range of 0 - 1 based on the control points
camera going backwards
Definition: PathCamera.h:121
Real m_eyeCurvePoint
the eye path of the camera&#39;s current position value
Definition: PathCamera.h:101
BezierCurve m_eyePath
BezierCurve for the the eye positions.
Definition: PathCamera.h:109
void set(Real _x, Real _y, Real _z, Real _w=1.0) noexcept
sets the vector component from 3 values
Definition: Vec4.cpp:41
Vec4 m_eye
the position of the Camera used to calculate the local cord frame
Definition: Camera.h:319
Vec4 m_up
gives a general indication of which way up the camera is
Definition: Camera.h:327
Vec4 m_n
vector for the Camera local cord frame
Definition: Camera.h:315
stream helpers for ngl data types
DIRECTION m_dir
current direction of the camera
Definition: PathCamera.h:126
void drawPaths() const noexcept
a method to draw the camera paths for debugging etc (note uses immediate mode GL) ...
Definition: PathCamera.cpp:228
Vec4 m_u
vector for the Camera local cord frame
Definition: Camera.h:307
void loadPath(const std::string &_fName) noexcept
load a path from a file
Definition: PathCamera.cpp:113
a simple camera attached to a path inherits from Camera
BezierCurve m_lookPath
BezierCurve for the look positions.
Definition: PathCamera.h:112
void createCurvesForDrawing(int _lod) noexcept
create the display lists for the paths so we can see them
Definition: PathCamera.cpp:233
void setLOD(int _lod) noexcept
set the Level of Detail for Drawing
Definition: BezierCurve.h:138
void update() noexcept
update the camera by incrementing the step value and re-calculating the tx matrix ...
Definition: PathCamera.cpp:156
GLsizei const GLchar *const * string
Definition: glew.h:1847
void cross(const Vec4 &_v1, const Vec4 &_v2) noexcept
set the vector as the cross product from 2 other vectors
Definition: Vec4.cpp:110