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


Java Vector3.dot方法代码示例

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


在下文中一共展示了Vector3.dot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intersects

import com.ra4king.opengl.util.math.Vector3; //导入方法依赖的package包/类
public boolean intersects(Vector3 position, Vector3 delta) {
		Vector3 prevPos = new Vector3(position).sub(delta);
		Vector3 normal = orientation.mult3(Vector3.FORWARD, new Vector3()).normalize();
		
		float t = new Vector3(this.position).sub(prevPos).dot(normal) / delta.dot(normal);
		if(t < 0f || t > 1f) {
			return false;
		}
		
		Vector3 intersection = new Vector3(delta).mult(t).add(prevPos).sub(this.position);
		
		Quaternion inverse = new Quaternion(orientation).inverse();
		Vector3 offset = inverse.mult3(intersection, intersection);
		
		offset.mult(2.0f).sub(new Vector3(size, 0.0f)).divide(new Vector3(size, 1.0f));
		return offset.dot(offset) <= 1.0f; // oval portal
		
		// rectangular portal
//		return offset.x() >= 0f && offset.x() < size.x() &&
//				       offset.y() > 0f && offset.y() < size.y();
	}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:22,代码来源:Portal.java

示例2: render

import com.ra4king.opengl.util.math.Vector3; //导入方法依赖的package包/类
public void render(int currentFbo, Camera camera, Matrix4 viewMatrix, FrustumCulling culling) {
	updated = false;
	
	if(rendered)
		return;
	
	rendered = true;
	
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, portalFbo);
	
	glEnable(GL_STENCIL_TEST);
	glClear(GL_STENCIL_BUFFER_BIT);
	
	// Setup stencil test: all pixels that pass depth test mark 1 in stencil buffer
	glStencilFunc(GL_ALWAYS, 1, 0xFF);
	glStencilOp(GL_ZERO, GL_ZERO, GL_REPLACE);
	
	portalProgram.begin();
	
	glUniformMatrix4(portalProgram.getUniformLocation("projectionMatrix"), false, camera.getProjectionMatrix().toBuffer());
	glUniformMatrix4(portalProgram.getUniformLocation("viewMatrix"), false, new Matrix4(viewMatrix).translate(portal.getPosition()).mult(portal.getOrientation().toMatrix(new Matrix4())).toBuffer());
	glUniform2f(portalProgram.getUniformLocation("resolution"), RenderUtils.getWidth(), RenderUtils.getHeight());
	
	// Now render the portal quad, with each pixel marking the stencil buffer
	glDisable(GL_CULL_FACE);
	RenderUtils.glBindVertexArray(vao);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	glEnable(GL_CULL_FACE);
	
	glStencilFunc(GL_EQUAL, 1, 0xFF);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	portalCamera.setCamera(camera);
	portal.transform(portalCamera.getPosition(), portalCamera.getOrientation());
	
	Vector3 destNormal = portal.getDestPortal().getOrientation().mult3(Vector3.FORWARD, new Vector3()).normalize();
	Vector4 portalPlane = new Vector4(destNormal, -destNormal.dot(portal.getDestPortal().getPosition()));
	
	Vector3 normal = portal.getOrientation().mult3(Vector3.FORWARD, new Vector3()).normalize();
	if(camera.getPosition().dot(normal) - normal.dot(portal.getPosition()) > 0) {
		portalPlane.mult(-1f);
	}
	
	worldRenderer.render(portalPlane, portal, portalFbo, portalCamera);
	
	glDisable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);
	
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, currentFbo);
	
	portalProgram.begin();
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, portalTexture);
	
	RenderUtils.glBindVertexArray(vao);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	
	glEnable(GL_CULL_FACE);
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:60,代码来源:PortalRenderer.java


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