-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign2.cpp
1206 lines (972 loc) · 45.1 KB
/
assign2.cpp
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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
CSCI 480
Assignment 2
Wei-Hung Liu
weihungl@usc.edu
*/
#include <stdio.h>
#include <stdlib.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#include <math.h>
#include "pic.h"
#include <math.h>
const int WIDTH = 640; /* initial window width */
const int HEIGHT = 480; /* initial window height */
const GLdouble FOV = 20.0; /* perspective field of view */
bool SAVE_SCREENSHOT = false;
bool START_ANIMATION = true;
/* represents one control point along the spline */
struct point {
double x;
double y;
double z;
};
/* spline struct which contains how many control points, and an array of control points */
struct spline {
int numControlPoints;
struct point *points;
};
/* the spline array */
struct spline *g_Splines;
/* total number of splines */
int g_iNumOfSplines;
int g_iMenuId;
/* - Mouse State Variables - */
int g_vMousePos[2] = {0, 0};
int g_iLeftMouseButton = 0; /* 1 if pressed, 0 if not */
int g_iMiddleMouseButton = 0;
int g_iRightMouseButton = 0;
/* state of the world */
float g_vLandRotate[3] = {0.0, 0.0, 0.0};
float g_vLandTranslate[3] = {0.0, 0.0, 0.0};
float g_vLandScale[3] = {1.0, 1.0, 1.0};
/* control state derived from mouse button state */
typedef enum { ROTATE, TRANSLATE, SCALE } CONTROLSTATE;
CONTROLSTATE g_ControlState = ROTATE;
/* for splines */
float delta=0.0f;
int count_control_points = -1;
float moveunit = 0.009;
/* arbitrary point for nomral vector */
point arbitrary_point;
/* point for spline tangent vector, position, normal vector, binormal vector */
point t,p,n,b;
point t1,p1,n1,b1;
/* point for camera eye and focus */
point eye, focus;
float up_step_size_Factor = 1.5;
/* storage for textures (only one for now)*/
GLuint texIndexSky;
GLuint texIndexGround;
/* screenshot number */
int frame_Num = 0;
/*----------------------- Utility function ------------------------------*/
int loadSplines(char *argv) {
char *cName = (char *)malloc(128 * sizeof(char));
FILE *fileList;
FILE *fileSpline;
int iType, i = 0, j, iLength;
/* load the track file */
fileList = fopen(argv, "r");
if (fileList == NULL) {
printf ("can't open file\n");
exit(1);
}
/* stores the number of splines in a global variable */
fscanf(fileList, "%d", &g_iNumOfSplines);
g_Splines = (struct spline *)malloc(g_iNumOfSplines * sizeof(struct spline));
/* reads through the spline files */
for (j = 0; j < g_iNumOfSplines; j++) {
i = 0;
fscanf(fileList, "%s", cName);
fileSpline = fopen(cName, "r");
if (fileSpline == NULL) {
printf ("can't open file\n");
exit(1);
}
/* gets length for spline file */
fscanf(fileSpline, "%d %d", &iLength, &iType);
/* allocate memory for all the points */
g_Splines[j].points = (struct point *)malloc(iLength * sizeof(struct point));
g_Splines[j].numControlPoints = iLength;
/* saves the data to the struct */
while (fscanf(fileSpline, "%lf %lf %lf",
&g_Splines[j].points[i].x,
&g_Splines[j].points[i].y,
&g_Splines[j].points[i].z) != EOF) {
i++;
}
}
free(cName);
return 0;
}
/* Write a screenshot to the specified filename */
void saveScreenshot (char *filename){
int i, j;
Pic *in = NULL;
Pic *out = NULL;
if (filename == NULL)
return;
in = pic_alloc(640, 480, 3, NULL);
out = pic_alloc(640, 480, 3, NULL);
printf("File to save to: %s\n", filename);
glReadPixels(0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, &in->pix[0]);
for ( int j=0; j<480; j++ ) {
for ( int i=0; i<640; i++ ) {
PIC_PIXEL(out, i, j, 0) = PIC_PIXEL(in, i, 480-1-j, 0);
PIC_PIXEL(out, i, j, 1) = PIC_PIXEL(in, i, 480-1-j, 1);
PIC_PIXEL(out, i, j, 2) = PIC_PIXEL(in, i, 480-1-j, 2);
}
}
if (jpeg_write(filename, out))
printf("File saved Successfully\n");
else
printf("Error in Saving\n");
pic_free(in);
pic_free(out);
}
/* call screenshot function and create filename */
void triggerSaveScreenshot(){
char str[2048];
if (SAVE_SCREENSHOT && frame_Num < 1000) {
frame_Num++;
sprintf(str, "%03d.jpg", frame_Num);
saveScreenshot(str);
} else {
SAVE_SCREENSHOT = false;
}
}
void drawText(char *string, GLfloat z)
{
glColor3f(1, 1, 0);
glRasterPos3f( eye.x, eye.y,eye.z);
for(int i = 0; string[i] != '\0'; i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, string[i]);
}
/*
loadTexture - Loads a texture from a JPEG file to memory and returns the handle
Note: pWidth and pHeight are pointers to return imageWidth and imageHeight
*/
//GLuint loadTexture ( char * filename, int width, int height ){
void loadTexture (){
Pic *textureSky = jpeg_read((char*)"sky6.jpg", NULL);
glGenTextures( 1, &texIndexSky );
glBindTexture( GL_TEXTURE_2D, texIndexSky );
// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSky->nx, textureSky->ny, 0, GL_RGB, GL_UNSIGNED_BYTE, textureSky->pix);
Pic *textureGround = jpeg_read((char*)"ground1.jpg", NULL);
glGenTextures( 1, &texIndexGround );
glBindTexture( GL_TEXTURE_2D, texIndexGround );
// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureGround->nx, textureGround->ny, 0, GL_RGB, GL_UNSIGNED_BYTE, textureGround->pix);
pic_free(textureSky);
pic_free(textureGround);
}
/* implement Catmull-Rom Spline equation: f(x) = [1, x, x^2, x^3] * M * [v0, v1, v2, v3]
Coefficients for Matrix M
M11 0.0 M12 1.0 M13 0.0 M14 0.0
M21 -0.5 M22 0.0 M23 0.5 M24 0.0
M31 1.0 M32 -2.5 M33 2.0 M34 -0.5
M41 -0.5 M42 1.5 M43 -1.5 M44 0.5
*/
float catmullRomSpline(float x, float v0,float v1,
float v2,float v3) {
float c1,c2,c3,c4;
c1 = 0.0*v0 + 1.0*v1 + 0.0*v2 + 0.0*v3;
c2 = -0.5*v0 + 0.0*v1 + 0.5*v2 + 0.0*v3;
c3 = 1.0*v0 +(-2.5)*v1 + 2.0*v2 + (-0.5)*v3;
c4 = -0.5*v0 + 1.5*v1 + (-1.5)*v2 + 0.5*v3;
return(((c4*x + c3)*x +c2)*x + c1);
}
/*implement first derivative of Catmull-Rom Spline equation: f(x) = [0, 1, 2*x, 3*x^2] * M * [v0, v1, v2, v3] */
float tangent(float x, float v0,float v1,
float v2,float v3) {
float c1,c2,c3,c4;
c1 = 0.0*v0 + 1.0*v1 + 0.0*v2 + 0.0*v3;
c2 = -0.5*v0 + 0.0*v1 + 0.5*v2 + 0.0*v3;
c3 = 1.0*v0 +(-2.5)*v1 + 2.0*v2 + (-0.5)*v3;
c4 = -0.5*v0 + 1.5*v1 + (-1.5)*v2 + 0.5*v3;
return((3*c4*x + 2*c3)*x + 1*c2);
}
/*implement cross product
s_1 = u_2v_3 - u_3v_2
s_2 = u_3v_1 - u_1v_3
s_3 = u_1v_2 - u_2v_1
*/
point crossProduct(point a, point b) {
point result_point;
result_point.x = a.y*b.z - a.z*b.y;
result_point.y = a.z*b.x - a.x*b.z;
result_point.z = a.x*b.y - a.y*b.x;
return result_point;
}
/* implement u / ||u|| */
point unit(point unit){
float length;
point normalized_point;
length = sqrt( (unit.x*unit.x) + (unit.y*unit.y) + (unit.z*unit.z) );
normalized_point.x=(float) unit.x/length;
normalized_point.y=(float) unit.y/length;
normalized_point.z=(float) unit.z/length;
return normalized_point;
}
/* implement dynamic gluLookAt(ex, ey, ez, fx, fy, fz, ux, uy, uz) = gluLookAt(P, T, B) */
void camera() {
int spline_index = 0;
int control_point_index = count_control_points;
float cross_step_size = 0.08;
float up_step_size_camera = 0.1;
p.x = catmullRomSpline(delta, g_Splines[spline_index].points[control_point_index].x, g_Splines[spline_index].points[control_point_index+1].x, g_Splines[spline_index].points[control_point_index+2].x, g_Splines[spline_index].points[control_point_index+3].x);
p.y = catmullRomSpline(delta, g_Splines[spline_index].points[control_point_index].y, g_Splines[spline_index].points[control_point_index+1].y, g_Splines[spline_index].points[control_point_index+2].y, g_Splines[spline_index].points[control_point_index+3].y);
p.z = catmullRomSpline(delta, g_Splines[spline_index].points[control_point_index].z, g_Splines[spline_index].points[control_point_index+1].z, g_Splines[spline_index].points[control_point_index+2].z, g_Splines[spline_index].points[control_point_index+3].z);
t.x = tangent(delta, g_Splines[spline_index].points[control_point_index].x, g_Splines[spline_index].points[control_point_index+1].x, g_Splines[spline_index].points[control_point_index+2].x, g_Splines[spline_index].points[control_point_index+3].x);
t.y = tangent(delta, g_Splines[spline_index].points[control_point_index].y, g_Splines[spline_index].points[control_point_index+1].y, g_Splines[spline_index].points[control_point_index+2].y, g_Splines[spline_index].points[control_point_index+3].y);
t.z = tangent(delta, g_Splines[spline_index].points[control_point_index].z, g_Splines[spline_index].points[control_point_index+1].z, g_Splines[spline_index].points[control_point_index+2].z, g_Splines[spline_index].points[control_point_index+3].z);
t = unit(t);
n = crossProduct(t, arbitrary_point);
n = unit(n);
b = crossProduct(t, n);
b = unit(b);
eye.x = p.x + (cross_step_size/2.0)*n.x + up_step_size_camera*b.x;
eye.y = p.y + (cross_step_size/2.0)*n.y + up_step_size_camera*b.y;
eye.z = p.z + (cross_step_size/2.0)*n.z + up_step_size_camera*b.z;
focus.x = p.x + (cross_step_size/2.0)*n.x + t.x+ up_step_size_camera*b.x*1.3;
focus.y = p.y + (cross_step_size/2.0)*n.y + t.y+ up_step_size_camera*b.y*1.3;
focus.z = p.z + (cross_step_size/2.0)*n.z + t.z+ up_step_size_camera*b.z*1.3;
gluLookAt(eye.x, eye.y, eye.z, focus.x, focus.y, focus.z, b.x, b.y, b.z);
}
void animation () {
delta+=moveunit; /* Increase */
/* loop back from zero because delta range 0 ~ 1*/
if ( delta >= 1.0 ) {
count_control_points++;
delta = 0.0;
/* loop back from the start */
if(count_control_points >= g_Splines[0].numControlPoints - 4)
count_control_points = 0;
}
}
/*----------------------- Draw function ------------------------------*/
void drawSkyAndGround()
{
/* NOTE: necessary to clean all color */
glColor3f(1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texIndexSky);
glBegin(GL_QUADS);
/*xz plane*/
glTexCoord2d(0.0,0.0); glVertex3d(-128,-128.0,-128);
glTexCoord2d(1.0,0.0); glVertex3d(128.0,-128.0,-128);
glTexCoord2d(1.0,1.0); glVertex3d(128.0,-128.0,128);
glTexCoord2d(0.0,1.0); glVertex3d(-128.0,-128.0,128);
/*zy plane*/
glTexCoord2d(0.0,0.0); glVertex3d(-128,-128,-128);
glTexCoord2d(1.0,0.0); glVertex3d(-128,128.0,-128);
glTexCoord2d(1.0,1.0); glVertex3d(-128,128.0,128);
glTexCoord2d(0.0,1.0); glVertex3d(-128,-128.0,128);
/*xz plane*/
glTexCoord2d(0.0,0.0); glVertex3d(-128,128.0,-128);
glTexCoord2d(1.0,0.0); glVertex3d(128.0,128.0,-128);
glTexCoord2d(1.0,1.0); glVertex3d(128.0,128.0,128);
glTexCoord2d(0.0,1.0); glVertex3d(-128.0,128.0,128);
/*zy plane*/
glTexCoord2d(0.0,0.0); glVertex3d(128,-128,-128);
glTexCoord2d(1.0,0.0); glVertex3d(128,128.0,-128);
glTexCoord2d(1.0,1.0); glVertex3d(128,128.0,128);
glTexCoord2d(0.0,1.0); glVertex3d(128,-128.0,128);
/*xy plane*/
glTexCoord2d(0.0,0.0); glVertex3d(-128,-128.0,128);
glTexCoord2d(1.0,0.0); glVertex3d(128.0,-128.0,128);
glTexCoord2d(1.0,1.0); glVertex3d(128.0,128.0,128);
glTexCoord2d(0.0,1.0); glVertex3d(-128.0,128.0,128);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texIndexGround);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex3d(-128,-128.0,-2);
glTexCoord2d(1.0,0.0); glVertex3d(128.0,-128.0,-2);
glTexCoord2d(1.0,1.0); glVertex3d(128.0,128.0,-2);
glTexCoord2d(0.0,1.0); glVertex3d(-128.0,128.0,-2);
glEnd();
glDisable(GL_TEXTURE_2D);
}
/* implement 3 rails like 'V' shape */
/* . . side rails
. bottom rail
*/
void drawSplines()
{
/* horizontal scale factor */
float cross_step_size=0.08;
/* vertical scale factor */
float up_step_size=0.04;
/* tube scale factor */
float tube_step_size=0.006;
/* parallel rail number (implement V shape so we have 3 parallel spline path and therefore for loop 3 times ) */
for(int index=1;index<4;index++){
glBegin(GL_QUADS);
/* red */
glColor3f(1 , 0, 0);
for (int spline_index = 0; spline_index < g_iNumOfSplines; spline_index++) {
for(int i=-2;i<g_Splines[spline_index].numControlPoints-1;i++) {
for(float u=0.0;u<1.0;u+=0.04) {
/*Point*/
p.x= catmullRomSpline(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
p.y= catmullRomSpline(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
p.z= catmullRomSpline(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
/*Tangent*/
t.x= tangent(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
t.y= tangent(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
t.z= tangent(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
t = unit(t);
/*Normal*/
n = crossProduct(t, arbitrary_point);
n = unit(n);
/*Binormal*/
b = crossProduct(t, n);
b = unit(b);
/* use u+0.02 to generate dense square cross-section */
/*Point*/
p1.x= catmullRomSpline(u+0.04, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
p1.y= catmullRomSpline(u+0.04, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
p1.z= catmullRomSpline(u+0.04, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
/*Tangent*/
t1.x= tangent(u+0.04, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
t1.y= tangent(u+0.04, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
t1.z= tangent(u+0.04, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
t1 = unit(t1);
/*Normal*/
n1 = crossProduct(t1, arbitrary_point);
n1 = unit(n1);
/*Binormal*/
b1 = crossProduct(t1, n1);
b1 = unit(b1);
/* implement V shape roller coaster rail */
/* main bottom rail - Center (V bottom vetex)*/
if(index==1)
{
p.x+=cross_step_size*n.x/2;
p.y+=cross_step_size*n.y/2;
p.z+=cross_step_size*n.z/2;
p1.x+=cross_step_size*n1.x/2;
p1.y+=cross_step_size*n1.y/2;
p1.z+=cross_step_size*n1.z/2;
}
/* side rail - Left-Top(V left vetex)*/
if(index==2)
{
p.x+=up_step_size*b.x*up_step_size_Factor;
p.y+=up_step_size*b.y*up_step_size_Factor;
p.z+=up_step_size*b.z*up_step_size_Factor;
p1.x+=up_step_size*b1.x*up_step_size_Factor;
p1.y+=up_step_size*b1.y*up_step_size_Factor;
p1.z+=up_step_size*b1.z*up_step_size_Factor;
}
/* side rail - Right-Top(V right vetex)*/
if(index==3)
{
p.x+=cross_step_size*n.x+ up_step_size*b.x*up_step_size_Factor;
p.y+=cross_step_size*n.y+ up_step_size*b.y*up_step_size_Factor;
p.z+=cross_step_size*n.z+ up_step_size*b.z*up_step_size_Factor;
p1.x+=cross_step_size*n1.x+ up_step_size*b1.x*up_step_size_Factor;
p1.y+=cross_step_size*n1.y+ up_step_size*b1.y*up_step_size_Factor;
p1.z+=cross_step_size*n1.z+ up_step_size*b1.z*up_step_size_Factor;
}
/* SQUARE TUBE RAIL
TOP FACE
(P1)v2 _____ v1(P1)
/ /|
(P1)v3/|___/_| v0(P1)
/ / / /
LEFT FACE ---> /_/__/ / <--- RIGHT FACE
(P0)v2|/ | /v1(P0)
|____|/
(P0)v3 v0(P0)
BOTTOM FACE
P0: current point, P1: next point
.v2(-n+b) .v1(+n+b)
.v3(-n-b) .v0(+n-b)
RIGHT FACE : v0(P0) - v0(P1) - v1(P1) - v1(P0)
LEFT FACE : (P0)v3 - (P1)v3 - (P1)v2 -(P0)v2
TOP FACE : (P0)v2 - v1(P0) - v1(P1) - (P1)v2
BOTTOM FACE: (P0)v3 - v0(P0) - v0(P1) - (P1)v3
*/
/* V-SHAPED SQUARE TUBE RAIL
(P1)v2 _____ v1(P1) (P1)v2 _____ v1(P1)
/ /| / /|
(P1)v3/|___/_| v0(P1) (P1)v3/|___/_| v0(P1)
/ / / / / / / /
TOP_LEFT RAIL --> /_/__/ / /_/__/ / <-- TOP-RIGHT RAIL
(P0)v2|/ | /v1(P0) (P0)v2|/ | /v1(P0)
|____|/ |____|/
(P0)v3 v0(P0) (P0)v3 v0(P0)
(P1)v2 _____ v1(P1)
/ /|
(P1)v3/|___/_| v0(P1)
/ / / / <-- BOTTOM RAIL
/_/__/ /
(P0)v2|/ | /v1(P0)
|____|/
(P0)v3 v0(P0)
In drawSplines()
render tripe rail as a V-shpaed by using different start point of P0
BOTTOM RAIL: like index==1 render the first rail which lies in the bottom of V-shaped
TOP_LEFT RAIL: like index==2 render the second rail which lies in the top-left of V-shaped
TOP-RIGHT RAIL: like index==3 render the third rail which lies in the top-right of V-shaped
*/
/* p0 v0 */
glVertex3f(p.x + tube_step_size*( n.x - b.x), p.y + tube_step_size*( n.y - b.y), p.z + tube_step_size*( n.z - b.z));
/* p1 v0 */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p1.y + tube_step_size*( n1.y - b1.y), p1.z + tube_step_size*( n1.z - b1.z));
/* p1 v1 */
glVertex3f(p1.x + tube_step_size*(+n1.x + b.x), p1.y + tube_step_size*( n1.y + b1.y), p1.z + tube_step_size*( n1.z + b1.z));
/* p0 v1 */
glVertex3f(p.x + tube_step_size*( n.x + b.x), p.y + tube_step_size*( n.y + b.y), p.z + tube_step_size*( n.z + b.z));
/* p0 v3 */
glVertex3f(p.x + tube_step_size*(-n.x - b.x), p.y + tube_step_size*(-n.y - b.y), p.z + tube_step_size*(-n.z - b.z));
/* p1 v3 */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), p1.z + tube_step_size*(-n1.z - b1.z));
/* p1 v2 */
glVertex3f(p1.x + tube_step_size*(-n1.x + b1.x), p1.y + tube_step_size*(-n1.y + b1.y), p1.z + tube_step_size*(-n1.z + b1.z));
/* p0 v2 */
glVertex3f(p.x + tube_step_size*(-n.x + b.x), p.y + tube_step_size*(-n.y + b.y), p.z + tube_step_size*(-n.z + b.z));
/* left side rail form bottom quad */
/* p0 v2 */
glVertex3f(p.x + tube_step_size*(-n.x + b.x), p.y + tube_step_size*(-n.y + b.y), p.z + tube_step_size*(-n.z + b.z));
/* p0 v1 */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), p1.z + tube_step_size*(-n1.z - b1.z));
/* p1 v1 */
glVertex3f(p1.x + tube_step_size*(+n1.x + b.x), p1.y + tube_step_size*( n1.y + b1.y), p1.z + tube_step_size*( n1.z + b1.z));
/* p1 v2 */
glVertex3f(p1.x + tube_step_size*(-n1.x + b1.x), p1.y + tube_step_size*(-n1.y + b1.y), p1.z + tube_step_size*(-n1.z + b1.z));
/* form top quad */
/* p0 v3 */
glVertex3f(p.x + tube_step_size*(-n.x - b.x), p.y + tube_step_size*(-n.y - b.y), p.z + tube_step_size*(-n.z - b.z));
/* p0 v0 */
glVertex3f(p.x + tube_step_size*( n.x - b.x), p.y + tube_step_size*( n.y - b.y), p.z + tube_step_size*( n.z - b.z));
/* p1 v0 */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p1.y + tube_step_size*( n1.y - b1.y), p1.z + tube_step_size*( n1.z - b1.z));
/* p1 v3 */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), p1.z + tube_step_size*(-n1.z - b1.z));
}/* end of for loop*/
}/* end of for loop*/
}/* end of for loop*/
glEnd();
}/* end of for loop*/
}
/* implement cross rail (45 degrss '/' and 135 degree '\') between two side rails and bottom rail respeactively */
void drawCrossRail()
{
int factor=0;
float cross_step_size=0.08;
float up_step_size=0.035;
/* parallel rail number */
for(int index=2;index<4;index++){
glLineWidth(7);
glBegin(GL_LINES);
/* white */
glColor3f(1, 1, 1);
for (int spline_index = 0; spline_index < g_iNumOfSplines; spline_index++) {
for(int i=-2;i<g_Splines[spline_index].numControlPoints-1;i++) {
for(float u=0.0;u<1.0;u+=0.1) {
/*Point*/
p.x= catmullRomSpline(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
p.y= catmullRomSpline(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
p.z= catmullRomSpline(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
/*Tangent*/
t.x= tangent(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
t.y= tangent(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
t.z= tangent(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
t = unit(t);
/*Normal*/
n = crossProduct(t, arbitrary_point);
n = unit(n);
/*Binormal*/
b = crossProduct(t, n);
b = unit(b);
/*
(P1)v2 _____ v1(P1) (P1)v2 _____ v1(P1)
/ /| / /|
(P1)v3/|___/_| v0(P1) (P1)v3/|___/_| v0(P1)
/ / / / / / / /
/_/__/ / /_/__/ /
(P0)v2|/ | /v1(P0) (P0)v2|/ | /v1(P0)
|____|/ |____|/
(P0)v3 v0(P0) (P0)v3 v0(P0)
\ \ / /
\ \ / /
\ \ (P1)v2 _____ v1(P1) / /
CROSS RAIL SUPPORT--> \ \ / /| / / <--- CROSS RAIL SUPPORT
\ \(P1)v3/|___/_| v0(P1) / /
\ \ / / / / / /
/_/__/ / / /
(P0)v2|/ | /v1(P0)
|____|/
(P0)v3 v0(P0)
*/
/* top*/
if(index==2)
{
p.x+=up_step_size*b.x*up_step_size_Factor;
p.y+=up_step_size*b.y*up_step_size_Factor;
p.z+=up_step_size*b.z*up_step_size_Factor;
factor = 1;
}
/* top-right*/
if(index==3)
{
p.x+=cross_step_size*n.x+ up_step_size*b.x*up_step_size_Factor;
p.y+=cross_step_size*n.y+ up_step_size*b.y*up_step_size_Factor;
p.z+=cross_step_size*n.z+ up_step_size*b.z*up_step_size_Factor;
factor = -1;
}
/* side rail */
glVertex3f(p.x, p.y, p.z);
/* main bottom rail*/
glVertex3f(p.x-up_step_size*b.x*up_step_size_Factor+factor*cross_step_size*n.x/2, p.y-up_step_size*b.y*up_step_size_Factor+factor*cross_step_size*n.y/2, p.z-up_step_size*b.z*up_step_size_Factor+factor*cross_step_size*n.z/2);
}/* end of for loop*/
}/* end of for loop*/
}/* end of for loop*/
glEnd();
}/* end of for loop*/
}
/* implement touch ground pillar ( 4 faces ) to support roller coaster */
void drawSupportedPillar()
{
/* horizontal scale factor */
float cross_step_size=0.08;
/* vertical scale factor */
float up_step_size=0.04;
/* tube scale factor */
float tube_step_size=0.006;
/* parallel rail number (implement V shape so we have 3 parallel spline path and therefore for loop 3 times ) */
for(int index=1;index<4;index++){
glBegin(GL_QUADS);
/* blue */
glColor3f(0.1,0.1, 0.8);
for (int spline_index = 0; spline_index < g_iNumOfSplines; spline_index++) {
for(int i=-2;i<g_Splines[spline_index].numControlPoints-1;i++) {
for(float u=0.0;u<1.0;u+=0.4) {
/*Point*/
p.x= catmullRomSpline(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
p.y= catmullRomSpline(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
p.z= catmullRomSpline(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
/*Tangent*/
t.x= tangent(u, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
t.y= tangent(u, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
t.z= tangent(u, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
t = unit(t);
/*Normal*/
n = crossProduct(t, n);
n = unit(n);
/*Binormal*/
b = crossProduct(t, n);
b = unit(b);
/* use u+0.02 to generate dense square cross-section
PILAR(SQUARE TUBE) UNDER V-SHAPED SQUARE TUBE RAIL
(P1)v2 _____ v1(P1) (P1)v2 _____ v1(P1)
/ /| / /|
(P1)v3/|___/_| v0(P1) (P1)v3/|___/_| v0(P1)
/ / / / / / / /
/_/__/ / /_/__/ /
(P0)v2|/ | /v1(P0) (P0)v2|/ | /v1(P0)
|____|/ |____|/
(P0)v3 v0(P0) (P0)v3 v0(P0)
p1 v3__ p1 v0 (P1)v2 _____ v1(P1)
/_/| / /| p1 v3__ p1 v0
p0 v3 ||||p0 v0 (P1)v3/|___/_| v0(P1 /_/|
PILAR SUPPORT--> | || / / / / p0 v3 ||||p0 v0
|||| /_/__/ / | || <--- PILAR SUPPORT
p1 v3 ground|.|| p1 v0 ground(P0)v2|/ | /v1(P0) ||||
|||/ |____|/ p1 v3 ground|.|| p1 v0 ground
p0 v3 ground p0 v0 ground (P0)v3 v0(P0) |||/
p0 v3 ground p0 v0 ground
p1 v3__ p1 v0
/_/|
p0 v3 ||||p0 v0
| || <--- PILAR SUPPORT
||||
p1 v3 ground|.|| p1 v0 ground
|||/
p0 v3 ground p0 v0 ground
PILAR SUPPORT right face: p0 v0 - p1 v0 - p1 v0 ground - p0 v0 ground
PILAR SUPPORT back face: p0 v0 - p0 v3 - p0 v3 ground - p0 v0 ground
PILAR SUPPORT left face: p0 v3 - p1 v3 - p1 v3 ground - p0 v3 ground
PILAR SUPPORT front face: p1 v0 - p1 v3 - p1 v3 ground - p1 v0 ground
*/
/*Point*/
p1.x= catmullRomSpline(u+0.02, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
p1.y= catmullRomSpline(u+0.02, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
p1.z= catmullRomSpline(u+0.02, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
/*Tangent*/
t1.x= tangent(u+0.02, g_Splines[spline_index].points[i].x, g_Splines[spline_index].points[i+1].x, g_Splines[spline_index].points[i+2].x, g_Splines[spline_index].points[i+3].x);
t1.y= tangent(u+0.02, g_Splines[spline_index].points[i].y, g_Splines[spline_index].points[i+1].y, g_Splines[spline_index].points[i+2].y, g_Splines[spline_index].points[i+3].y);
t1.z= tangent(u+0.02, g_Splines[spline_index].points[i].z, g_Splines[spline_index].points[i+1].z, g_Splines[spline_index].points[i+2].z, g_Splines[spline_index].points[i+3].z);
t1 = unit(t1);
/*Normal*/
n1 = crossProduct(t1, arbitrary_point);
n1 = unit(n1);
/*Binormal*/
b1 = crossProduct(t1, n1);
b1 = unit(b1);
/* implement V shape roller coaster rail */
/* main bottom rail - Center (V bottom vetex)*/
if(index==1)
{
p.x+=cross_step_size*n.x/2;
p.y+=cross_step_size*n.y/2;
p.z+=cross_step_size*n.z/2;
p1.x+=cross_step_size*n1.x/2;
p1.y+=cross_step_size*n1.y/2;
p1.z+=cross_step_size*n1.z/2;
}
/* side rail - Left-Top(V left vetex)*/
if(index==2)
{
p.x+=up_step_size*b.x*up_step_size_Factor;
p.y+=up_step_size*b.y*up_step_size_Factor;
p.z+=up_step_size*b.z*up_step_size_Factor;
p1.x+=up_step_size*b1.x*up_step_size_Factor;
p1.y+=up_step_size*b1.y*up_step_size_Factor;
p1.z+=up_step_size*b1.z*up_step_size_Factor;
}
/* side rail - Right-Top(V right vetex)*/
if(index==3)
{
p.x+=cross_step_size*n.x+ up_step_size*b.x*up_step_size_Factor;
p.y+=cross_step_size*n.y+ up_step_size*b.y*up_step_size_Factor;
p.z+=cross_step_size*n.z+ up_step_size*b.z*up_step_size_Factor;
p1.x+=cross_step_size*n1.x+ up_step_size*b1.x*up_step_size_Factor;
p1.y+=cross_step_size*n1.y+ up_step_size*b1.y*up_step_size_Factor;
p1.z+=cross_step_size*n1.z+ up_step_size*b1.z*up_step_size_Factor;
}
/* implement 4 face of a pillar: right, backawrd, left, forward*/
/* .v2(-n+b) .v1(+n+b)
.v3(-n-b) .v0(+n-b)
*/
/* pillar right face */
/* p0 v0 */
glVertex3f(p.x + tube_step_size*( n.x - b.x), p.y + tube_step_size*( n.y - b.y), p.z + tube_step_size*( n.z - b.z));
/* p1 v0 */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p.y + tube_step_size*( n1.y - b1.y), p1.z + tube_step_size*( n1.z - b1.z));
/* p1 v0 ground */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p.y + tube_step_size*( n1.y - b1.y), -3);
/* p0 v0 ground */
glVertex3f(p.x + tube_step_size*( n.x - b.x), p.y + tube_step_size*( n.y - b.y), -3);
/* pillar back face */
/* p0 v0 */
glVertex3f(p.x + tube_step_size*( n.x - b.x), p.y + tube_step_size*( n.y - b.y), p.z + tube_step_size*( n.z - b.z));
/* p0 v3 */
glVertex3f(p.x + tube_step_size*( -n.x - b.x), p.y + tube_step_size*(- n.y - b.y), p.z + tube_step_size*( -n.z - b.z));
/* p0 v3 ground */
glVertex3f(p.x + tube_step_size*(-n.x - b.x), p.y + tube_step_size*(-n.y - b.y), -3);
/* p0 v0 ground */
glVertex3f(p.x + tube_step_size*(n.x - b.x), p.y + tube_step_size*(n.y - b.y), -3);
/* pillar left face */
/* p0 v3 */
glVertex3f(p.x + tube_step_size*(-n.x - b.x), p.y + tube_step_size*(-n.y - b.y), p.z + tube_step_size*(-n.z - b.z));
/* p1 v3 */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), p1.z + tube_step_size*(-n1.z - b1.z));
/* p1 v3 ground */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), -3);
/* p0 v3 ground */
glVertex3f(p.x + tube_step_size*(-n.x - b.x), p.y + tube_step_size*(-n.y - b.y), -3);
/* pillar front face */
/* p1 v0 */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p1.y + tube_step_size*( n1.y - b1.y), p1.z + tube_step_size*( n1.z - b1.z));
/* p1 v3 */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), p1.z + tube_step_size*(-n1.z - b1.z));
/* p1 v3 ground */
glVertex3f(p1.x + tube_step_size*(-n1.x - b1.x), p1.y + tube_step_size*(-n1.y - b1.y), -3);
/* p1 v0 ground */
glVertex3f(p1.x + tube_step_size*( n1.x - b1.x), p1.y + tube_step_size*( n1.y - b1.y), -3);
}/* end of for loop*/
}/* end of for loop*/
}/* end of for loop*/
glEnd();
}/* end of for loop*/
}
/*----------------------- Opengl Default function ------------------------------*/
void myinit()
{
glClearColor(0.0, 0.0, 0.0, 0.0);/* setup gl view here */
glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glShadeModel(GL_SMOOTH); /* interpolate colors during rasterization */
// set up lighting
GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
GLfloat light_diffuse[] = {0.8, 0.8, 0.8, 1.0};
GLfloat light_specular[] = {0.8, 0.8, 0.8, 1.0};
GLfloat light_position[] = {eye.x, eye.y, eye.z, 0.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
// spotlight
GLfloat sd[] = {focus.x, focus.y, focus.z};
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, sd);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90.0);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 5.0);
// setup lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
}
/* reshape callback */
/* set projection to aspect ratio of window */
void reshape(int w, int h)
{
GLfloat aspect = (GLfloat) w / (GLfloat) h;
glViewport(0, 0, w, h); /* scale viewport with window */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(FOV, aspect, 1.0, 100.0);
gluPerspective(FOV, aspect, 0.01, 1000.0);
glMatrixMode(GL_MODELVIEW);
}
void doIdle()
{
/* do some stuff... */
triggerSaveScreenshot();
if(START_ANIMATION)
animation(); /* make the screen update */
glutPostRedisplay();
}
/* draw 1x1 cube about origin */
/* replace this code with your height field implementation */
/* you may also want to precede it with your rotation/translation/scaling */
void display()
{
/* clear buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* reset transformation - identity matrix*/
glLoadIdentity(); /*get the (modelview) matrix into the original state*/
/* Set current matrix on the stack */
glPushMatrix();
/* transformation */
glTranslatef(g_vLandTranslate[0], g_vLandTranslate[1], g_vLandTranslate[2]);
glRotatef(g_vLandRotate[0], 1.0, 0.0, 0.0);
glRotatef(g_vLandRotate[1], 0.0, 1.0, 0.0);
glRotatef(g_vLandRotate[2], 0.0, 0.0, 1.0);
glScalef(g_vLandScale[0], g_vLandScale[1], g_vLandScale[2]);
arbitrary_point.x = 0.0;arbitrary_point.y = 0.0;arbitrary_point.z = -1.0;
camera();
/* background */
drawSkyAndGround();
/* 3 main rails */
drawSplines();
/* cross rail between mail running rails */
drawCrossRail();
/* ground pillars */
drawSupportedPillar();
glFlush();
/* Pop the old matrix without the transformations */
glPopMatrix();
glutSwapBuffers();
}
/*-----------------------User Input function ------------------------------*/
void menufunc(int value)
{
switch (value)
{
case 0:
exit(0);
break;
}
}
/* converts mouse drags into information about rotation/translation/scaling */
void mousedrag(int x, int y)
{
int vMouseDelta[2] = {x-g_vMousePos[0], y-g_vMousePos[1]};