Index: draw.html
==================================================================
--- draw.html
+++ draw.html
@@ -55,11 +55,11 @@
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 = [];
@@ -440,12 +440,12 @@
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); }
@@ -457,15 +457,17 @@
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");
@@ -484,13 +486,10 @@
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); }
@@ -932,19 +931,30 @@
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;