• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Vector2f类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: update

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public void update(float delta, Window window, Camera camera, World world) {
    Vector2f movement = new Vector2f();
    if (window.getInput().isKeyDown(GLFW_KEY_LEFT)) {
        movement.add(-10 * delta, 0);
    }
    if (window.getInput().isKeyDown(GLFW_KEY_RIGHT)) {
        movement.add(10 * delta, 0);
    }
    if (window.getInput().isKeyDown(GLFW_KEY_UP)) {
        movement.add(0, 10 * delta);
    }
    if (window.getInput().isKeyDown(GLFW_KEY_DOWN)) {
        movement.add(0, -10 * delta);
    }
    move(movement);

    if(movement.x != 0|| movement.y != 0) {
        useAnimation(ANIM_WALKING);
    } else {
        useAnimation(ANIM_IDLE);
    }

    camera.getPosition().lerp(transform.pos.mul(-world.getScale(), new Vector3f()), 0.05f);
}
 
开发者ID:nitrodragon,项目名称:lwjgl3_stuff,代码行数:26,代码来源:Player.java


示例2: render

import org.joml.Vector2f; //导入依赖的package包/类
public void render(Camera camera, TileSheet sheet, Shader shader) {
	Vector2f position = boundingBox.getCenter(), scale = boundingBox.getHalfExtent();
	
	transform.identity().translate(position.x, position.y, 0).scale(scale.x, scale.y, 1); // Middle/Fill
	
	shader.setUniform("projection", camera.getProjection().mul(transform));
	switch (selectedState) {
		case STATE_SELECTED :
			sheet.bindTile(shader, 4, 1);
			break;
		case STATE_CLICKED :
			sheet.bindTile(shader, 7, 1);
			break;
		default :
			sheet.bindTile(shader, 1, 1);
			break;
	}
	Assets.getModel().render();
	
	renderSides(position, scale, camera, sheet, shader);
	renderCorners(position, scale, camera, sheet, shader);
}
 
开发者ID:MarcPopescu-Pfeiffer,项目名称:2DGame,代码行数:23,代码来源:Button.java


示例3: processFaceVertex

import org.joml.Vector2f; //导入依赖的package包/类
/**
 * Processes all the Face vertices by transforming them into the
 * correct data types.
 *
 * @param indices - Indices to process.
 * @param textCoordList - List of read texture coordinates.
 * @param normalsList - List of read normals.
 * @param indicesList - Destination indices list.
 * @param textCoordArr - Destination texture coordinates array.
 * @param normalsArr - Destination normals array.
 */
private static void processFaceVertex(IndexGroup indices, List<Vector2f> textCoordList,
                                      List<Vector3f> normalsList, List<Integer> indicesList,
                                      float[] textCoordArr, float[] normalsArr) {
    // Set index for vertex coordinates.
    int positionIndex = indices.indexPos;
    indicesList.add(positionIndex);

    // Reorder texture coordinates.
    if (indices.indexTextCoordinate >= 0) {
        Vector2f textCoord = textCoordList.get(indices.indexTextCoordinate);
        textCoordArr[positionIndex * 2] = textCoord.x;
        textCoordArr[positionIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.indexVecNormal >= 0) {
        Vector3f vecNormal = normalsList.get(indices.indexVecNormal);
        normalsArr[positionIndex * 3] = vecNormal.x;
        normalsArr[positionIndex * 3 + 1] = vecNormal.y;
        normalsArr[positionIndex * 3 + 2] = vecNormal.z;
    }
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:32,代码来源:OBJLoader.java


示例4: getExportArea

import org.joml.Vector2f; //导入依赖的package包/类
public Rectangle2D getExportArea(ViewPort view)
{
	Vector2fc pos = ViewPort.getWorldPos(view,
			0, 0, new Vector2f());
	Vector2dc offset = ViewPort.getScreenPos(view,
			(int) Math.ceil(pos.x()),
			(int) Math.ceil(pos.y()),
			new Vector2d());

	Vector2fc endPos = ViewPort.getWorldPos(view,
			view.getWidth(),
			view.getHeight(), new Vector2f());
	Vector2dc endScreen = ViewPort.getScreenPos(view,
			(int) Math.floor(endPos.x()),
			(int) Math.floor(endPos.y()),
			new Vector2d());

	return new Rectangle2D(offset.x(), offset.y(),
			endScreen.x() - offset.x(), endScreen.y() - offset.y());
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:21,代码来源:DungeonHandler.java


示例5: decode

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public MovePlayerPacket decode(ByteBuf buf) {
    MovePlayerPacket packet = new MovePlayerPacket();
    packet.setEntityId(ByteBufUtils.readUnsignedVarLong(buf));

    Vector3f position = new Vector3f();
    position.x = ByteBufUtils.readFloatLE(buf);
    position.y = ByteBufUtils.readFloatLE(buf);
    position.z = ByteBufUtils.readFloatLE(buf);
    packet.setPosition(position);

    Vector2f rotation = new Vector2f();
    rotation.x = ByteBufUtils.readFloatLE(buf);
    rotation.y = ByteBufUtils.readFloatLE(buf);
    packet.setRotation(rotation);

    packet.setHeadYaw(ByteBufUtils.readFloatLE(buf));

    packet.setMotionType(MotionType.fromOrdinal(buf.readByte()));
    packet.setOnGround(buf.readBoolean());
    packet.setRidingEntityId(ByteBufUtils.readUnsignedVarLong(buf));

    return packet;
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:25,代码来源:MovePlayerCodec.java


示例6: TextureSheet

import org.joml.Vector2f; //导入依赖的package包/类
public TextureSheet(Texture tex, int subWidth, int subHeight, String name){
	this.texture = tex;
	
	this.subWidth = subWidth;
	this.subHeight = subHeight;
	
	subSize = new Vector2f(this.subWidth, this.subHeight);
	
	this.name = name;
	
	perWidth = texture.width / subWidth;
	perHeight = texture.height / subHeight;
	
	offsets = new Vector2f[perWidth * perHeight];
	
	for(int i=0;i<offsets.length;i++){
		int x = getX(i);
		int y = getY(i);
		offsets[i] = new Vector2f(x, y);
		offsets[i].mul(subSize);
	}
	names = new String[perWidth * perHeight];
	
	sheets.add(this);
}
 
开发者ID:tek256,项目名称:LD38,代码行数:26,代码来源:TextureSheet.java


示例7: processFaceVertex

import org.joml.Vector2f; //导入依赖的package包/类
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList, List<Vector3f> normList,
                                      List<Integer> indicesList, float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:22,代码来源:OBJLoader.java


示例8: explode

import org.joml.Vector2f; //导入依赖的package包/类
public static void explode(GobletWorld world, float x, float y, int power, boolean restrict, List<ExplosionUnit> dst)
{
	int ix = (int) Math.floor(x);
	int iy = (int) Math.floor(y);

	ExplosionUnit root = new ExplosionUnit(ix, iy, power);
	dst.add(root);

	spreadAll(world, dst, restrict);

	float maxDist = power * power;
	Vector2f center = new Vector2f(root.x, root.y);
	for(ExplosionUnit explosion : dst)
	{
		float dist = center.distanceSquared(explosion.x, explosion.y);
		attemptFire(world, explosion.x + 0.5F, explosion.y + 0.5F, 1 - dist / maxDist);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:19,代码来源:Explosion.java


示例9: getNormalizedAnchorOffset

import org.joml.Vector2f; //导入依赖的package包/类
public static Vector2f getNormalizedAnchorOffset(Direction anchor, Vector2f dst)
{
	switch (anchor)
	{
		case EAST:
			return dst.set(1, 0.5F);
		case NORTHEAST:
			return dst.set(1, 0);
		case NORTH:
			return dst.set(0.5F, 0);
		case NORTHWEST:
			return dst.set(0, 0);
		case WEST:
			return dst.set(0, 0.5F);
		case SOUTHWEST:
			return dst.set(0, 1);
		case SOUTH:
			return dst.set(0.5F, 1);
		case SOUTHEAST:
			return dst.set(1, 1);
		case CENTER:
			return dst.set(0.5F, 0.5F);
	}

	return dst.set(0, 0);
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:27,代码来源:Gui.java


示例10: setTile

import org.joml.Vector2f; //导入依赖的package包/类
public void setTile(Tile tile, int x, int y) {
    tiles[x + y * width] = tile.getId();
    if(tile.isSolid()) {
        bounding_boxes[x + y * width] = new AABB(new Vector2f(x*2, -y*2), new Vector2f(1,1));
    }else{
        bounding_boxes[x + y * width] = null;
    }
}
 
开发者ID:nitrodragon,项目名称:lwjgl3_stuff,代码行数:9,代码来源:World.java


示例11: circleLineIntersect

import org.joml.Vector2f; //导入依赖的package包/类
public static Vector2f[] circleLineIntersect(Vector2f lineP1, Vector2f lineP2, Vector2f circleCenter, float circleRadius)
{
    // Circle-line intersection
    float x_0 = lineP1.x, y_0 = lineP1.y;
    float x_1 = lineP2.x, y_1 = lineP2.y;
    float x_c = circleCenter.x, y_c = circleCenter.y;

    float f = x_1 - x_0;
    float g = y_1 - y_0;

    float xc0 = x_c - x_0;
    float yc0 = y_c - y_0;

    float t = f * xc0 + g * yc0;

    float fg2 = f * f + g * g;

    float inRoot = (circleRadius * circleRadius + fg2 - pow2f(f * yc0 - g * xc0));
    if(inRoot < 0) { return new Vector2f[0]; }
    if(inRoot == 0)
    {
        float intersectT = t / fg2;
        Vector2f intersection = new Vector2f(intersectT * f, intersectT * g);
        if(between(lineP1, intersection, lineP2)) { return new Vector2f[] { intersection }; }
        else { return new Vector2f[0]; }
    }
    float pm = (float) Math.sqrt(inRoot);
    float intersectT1 = (t + pm) / fg2;
    float intersectT2 = (t - pm) / fg2;
    Vector2f intersect1 = new Vector2f(intersectT1 * f + x_0, intersectT1 * g + y_0);
    Vector2f intersect2 = new Vector2f(intersectT2 * f + x_0, intersectT2 * g + y_0);
    if(between(lineP1, intersect1, lineP2))
    {
        if(between(lineP1, intersect2, lineP2)) { return new Vector2f[] { intersect1, intersect2 }; }
        else { return new Vector2f[] { intersect1 }; }
    }
    else if(between(lineP1, intersect2, lineP2)) { return new Vector2f[] { intersect2 }; }
    return new Vector2f[0];
}
 
开发者ID:Team-2502,项目名称:RobotCode2018,代码行数:40,代码来源:MathUtils.java


示例12: setPlanetAndPlayer

import org.joml.Vector2f; //导入依赖的package包/类
public void setPlanetAndPlayer(Planet planet, Player player) {
	System.out.println(planet.toString());
	player.getComponent(PhysicsComponent2D.class).getBody().getTransform()
			.setTranslation(ConverterUtil.convertToPhysics2D(
					new Vector2f(0, planet.getPlanetData().getFadeRadius() * TileDefinition.TILE_SIZE)));
	planet.setAsScene(player);
}
 
开发者ID:pcfreak9000,项目名称:SpaceExplorer2D,代码行数:8,代码来源:Universe.java


示例13: getCollision

import org.joml.Vector2f; //导入依赖的package包/类
public Collision getCollision(Vector2f point) {
	Vector2f distance = point.sub(center);
	distance.x = Math.abs(distance.x);
	distance.y = Math.abs(distance.y);
	
	distance.sub(half_extent);
	
	return new Collision(distance, distance.x < 0 && distance.y < 0);
}
 
开发者ID:MarcPopescu-Pfeiffer,项目名称:2DGame,代码行数:10,代码来源:AABB.java


示例14: getColumn

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public Vector2f getColumn(int column, Vector2f dest) throws IndexOutOfBoundsException
{
	switch (column)
	{
		case 0:
			return dest.set(m00, m10);
		case 1:
			return dest.set(m01, m11);
		default:
			throw new IndexOutOfBoundsException();
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:14,代码来源:Matrix2f.java


示例15: getRow

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public Vector2f getRow(int row, Vector2f dest) throws IndexOutOfBoundsException
{
	switch(row)
	{
		case 0:
			return dest.set(m00, m01);
		case 1:
			return dest.set(m10, m11);
		default:
			throw new IndexOutOfBoundsException();
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:14,代码来源:Matrix2f.java


示例16: update

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public void update(float delta, Window window, Camera camera, World world) {
	Vector2f movement = new Vector2f();
	if (window.getInput().isKeyDown(GLFW.GLFW_KEY_A)){
		movement.add(-10 * delta, 0);
	}
	
	if (window.getInput().isKeyDown(GLFW.GLFW_KEY_D)){
		movement.add(10 * delta, 0);
	}
	
	if (window.getInput().isKeyDown(GLFW.GLFW_KEY_W)){
		movement.add(0, 10 * delta * JUMP_STRENGTH);
	}
	
	movement.add(0, -10 * delta * GRAVITATION);
	
	move(movement);
	if(movement.y > 0){
		useAnimation(ANIM_JETPACK);
	}else if (movement.x != 0){
		useAnimation(ANIM_WALK);
	}else{		
		useAnimation(ANIM_IDLE);
	}		
	camera.getPosition().lerp(transform.pos.mul(-world.getScale(), new Vector3f()), 0.2f);

	if (window.getInput().isKeyDown(GLFW.GLFW_KEY_SPACE)){
		Rocket rocket = new Rocket(1, transform);
	}

}
 
开发者ID:MarcPopescu-Pfeiffer,项目名称:2DGame,代码行数:33,代码来源:Player.java


示例17: reorderLists

import org.joml.Vector2f; //导入依赖的package包/类
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList, List<Vector3f> normList,
                                 List<Face> facesList, int instances) {

    List<Integer> indices = new ArrayList();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList, indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = Utils.listIntToArray(indices);
    Mesh mesh;
    if (instances > 1) {
        mesh = new InstancedMesh(posArr, textCoordArr, normArr, indicesArr, instances);
    } else {
        mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    }
    return mesh;
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:32,代码来源:OBJLoader.java


示例18: onInputUpdate

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public void onInputUpdate(InputContext context)
{
	//Look
	boolean mouseLocked = context.getInputEngine().getMouse().getCursorMode();

	if (mouseLocked)
	{
		//Update camera rotation
		Vector2fc mouse = new Vector2f(
				context.getRange(INPUT_LOOK_X).getMotion(),
				context.getRange(INPUT_LOOK_Y).getMotion()
		);

		float rotx = mouse.x() * this.sensitivity;
		float roty = mouse.y() * this.sensitivity;

		this.yaw += rotx;
		this.pitch += roty;
		this.pitch = MathUtil.clamp(this.pitch, -MAX_PITCH, MAX_PITCH);
	}

	if (context.getAction(INPUT_LOOK_LOCK).isPressedAndConsume())
	{
		context.getInputEngine().getMouse().setCursorMode(!mouseLocked);
	}

	//Move
	this.forward = context.getRange(INPUT_FORWARD).getRangeAndConsume();
	this.up = context.getRange(INPUT_UP).getRangeAndConsume();
	this.right = context.getRange(INPUT_RIGHT).getRangeAndConsume();

	this.sprint = context.getState(INPUT_SPRINT).isDown();
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:35,代码来源:FirstPersonCameraController.java


示例19: reorderLists

import org.joml.Vector2f; //导入依赖的package包/类
/**
 * Reorders the given lists translating them into the right format to
 * produce a new mesh out of the data.
 *
 * @param posList - List of read vertices.
 * @param textCoordList - List of read texture coordinates.
 * @param normalsList - List of read normals.
 * @param facesList - List of read faces.
 * @param instances - 
 *
 * @return
 */
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
                                 List<Vector3f> normalsList, List<Face> facesList, int instances) {

    List<Integer> indices = new ArrayList<>();

    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }

    float[] textCoordArr = new float[posList.size() * 2];
    float[] normalsArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IndexGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IndexGroup indexValue : faceVertexIndices) {
            processFaceVertex(indexValue, textCoordList, normalsList, indices, textCoordArr, normalsArr);
        }
    }

    int[] indicesArr = new int[indices.size()];
    indicesArr = indices.stream().mapToInt((Integer v) -> v).toArray();

    Mesh mesh;

    /*if (instances > 1) {
    } else {
        mesh = new Mesh(posArr, textCoordArr, normalsArr, indicesArr);
    }*/


    mesh = new Mesh(posArr, textCoordArr, normalsArr, indicesArr);
    return mesh;
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:51,代码来源:OBJLoader.java


示例20: Update

import org.joml.Vector2f; //导入依赖的package包/类
@Override
public void Update(long delta){
	if(!listener.getPosition().equals(transform.getPosition())){
		listener.setPosition(transform.getPosition());
	}
	
	double adjustedDelta = delta / 1000d; //1s / delta time
	
	float mx = 0, my = 0;
	if(Keyboard.isDown('a')){
		mx = -1;
	}else if(Keyboard.isDown('d')){
		mx = 1;
	}
	
	if(Keyboard.isDown('w')){
		my = 1;
	}else if(Keyboard.isDown('s')){
		my = -1;
	}
	
	if(Keyboard.isClicked(Keyboard.KEY_SPACE)){
		playAnimation();
	}
	
	Vector2f pos = transform.getPosition();
	
	//transform.move((float)(mx * movespeed * adjustedDelta),(float)(my * movespeed * adjustedDelta));
}
 
开发者ID:tek256,项目名称:LD38,代码行数:30,代码来源:TestPlayer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Assertion类代码示例发布时间:2022-05-21
下一篇:
Java CellSet类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap