Overview
Comment: | got rotation of selected points to work |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
e34dd1120f0d36ea8d8678cd233b987d |
User & Date: | Jacob on 2012-12-30 22:51:52 |
Other Links: | manifest | tags |
Context
2013-01-02
| ||
17:22 | started moving around code in files to factor stuff. check-in: 1514d83c29 user: Derek tags: trunk | |
2012-12-30
| ||
22:51 | got rotation of selected points to work check-in: e34dd1120f user: Jacob tags: trunk | |
19:55 | working on rotating selected points. check-in: 09450376b4 user: Derek tags: trunk | |
Changes
Modified draw.html from [d374aefa95] to [2d990104f4].
︙ | ︙ | |||
53 54 55 56 57 58 59 | 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; | | | 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 = [0,0,0]; var zoom_center = origin.slice(0); var selected_points_start_loc = []; |
︙ | ︙ | |||
438 439 440 441 442 443 444 | // right click addKeyListener(1002, function(e, s, lasts){ if(s == 0){ delta_horizontal_angle = 0; delta_vertical_angle = 0; } | | | | | > > | 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(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 rotation_center = [0,0,0]; for(var i = 0; i < selected_points.length; ++i){ 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 | // 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); } | < < < | 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 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 | var pt = points[selected_points[i]]; vector_add(pt, delta_position, pt); }} else{ moveCamera(delta_position, false); } | | | > > > > | > > > | > > > > | 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 || getKeyState(16)){ if(delta_horizontal_angle) rotateHorizontal(delta_horizontal_angle); if(delta_vertical_angle) rotateVertical(delta_vertical_angle); } 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); } |
︙ | ︙ |