本文整理汇总了Java中ch.fhnw.util.math.Vec3类的典型用法代码示例。如果您正苦于以下问题:Java Vec3类的具体用法?Java Vec3怎么用?Java Vec3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vec3类属于ch.fhnw.util.math包,在下文中一共展示了Vec3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPointInPolygon2D
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
/**
* Tests whether a point is within a 2D (convex or concave) polygon (x-y
* plane, z coordinate is ignored).
*/
public static boolean testPointInPolygon2D(float x, float y, Polygon polygon) {
boolean oddNodes = false;
int j = polygon.getNumVertices() - 1;
for (int i = 0; i < polygon.getNumVertices(); i++) {
Vec3 a = polygon.get(i);
Vec3 b = polygon.get(j);
if ((a.y < y && b.y >= y) || (b.y < y && a.y >= y)) {
if (a.x + (y - a.y) / (b.y - a.y) * (b.x - a.x) < x) {
oddNodes = !oddNodes;
}
}
j = i;
}
return oddNodes;
}
示例2: getError
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
private double getError(RealMatrix projMatrix, RealMatrix viewMatrix, List<Vec3> modelVertices, List<Vec3> projectedVertices) {
if (modelVertices.size() != projectedVertices.size())
throw new IllegalArgumentException("lists of vectors do not have same size");
RealMatrix pm = projMatrix.multiply(viewMatrix);
ArrayList<Vec3> projectedPoints = new ArrayList<>(modelVertices.size());
RealVector rp = new ArrayRealVector(4);
for (Vec3 p : modelVertices) {
rp.setEntry(0, p.x);
rp.setEntry(1, p.y);
rp.setEntry(2, p.z);
rp.setEntry(3, 1.0);
RealVector pp = pm.operate(rp);
pp = pp.mapDivide(pp.getEntry(3));
projectedPoints.add(new Vec3(pp.getEntry(0), pp.getEntry(1), 0.0));
}
double error = 0.0;
for (int i = 0; i < projectedPoints.size(); ++i) {
error += projectedPoints.get(i).distance(projectedVertices.get(i));
}
return error;
}
示例3: getPoints
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public float[] getPoints() {
if (points == null) {
List<Vec3> vertices = new ArrayList<>();
if (vertexCoherence) {
for (int i = 0; i < 20; i++)
subdividePoints(VERTICES[INDICES[i][0]], VERTICES[INDICES[i][1]], VERTICES[INDICES[i][2]], vertices, true, true, true, depth);
} else {
for (int i = 0; i < 20; i++)
subdividePoints(VERTICES[INDICES[i][0]], VERTICES[INDICES[i][1]], VERTICES[INDICES[i][2]], vertices, PFLAGS[i][0], PFLAGS[i][1],
PFLAGS[i][2], depth);
}
log.debug("# points:" + vertices.size());
points = Vec3.toArray(vertices);
}
return points;
}
示例4: keyPressed
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
@Override
public void keyPressed(IKeyEvent e) {
switch (e.getKey()) {
case GLFW.GLFW_KEY_UP:
yOffset += KEY_INCREMENT;
break;
case GLFW.GLFW_KEY_DOWN:
yOffset -= KEY_INCREMENT;
break;
case GLFW.GLFW_KEY_LEFT:
xOffset -= KEY_INCREMENT;
break;
case GLFW.GLFW_KEY_RIGHT:
xOffset += KEY_INCREMENT;
break;
}
mesh.setPosition(new Vec3(xOffset, yOffset, 0));
}
示例5: projectToScreen
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public static Vec3 projectToScreen(Mat4 viewProjMatrix, Viewport viewport, Vec4 v) {
Vec4 proj = viewProjMatrix.transform(v);
if (proj.w == 0)
return null;
// map x, y and z to range [0, 1]
float x = 0.5f * (proj.x / proj.w + 1);
float y = 0.5f * (proj.y / proj.w + 1);
float z = 0.5f * (proj.z / proj.w + 1);
// map x and y to viewport
x = x * viewport.w + viewport.x;
y = y * viewport.h + viewport.y;
return new Vec3(x, y, z);
}
示例6: getLines
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public float[] getLines() {
if (lines == null) {
List<Vec3> vertices = new ArrayList<>();
if (vertexCoherence) {
for (int i = 0; i < 20; i++)
subdivideLines(VERTICES[INDICES[i][0]], VERTICES[INDICES[i][1]], VERTICES[INDICES[i][2]], vertices, true, true, true, depth);
} else {
for (int i = 0; i < 20; i++)
subdivideLines(VERTICES[INDICES[i][0]], VERTICES[INDICES[i][1]], VERTICES[INDICES[i][2]], vertices, LFLAGS[i][0], LFLAGS[i][1],
LFLAGS[i][2], depth);
}
log.debug("# lines:" + vertices.size() / 2);
lines = Vec3.toArray(vertices);
}
return lines;
}
示例7: extrude
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
/**
* Extrudes this polygon along given direction by distance d, and returns list of
* new polygons. Edges of original polygon will become first edges of each
* side polygon. Adds bottom cap (= this polygon, reversed) and top cap (=
* this polygon, translated) if requested. Bottom cap will be added as first
* element in the list, top cap as last element.
*/
public List<Polygon> extrude(Vec3 direction, float d, boolean addBottomCap, boolean addTopCap) {
List<Polygon> p = new ArrayList<>(vertices.length + (addBottomCap ? 1 : 0) + (addTopCap ? 1 : 0));
if (addBottomCap)
p.add(flip());
for (int i = 0; i < vertices.length; ++i) {
Vec3 v0 = get(i);
Vec3 v1 = get(i + 1);
Vec3 v2 = v1.add(direction.scale(d));
Vec3 v3 = v0.add(direction.scale(d));
p.add(new Polygon(v0, v1, v2, v3));
}
if (addTopCap)
p.add(transform(Mat4.translate(direction.scale(d))));
return p;
}
示例8: splitToInnerFixedWidth
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
private Polygon[] splitToInnerFixedWidth(Polygon p, float w) {
Vec3 v0 = p.get(0);
Vec3 v1 = p.get(1);
Vec3 v4 = p.get(2);
Vec3 v5 = p.get(3);
float l0 = v5.distance(v0);
float t6 = 0.5f * (1 - w / l0);
float t7 = 1 - t6;
float l1 = v4.distance(v1);
float t2 = 0.5f * (1 - w / l1);
float t3 = 1 - t2;
Vec3 v2 = p.getVertexOnEdge(1, t2);
Vec3 v3 = p.getVertexOnEdge(1, t3);
Vec3 v6 = p.getVertexOnEdge(3, t6);
Vec3 v7 = p.getVertexOnEdge(3, t7);
return new Polygon[] {
new Polygon(v0, v1, v2, v7),
new Polygon(v7, v2, v3, v6),
new Polygon(v4, v5, v6, v3)
};
}
示例9: generateTrees
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
private void generateTrees(Materials materials, List<IMesh> meshes, List<Vec3> occlusion) {
for (PlantGroup g : trees) {
Vec3 p0 = g.p0;
Vec3 p1 = g.p1;
float h = MathUtilities.random(TREE_MIN_HEIGHT, TREE_MAX_HEIGHT);
if (p1 == null) {
generateTree(materials, meshes, occlusion, p0, h);
} else {
Vec3 d = p1.subtract(p0);
int n = (int)(1 + d.length() / MathUtilities.random(TREE_DISTANCE, 1.4f * TREE_DISTANCE));
for (int i = 0; i < n; ++i) {
if (Math.random() > 0.95)
continue;
Vec3 p = p0.add(d.scale((i + 1f) / (n + 1f)));
generateTree(materials, meshes, occlusion, p, h);
}
}
}
}
示例10: subdividePoints
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
private void subdividePoints(Vec3 v1, Vec3 v2, Vec3 v3, List<Vec3> vertices, boolean d1, boolean d2, boolean d3, int depth) {
if (depth == 0) {
if (d1)
vertices.add(v1);
if (d2)
vertices.add(v2);
if (d3)
vertices.add(v3);
return;
}
Vec3 v12 = v1.add(v2).normalize().scale(SCALE);
Vec3 v23 = v2.add(v3).normalize().scale(SCALE);
Vec3 v31 = v3.add(v1).normalize().scale(SCALE);
subdividePoints(v1, v12, v31, vertices, d1, true, false, depth - 1);
subdividePoints(v2, v23, v12, vertices, d2, true, false, depth - 1);
subdividePoints(v3, v31, v23, vertices, d3, false, false, depth - 1);
subdividePoints(v12, v23, v31, vertices, false, false, false, depth - 1);
}
示例11: Viereck
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public void Viereck(GL3 gl, Vec3 A, Vec3 B, Vec3 C, Vec3 D,
Vec3 n) // Normale
{
vb.setNormal(n.x, n.y, n.z);
vb.putVertex(A.x, A.y, A.z); // Dreieck 1
vb.putVertex(B.x, B.y, B.z);
vb.putVertex(C.x, C.y, C.z);
vb.putVertex(C.x, C.y, C.z); // Dreieck 2
vb.putVertex(D.x, D.y, D.z);
vb.putVertex(A.x, A.y, A.z);
}
示例12: initState
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public void initState(double w1, double w2, double w3, double phi, double x, double y, double z) {
double q0 = Math.cos(0.5 * phi * Math.PI / 180);
Vec3 n = new Vec3(x, y, z);
n = n.normalize();
double s = Math.sin(0.5 * phi * Math.PI / 180);
this.x = new double[] { w1, w2, w3, q0, s * n.x, s * n.y, s * n.z };
}
示例13: setState
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public void setState(double w1, double w2, double w3, double phi, double x, double y, double z) {
double q0 = Math.cos(0.5 * phi * Math.PI / 180);
Vec3 n = new Vec3(x, y, z);
n = n.normalize();
double s = Math.sin(0.5 * phi * Math.PI / 180);
this.x = new double[] { w1, w2, w3, q0, s * n.x, s * n.y, s * n.z };
}
示例14: PlantGroup
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
public PlantGroup(Vec3 p0, Vec3 p1, boolean shrub) {
this.p0 = p0;
this.p1 = p1;
this.radius = 0;
Vec3 d = p1.subtract(p0);
int n = (int)(1 + d.length() / 40);
for (int i = 0; i < n; ++i) {
positions.add(p0.add(d.scale((i + 1f) / (n + 1f))));
}
mesh = new DefaultMesh(Primitive.POINTS, shrub ? SHRUB_MATERIAL : TREE_MATERIAL, DefaultGeometry.createV(Vec3.toArray(positions)));
mesh.setPosition(new Vec3(0, 0, I3DConfig.LAYER_2));
}
示例15: intersect
import ch.fhnw.util.math.Vec3; //导入依赖的package包/类
/**
* Intersect line with plane and returns intersection point, or null if no
* intersection exists.
*/
public Vec3 intersect(Line line) {
float dot = normal.dot(line.getDirection());
if (dot == 0)
return null;
float k = -(offset + normal.dot(line.getOrigin())) / dot;
return line.getOrigin().add(line.getDirection().scale(k));
}