Check-in [e34dd1120f]
Not logged in
Overview
SHA1:e34dd1120f0d36ea8d8678cd233b987dd0893a18
Date: 2012-12-30 22:51:52
User: Jacob
Comment:got rotation of selected points to work
Timelines: family | ancestors | descendants | both | trunk
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2013-01-02
17:22
[1514d83c29] started moving around code in files to factor stuff. (user: Derek, tags: trunk)
2012-12-30
22:51
[e34dd1120f] got rotation of selected points to work (user: Jacob, tags: trunk)
19:55
[09450376b4] working on rotating selected points. (user: Derek, tags: trunk)
Changes

Modified draw.html from [d374aefa95] to [2d990104f4].

    53     53   var delta_horizontal_angle = 0;
    54     54   var delta_vertical_angle = 0;
    55     55   var delta_position = [0,0,0];
    56     56   
    57     57   
    58     58   //  Use to rotate selected points about a vector line
    59     59   var selection_rotation_axis = null;
    60         -var rotation_center = origin.slice(0);
           60  +var rotation_center = [0,0,0];
    61     61   var zoom_center = origin.slice(0);
    62     62   
    63     63   var selected_points_start_loc = [];
    64     64   
    65     65   
    66     66   
    67     67   
................................................................................
   438    438   
   439    439   // right click
   440    440   addKeyListener(1002, function(e, s, lasts){
   441    441   	if(s == 0){
   442    442   		delta_horizontal_angle = 0;
   443    443   		delta_vertical_angle = 0; }
   444    444   		
   445         -	else if(getKeyState(16)){  // use default as rotation center
   446         -		rotation_center = origin.slice(0); }
          445  +	//else if(getKeyState(16)){  // use default as rotation center
          446  +		//rotation_center = origin.slice(0); }
   447    447   		
   448    448   	else if(highlight_object > 0){  // use highlighted points for rotation center.
   449    449   		if(highlight_object < points.length){
   450    450   			rotation_center = points[highlight_object].slice(0); }
   451    451   			
   452    452   		else{
   453    453   			var line = lines[highlight_object];
................................................................................
   455    455   			var pointb = points[line[1]];
   456    456   			rotation_center = vector_midpoint(pointa, pointb);
   457    457   			selection_rotation_axis = vector_minus(pointa, pointb);
   458    458   			if(vector_dot(selection_rotation_axis, view_transform[2]) < 0){
   459    459   				vector_scale(-1, selection_rotation_axis, selection_rotation_axis); }}}  // axis should be pointing vertical, horizontal motions along the screen will dictate motion angle.
   460    460   	
   461    461   	else if(selected_points.length){  //find average of selected points for rotation center
   462         -		var rotation_center = [0,0,0];
          462  +		rotation_center = [0,0,0];
   463    463   	    for(var i = 0; i < selected_points.length; ++i){
   464         -			vector_add(rotation_center, selected_points[i], rotation_center); }
          464  +			vector_add(rotation_center, points[selected_points[i]], rotation_center); }
   465    465   		var l = selected_points.length;
   466    466   		rotation_center = [rotation_center[0]/l, rotation_center[1]/l, rotation_center[2]/l];
          467  +        // alert("Rotation center: " + rotation_center);
          468  +
   467    469   		}});
   468    470   
   469    471   
   470    472   function writeMsg(canvas, msg){
   471    473   	var lines = msg.split("\n");
   472    474   	var ctx = canvas.getContext("2d");
   473    475   	ctx.font = "9pt sans-serif"
................................................................................
   482    484       // camera centric uses the camera axes to perform the rotation instead of the space axes.   
   483    485       if(cameracentric) norm = matrix_mult(view_transform, [norm])[0];
   484    486       var rotation = vector_rotation(norm, theta);
   485    487       
   486    488       view_transform = matrix_mult(rotation, view_transform); }
   487    489   	
   488    490   	
   489         -function rotatePoint(point, axis, angle, center){
   490         -}
   491         -    
   492    491       
   493    492       
   494    493   function rotateHorizontal(theta){
   495    494       rotateView([0, 1, 0], theta, false); }
   496    495       
   497    496   function rotateVertical(theta){
   498    497       if(vertical_camera_rotation + theta > Math.PI/2)
................................................................................
   930    929   				var pt = points[selected_points[i]];
   931    930   				vector_add(pt, delta_position, pt); }}
   932    931   		
   933    932   		else{
   934    933   			moveCamera(delta_position, false); }
   935    934   			
   936    935   			
   937         -		if(!selected_points.length){
          936  +		if(!selected_points.length || getKeyState(16)){
   938    937   			if(delta_horizontal_angle) rotateHorizontal(delta_horizontal_angle);
   939    938   			if(delta_vertical_angle) rotateVertical(delta_vertical_angle); }
   940    939   			
   941         -		else{
          940  +		else{ // rotate selected points
   942    941               var rotation_transform;
   943    942               if(selection_rotation_axis){  // 
   944         -                
   945         -            }}}
          943  +                rotation_transform = vector_rotation(selection_rotation_axis, delta_horizontal_angle); }
          944  +            else{
          945  +                rotation_transform = vector_rotation([0, 1, 0], delta_horizontal_angle);
          946  +                rotation_transform = matrix_mult(vector_rotation([0, 0, 1], -delta_vertical_angle), rotation_transform); }
          947  +
          948  +            for(var i = 0; i < selected_points.length; ++i){
          949  +                var index = selected_points[i];
          950  +                var pt = points[index];
          951  +
          952  +                vector_minus(pt, rotation_center, pt);
          953  +                pt = matrix_mult(rotation_transform, [pt])[0];
          954  +                vector_add(pt, rotation_center, pt);
          955  +                points[index] = pt; }}
   946    956           
   947    957          
   948    958           //  overwrite point projections
   949    959           //  TODO this may not be perfect if points are deleted etc.        
   950    960           point_projections.length = 0;
   951    961           for(var i = 0; i < points.length; ++i){
   952    962               point_projections[i] = project(canvas, points[i], view_transform, origin); }