diff options
Diffstat (limited to 'src/mvp.maxima')
-rw-r--r-- | src/mvp.maxima | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/mvp.maxima b/src/mvp.maxima new file mode 100644 index 0000000..8ec7d35 --- /dev/null +++ b/src/mvp.maxima @@ -0,0 +1,56 @@ +/* Copyright 2022 Benjamin Barenblat + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. */ + +/* Computes the model-view-projection matrix for glplanet. Variables are as follows: + + - beta is the desired latitude in radians. + + - gamma is the desired longitude in radians _west_ of the prime meridian (the + opposite of the usual convention). + + - d is the distance to the center of the Earth (i.e., the z-coordinate of the + translated Earth), in Earth radii. Since this transformation also switches + from a right-handed model coordinate system to a left-handed scene + coordinate system, this should always be a positive value. + + - phix and phiy are the camera field of view, in radians, in the x and y + directions. + + - zn and zf are the near and far clip planes, again in Earth radii. These + should both be positive, and zf should be more than zn. */ + +/* Rotation around the model z axis (turning to longitude) */ +Z : matrix([cos(gamma), -sin(gamma), 0, 0], + [sin(gamma), cos(gamma), 0, 0], + [ 0, 0, 1, 0], + [ 0, 0, 0, 1])$ + +/* Rotation around the model y axis (tilting to latitude) */ +Y : matrix([ cos(beta), 0, sin(beta), 0], + [ 0, 1, 0, 0], + [-sin(beta), 0, cos(beta), 0], + [ 0, 0, 0, 1])$ + +/* Transformation from model coordinates to view coordinates */ +T : matrix([ 0, 1, 0, 0], + [ 0, 0, 1, 0], + [-1, 0, 0, z], + [ 0, 0, 0, 1])$ + +/* Perspective transformation */ +P : matrix([1 / tan(phix / 2), 0, 0, 0 ], + [ 0, 1 / tan(phiy / 2), 0, 0 ], + [ 0, 0, (zn + zf) / (zf - zn), 2 * zn * zf / (zn - zf)], + [ 0, 0, 1, 0 ])$ + +P . T . Y . Z; |