本文整理汇总了Java中ch.fhnw.util.math.Mat4类的典型用法代码示例。如果您正苦于以下问题:Java Mat4类的具体用法?Java Mat4怎么用?Java Mat4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mat4类属于ch.fhnw.util.math包,在下文中一共展示了Mat4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: projectToScreen
import ch.fhnw.util.math.Mat4; //导入依赖的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);
}
示例2: unprojectFromScreen
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
public static Vec3 unprojectFromScreen(Mat4 viewProjInvMatrix, Viewport viewport, Vec3 v) {
// map x and y from window coordinates
float x = (v.x - viewport.x) / viewport.w;
float y = (v.y - viewport.y) / viewport.h;
float z = v.z;
// map to range -1 to 1
x = x * 2 - 1;
y = y * 2 - 1;
z = z * 2 - 1;
Vec4 result = viewProjInvMatrix.transform(new Vec4(x, y, z, 1));
if (result.w == 0) {
return null;
}
return new Vec3(result.x / result.w, result.y / result.w, result.z / result.w);
}
示例3: getTransformedGeometryData
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@Override
public float[][] getTransformedGeometryData() {
float[][] src = geometry.getData();
float[][] dst = new float[src.length][];
IGeometryAttribute[] attrs = geometry.getAttributes();
Mat4 tp = Mat4.multiply(Mat4.translate(position), transform);
dst[0] = tp.transform(src[0]);
for (int i = 1; i < src.length; ++i) {
if (attrs[i].equals(IGeometry.NORMAL_ARRAY)) {
Mat3 tn = new Mat3(tp).inverse().transpose();
dst[i] = tn.transform(src[i]);
} else {
dst[i] = Arrays.copyOf(src[i], src[i].length);
}
}
return dst;
}
示例4: toUniform
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public IShaderUniform<?> toUniform(int unit) {
if(value instanceof Boolean)
return new BooleanUniform((ITypedAttribute<Boolean>)this, id());
else if(value instanceof Float)
return new FloatUniform((ITypedAttribute<Float>)this, id());
else if(value instanceof Integer)
return new IntUniform((ITypedAttribute<Integer>)this, id());
else if(value instanceof Mat3)
return new Mat3FloatUniform((ITypedAttribute<Mat3>)this, id());
else if(value instanceof Mat4)
return new Mat4FloatUniform((ITypedAttribute<Mat4>)this, id());
else if(value instanceof IVec3)
return new Vec3FloatUniform((ITypedAttribute<IVec3>)this, id());
else if(value instanceof IVec4)
return new Vec4FloatUniform((ITypedAttribute<IVec4>)this, id());
else if(value instanceof IImage || value instanceof VideoFrame)
return new SamplerUniform(id(), id(), unit, GL11.GL_TEXTURE_2D);
else
throw new IllegalArgumentException("Unsupported unifrom type:" + value.getClass().getName());
}
示例5: extrude
import ch.fhnw.util.math.Mat4; //导入依赖的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;
}
示例6: reshape
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL3 gl = drawable.getGL().getGL3();
// Set the viewport to be the entire window
gl.glViewport(0, 0, width, height);
double aspect = (double) height / width;
ybottom = aspect * xleft;
ytop = aspect * xright;
P = Mat4.ortho(xleft, xright, (float) ybottom, (float) ytop, znear, zfar);
mygl.setP(gl, P);
}
示例7: display
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@Override
public void display(GLAutoDrawable drawable) {
GL3 gl = drawable.getGL().getGL3();
gl.glClear(GL3.GL_COLOR_BUFFER_BIT); // Bildschirm loeschen
mygl.setColor(0, 1, 0); // Farbe der Vertices
double alpha = 0;
//Quader viereck = new Quader(mygl);
//viereck.zeichne(gl, a, b, c, true);
M=Mat4.ID;
mygl.setM(gl, M);
zeichneKreis(gl, 0.2f, (float) x, (float) y, 20);
M= Mat4.translate((float)x,(float)y,0);
alpha = (Math.atan(vy/vx)) * (180/Math.PI);
M = M.postMultiply(Mat4.rotate((float)alpha, 0,0,1));
mygl.setM(gl,M);
zeichneSpeer(gl, 1.2f, 0.04f, 0.2f);
// eulerischer Algorythmus 2D
if (stopped)
return;
x = x + vx * dt;
y = y + vy * dt;
vx = vx + ax * dt;
vy = vy + ay * dt;
if (y < ybottom) {
x = x0;
y = y0;
vx = v0x;
vy = v0y;
}
// y = y + v*dt;
// v = v + -g*dt;
}
示例8: reshape
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL3 gl = drawable.getGL().getGL3();
// Set the viewport to be the entire window
gl.glViewport(0, 0, width, height);
double aspect = (double) height / width;
ybottom = aspect * xleft;
ytop = aspect * xright;
P = Mat4.ortho(xleft, xright, (float) ybottom, (float) ytop, znear, zfar);
mygl.setP(gl, P);
}
示例9: toMat4
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
private Mat4 toMat4(RealMatrix m) {
float[] v = new float[16];
for (int i = 0; i < 16; ++i) {
v[i] = (float) m.getEntry(i % 4, i / 4);
}
return new Mat4(v);
}
示例10: projectToDevice
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
public static Vec3 projectToDevice(Mat4 viewProjMatrix, Vec4 v) {
Vec4 proj = viewProjMatrix.transform(v);
if (proj.w == 0)
return null;
// map x, y and z to range [-1, 1]
float x = proj.x / proj.w;
float y = proj.y / proj.w;
float z = proj.z / proj.w;
return new Vec3(x, y, z);
}
示例11: addToAzimuth
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
/**
* Orbit around target with camera orbit axis. Positive value orbits
* counter-clock-wise around axis.
*
* @param delta
* relative angle in degrees
*/
public void addToAzimuth(float delta) {
Mat4 m = Mat4.multiply(Mat4.translate(camera.getTarget()), Mat4.rotate(delta, camera.getCameraOrbitAxis()),
Mat4.translate(camera.getTarget().negate()));
Vec3 p = m.transform(camera.getPosition());
Vec3 u = m.transform(camera.getPosition().add(camera.getUp())).subtract(p);
camera.setPosition(p);
camera.setUp(u);
}
示例12: addToElevation
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
/**
* Orbit around target on camera-x axis. Positive value orbits clock-wise
* around camera-x axis, i.e. moves camera "up"
*
* @param delta
* relative angle in degrees
*/
public void addToElevation(float delta) {
Mat4 m = Mat4.multiply(Mat4.translate(camera.getTarget()), Mat4.rotate(-delta, camera.getCameraXAxis()),
Mat4.translate(camera.getTarget().negate()));
Vec3 p = m.transform(camera.getPosition());
Vec3 u = m.transform(camera.getPosition().add(camera.getUp())).subtract(p);
if (KEEP_ROT_X_POSITIVE && Vec3.Z.dot(u) < 0)
return;
camera.setPosition(p);
camera.setUp(u);
}
示例13: setTransform
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
@Override
public void setTransform(Mat4 transform) {
if (this.transform != transform) {
this.transform = transform;
bb = null;
updateRequest();
}
}
示例14: loadUniforms
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
public static void loadUniforms(FloatUniformBuffer uniforms, IViewCameraState vcs) {
uniforms.load((blockIndex, buffer) -> {
switch (blockIndex) {
case 0:
// 3d setup
addMat4(buffer, vcs.getViewMatrix());
addMat4(buffer, vcs.getViewProjMatrix());
addMat4(buffer, vcs.getProjMatrix());
addMat3(buffer, vcs.getNormalMatrix());
break;
case 1:
// ortho device space
buffer.put(ID_4X4);
buffer.put(ID_4X4);
buffer.put(ID_4X4);
buffer.put(PAD_12);
break;
case 2:
// ortho screen space
float[] ortho = Mat4.ortho(0, vcs.getViewport().w, 0, vcs.getViewport().h, -1, 1).toArray();
buffer.put(ID_4X4);
buffer.put(ortho);
buffer.put(ortho);
buffer.put(PAD_12);
break;
}
});
}
示例15: ViewCameraState
import ch.fhnw.util.math.Mat4; //导入依赖的package包/类
public ViewCameraState(IView view, Mat4 viewMatrix, Mat4 projMatrix) {
this.viewport = view.getViewport();
this.locked = true;
position = target = up = null;
fov = near = far = 0;
this.viewMatrix = viewMatrix;
this.projMatrix = projMatrix;
}