Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Notes: R=v*v'+cos(alpha)*(identity-v*v')+sin(alpha)*cross(v,v);
- %Where v is the vector we want to rotate around, not the camera axis itself
- %World coordinate system.
- ey = [0 0 0]'; %Camera is at world origin.
- look_at = [0 0 -1]'; %Bunny is centered around 0,0,-1
- up = [0 1 0]'; %1 on the y axis is up. Makes sense
- %Get the camera coordinate system.
- n = normc(ey-look_at); %z-axis
- u = cross(up', n)'; %x-axis
- v = cross(n,u); % y-axis
- %convert degrees to radians
- alpha_deg = 25;
- alpha = (alpha_deg*pi)/180;
- %Develop the view matrix to go from world to camera coordinate.
- %trans = [-(e'*u),-(e'*v),-(e'*n),1]';
- trans = [0,-1,-2,1]';
- left = vertcat(u',v',n',[0 0 0]);
- V = horzcat(left,trans);
- %Find the new e aka camera position
- new_e = V*vertcat(ey,1);
- %Find the new look_at
- new_look_at = V*vertcat(look_at,1);
- %Find the new up
- new_up = V*vertcat(up,1);
- %Trim off the fourth for now
- new_e = new_e(1:3);
- new_look_at = new_look_at(1:3);
- new_up = new_up(1:3);
- %We now have our rotation matrix, rotating about v, our y-axis
- R=v*v'+cos(alpha)*(eye(3)-v*v')+sin(alpha)*cross(v,v);
- %Calculate the new u,v,n.
- new_n = n'*R;
- new_u = u'*R; %Our new x-axis about y.
- new_v = v'*R;
- %Calculate the rotated e,look_at, and up
- new_e = vertcat((new_e'*R)',0);
- new_look_at = vertcat((new_look_at'*R)',0);
- new_up = vertcat((new_up'*R)',0);
- %We need to translate back to the world for new_e,new_look_at, and new_up
- %Get the transpose of our V (same as inverse)
- V = inv(V);
- %Convert back to world coordinates
- new_e = V*new_e;
- new_look_at = V*new_look_at;
- new_up = V*new_up;
- %Chop off the fourth for the final results
- new_e = new_e(1:3)'
- new_look_at = new_look_at(1:3)'
- new_up = new_up(1:3)'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement