-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleViewer.cpp
More file actions
726 lines (609 loc) · 20.6 KB
/
simpleViewer.cpp
File metadata and controls
726 lines (609 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/****************************************************************************
Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
This file is part of the QGLViewer library version 2.8.0.
http://www.libqglviewer.com - contact@libqglviewer.com
This file may be used under the terms of the GNU General Public License
versions 2.0 or 3.0 as published by the Free Software Foundation and
appearing in the LICENSE file included in the packaging of this file.
In addition, as a special exception, Gilles Debunne gives you certain
additional rights, described in the file GPL_EXCEPTION in this package.
libQGLViewer uses dual licensing. Commercial/proprietary software must
purchase a libQGLViewer Commercial License.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/
#include "simpleViewer.h"
#include <QCursor>
#include <QKeyEvent>
#include <QMap>
#include <QMenu>
#include <QPoint>
#include <QDebug>
#include <QMouseEvent>
#include <QCursor>
#include <limits>
#include <cfloat>
#include <QtMath>
#include <QGLViewer/camera.h>
#include <qmessagebox.h>
#ifdef Q_OS_WIN
#include "gl/GLU.h"
#else
#include <glu.h>
#endif
#include <chrono>
using namespace std::chrono;
using namespace std;
const float dy = 3.;
void drawBigAxis(qreal length)
{
glLineWidth(2.);
glBegin(GL_LINES);
glColor3d(1.,0.,0.);
glVertex3d(-length, 0., 0);
glVertex3d(length, 0., 0.);
glEnd();
glLineWidth(1.);
}
Vec computeMovement(Vec startHandler, QPoint start, QPoint end)
{
double dx=0,dy=0;
if( (end.x() - start.x()) > 0)
{
dx += 0.1;
}
else
{
dx -= 0.1;
}
if( (end.y() - start.y()) > 0)
{
dy += 0.1;
}
else
{
dy -= 0.1;
}
//Vec ray = startHandler - this->camera->position();
Vec ray(0.,1.,0.);
Vec x = cross (ray, startHandler.unit());
return startHandler + dx*x - dy*ray;
}
void printMatrix(GLdouble m[16])
{
std::cout<<"matrix"<<std::endl;
for(int i = 0 ; i < 4 ; i++)
{
for(int j = 0 ; j < 4 ; j++)
{
std::cout<<m[4*i+j]<<" ";
}
std::cout<<"\n";
}
std::cout<<"matrix"<<std::endl;
}
void printMatrix(GLfloat m[16])
{
std::cout<<"matrix"<<std::endl;
for(int i = 0 ; i < 4 ; i++)
{
for(int j = 0 ; j < 4 ; j++)
{
std::cout<<m[4*i+j]<<" ";
}
std::cout<<"\n";
}
std::cout<<"matrix"<<std::endl;
}
void Viewer::mousePressEvent(QMouseEvent* e)
{
if ((e->modifiers() == Qt::ControlModifier))
{
selection = true;
std::cout<<"Begin1"<<std::endl;
QPoint point(e->pos());
beginSelection(point);
bool found;
startHandler = this->camera()->pointUnderPixel(point,found);
}
else
QGLViewer::mousePressEvent(e);
}
void Viewer::mouseMoveEvent(QMouseEvent *e)
{
if (selection)
{
/*std::cout<<"move1"<<std::endl;
QPoint point(e->pos());
bool found;
startHandler = this->camera()->pointUnderPixel(point,found);
*/
}
else if(mySelection)
{
//std::cout<<"move"<<std::endl;
QPoint point(e->pos());
//std::cout<<point.x()<<" "<<point.y()<<std::endl;
currentMovement = point;
bool found;
startClick = currentMovement;
auto v = this->camera()->pointUnderPixel(point,found);
auto vec = v-this->camera()->position();
vec = vec.unit();
endHandler = this->camera()->position() + distanceToCamera*vec;
Vec delta = endHandler - currentHandler;
move(Eigen::Vector3d(delta[0],delta[1],delta[2]));
currentHandler = endHandler;
auto vec2 = currentHandler - this->camera()->position();
distanceToCamera = vec2.norm();
}
else
QGLViewer::mouseMoveEvent(e);
}
void Viewer::mouseReleaseEvent(QMouseEvent* e)
{
if (selection)
{
selection = false;
std::cout<<"End1"<<std::endl;
QPoint point(e->pos());
std::cout<<point.x()<<" "<<point.y()<<std::endl;
bool found;
startHandler = this->camera()->pointUnderPixel(point,found);
}
else if(mySelection)
{
std::cout<<"End"<<std::endl;
QPoint point(e->pos());
//std::cout<<point.x()<<" "<<point.y()<<std::endl;
//bool found;
//auto v = this->camera()->pointUnderPixel(point,found);
//std::cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<std::endl;
//glFlush();
mySelection = false;
}
else
QGLViewer::mouseReleaseEvent(e);
}
void Viewer::wheelEvent(QWheelEvent *event)
{
double angle = event->angleDelta().y();
radiusBall += angle/120;
std::cout<<"radiusBall "<<radiusBall<<std::endl;
}
void Viewer::postSelection(const QPoint &point) {
bool found=false;
startHandler = this->camera()->pointUnderPixel(point,found);
startClick = point;
auto vec = startHandler - this->camera()->position();
currentHandler = startHandler;
distanceToCamera = vec.norm();
mySelection = true;
startSelection = !startSelection;
}
void Viewer::keyPressEvent(QKeyEvent *e) {
// Get event modifiers key
const Qt::KeyboardModifiers modifiers = e->modifiers();
bool handled = false;
if((modifiers == Qt::NoButton))
{
switch(e->key())
{
case Qt::Key_W:
wireframe_ = !wireframe_;
handled = true;
break;
case Qt::Key_B:
selection = !selection;
handled = true;
break;
case Qt::Key_G:
grabFlag = !grabFlag;
handled = true;
break;
case Qt::Key_H:
hideFlag = !hideFlag;
handled = true;
break;
case Qt::Key_F:
flatShading_ = !flatShading_;
handled = true;
break;
case Qt::Key_Up:
if(offsetY<0)
offsetY*=-1;
test[1]+=dy;
move(Eigen::Vector3d(0.,0.,0));
handled = true;
break;
case Qt::Key_Down:
handled = true;
break;
}
if(handled)
{
//move();
update();
}
}
if (!handled)
QGLViewer::keyPressEvent(e);
}
constexpr double density_fonction(const double epsilon, const double repsilon)
{
return (15*pow(epsilon,4)/(8*M_PI))/(pow(repsilon,7));
}
constexpr double r_epsilon(const double radius,const double epsilon)
{
return sqrt(radius*radius + epsilon*epsilon);
}
Eigen::Vector3d force_u()
{
//return test;
}
Eigen::Matrix3d computeKelvinForce(double t, Eigen::Vector3d x, const KelvinParameters& parameters)
{
const auto identity = Eigen::Matrix3d::Identity();
const Eigen::Vector3d rvector = x- parameters.x0;
const double radius = rvector.norm();
const double repsilon =r_epsilon(radius,parameters.epsilon);
//std::cout<<"repsilon "<<parameters.epsilon<<std::endl;
const double repsilon3=repsilon*repsilon*repsilon;
const auto first = ((parameters.a-parameters.b)*1./repsilon)*identity;
const auto second = parameters.b/(repsilon3);
const auto last = ((parameters.a*parameters.epsilon*parameters.epsilon)/(2*repsilon3))*identity;
const Eigen::Matrix3d rrt = rvector * rvector.transpose();
//const auto density= density_fonction(parameters.epsilon, repsilon);
const auto force = first + second*rrt + last;
return force;
}
Eigen::Vector3d computeKelvinTwist(double t, Eigen::Vector3d x, const KelvinParameters& parameters)
{
const Eigen::Vector3d rvector = x- parameters.x0;
const double radius = rvector.norm();
const double repsilon =r_epsilon(radius,parameters.epsilon);
const double repsilon3=repsilon*repsilon*repsilon;
double epsilon2 = parameters.epsilon*parameters.epsilon;
double affineScalar = 1/repsilon3 + (3*epsilon2)/(2*repsilon3*repsilon*repsilon);
auto qxr = rvector.cross(parameters.force);
double scaleFactor = 10.;
return -scaleFactor*parameters.a*affineScalar*qxr;
}
Eigen::Vector3d computeKelvinScale(double t, Eigen::Vector3d x, const KelvinParameters& parameters)
{
const auto identity = Eigen::Matrix3d::Identity();
const Eigen::Vector3d rvector = x- parameters.x0;
const double radius = rvector.norm();
const double repsilon =r_epsilon(radius,parameters.epsilon);
const double repsilon3=repsilon*repsilon*repsilon;
double epsilon2 = parameters.epsilon*parameters.epsilon;
double affineScalar = 1/repsilon3 + (3*epsilon2)/(2*repsilon3*repsilon*repsilon);
double scale = 2*parameters.b -parameters.a;
//std::cout<<"NORM"<<parameters.force.norm()<<std::endl;
auto scaleMatrix = parameters.force.norm() * identity;
double scaleFactor = 10.;
auto delta = -scaleFactor* scale*affineScalar *scaleMatrix;
//std::cout<<"SCALE"<<delta[0]<<" "<<delta[1]<<" "<<delta[2]<<std::endl;
//std::cout<<"SCALE"<<delta<<std::endl;
return delta*parameters.force;
}
enum BRUSH_TYPE {SINGLE_SCALE,BI_SCALE,TRI_SCALE,
TWIST, SCALE};
Eigen::Vector3d computeKelvin(double t, Eigen::Vector3d x, const KelvinParameters& parameters)
{
BRUSH_TYPE type = SCALE;
Eigen::Matrix3d force;
if(type==BI_SCALE)
{
// e1
auto force1 = computeKelvinForce(t, x, parameters);
KelvinParameters parameters2 = parameters;
parameters2.epsilon = parameters.epsilon*1.1;
//e2
auto force2 = computeKelvinForce(t, x, parameters2);
force = force1-force2;
force *= (parameters.c / (1.0 / parameters.epsilon - 1. / parameters2.epsilon));
}
else if (type==TRI_SCALE)
{
KelvinParameters parameters2 = parameters;
parameters2.epsilon = parameters.epsilon*1.1;
KelvinParameters parameters3 = parameters2;
parameters3.epsilon = parameters2.epsilon*1.1;
double e12 = parameters.epsilon*parameters.epsilon;
double e22 = parameters2.epsilon*parameters2.epsilon;
double e32 = parameters3.epsilon*parameters3.epsilon;
double w = 1.;
double w2 = -(e32-e12)/(e32-e22);
double w3 = (e22-e12)/(e32-e22);
double sum_w = w/parameters.epsilon+w2/parameters2.epsilon+w3/parameters3.epsilon;
// e1
auto force1 = computeKelvinForce(t, x, parameters);
//e2
auto force2 = computeKelvinForce(t, x, parameters2);
//e3
auto force3 = computeKelvinForce(t, x, parameters3);
force = w*force1 +w2*force2+w3*force3;
force *= parameters.c / sum_w;
}
else if(type == TWIST)
{
return computeKelvinTwist(t,x,parameters);
}
else if(type == SCALE)
{
return computeKelvinScale(t,x,parameters);
}
else
{
force = computeKelvinForce(t, x, parameters);
force = parameters.c*force;
}
const auto delta = force* parameters.force;
return delta;
}
Eigen::Vector3d compute(double t, Eigen::Vector3d x ,Eigen::Vector3d x0 )
{
return (x0-x)/2;
}
Eigen::Vector3d Viewer::rungeKutta( Eigen::Vector3d x,int index,const KelvinParameters& parameters, float h)
{
//Eigen::Vector3d xx0 = (x - parameters.x0);
//Eigen::Vector3d x0 = Eigen::Vector3d(0.,1.,1.);
//Eigen::Vector3d xx0 = ( parameters.x0-x );
//h = 0.1;
const int n = static_cast<int>(1./h);
Eigen::Vector3d k1, k2, k3, k4, k5;
double t = 0;
auto start = high_resolution_clock::now();
rungePoints[index].clear();
rungePoints[index].push_back(x);
for (int i=1; i<=n; i++)
{
auto startk0 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(startk0 - start);
//cout << "Time taken by k0: "<< duration.count() << " microseconds" << endl;
k1 = computeKelvin(t, x,parameters);
//auto startk1 = high_resolution_clock::now();
//duration = duration_cast<microseconds>(startk1 - startk0);
//cout << "Time taken by k1: "<< duration.count() << " microseconds" << endl;
k2 = computeKelvin(t+ 0.5*h, x + 0.5*h*k1,parameters);
//auto startk2 = high_resolution_clock::now();
//duration = duration_cast<microseconds>(startk2 - startk1);
//cout << "Time taken by k2: "<< duration.count() << " microseconds" << endl;
k3 = computeKelvin(t + 0.5*h, x + 0.5*h*k2,parameters);
//auto startk3 = high_resolution_clock::now();
//duration = duration_cast<microseconds>(startk3 - startk2);
//cout << "Time taken by k3: "<< duration.count() << " microseconds" << endl;
k4 = computeKelvin(t + h, x + h*k3,parameters);
//auto startk4 = high_resolution_clock::now();
//duration = duration_cast<microseconds>(startk4 - startk3);
//cout << "Time taken by k4: "<< duration.count() << " microseconds" << endl;
/*
k1 = compute(t, x,x0);
k2 = compute(t+ 0.5*h, x + 0.5*h*k1,x0);
k3 = compute(t + 0.5*h, x + 0.5*h*k2,x0);
k4 = compute(t + h, x + h*k3,x0);
*/
Eigen::Vector3d delta = ((1.0*h)/6.0)*(k1 + 2*k2 + 2*k3 + k4);
x = x + delta;
rungePoints[index].push_back(x);
//x=k1;
//std::cout<<"x->"<<x<<std::endl;
t = t + h;
}
auto startk5 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(startk5 - start);
//cout << "Time taken by Runge: "<< duration.count() << " microseconds" << endl;
return x;
}
void Viewer::move(Eigen::Vector3d force) {
constexpr double mu = 1.;
//constexpr double v = -10000000000;
constexpr double v = 0.;
constexpr double a = 1./(4*M_PI*mu);
constexpr double b = a / (4*(1.-v));
constexpr double c = 2 / (3 * a - 2 * b);
double epsilon = radiusBall;
//double radius = 1.;
if(std::isnan(force[0]))
{
force = Eigen::Vector3d(0.,0.,0.);
}
//double repsilon =r_epsilon(radius,parameters.epsilon);
std::cout<<"force"<<force[0]<<" "<<force[1]<<" "<<force[2]<<std::endl;
//force = 50.*force;
//std::cout<<"force"<<force[0]<<" "<<force[1]<<" "<<force[2]<<std::endl;
std::vector<Eigen::Vector3d> points;
for(auto vertex : mesh.V)
{
points.push_back(Eigen::Vector3d(vertex.p[0],vertex.p[1],vertex.p[2]));
}
Eigen::Vector3d x0 = Eigen::Vector3d(startHandler[0],startHandler[1],startHandler[2]);//points[indiceTomove];
auto cv = this->camera()->position();
Eigen::Vector3d axis = x0- Eigen::Vector3d(cv[0],cv[1],cv[2]);
axis.normalize();
//std::cout<<"size "<<mesh.vertex.size()<<std::endl;
//Eigen::Vector3d x0 = points[indiceTomove];
//force = Eigen::Vector3d(0.,1.,0.);
KelvinParameters parameters;
parameters.x0 = x0;
parameters.a=a;
parameters.b=b;
parameters.c=c;
parameters.epsilon = epsilon;
parameters.force = force;
parameters.axis = axis;
//int k =0;
auto start = high_resolution_clock::now();
//std::cout<<"Mesh size :"<<points.size()<<std::endl;
#pragma omp parallel num_threads(8)
{
/*for(auto &p : points)
{
//double t = 0;
//auto dforce = computeKelvin(t, p, parameters);
//p+=dforce;
p = rungeKutta(p,parameters, .5);
//std::cout<<"p after "<<p[0]<<" "<<p[1]<<" "<<p[2]<<std::endl;
}*/
#pragma omp for
for(int i =0 ; i <points.size();i++)
{
//double t = 0;
//auto dforce = computeKelvin(t, p, parameters);
//p+=dforce;
points[i] = rungeKutta(points[i],i,parameters, .05);
//std::cout<<"p after "<<p[0]<<" "<<p[1]<<" "<<p[2]<<std::endl;
}
}
auto startk5 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(startk5 - start);
cout << "Time taken by Runge: "<< duration.count()/1000. << " mili seconds" << endl;
int k =0;
for(auto p : points)
{
mesh.V[k++].p = Vec3(p[0],p[1],p[2]);
}
}
void drawSphere(Vec origin, double r, int lats, int longs) {
int i, j;
for(i = 0; i <= lats; i++) {
double lat0 = M_PI * (-0.5 + (double) (i - 1) / lats);
double z0 = sin(lat0);
double zr0 = cos(lat0);
double lat1 = M_PI * (-0.5 + (double) i / lats);
double z1 = sin(lat1);
double zr1 = cos(lat1);
glBegin(GL_QUAD_STRIP);
for(j = 0; j <= longs; j++) {
double lng = 2 * M_PI * (double) (j - 1) / longs;
double x = cos(lng);
double y = sin(lng);
glNormal3f(origin[0]+x * zr0,origin[1]+ y * zr0, origin[2]+z0);
glVertex3f(origin[0]+x * zr0*r,origin[1]+ y * zr0*r, origin[2]+z0*r);
glNormal3f(origin[0]+x * zr1,origin[1]+ y * zr1, origin[2]+z1);
glVertex3f(origin[0]+x * zr1*r,origin[1]+ y * zr1*r, origin[2]+z1*r);
}
glEnd();
}
}
void Viewer::draw() {
glColor3d(1.,1.,1.);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
drawGrid(size,2*size);
//drawBigAxis(20.);
drawAxis(1.);
wireframe_ ? glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
flatShading_ ? glShadeModel(GL_FLAT) : glShadeModel(GL_SMOOTH);
for(auto vec : rungePoints)
{
double k = 0;
glBegin (GL_LINE_STRIP);
for(auto v : vec)
{
glColor3f( k,0.,1-k);
glVertex3f (v[0], v[1], v[2]);
k+=0.1;
}
glEnd();
}
if(hideFlag)
{
glColor3f( 0.8,0.8,0.8);
glBegin (GL_TRIANGLES);
for (unsigned int i = 0; i < mesh.T.size (); i++)
for (unsigned int j = 0; j < 3; j++) {
const MeshVertex & v = mesh.V[mesh.T[i].v[j]];
//const MeshVertex & vert = mesh.[mesh.T[i].v[j]];
glNormal3f (v.n[0], v.n[1], v.n[2]);
glVertex3f (v.p[0], v.p[1], v.p[2]);
}
glEnd ();
}
/*if(!startSelection)
glColor4f (0.0, 1.0, 0.0, 0.2);
else
glColor4f (1.0, 0.0, 0.0, 0.2);
*/
//glVertex3f (startHandler[0], startHandler[1], startHandler[2]);
glDisable(GL_LIGHTING);
glPointSize(8.);
glBegin (GL_POINTS);
int k=0;
//glDisable(GL_LIGHTING);
for(auto v : mesh.V)
{
Vec vToSphere = startHandler-Vec(v.p[0],v.p[1],v.p[2]);
if(vToSphere.norm()>radiusBall)
{
glColor3f( 1.,1.0,0.);
}
else
{
glColor3f( 0.,1.0,0.);
}
double offset =0.005;
glVertex3f (v.p[0]+offset*v.n[0], v.p[1]+offset*v.n[1], v.p[2]+offset*v.n[2]);
k++;
}
glEnd();
glColor4f (0.0, 1.0, 0.0, 0.2);
drawSphere(startHandler, radiusBall, 40, 40);
glColor4f (1.0, 0.0, 0.0, 0.2);
drawSphere(currentHandler, radiusBall, 40, 40);
//glEnable(GL_LIGHTING);
update();
}
void Viewer::init() {
setSceneRadius(50.);
setMouseTracking(true);
mf = ManipulatedFrame();
startSelection = true;
mesh.loadOFF (std::string("C:\\Users\\pups\\libqgl\\libQGLViewer-2.8.0\\examples\\simpleViewer\\models\\cube2.off"));
size = mesh.size;
mini = FLT_MAX;
maxi = -FLT_MAX;
for(auto vertex : mesh.V)
{
mini = std::min(mini,vertex.p[1]);
maxi = std::max(maxi,vertex.p[1]);
}
offsetY = dy;
int k =0;
for(auto & vertex : mesh.V)
{
if( vertex.p[1] == maxi )
{
indiceTomove = k;
}
k++;
}
GLfloat light_position[] = { 0.0, 0.0, 10.0, 0.0 };
GLfloat light_position2[] = { 0.0, 0.0, 10.0, 0.0 };
GLfloat light_diffuse[] = { 1.0, 0.0, 0.0, 0.0 };
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
glEnable(GL_LIGHTING);
GLfloat cyan[] = {0.f, .8f, .8f, 1.f};
glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan);
//cyan[] = {0.f, .8f, .8f, 1.f};
glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse);
this->camera()->setPosition(Vec(0.,0.,-20.));
this->camera()->setViewDirection(Vec(0.,0.,1.));
startHandler = Vec(0.,0.,0.);
currentHandler = Vec(0.,0.,0.);
rungePoints.resize(mesh.V.size());
for(auto v : mesh.V)
{
rungePoints.push_back(std::vector<Eigen::Vector3d>{Eigen::Vector3d(v.p[0],v.p[1],v.p[2])});
}
//Eigen::Vector3d v = rungeKutta( Eigen::Vector3d(0.,0.,0.), 0.1f);
//std::cout<<"v->"<<v<<std::endl;
//glEnable(GL_LIGHT1);
//glEnable(GL_LIGHT2);
}