1 /*
2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
185 if (w != 0.0f) {
186 pointOut.x /= w;
187 pointOut.y /= w;
188 pointOut.z /= w;
189 }
190
191 return pointOut;
192 }
193
194
195 /**
196 * Transforms the point parameter with this transform and
197 * places the result back into point. The fourth element of the
198 * point input paramter is assumed to be one.
199 *
200 * @param point the input point to be transformed
201 *
202 * @return the transformed point
203 */
204 public Vec3d transform(Vec3d point) {
205 return transform(point, point);
206 }
207
208 /**
209 * Transforms the normal parameter by this transform and places the value
210 * into normalOut. The fourth element of the normal is assumed to be zero.
211 * Note: For correct lighting results, if a transform has uneven scaling
212 * surface normals should transformed by the inverse transpose of
213 * the transform. This the responsibility of the application and is not
214 * done automatically by this method.
215 *
216 * @param normal the input normal to be transformed
217 *
218 * @param normalOut the transformed normal
219 *
220 * @return the transformed normal
221 */
222 public Vec3f transformNormal(Vec3f normal, Vec3f normalOut) {
223 normal.x = (float) (mat[0]*normal.x + mat[1]*normal.y +
224 mat[2]*normal.z);
225 normal.y = (float) (mat[4]*normal.x + mat[5]*normal.y +
226 mat[6]*normal.z);
227 normal.z = (float) (mat[8]*normal.x + mat[9]*normal.y +
228 mat[10]*normal.z);
229 return normalOut;
230 }
231
232 /**
233 * Transforms the normal parameter by this transform and places the value
234 * back into normal. The fourth element of the normal is assumed to be zero.
235 * Note: For correct lighting results, if a transform has uneven scaling
236 * surface normals should transformed by the inverse transpose of
237 * the transform. This the responsibility of the application and is not
238 * done automatically by this method.
239 *
240 * @param normal the input normal to be transformed
241 *
242 * @return the transformed normal
243 */
244 public Vec3f transformNormal(Vec3f normal) {
245 return transformNormal(normal, normal);
246 }
247
248 /**
249 * Sets the value of this transform to a perspective projection transform.
250 * This transform maps points from Eye Coordinates (EC)
251 * to Clipping Coordinates (CC).
252 * Note that the field of view is specified in radians.
253 *
254 * @param verticalFOV specifies whether the fov is vertical (Y direction).
255 *
256 * @param fov specifies the field of view in radians
257 *
258 * @param aspect specifies the aspect ratio. The aspect ratio is the ratio
259 * of width to height.
260 *
261 * @param zNear the distance to the frustum's near clipping plane.
262 * This value must be positive, (the value -zNear is the location of the
263 * near clip plane).
264 *
265 * @param zFar the distance to the frustum's far clipping plane
|
1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
185 if (w != 0.0f) {
186 pointOut.x /= w;
187 pointOut.y /= w;
188 pointOut.z /= w;
189 }
190
191 return pointOut;
192 }
193
194
195 /**
196 * Transforms the point parameter with this transform and
197 * places the result back into point. The fourth element of the
198 * point input paramter is assumed to be one.
199 *
200 * @param point the input point to be transformed
201 *
202 * @return the transformed point
203 */
204 public Vec3d transform(Vec3d point) {
205 return transform(new Vec3d(point), point);
206 }
207
208 /**
209 * Transforms the normal parameter by this transform and places the value
210 * into normalOut. The fourth element of the normal is assumed to be zero.
211 * Note: For correct lighting results, if a transform has uneven scaling
212 * surface normals should transformed by the inverse transpose of
213 * the transform. This the responsibility of the application and is not
214 * done automatically by this method.
215 *
216 * @param normal the input normal to be transformed
217 *
218 * @param normalOut the transformed normal
219 *
220 * @return the transformed normal
221 */
222 public Vec3f transformNormal(Vec3f normal, Vec3f normalOut) {
223 if (normalOut == null) {
224 normalOut = new Vec3f();
225 }
226 normalOut.x = (float) (mat[0]*normal.x + mat[1]*normal.y +
227 mat[2]*normal.z);
228 normalOut.y = (float) (mat[4]*normal.x + mat[5]*normal.y +
229 mat[6]*normal.z);
230 normalOut.z = (float) (mat[8]*normal.x + mat[9]*normal.y +
231 mat[10]*normal.z);
232 return normalOut;
233 }
234
235 /**
236 * Transforms the normal parameter by this transform and places the value
237 * back into normal. The fourth element of the normal is assumed to be zero.
238 * Note: For correct lighting results, if a transform has uneven scaling
239 * surface normals should transformed by the inverse transpose of
240 * the transform. This the responsibility of the application and is not
241 * done automatically by this method.
242 *
243 * @param normal the input normal to be transformed
244 *
245 * @return the transformed normal
246 */
247 public Vec3f transformNormal(Vec3f normal) {
248 return transformNormal(new Vec3f(normal), normal);
249 }
250
251 /**
252 * Sets the value of this transform to a perspective projection transform.
253 * This transform maps points from Eye Coordinates (EC)
254 * to Clipping Coordinates (CC).
255 * Note that the field of view is specified in radians.
256 *
257 * @param verticalFOV specifies whether the fov is vertical (Y direction).
258 *
259 * @param fov specifies the field of view in radians
260 *
261 * @param aspect specifies the aspect ratio. The aspect ratio is the ratio
262 * of width to height.
263 *
264 * @param zNear the distance to the frustum's near clipping plane.
265 * This value must be positive, (the value -zNear is the location of the
266 * near clip plane).
267 *
268 * @param zFar the distance to the frustum's far clipping plane
|