OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vector4f.java
Go to the documentation of this file.
1 /* Copyright (c) 2013-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.highqualitytextjava;
22 
23 import java.lang.Math;
24 
25 public class Vector4f {
26  public float x;
27  public float y;
28  public float z;
29  public float w = 1.0f;
30 
31  // Custom toString() Method.
32  public String toString() {
33  return "[" + x + ", " + y + ", " + z + ", " + w + "]";
34  }
35 
36  // Default constructor
37  public Vector4f() {
38  x = 0.0f;
39  y = 0.0f;
40  z = 0.0f;
41  w = 1.0f;
42  }
43 
44  // Constructor
45  public Vector4f(float aX,
46  float aY,
47  float aZ,
48  float aW) {
49  x = aX;
50  y = aY;
51  z = aZ;
52  w = aW;
53  }
54 
55  public void set(float aX, float aY, float aZ, float aW) {
56  x = aX;
57  y = aY;
58  z = aZ;
59  w = aW;
60  }
61 
62  /* [Make Pixel Coords] */
63  public void makePixelCoords(float[] aMatrix,
64  int aViewportWidth,
65  int aViewportHeight) {
66  // Transform the vector into screen coordinates we assumes aMatrix is ModelViewProjection matrix
67  // transform method multiplies this vector by the matrix
68  transform(aMatrix);
69 
70  // Make coordinates as homogenous
71  x /= w;
72  y /= w;
73  z /= w;
74  w = 1.0f;
75  // Now the vector is normalized to the range [-1.0, 1.0]
76 
77  // Normalize values into NDC.
78  x = 0.5f + x * 0.5f;
79  y = 0.5f + y * 0.5f;
80  z = 0.5f + z * 0.5f;
81  w = 1.0f;
82  // Currently the valuse are clipped to the [0.0, 1.0] range
83 
84  // Move coordinates into window space (in pixels)
85  x *= (float) aViewportWidth;
86  y *= (float) aViewportHeight;
87  }
88  /* [Make Pixel Coords] */
89 
90  // Multiply the vector by matrix
91  public void transform(float[] aMatrix) {
92  if (aMatrix.length < 16)
93  return;
94 
95  Vector4f r = new Vector4f();
96  //
97  r.x = x * aMatrix[ 0];
98  r.x += y * aMatrix[ 4];
99  r.x += z * aMatrix[ 8];
100  r.x += w * aMatrix[12];
101 
102  r.y = x * aMatrix[ 1];
103  r.y += y * aMatrix[ 5];
104  r.y += z * aMatrix[ 9];
105  r.y += w * aMatrix[13];
106 
107  r.z = x * aMatrix[ 2];
108  r.z += y * aMatrix[ 6];
109  r.z += z * aMatrix[10];
110  r.z += w * aMatrix[14];
111 
112  r.w = x * aMatrix[ 3];
113  r.w += y * aMatrix[ 7];
114  r.w += z * aMatrix[11];
115  r.w += w * aMatrix[15];
116 
117  x = r.x;
118  y = r.y;
119  z = r.z;
120  w = r.w;
121  }
122 
123  static public Vector4f sub(final Vector4f aLeft,
124  final Vector4f aRight) {
125  Vector4f v = new Vector4f(aLeft.x, aLeft.y, aLeft.z, aLeft.w);
126  //
127  v.x -= aRight.x;
128  v.y -= aRight.y;
129  v.z -= aRight.z;
130  v.w -= aRight.w;
131  //
132  return v;
133  }
134 
135  // Calculate length of the vector with 3 first components only [x, y, z]
136  public float length3() {
137  return (float)Math.sqrt(x * x + y * y + z * z);
138  }
139 
140 }
const GLfloat * v
Definition: gl2ext.h:2231
void makePixelCoords(float[] aMatrix, int aViewportWidth, int aViewportHeight)
Definition: Vector4f.java:63
GLboolean r
Definition: gl2ext.h:306
void set(float aX, float aY, float aZ, float aW)
Definition: Vector4f.java:55
GLfloat GLfloat GLfloat w
Definition: gl2ext.h:2701
static Vector4f sub(final Vector4f aLeft, final Vector4f aRight)
Definition: Vector4f.java:123
Vector4f(float aX, float aY, float aZ, float aW)
Definition: Vector4f.java:45
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
precision highp float
Definition: hiz_cull.cs:37
GLint y
Definition: gl2ext.h:179