当前位置: 首页>>代码示例>>Java>>正文


Java Matrix4类代码示例

本文整理汇总了Java中com.ra4king.opengl.util.math.Matrix4的典型用法代码示例。如果您正苦于以下问题:Java Matrix4类的具体用法?Java Matrix4怎么用?Java Matrix4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Matrix4类属于com.ra4king.opengl.util.math包,在下文中一共展示了Matrix4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadCube

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public static float[] loadCube(Vector3 sideLength, Vector3 center, boolean interleaved, boolean vec4, Matrix4 modelMatrix) {
	float[] buffer = vec4 ? (interleaved ? cubeVec4interleaved : cubeVec4) : (interleaved ? cubeVec3interleaved : cubeVec3);
	
	for(int a = 0; a < cubeData.length / 2; a += 3) {
		int position = (a / 3) * ((interleaved ? 3 : 0) + (vec4 ? 4 : 3));
		
		Vector4 pos = new Vector4();
		if(modelMatrix == null) {
			pos.set(center.x() + cubeData[a] * sideLength.x(), center.y() + cubeData[a + 1] * sideLength.y(), center.z() + cubeData[a + 2] * sideLength.z(), 1);
		} else {
			modelMatrix.mult4(new Vector4(center.x() + cubeData[a] * sideLength.x(), center.y() + cubeData[a + 1] * sideLength.y(), center.z() + cubeData[a + 2] * sideLength.z(), 1), pos);
		}
		
		buffer[position + 0] = pos.x();
		buffer[position + 1] = pos.y();
		buffer[position + 2] = pos.z();
	}
	
	return buffer;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:21,代码来源:PolygonLoader.java

示例2: loadPlane

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public static float[] loadPlane(Vector2 sideLength, Vector3 center, boolean interleaved, boolean vec4, Matrix4 modelMatrix) {
	float[] buffer = vec4 ? (interleaved ? planeVec4interleaved : planeVec4) : (interleaved ? planeVec3interleaved : planeVec3);
	
	for(int a = 0; a < planeData.length / 2; a += 3) {
		int position = (a / 3) * ((interleaved ? 3 : 0) + (vec4 ? 4 : 3));
		
		Vector4 pos = new Vector4();
		if(modelMatrix == null) {
			pos.set(center.x() + cubeData[a] * sideLength.x(), center.y() + cubeData[a + 1] * sideLength.y(), center.z() + cubeData[a + 2], 1);
		} else {
			modelMatrix.mult4(new Vector4(center.x() + cubeData[a] * sideLength.x(), center.y() + cubeData[a + 1] * sideLength.y(), center.z() + cubeData[a + 2], 1), pos);
		}
		
		buffer[position + 0] = pos.x();
		buffer[position + 1] = pos.y();
		buffer[position + 2] = pos.z();
	}
	
	return buffer;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:21,代码来源:PolygonLoader.java

示例3: render

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public void render() {
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glDisable(GL_BLEND);
	
	uiProgram.begin();
	
	glUniform4(uiProgram.getUniformLocation("color"), color.toBuffer());
	glUniformMatrix4(uiProgram.getUniformLocation("projectionMatrix"), false, new Matrix4().clearToOrtho(0, RenderUtils.getWidth(), 0, RenderUtils.getHeight(), 0, 1).toBuffer());
	
	RenderUtils.glBindVertexArray(vao);
	glDrawArrays(GL_LINES, 0, graphOffset / 2);
	glDrawArrays(GL_LINE_STRIP, graphOffset / 2, stepCount);
	RenderUtils.glBindVertexArray(0);
	
	uiProgram.end();
	
	glEnable(GL_BLEND);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:22,代码来源:PerformanceGraph.java

示例4: resized

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
@Override
public void resized() {
	super.resized();
	
	Matrix4 persMatrix = new Matrix4().clearToPerspectiveDeg(45, getWidth(), getHeight(), 1, 1000);
	
	glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, persMatrix.toBuffer());
	glBindBuffer(GL_UNIFORM_BUFFER, 0);
	
	unprojectionData.clear();
	unprojectionData.asFloatBuffer().put(persMatrix.inverse().toBuffer());
	unprojectionData.position(16 * 4);
	unprojectionData.asIntBuffer().put(getWidth()).put(getHeight());
	unprojectionData.position(18 * 4).flip();
	
	glBindBuffer(GL_UNIFORM_BUFFER, unprojectionUniformBuffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, unprojectionData);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:21,代码来源:Example10_3.java

示例5: setupRotateAxis

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
private void setupRotateAxis(Matrix4 m) {
	float angle = computeAngle(2);
	float cos = (float)Math.cos(angle);
	float sin = (float)Math.sin(angle);
	float invCos = 1 - cos;
	
	Vector3 v = new Vector3(1, 1, 1).normalize();
	
	m.clearToIdentity()
			.put(0, v.x() * v.x() + (1 - v.x() * v.x()) * cos)
			.put(4, v.x() * v.y() * invCos - v.z() * sin)
			.put(8, v.x() * v.z() * invCos + v.y() * sin)
			
			.put(1, v.y() * v.x() * invCos + v.z() * sin)
			.put(5, v.y() * v.y() + (1 - v.y() * v.y()) * cos)
			.put(9, v.y() * v.z() * invCos - v.x() * sin)
			
			.put(2, v.z() * v.x() * invCos - v.y() * sin)
			.put(6, v.z() * v.y() * invCos + v.x() * sin)
			.put(10, v.z() * v.z() + (1 - v.z() * v.z()) * cos)
			
			.put(12, 5)
			.put(13, -5)
			.put(14, -25);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:26,代码来源:Example6_3.java

示例6: init

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	
	smoothInterpolation = loadProgram("example14.2.SmoothVertexColors.vert", "example14.2.SmoothVertexColors.frag");
	linearInterpolation = loadProgram("example14.2.NoCorrectVertexColors.vert", "example14.2.NoCorrectVertexColors.frag");
	
	Matrix4 perspectiveMatrix = new Matrix4().clearToPerspectiveDeg(60, 1, 1, 1, 1000);
	
	smoothInterpolation.program.begin();
	glUniformMatrix4(smoothInterpolation.cameraToClipMatrixUniform, false, perspectiveMatrix.toBuffer());
	linearInterpolation.program.begin();
	glUniformMatrix4(linearInterpolation.cameraToClipMatrixUniform, false, perspectiveMatrix.toBuffer());
	linearInterpolation.program.end();
	
	try {
		realHallway = new Mesh(getClass().getResource("example14.2.RealHallway.xml"));
		fauxHallway = new Mesh(getClass().getResource("example14.2.FauxHallway.xml"));
	} catch(Exception exc) {
		exc.printStackTrace();
		destroy();
	}
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:25,代码来源:Example14_2.java

示例7: offsetOrientation

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
private void offsetOrientation(Vector3 axis, float angle) {
	angle = angle * (float)Math.PI / 180;
	
	axis.normalize().mult((float)Math.sin(angle / 2));
	
	Quaternion offset = new Quaternion(axis.x(), axis.y(), axis.z(), (float)Math.cos(angle / 2));
	
	switch(offsetRelative) {
		case MODEL_RELATIVE:
			orientation.mult(offset);
			break;
		case WORLD_RELATIVE:
			orientation = offset.mult(orientation);
			break;
		case CAMERA_RELATIVE:
			Matrix4 camMat = calcLookAtMatrix(resolveCamPosition(), camTarget, new Vector3(0, 1, 0));
			Quaternion viewQuat = camMat.toQuaternion();
			orientation = new Quaternion(viewQuat).conjugate().mult(offset).mult(viewQuat).mult(orientation);
			break;
	}
	
	orientation.normalize();
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:24,代码来源:Example8_3.java

示例8: calcMatrix

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
@Override
@CopyStruct
public Matrix4 calcMatrix() {
	Matrix4 mat = new Matrix4().clearToIdentity();
	
	mat.translate(0, 0, -currView.radius);
	
	Quaternion fullRotation = Utils.angleAxisDeg(currView.degSpinRotation, new Vector3(0, 0, 1)).mult(currView.orient);
	mat.mult(fullRotation.toMatrix(new Matrix4()));
	
	mat.translate(new Vector3(currView.targetPos).mult(-1));
	
	return mat;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:15,代码来源:MousePoles.java

示例9: render

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public void render(String variation, Matrix4 baseMatrix) {
	Variant v = variants.get(variation);
	if(v == null)
		throw new IllegalArgumentException("Invalid variation");
	
	render(v, baseMatrix);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:8,代码来源:Scene.java

示例10: setupPlanes

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public void setupPlanes(Matrix4 matrix) {
	getPlane(matrix, 1, planes[Plane.LEFT.ordinal()]);
	getPlane(matrix, -1, planes[Plane.RIGHT.ordinal()]);
	getPlane(matrix, 2, planes[Plane.BOTTOM.ordinal()]);
	getPlane(matrix, -2, planes[Plane.TOP.ordinal()]);
	getPlane(matrix, 3, planes[Plane.NEAR.ordinal()]);
	getPlane(matrix, -3, planes[Plane.FAR.ordinal()]);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:9,代码来源:RenderUtils.java

示例11: lookAt

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public static Matrix4 lookAt(Vector3 eye, Vector3 center, Vector3 up) {
	Vector3 f = center.copy().sub(eye).normalize();
	up = up.copy().normalize();
	
	Vector3 s = f.cross(up);
	Vector3 u = s.cross(f);
	
	return new Matrix4(new float[] {
			s.x(), u.x(), -f.x(), 0,
			s.y(), u.y(), -f.y(), 0,
			s.z(), u.z(), -f.z(), 0,
			0, 0, 0, 1
	}).translate(eye.copy().mult(-1));
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:15,代码来源:Utils.java

示例12: lookAt

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
@CopyStruct
public static Matrix4 lookAt(Vector3 eye, Vector3 center, Vector3 up) {
	Vector3 w = new Vector3(center).sub(eye).normalize();
	up = new Vector3(up).normalize();
	
	Vector3 u = w.cross(up, new Vector3());
	Vector3 v = u.cross(w, new Vector3());
	
	return new Matrix4(new float[] {
			u.x(), v.x(), -w.x(), 0,
			u.y(), v.y(), -w.y(), 0,
			u.z(), v.z(), -w.z(), 0,
			0, 0, 0, 1
	}).translate(new Vector3(eye).mult(-1));
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:16,代码来源:Utils.java

示例13: getBulletLightData

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public int getBulletLightData(Matrix4 viewMatrix, FloatBuffer bulletData, int maxBulletCount) {
	final float bulletK = 1f, nonSolidBulletK = 1f;
	
	BulletVectorPair[] bulletVectorPairs = new BulletVectorPair[bulletManager.getBullets().size()];
	for(int a = 0; a < bulletVectorPairs.length; a++)
		bulletVectorPairs[a] = new BulletVectorPair(null, new Vector3());
	sort(bulletManager.getBullets(), viewMatrix, bulletVectorPairs);
	
	int count = 0;
	
	for(int a = bulletVectorPairs.length - 1; a >= 0 && count < maxBulletCount; a--) {
		Bullet b = bulletVectorPairs[a].bullet;
		Vector3 v = bulletVectorPairs[a].vector;
		
		if(v.z() >= 0) {
			continue;
		}
		
		bulletData.put(v.toBuffer());
		bulletData.put(b.getRange());
		bulletData.put(b.getColor().toBuffer());
		bulletData.put((b.isSolid() ? bulletK / (0.1f * b.getSize()) : nonSolidBulletK) / b.getAlpha());
		
		count++;
	}
	
	return count;
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:29,代码来源:BulletRenderer.java

示例14: sort

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
private static void sort(List<Bullet> bullets, Matrix4 viewMatrix, BulletVectorPair[] sortedBullets) {
	if(bullets.size() != sortedBullets.length) {
		throw new IllegalArgumentException("sortedBullets array is invalid length!");
	}
	
	for(int a = 0; a < bullets.size(); a++) {
		Bullet b = bullets.get(a);
		sortedBullets[a].bullet = bullets.get(a);
		viewMatrix.mult3(b.getPosition(), 1.0f, sortedBullets[a].vector);
	}
	
	Arrays.sort(sortedBullets);
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:14,代码来源:BulletRenderer.java

示例15: render

import com.ra4king.opengl.util.math.Matrix4; //导入依赖的package包/类
public void render(Matrix4 projectionMatrix, MatrixStack modelViewMatrix, FrustumCulling culling) {
	BulletVectorPair[] bulletVectorPairs = new BulletVectorPair[bulletManager.getBullets().size()];
	for(int a = 0; a < bulletVectorPairs.length; a++)
		bulletVectorPairs[a] = new BulletVectorPair(null, new Vector3());
	
	sort(bulletManager.getBullets(), modelViewMatrix.getTop(), bulletVectorPairs);
	
	render(projectionMatrix, modelViewMatrix, bulletVectorPairs, culling);
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:10,代码来源:BulletRenderer.java


注:本文中的com.ra4king.opengl.util.math.Matrix4类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。