︙ | | |
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
-
+
|
var delta_horizontal_angle = 0;
var delta_vertical_angle = 0;
var delta_position = [0,0,0];
// Use to rotate selected points about a vector line
var selection_rotation_axis = null;
var rotation_center = origin.slice(0);
var rotation_center = [0,0,0];
var zoom_center = origin.slice(0);
var selected_points_start_loc = [];
|
︙ | | |
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
|
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
|
-
-
+
+
-
+
-
+
+
+
|
// right click
addKeyListener(1002, function(e, s, lasts){
if(s == 0){
delta_horizontal_angle = 0;
delta_vertical_angle = 0; }
else if(getKeyState(16)){ // use default as rotation center
rotation_center = origin.slice(0); }
//else if(getKeyState(16)){ // use default as rotation center
//rotation_center = origin.slice(0); }
else if(highlight_object > 0){ // use highlighted points for rotation center.
if(highlight_object < points.length){
rotation_center = points[highlight_object].slice(0); }
else{
var line = lines[highlight_object];
var pointa = points[line[0]];
var pointb = points[line[1]];
rotation_center = vector_midpoint(pointa, pointb);
selection_rotation_axis = vector_minus(pointa, pointb);
if(vector_dot(selection_rotation_axis, view_transform[2]) < 0){
vector_scale(-1, selection_rotation_axis, selection_rotation_axis); }}} // axis should be pointing vertical, horizontal motions along the screen will dictate motion angle.
else if(selected_points.length){ //find average of selected points for rotation center
var rotation_center = [0,0,0];
rotation_center = [0,0,0];
for(var i = 0; i < selected_points.length; ++i){
vector_add(rotation_center, selected_points[i], rotation_center); }
vector_add(rotation_center, points[selected_points[i]], rotation_center); }
var l = selected_points.length;
rotation_center = [rotation_center[0]/l, rotation_center[1]/l, rotation_center[2]/l];
// alert("Rotation center: " + rotation_center);
}});
function writeMsg(canvas, msg){
var lines = msg.split("\n");
var ctx = canvas.getContext("2d");
ctx.font = "9pt sans-serif"
|
︙ | | |
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
-
-
-
|
// camera centric uses the camera axes to perform the rotation instead of the space axes.
if(cameracentric) norm = matrix_mult(view_transform, [norm])[0];
var rotation = vector_rotation(norm, theta);
view_transform = matrix_mult(rotation, view_transform); }
function rotatePoint(point, axis, angle, center){
}
function rotateHorizontal(theta){
rotateView([0, 1, 0], theta, false); }
function rotateVertical(theta){
if(vertical_camera_rotation + theta > Math.PI/2)
|
︙ | | |
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
|
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
|
-
+
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
|
var pt = points[selected_points[i]];
vector_add(pt, delta_position, pt); }}
else{
moveCamera(delta_position, false); }
if(!selected_points.length){
if(!selected_points.length || getKeyState(16)){
if(delta_horizontal_angle) rotateHorizontal(delta_horizontal_angle);
if(delta_vertical_angle) rotateVertical(delta_vertical_angle); }
else{
else{ // rotate selected points
var rotation_transform;
if(selection_rotation_axis){ //
rotation_transform = vector_rotation(selection_rotation_axis, delta_horizontal_angle); }
else{
rotation_transform = vector_rotation([0, 1, 0], delta_horizontal_angle);
rotation_transform = matrix_mult(vector_rotation([0, 0, 1], -delta_vertical_angle), rotation_transform); }
}}}
for(var i = 0; i < selected_points.length; ++i){
var index = selected_points[i];
var pt = points[index];
vector_minus(pt, rotation_center, pt);
pt = matrix_mult(rotation_transform, [pt])[0];
vector_add(pt, rotation_center, pt);
points[index] = pt; }}
// overwrite point projections
// TODO this may not be perfect if points are deleted etc.
point_projections.length = 0;
for(var i = 0; i < points.length; ++i){
point_projections[i] = project(canvas, points[i], view_transform, origin); }
|
︙ | | |