forked from asalga/XB-PointStream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psapi.js
1834 lines (1514 loc) · 48.1 KB
/
psapi.js
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
/*
Copyright (c) 2010 Seneca College
MIT LICENSE
*/
/**
@class XB PointStream is a WebGL library designed to efficiently stream and
render point cloud data in a canvas element.
@version 0.75
*/
var PointStream = (function() {
/**
@private
*/
function PointStream() {
// Intentionally left undefined
var undef;
var __empty_func = function(){};
// Chrome still does not have subarray, so we add it here.
if(!Float32Array.prototype.subarray){
/**
@private
*/
Float32Array.prototype.subarray = function(s,e){
return !e ? this.slice(0) : this.slice(s,e);
};
}
// Mouse
var userMouseReleased = __empty_func;
var userMousePressed = __empty_func;
var userMouseScroll = __empty_func;
var mouseX = 0;
var mouseY = 0;
// Keyboard
var userKeyUp = __empty_func;
var userKeyDown = __empty_func;
var userKeyPressed = __empty_func;
var key = 0;
var usersRender = __empty_func;
// These are parallel arrays. Each parser
// has a point cloud it works with
var parsers = [];
var pointClouds = [];
var registeredParsers = {};
registeredParsers["asc"] = ASCParser;
registeredParsers["psi"] = PSIParser;
registeredParsers["pts"] = PTSParser;
registeredParsers["ply"] = PLYParser;
const VERSION = "0.75";
// file status of point clouds
const FILE_NOT_FOUND = -1;
const STARTED = 1;
const STREAMING = 2;
const COMPLETE = 3;
// for calculating fps
var frames = 0;
var frameRate = 0;
var lastTime;
// default rendering states
var bk = [1, 1, 1, 1];
var attn = [0.01, 0.0, 0.003];
// tinylogLite
var logBuffer = [];
// browser detection to handle differences such as mouse scrolling
var browser = -1;
const MINEFIELD = 0;
const CHROME = 1;
const CHROMIUM = 2;
const WEBKIT = 3;
// not used yet
const FIREFOX = 4;
const OPERA = 5;
const SAFARI = 6;
const IE = 7;
var canvas = null;
var ctx = null;
// Transformation matrices
var matrixStack = [];
var projectionMatrix;
var normalMatrix;
var currProgram;
// Keep a reference to the default program object
// in case the user wants to unset his shaders.
var defaultProgram;
var programCaches = [];
// Both key and keyCode will be equal to these values
const _BACKSPACE = 8;
const _TAB = 9;
const _ENTER = 10;
const _RETURN = 13;
const _ESC = 27;
const _DELETE = 127;
const _CODED = 0xffff;
// p.key will be CODED and p.keyCode will be this value
const _SHIFT = 16;
const _CONTROL = 17;
const _ALT = 18;
const _UP = 38;
const _RIGHT = 39;
const _DOWN = 40;
const _LEFT = 37;
var codedKeys = [_SHIFT, _CONTROL, _ALT, _UP, _RIGHT, _DOWN, _LEFT];
var vertexShaderSource =
"varying vec4 frontColor;" +
"attribute vec3 ps_Vertex;" +
"attribute vec4 ps_Color;" +
"uniform float ps_PointSize;" +
"uniform vec3 ps_Attenuation;" +
"uniform mat4 ps_ModelViewMatrix;" +
"uniform mat4 ps_ProjectionMatrix;" +
"void main(void) {" +
" frontColor = ps_Color;" +
" vec4 ecPos4 = ps_ModelViewMatrix * vec4(ps_Vertex, 1.0);" +
" float dist = length(ecPos4);" +
" float attn = ps_Attenuation[0] + " +
" (ps_Attenuation[1] * dist) + " +
" (ps_Attenuation[2] * dist * dist);" +
" gl_PointSize = (attn > 0.0) ? ps_PointSize * sqrt(1.0/attn) : 1.0;" +
" gl_Position = ps_ProjectionMatrix * ecPos4;" +
"}";
var fragmentShaderSource =
'#ifdef GL_ES \n\
precision highp float; \n\
#endif \n\
\n\
varying vec4 frontColor; \n\
void main(void){ \n\
gl_FragColor = frontColor; \n\
}';
/**
@private
Set a uniform integer
@param {WebGLProgram} programObj
@param {String} varName
@param {Number} varValue
*/
function uniformi(programObj, varName, varValue) {
var varLocation = ctx.getUniformLocation(programObj, varName);
// the variable won't be found if it was optimized out.
if (varLocation !== -1) {
if (varValue.length === 4) {
ctx.uniform4iv(varLocation, varValue);
} else if (varValue.length === 3) {
ctx.uniform3iv(varLocation, varValue);
} else if (varValue.length === 2) {
ctx.uniform2iv(varLocation, varValue);
} else {
ctx.uniform1i(varLocation, varValue);
}
}
}
/**
@private
Set a uniform float
@param {WebGLProgram} programObj
@param {String} varName
@param {Number} varValue
*/
function uniformf(programObj, varName, varValue) {
var varLocation = ctx.getUniformLocation(programObj, varName);
// the variable won't be found if it was optimized out.
if (varLocation !== -1) {
if (varValue.length === 4) {
ctx.uniform4fv(varLocation, varValue);
} else if (varValue.length === 3) {
ctx.uniform3fv(varLocation, varValue);
} else if (varValue.length === 2) {
ctx.uniform2fv(varLocation, varValue);
} else {
ctx.uniform1f(varLocation, varValue);
}
}
}
/**
@private
@param {WebGLProgram} programObj
@param {String} varName
@param {Number} size
@param {} VBO
*/
function vertexAttribPointer(programObj, varName, size, VBO) {
var varLocation = ctx.getAttribLocation(programObj, varName);
if (varLocation !== -1) {
ctx.bindBuffer(ctx.ARRAY_BUFFER, VBO);
ctx.vertexAttribPointer(varLocation, size, ctx.FLOAT, false, 0, 0);
ctx.enableVertexAttribArray(varLocation);
}
}
/**
@private
@param {} parser
*/
function getParserIndex(parser){
var i;
for(i = 0; i < parsers.length; i++){
if(parsers[i] === parser){break;}
}
return i;
}
/**
@private
Create a buffer object which will contain
the Vertex buffer object for the shader along
with a reference to the original array
A 3D context must exist before calling this function
@param {Array} arr
@returns {Object}
*/
function createBufferObject(arr){
// !! add check for length > 0
if(ctx){
var VBO = ctx.createBuffer();
ctx.bindBuffer(ctx.ARRAY_BUFFER, VBO);
ctx.bufferData(ctx.ARRAY_BUFFER, arr, ctx.STATIC_DRAW);
// length is simply for convenience
var obj = {
length: arr.length,
VBO: VBO,
array: arr
}
return obj;
}
}
/**
@private
@param {WebGLProgram} programObj
@param {String} varName
*/
function disableVertexAttribPointer(programObj, varName){
var varLocation = ctx.getAttribLocation(programObj, varName);
if (varLocation !== -1) {
ctx.disableVertexAttribArray(varLocation);
}
}
/**
@private
*/
function getUserAgent(userAgentString){
// keep in this order
if(userAgentString.match(/Chrome/)){
return CHROME;
}
if(userAgentString.match(/AppleWebKit/)){
return WEBKIT;
}
if(userAgentString.match(/Minefield/)){
return MINEFIELD;
}
}
/**
@private
Sets a uniform matrix
@param {WebGLProgram} programObj
@param {String} varName
@param {Boolean} transpose must be false
@param {Array} matrix
*/
function uniformMatrix(programObj, varName, transpose, matrix) {
var varLocation = ctx.getUniformLocation(programObj, varName);
// the variable won't be found if it was optimized out.
if (varLocation !== -1) {
if (matrix.length === 16) {
ctx.uniformMatrix4fv(varLocation, transpose, matrix);
} else if (matrix.length === 9) {
ctx.uniformMatrix3fv(varLocation, transpose, matrix);
} else {
ctx.uniformMatrix2fv(varLocation, transpose, matrix);
}
}
}
/**
@private
@param {} ctx
@param {String} vetexShaderSource
@param {String} fragmentShaderSource
*/
function createProgramObject(ctx, vetexShaderSource, fragmentShaderSource) {
var vertexShaderObject = ctx.createShader(ctx.VERTEX_SHADER);
ctx.shaderSource(vertexShaderObject, vetexShaderSource);
ctx.compileShader(vertexShaderObject);
if (!ctx.getShaderParameter(vertexShaderObject, ctx.COMPILE_STATUS)) {
throw ctx.getShaderInfoLog(vertexShaderObject);
}
var fragmentShaderObject = ctx.createShader(ctx.FRAGMENT_SHADER);
ctx.shaderSource(fragmentShaderObject, fragmentShaderSource);
ctx.compileShader(fragmentShaderObject);
if (!ctx.getShaderParameter(fragmentShaderObject, ctx.COMPILE_STATUS)) {
throw ctx.getShaderInfoLog(fragmentShaderObject);
}
var programObject = ctx.createProgram();
ctx.attachShader(programObject, vertexShaderObject);
ctx.attachShader(programObject, fragmentShaderObject);
ctx.linkProgram(programObject);
if (!ctx.getProgramParameter(programObject, ctx.LINK_STATUS)) {
throw "Error linking shaders.";
}
return programObject;
};
/**
@private
Used by keyboard event handlers
@param {} code
@param {} shift
@returns
*/
function keyCodeMap(code, shift) {
// Letters
if (code >= 65 && code <= 90) { // A-Z
// Keys return ASCII for upcased letters.
// Convert to downcase if shiftKey is not pressed.
if (shift) {
return code;
}
else {
return code + 32;
}
}
// Numbers and their shift-symbols
else if (code >= 48 && code <= 57) { // 0-9
if (shift) {
switch (code) {
case 49:
return 33; // !
case 50:
return 64; // @
case 51:
return 35; // #
case 52:
return 36; // $
case 53:
return 37; // %
case 54:
return 94; // ^
case 55:
return 38; // &
case 56:
return 42; // *
case 57:
return 40; // (
case 48:
return 41; // )
}
}
}
// Symbols and their shift-symbols
else {
if (shift) {
switch (code) {
case 107:
return 43; // +
case 219:
return 123; // {
case 221:
return 125; // }
case 222:
return 34; // "
}
} else {
switch (code) {
case 188:
return 44; // ,
case 109:
return 45; // -
case 190:
return 46; // .
case 191:
return 47; // /
case 192:
return 96; // ~
case 219:
return 91; // [
case 220:
return 92; // \
case 221:
return 93; // ]
case 222:
return 39; // '
}
}
}
return code;
}
/**
@private
@param {} evt
@param {} type
*/
function keyFunc(evt, type){
var key;
if (evt.charCode){
key = keyCodeMap(evt.charCode, evt.shiftKey);
} else {
key = keyCodeMap(evt.keyCode, evt.shiftKey);
}
return key;
}
// tinylog lite JavaScript library
// http://purl.eligrey.com/tinylog/lite
/**
@private
*/
var tinylogLite = (function() {
"use strict";
var tinylogLite = {},
undef = "undefined",
func = "function",
False = !1,
True = !0,
logLimit = 512,
log = "log";
if (typeof tinylog !== undef && typeof tinylog[log] === func) {
// pre-existing tinylog present
tinylogLite[log] = tinylog[log];
} else if (typeof document !== undef && !document.fake) {
(function() {
// DOM document
var doc = document,
$div = "div",
$style = "style",
$title = "title",
containerStyles = {
zIndex: 10000,
position: "fixed",
bottom: "0px",
width: "100%",
height: "15%",
fontFamily: "sans-serif",
color: "#ccc",
backgroundColor: "black"
},
outputStyles = {
position: "relative",
fontFamily: "monospace",
overflow: "auto",
height: "100%",
paddingTop: "5px"
},
resizerStyles = {
height: "5px",
marginTop: "-5px",
cursor: "n-resize",
backgroundColor: "darkgrey"
},
closeButtonStyles = {
position: "absolute",
top: "5px",
right: "20px",
color: "#111",
MozBorderRadius: "4px",
webkitBorderRadius: "4px",
borderRadius: "4px",
cursor: "pointer",
fontWeight: "normal",
textAlign: "center",
padding: "3px 5px",
backgroundColor: "#333",
fontSize: "12px"
},
entryStyles = {
//borderBottom: "1px solid #d3d3d3",
minHeight: "16px"
},
entryTextStyles = {
fontSize: "12px",
margin: "0 8px 0 8px",
maxWidth: "100%",
whiteSpace: "pre-wrap",
overflow: "auto"
},
view = doc.defaultView,
docElem = doc.documentElement,
docElemStyle = docElem[$style],
/**
@private
*/
setStyles = function() {
var i = arguments.length,
elemStyle, styles, style;
while (i--) {
styles = arguments[i--];
elemStyle = arguments[i][$style];
for (style in styles) {
if (styles.hasOwnProperty(style)) {
elemStyle[style] = styles[style];
}
}
}
},
/**
@private
*/
observer = function(obj, event, handler) {
if (obj.addEventListener) {
obj.addEventListener(event, handler, False);
} else if (obj.attachEvent) {
obj.attachEvent("on" + event, handler);
}
return [obj, event, handler];
},
/**
@private
*/
unobserve = function(obj, event, handler) {
if (obj.removeEventListener) {
obj.removeEventListener(event, handler, False);
} else if (obj.detachEvent) {
obj.detachEvent("on" + event, handler);
}
},
/**
@private
*/
clearChildren = function(node) {
var children = node.childNodes,
child = children.length;
while (child--) {
node.removeChild(children.item(0));
}
},
/**
@private
*/
append = function(to, elem) {
return to.appendChild(elem);
},
/**
@private
*/
createElement = function(localName) {
return doc.createElement(localName);
},
/**
@private
*/
createTextNode = function(text) {
return doc.createTextNode(text);
},
createLog = tinylogLite[log] = function(message) {
// don't show output log until called once
var uninit,
originalPadding = docElemStyle.paddingBottom,
container = createElement($div),
containerStyle = container[$style],
resizer = append(container, createElement($div)),
output = append(container, createElement($div)),
closeButton = append(container, createElement($div)),
resizingLog = False,
previousHeight = False,
previousScrollTop = False,
messages = 0,
/**
@private
*/
updateSafetyMargin = function() {
// have a blank space large enough to fit the output box at the page bottom
docElemStyle.paddingBottom = container.clientHeight + "px";
},
/**
@private
*/
setContainerHeight = function(height) {
var viewHeight = view.innerHeight,
resizerHeight = resizer.clientHeight;
// constrain the container inside the viewport's dimensions
if (height < 0) {
height = 0;
} else if (height + resizerHeight > viewHeight) {
height = viewHeight - resizerHeight;
}
containerStyle.height = height / viewHeight * 100 + "%";
updateSafetyMargin();
},
observers = [
observer(doc, "mousemove", function(evt) {
if (resizingLog) {
setContainerHeight(view.innerHeight - evt.clientY);
output.scrollTop = previousScrollTop;
}
}),
observer(doc, "mouseup", function() {
if (resizingLog) {
resizingLog = previousScrollTop = False;
}
}),
observer(resizer, "dblclick", function(evt) {
evt.preventDefault();
if (previousHeight) {
setContainerHeight(previousHeight);
previousHeight = False;
} else {
previousHeight = container.clientHeight;
containerStyle.height = "0px";
}
}),
observer(resizer, "mousedown", function(evt) {
evt.preventDefault();
resizingLog = True;
previousScrollTop = output.scrollTop;
}),
observer(resizer, "contextmenu", function() {
resizingLog = False;
}),
observer(closeButton, "click", function() {
uninit();
})
];
/**
@private
*/
uninit = function() {
// remove observers
var i = observers.length;
while (i--) {
unobserve.apply(tinylogLite, observers[i]);
}
// remove tinylog lite from the DOM
docElem.removeChild(container);
docElemStyle.paddingBottom = originalPadding;
clearChildren(output);
clearChildren(container);
tinylogLite[log] = createLog;
};
setStyles(
container, containerStyles, output, outputStyles, resizer, resizerStyles, closeButton, closeButtonStyles);
closeButton[$title] = "Close Log";
append(closeButton, createTextNode("\u2716"));
resizer[$title] = "Double-click to toggle log minimization";
docElem.insertBefore(container, docElem.firstChild);
tinylogLite[log] = function(message) {
if (messages === logLimit) {
output.removeChild(output.firstChild);
} else {
messages++;
}
var entry = append(output, createElement($div)),
entryText = append(entry, createElement($div));
entry[$title] = (new Date()).toLocaleTimeString();
setStyles(
entry, entryStyles, entryText, entryTextStyles);
append(entryText, createTextNode(message));
output.scrollTop = output.scrollHeight;
};
tinylogLite[log](message);
};
}());
} else if (typeof print === func) { // JS shell
tinylogLite[log] = print;
}
return tinylogLite;
}());
/***************************************/
/********** Parser callbacks **********/
/***************************************/
/**
@private
The parser calls this when the parsing has started.
@param {Object} parser
*/
function startCallback(parser){
var i = getParserIndex(parser);
pointClouds[i].status = STARTED;
}
/**
@private
The parser will call this when it is done parsing a chunk of data.
It cannot be assumed that the parsers will send in vertex, color,
and normal data at the same time. For example, the PSI parser will
send in all the vertex and color data first. Once it has finished
with those, it will begin sending normal data. The library must
accomodate for these cases.
@param {Object} parser - The instance of the parser. There can be many
instances the library is using if the user has loaded multiple point
clouds.
@param {Object} attributes - contains name/value pairs of arrays
For example, the PSI parser will send in data which looks something
like this:
{
"ps_Vertex": [.....],
"ps_Color": [.....],
"ps_Normal": [.....]
}
*/
function parseCallback(parser, attributes){
var parserIndex = getParserIndex(parser);
var pc = pointClouds[parserIndex];
pc.status = STREAMING;
pc.progress = parser.progress;
pc.numPoints = parser.numParsedPoints;
// assume the first attribute is vertex data
var gotVertexData = false;
for(var semantic in attributes){
// if not yet created
if(!pc.attributes[semantic]){
pc.attributes[semantic] = [];
}
var buffObj = createBufferObject(attributes[semantic]);
pc.attributes[semantic].push(buffObj);
if(gotVertexData === false){
gotVertexData = true;
var addedVertices = [0,0,0];
for(var j = 0; j < attributes[semantic].length; j += 3){
addedVertices[0] += attributes[semantic][j];
addedVertices[1] += attributes[semantic][j+1];
addedVertices[2] += attributes[semantic][j+2];
}
pc.addedVertices[0] += addedVertices[0];
pc.addedVertices[1] += addedVertices[1];
pc.addedVertices[2] += addedVertices[2];
pc.center[0] = pc.addedVertices[0] / pc.numPoints;
pc.center[1] = pc.addedVertices[1] / pc.numPoints;
pc.center[2] = pc.addedVertices[2] / pc.numPoints;
}
}
}
/**
@private
The parser will call this when the file is done being downloaded.
@param {Object} parser
*/
function loadedCallback(parser){
// We may have several point clouds streaming.
var parserIndex = getParserIndex(parser);
// Create a short alias.
var pc = pointClouds[parserIndex];
pc.status = COMPLETE;
pc.progress = parser.progress;
}
/**
@private
*/
function renderLoop(){
frames++;
var now = new Date();
matrixStack.push(M4x4.I);
// now call user's stuff
usersRender();
matrixStack.pop();
// if more than 1 second has elapsed, recalculate fps
if(now - lastTime > 1000){
frameRate = frames/(now-lastTime)*1000;
frames = 0;
lastTime = now;
}
}
/**
@private
*/
function getAverage(arr){
var objCenter = [0, 0, 0];
for(var i = 0; i < arr.length; i += 3){
objCenter[0] += arr[i];
objCenter[1] += arr[i+1];
objCenter[2] += arr[i+2];
}
objCenter[0] /= arr.length/3;
objCenter[1] /= arr.length/3;
objCenter[2] /= arr.length/3;
return objCenter;
}
/**
@private
Sets variables to default values.
*/
function runDefault(){
var fovy = 60;
var aspect = width/height;
var znear = 0.1;
var zfar = 1000;
var ymax = znear * Math.tan(fovy * Math.PI / 360.0);
var ymin = -ymax;
var xmin = ymin * aspect;
var xmax = ymax * aspect;
var left = xmin;
var right = xmax;
var top = ymax;
var bottom = ymin;
var X = 2 * znear / (right - left);
var Y = 2 * znear / (top - bottom);
var A = (right + left) / (right - left);
var B = (top + bottom) / (top - bottom);
var C = -(zfar + znear) / (zfar - znear);
var D = -2 * zfar * znear / (zfar - znear);
projectionMatrix = M4x4.$(
X, 0, 0, 0,
0, Y, 0, 0,
A, B, C, -1,
0, 0, D, 0);
normalMatrix = M4x4.I;
};
/**
@private
@param {} element
@param {} type
@param {Function} func
*/
function attach(element, type, func){
//
if(element.addEventListener){
element.addEventListener(type, func, false);
} else {
element.attachEvent("on" + type, fn);
}
}
/**
@private
These uniforms only need to be set once during the use of
the program. Unless of course the user explicitly sets the
point size, attenuation or projection.
*/
function setDefaultUniforms(){
uniformf(currProgram, "ps_PointSize", 1);
uniformf(currProgram, "ps_Attenuation", [attn[0], attn[1], attn[2]]);
uniformMatrix(currProgram, "ps_ProjectionMatrix", false, projectionMatrix);
}
/**
@private
@param {} evt
*/
function mouseScroll(evt){
var delta = 0;
if(evt.detail){
delta = evt.detail / 3;
}
else if(evt.wheelDelta){
delta = -evt.wheelDelta / 360;
}
userMouseScroll(delta);
}
/**
@private
*/
function mousePressed(){
userMousePressed();
}
/**
@private
*/
function mouseReleased(){
userMouseReleased();
}
/**
@private
@param {} evt
*/