Vec3 .java

net.minecraft.util.Vec3 (class): members: getIntermediateWithXValue, getIntermediateWithYValue, getIntermediateWithZValue, squareDistanceTo, lengthVector.

net.minecraft.utilclass213 linescommon6.2 KB

API Surface (17)

Vec3 subtractReverse(Vec3 vec)
Vec3 normalize()
double dotProduct(Vec3 vec)
Vec3 crossProduct(Vec3 vec)
Vec3 subtract(Vec3 vec)
Vec3 subtract(double x, double y, double z)
Vec3 add(Vec3 vec)
Vec3 addVector(double x, double y, double z)
double distanceTo(Vec3 vec)
double squareDistanceTo(Vec3 vec)
double lengthVector()
Vec3 getIntermediateWithXValue(Vec3 vec, double x)
Vec3 getIntermediateWithYValue(Vec3 vec, double y)
Vec3 getIntermediateWithZValue(Vec3 vec, double z)
String toString()
Vec3 rotatePitch(float pitch)
Vec3 rotateYaw(float yaw)

Fields & Constants (3)

xCoord
yCoord
zCoord

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Vec3.java213 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
public class Vec3
4
{
5
    /** X coordinate of Vec3D */
6
    public final double xCoord;
7
8
    /** Y coordinate of Vec3D */
9
    public final double yCoord;
10
11
    /** Z coordinate of Vec3D */
12
    public final double zCoord;
13
14
    public Vec3(double x, double y, double z)
15
    {
16
        if (x == -0.0D)
17
        {
18
            x = 0.0D;
19
        }
20
21
        if (y == -0.0D)
22
        {
23
            y = 0.0D;
24
        }
25
26
        if (z == -0.0D)
27
        {
28
            z = 0.0D;
29
        }
30
31
        this.xCoord = x;
32
        this.yCoord = y;
33
        this.zCoord = z;
34
    }
35
36
    public Vec3(Vec3i p_i46377_1_)
37
    {
38
        this((double)p_i46377_1_.getX(), (double)p_i46377_1_.getY(), (double)p_i46377_1_.getZ());
39
    }
40
41
    /**
42
     * Returns a new vector with the result of the specified vector minus this.
43
     */
44
    public Vec3 subtractReverse(Vec3 vec)
45
    {
46
        return new Vec3(vec.xCoord - this.xCoord, vec.yCoord - this.yCoord, vec.zCoord - this.zCoord);
47
    }
48
49
    /**
50
     * Normalizes the vector to a length of 1 (except if it is the zero vector)
51
     */
52
    public Vec3 normalize()
53
    {
54
        double d0 = (double)MathHelper.sqrt_double(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
55
        return d0 < 1.0E-4D ? new Vec3(0.0D, 0.0D, 0.0D) : new Vec3(this.xCoord / d0, this.yCoord / d0, this.zCoord / d0);
56
    }
57
58
    public double dotProduct(Vec3 vec)
59
    {
60
        return this.xCoord * vec.xCoord + this.yCoord * vec.yCoord + this.zCoord * vec.zCoord;
61
    }
62
63
    /**
64
     * Returns a new vector with the result of this vector x the specified vector.
65
     */
66
    public Vec3 crossProduct(Vec3 vec)
67
    {
68
        return new Vec3(this.yCoord * vec.zCoord - this.zCoord * vec.yCoord, this.zCoord * vec.xCoord - this.xCoord * vec.zCoord, this.xCoord * vec.yCoord - this.yCoord * vec.xCoord);
69
    }
70
71
    public Vec3 subtract(Vec3 vec)
72
    {
73
        return this.subtract(vec.xCoord, vec.yCoord, vec.zCoord);
74
    }
75
76
    public Vec3 subtract(double x, double y, double z)
77
    {
78
        return this.addVector(-x, -y, -z);
79
    }
80
81
    public Vec3 add(Vec3 vec)
82
    {
83
        return this.addVector(vec.xCoord, vec.yCoord, vec.zCoord);
84
    }
85
86
    /**
87
     * Adds the specified x,y,z vector components to this vector and returns the resulting vector. Does not change this
88
     * vector.
89
     */
90
    public Vec3 addVector(double x, double y, double z)
91
    {
92
        return new Vec3(this.xCoord + x, this.yCoord + y, this.zCoord + z);
93
    }
94
95
    /**
96
     * Euclidean distance between this and the specified vector, returned as double.
97
     */
98
    public double distanceTo(Vec3 vec)
99
    {
100
        double d0 = vec.xCoord - this.xCoord;
101
        double d1 = vec.yCoord - this.yCoord;
102
        double d2 = vec.zCoord - this.zCoord;
103
        return (double)MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2);
104
    }
105
106
    /**
107
     * The square of the Euclidean distance between this and the specified vector.
108
     */
109
    public double squareDistanceTo(Vec3 vec)
110
    {
111
        double d0 = vec.xCoord - this.xCoord;
112
        double d1 = vec.yCoord - this.yCoord;
113
        double d2 = vec.zCoord - this.zCoord;
114
        return d0 * d0 + d1 * d1 + d2 * d2;
115
    }
116
117
    /**
118
     * Returns the length of the vector.
119
     */
120
    public double lengthVector()
121
    {
122
        return (double)MathHelper.sqrt_double(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
123
    }
124
125
    /**
126
     * Returns a new vector with x value equal to the second parameter, along the line between this vector and the
127
     * passed in vector, or null if not possible.
128
     */
129
    public Vec3 getIntermediateWithXValue(Vec3 vec, double x)
130
    {
131
        double d0 = vec.xCoord - this.xCoord;
132
        double d1 = vec.yCoord - this.yCoord;
133
        double d2 = vec.zCoord - this.zCoord;
134
135
        if (d0 * d0 < 1.0000000116860974E-7D)
136
        {
137
            return null;
138
        }
139
        else
140
        {
141
            double d3 = (x - this.xCoord) / d0;
142
            return d3 >= 0.0D && d3 <= 1.0D ? new Vec3(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
143
        }
144
    }
145
146
    /**
147
     * Returns a new vector with y value equal to the second parameter, along the line between this vector and the
148
     * passed in vector, or null if not possible.
149
     */
150
    public Vec3 getIntermediateWithYValue(Vec3 vec, double y)
151
    {
152
        double d0 = vec.xCoord - this.xCoord;
153
        double d1 = vec.yCoord - this.yCoord;
154
        double d2 = vec.zCoord - this.zCoord;
155
156
        if (d1 * d1 < 1.0000000116860974E-7D)
157
        {
158
            return null;
159
        }
160
        else
161
        {
162
            double d3 = (y - this.yCoord) / d1;
163
            return d3 >= 0.0D && d3 <= 1.0D ? new Vec3(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
164
        }
165
    }
166
167
    /**
168
     * Returns a new vector with z value equal to the second parameter, along the line between this vector and the
169
     * passed in vector, or null if not possible.
170
     */
171
    public Vec3 getIntermediateWithZValue(Vec3 vec, double z)
172
    {
173
        double d0 = vec.xCoord - this.xCoord;
174
        double d1 = vec.yCoord - this.yCoord;
175
        double d2 = vec.zCoord - this.zCoord;
176
177
        if (d2 * d2 < 1.0000000116860974E-7D)
178
        {
179
            return null;
180
        }
181
        else
182
        {
183
            double d3 = (z - this.zCoord) / d2;
184
            return d3 >= 0.0D && d3 <= 1.0D ? new Vec3(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
185
        }
186
    }
187
188
    public String toString()
189
    {
190
        return "(" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + ")";
191
    }
192
193
    public Vec3 rotatePitch(float pitch)
194
    {
195
        float f = MathHelper.cos(pitch);
196
        float f1 = MathHelper.sin(pitch);
197
        double d0 = this.xCoord;
198
        double d1 = this.yCoord * (double)f + this.zCoord * (double)f1;
199
        double d2 = this.zCoord * (double)f - this.yCoord * (double)f1;
200
        return new Vec3(d0, d1, d2);
201
    }
202
203
    public Vec3 rotateYaw(float yaw)
204
    {
205
        float f = MathHelper.cos(yaw);
206
        float f1 = MathHelper.sin(yaw);
207
        double d0 = this.xCoord * (double)f + this.zCoord * (double)f1;
208
        double d1 = this.yCoord;
209
        double d2 = this.zCoord * (double)f - this.xCoord * (double)f1;
210
        return new Vec3(d0, d1, d2);
211
    }
212
}
213

Deobfuscated MCP 1.8.9 source of Vec3 from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/Vec3.java), stored verbatim.