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


Java Vector2类代码示例

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


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

示例1: loadPlane

import com.ra4king.opengl.util.math.Vector2; //导入依赖的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

示例2: onDragRotate

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public void onDragRotate(Vector2 position) {
	int diffX = (int)(position.x() - startDragMouseLoc.x());
	int diffY = -(int)(position.y() - startDragMouseLoc.y());
	
	switch(rotateMode) {
		case DUAL_AXIS_ROTATE:
			processXYChange(diffX, diffY);
			break;
		case BIAXIAL_ROTATE:
			if(Math.abs(diffX) > Math.abs(diffY))
				processXChange(diffX);
			else
				processYChange(diffY);
			break;
		case XZ_AXIS_ROTATE:
			processXChange(diffX);
			break;
		case Y_AXIS_ROTATE:
			processYChange(diffY);
			break;
		case SPIN_VIEW_AXIS:
			processSpinAxis(diffX);
			break;
	}
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:26,代码来源:MousePoles.java

示例3: mouseClick

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
@Override
public void mouseClick(MouseButton button, boolean isPressed, MouseModifier modifiers, Vector2 position) {
	if(isPressed) {
		if(!isDragging) {
			if(button == actionButton) {
				if(modifiers == MouseModifier.KEY_CTRL)
					beginDragRotate(position, RotateMode.BIAXIAL_ROTATE);
				else if(modifiers == MouseModifier.KEY_ALT)
					beginDragRotate(position, RotateMode.SPIN_VIEW_AXIS);
				else
					beginDragRotate(position, RotateMode.DUAL_AXIS_ROTATE);
			}
		}
	} else {
		if(isDragging) {
			if(button == actionButton) {
				if(rotateMode == RotateMode.DUAL_AXIS_ROTATE ||
						rotateMode == RotateMode.SPIN_VIEW_AXIS ||
						rotateMode == RotateMode.BIAXIAL_ROTATE)
					endDragRotate(position, true);
			}
		}
	}
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:25,代码来源:MousePoles.java

示例4: render

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
private void render(MatrixStack matrixStack, float angle, int curDepth, FloatBuffer buffer) {
	float radius = (float)Math.pow(pow, getDepth() - curDepth + change * timePassed / SPLIT_TIME) / SIZE_CONSTANT;
	
	matrixStack.getTop().translate(0, radius, 0);
	try {
		buffer.put(PolygonLoader.loadPlane(new Vector2(0.1f, 2 * radius), new Vector3(0, 0, 0), true, false, matrixStack.getTop()));
	} catch(Exception exc) {
		System.out.println(getDepth() + " " + getTotal() + " " + (getTotal() * 72) + " " + buffer.capacity());
		throw exc;
	}
	matrixStack.getTop().translate(0, radius, 0);
	
	if(curDepth < getDepth() && curDepth < MAX_DEPTH) {
		matrixStack.pushMatrix();
		matrixStack.getTop().rotate((float)(-Math.PI / 2 + angle), 0, 0, 1);
		render(matrixStack, angle, curDepth + 1, buffer);
		matrixStack.popMatrix();
		
		matrixStack.pushMatrix();
		matrixStack.getTop().rotate(angle, 0, 0, 1);
		render(matrixStack, angle, curDepth + 1, buffer);
		matrixStack.popMatrix();
	}
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:25,代码来源:Fractal.java

示例5: mouseMove

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
@Override
public void mouseMove(Vector2 position) {
	if(isDragging) {
		Vector2 diff = new Vector2(position).sub(prevMousePos);
		
		switch(rotateMode) {
			case DUAL_AXIS:
				Quaternion rot = calcRotationQuat(Axis.AXIS_Y, diff.x() * rotateScale);
				rot = calcRotationQuat(Axis.AXIS_X, diff.y() * rotateScale).mult(rot).normalize();
				rotateViewDegrees(rot, false);
				break;
			case BIAXIAL: {
				Vector2 initDiff = new Vector2(position).sub(startDragMousePos);
				
				Axis axis;
				float degAngle;
				if(Math.abs(initDiff.x()) > Math.abs(initDiff.y())) {
					axis = Axis.AXIS_Y;
					degAngle = initDiff.x() * rotateScale;
				} else {
					axis = Axis.AXIS_X;
					degAngle = initDiff.y() * rotateScale;
				}
				
				rotateViewDegrees(calcRotationQuat(axis, degAngle), true);
			}
				break;
			case SPIN:
				rotateViewDegrees(calcRotationQuat(Axis.AXIS_Z, -diff.x() * rotateScale), false);
				break;
		}
		
		prevMousePos.set(position);
	}
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:36,代码来源:MousePoles.java

示例6: endDragRotate

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public void endDragRotate(Vector2 end, boolean keepResults) {
	if(keepResults)
		onDragRotate(end);
	else
		currView.orient.set(startDragOrient);
	
	isDragging = false;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:9,代码来源:MousePoles.java

示例7: parseVector2

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
@CopyStruct
public static Vector2 parseVector2(String s) throws NumberFormatException {
	String[] comp = StringUtil.split(s, ' ');
	if(comp.length != 2)
		throw new IllegalArgumentException("invalid Vector2");
	
	Vector2 vec = new Vector2();
	vec.x(Float.parseFloat(comp[0]));
	vec.y(Float.parseFloat(comp[1]));
	
	return vec;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:13,代码来源:Utils.java

示例8: Portal

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
/**
 * Without orientation, the portal is by default on the XY plane with the position as the top left corner of the quad.
 */
public Portal(OpenGLWorlds worldsManager, World parentWorld, Vector3 position, Vector2 size, Quaternion orientation, World destWorld) {
	this.worldsManager = worldsManager;
	this.parentWorld = parentWorld;
	this.position = Struct.malloc(Vector3.class).set(position);
	this.size = Struct.malloc(Vector2.class).set(size);
	this.orientation = Struct.malloc(Quaternion.class).set(orientation).normalize();
	
	this.destWorld = destWorld;
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:13,代码来源:Portal.java

示例9: init

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
private void init() {
	Vector2 s = portal.getSize();
	
	final float[] portalData = {
	  0, 0, 0,
	  s.x(), 0, 0,
	  0, s.y(), 0,
	  
	  s.x(), s.y(), 0,
	  0, s.y(), 0,
	  s.x(), 0, 0,
	  };
	
	System.out.println(Arrays.toString(portalData));
	
	int vbo = glGenBuffers();
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(portalData.length).put(portalData).flip(), GL_STATIC_DRAW);
	
	vao = RenderUtils.glGenVertexArrays();
	RenderUtils.glBindVertexArray(vao);
	
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	
	RenderUtils.glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	portalProgram = new ShaderProgram(Utils.readFully(Resources.getInputStream("shaders/portal.vert")),
			                                 Utils.readFully(Resources.getInputStream("shaders/portal.frag")));
	
	portalProgram.begin();
	glUniform1i(portalProgram.getUniformLocation("portalTex"), 0);
	glUniform2f(portalProgram.getUniformLocation("size"), s.x(), s.y());
}
 
开发者ID:ra4king,项目名称:OpenGL-Worlds,代码行数:36,代码来源:PortalRenderer.java

示例10: mouseMove

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
@Override
public void mouseMove(Vector2 position) {
	if(isDragging) {
		Vector2 diff = position.copy().sub(prevMousePos);
		
		switch(rotateMode) {
			case DUAL_AXIS:
				Quaternion rot = calcRotationQuat(Axis.AXIS_Y, diff.x() * rotateScale);
				rot = calcRotationQuat(Axis.AXIS_X, diff.y() * rotateScale).mult(rot).normalize();
				rotateViewDegrees(rot, false);
				break;
			case BIAXIAL: {
				Vector2 initDiff = position.copy().sub(startDragMousePos);
				
				Axis axis;
				float degAngle;
				if(Math.abs(initDiff.x()) > Math.abs(initDiff.y())) {
					axis = Axis.AXIS_Y;
					degAngle = initDiff.x() * rotateScale;
				} else {
					axis = Axis.AXIS_X;
					degAngle = initDiff.y() * rotateScale;
				}
				
				rotateViewDegrees(calcRotationQuat(axis, degAngle), true);
			}
				break;
			case SPIN:
				rotateViewDegrees(calcRotationQuat(Axis.AXIS_Z, -diff.x() * rotateScale), false);
				break;
		}
		
		prevMousePos = position.copy();
	}
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:36,代码来源:MousePoles.java

示例11: endDragRotate

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public void endDragRotate(Vector2 end, boolean keepResults) {
	if(keepResults)
		onDragRotate(end);
	else
		currView.orient = startDragOrient.copy();
	
	isDragging = false;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:9,代码来源:MousePoles.java

示例12: parseVector2

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public static Vector2 parseVector2(String s) throws NumberFormatException {
	String[] comp = StringUtil.split(s, ' ');
	if(comp.length != 2)
		throw new IllegalArgumentException("invalid Vector2");
	
	Vector2 vec = new Vector2();
	vec.x(Float.parseFloat(comp[0]));
	vec.y(Float.parseFloat(comp[1]));
	
	return vec;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Tutorials,代码行数:12,代码来源:Utils.java

示例13: UniformVec2Binder

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public UniformVec2Binder(Vector2 vec) {
	setValue(vec);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:4,代码来源:UniformVec2Binder.java

示例14: setValue

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
public void setValue(Vector2 vec) {
	value.set(vec);
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:4,代码来源:UniformVec2Binder.java

示例15: getValue

import com.ra4king.opengl.util.math.Vector2; //导入依赖的package包/类
@CopyStruct
public Vector2 getValue() {
	return value;
}
 
开发者ID:ra4king,项目名称:LWJGL-OpenGL-Utils,代码行数:5,代码来源:UniformVec2Binder.java


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