jdk/src/share/demo/applets/MoleculeViewer/Matrix3D.java
author goetz
Thu, 21 Nov 2013 18:29:34 -0800
changeset 22852 1063026e8cee
parent 10292 ed7db6a12c2a
permissions -rw-r--r--
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization. Summary: Fixed Implicit NULL check optimization for AIX, where the page at address '0' is only write-protected. Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
     2
 * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8971
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/** A fairly conventional 3D matrix object that can transform sets of
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    43
3D points and perform a variety of manipulations on the transform */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class Matrix3D {
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    float xx, xy, xz, xo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    float yx, yy, yz, yo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    float zx, zy, zz, zo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final double pi = 3.14159265;
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    50
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /** Create a new unit matrix */
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    52
    Matrix3D() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        xx = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        yy = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        zz = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    57
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /** Scale by f in all dimensions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    void scale(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        xx *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        xy *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        xz *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        xo *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        yx *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        yy *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        yz *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        yo *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        zx *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        zy *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        zz *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        zo *= f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /** Scale along each axis independently */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    void scale(float xf, float yf, float zf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        xx *= xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        xy *= xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        xz *= xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        xo *= xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        yx *= yf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        yy *= yf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        yz *= yf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        yo *= yf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        zx *= zf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        zy *= zf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        zz *= zf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        zo *= zf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /** Translate the origin */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    void translate(float x, float y, float z) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        xo += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        yo += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        zo += z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
    96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /** rotate theta degrees about the y axis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    void yrot(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        theta *= (pi / 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        double ct = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        double st = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        float Nxx = (float) (xx * ct + zx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        float Nxy = (float) (xy * ct + zy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        float Nxz = (float) (xz * ct + zz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        float Nxo = (float) (xo * ct + zo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        float Nzx = (float) (zx * ct - xx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        float Nzy = (float) (zy * ct - xy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        float Nzz = (float) (zz * ct - xz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        float Nzo = (float) (zo * ct - xo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        xo = Nxo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        xx = Nxx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        xy = Nxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        xz = Nxz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        zo = Nzo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        zx = Nzx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        zy = Nzy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        zz = Nzz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   122
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /** rotate theta degrees about the x axis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    void xrot(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        theta *= (pi / 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        double ct = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        double st = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        float Nyx = (float) (yx * ct + zx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        float Nyy = (float) (yy * ct + zy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        float Nyz = (float) (yz * ct + zz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        float Nyo = (float) (yo * ct + zo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        float Nzx = (float) (zx * ct - yx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        float Nzy = (float) (zy * ct - yy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        float Nzz = (float) (zz * ct - yz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        float Nzo = (float) (zo * ct - yo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        yo = Nyo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        yx = Nyx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        yy = Nyy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        yz = Nyz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        zo = Nzo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        zx = Nzx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        zy = Nzy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        zz = Nzz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /** rotate theta degrees about the z axis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void zrot(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        theta *= (pi / 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        double ct = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        double st = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        float Nyx = (float) (yx * ct + xx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        float Nyy = (float) (yy * ct + xy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        float Nyz = (float) (yz * ct + xz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        float Nyo = (float) (yo * ct + xo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        float Nxx = (float) (xx * ct - yx * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        float Nxy = (float) (xy * ct - yy * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        float Nxz = (float) (xz * ct - yz * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        float Nxo = (float) (xo * ct - yo * st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        yo = Nyo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        yx = Nyx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        yy = Nyy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        yz = Nyz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        xo = Nxo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        xx = Nxx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        xy = Nxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        xz = Nxz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /** Multiply this matrix by a second: M = M*R */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    void mult(Matrix3D rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        float lxy = xy * rhs.xx + yy * rhs.xy + zy * rhs.xz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        float lxz = xz * rhs.xx + yz * rhs.xy + zz * rhs.xz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        float lxo = xo * rhs.xx + yo * rhs.xy + zo * rhs.xz + rhs.xo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        float lyx = xx * rhs.yx + yx * rhs.yy + zx * rhs.yz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        float lyy = xy * rhs.yx + yy * rhs.yy + zy * rhs.yz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        float lyz = xz * rhs.yx + yz * rhs.yy + zz * rhs.yz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        float lyo = xo * rhs.yx + yo * rhs.yy + zo * rhs.yz + rhs.yo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        float lzx = xx * rhs.zx + yx * rhs.zy + zx * rhs.zz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        float lzy = xy * rhs.zx + yy * rhs.zy + zy * rhs.zz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        float lzz = xz * rhs.zx + yz * rhs.zy + zz * rhs.zz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        float lzo = xo * rhs.zx + yo * rhs.zy + zo * rhs.zz + rhs.zo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        xx = lxx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        xy = lxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        xz = lxz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        xo = lxo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        yx = lyx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        yy = lyy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        yz = lyz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        yo = lyo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        zx = lzx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        zy = lzy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        zz = lzz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        zo = lzo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /** Reinitialize to the unit matrix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    void unit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        xo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        xx = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        xy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        xz = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        yo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        yx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        yy = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        yz = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        zo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        zx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        zy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        zz = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /** Transform nvert points from v into tv.  v contains the input
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   225
    coordinates in floating point.  Three successive entries in
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   226
    the array constitute a point.  tv ends up holding the transformed
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   227
    points as integers; three successive entries per point */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    void transform(float v[], int tv[], int nvert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        float lxx = xx, lxy = xy, lxz = xz, lxo = xo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        float lyx = yx, lyy = yy, lyz = yz, lyo = yo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        float lzx = zx, lzy = zy, lzz = zz, lzo = zo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        for (int i = nvert * 3; (i -= 3) >= 0;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            float x = v[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            float y = v[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            float z = v[i + 2];
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   236
            tv[i] = (int) (x * lxx + y * lxy + z * lxz + lxo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            tv[i + 1] = (int) (x * lyx + y * lyy + z * lyz + lyo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            tv[i + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
8971
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   241
c2519876ef49 7027686: /applets/MoleculeViewer demo needs to be improved
mrkam
parents: 5506
diff changeset
   242
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return ("[" + xo + "," + xx + "," + xy + "," + xz + ";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                + yo + "," + yx + "," + yy + "," + yz + ";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                + zo + "," + zx + "," + zy + "," + zz + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}