當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector2.nor方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.math.Vector2.nor方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.nor方法的具體用法?Java Vector2.nor怎麽用?Java Vector2.nor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.math.Vector2的用法示例。


在下文中一共展示了Vector2.nor方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMouseInput

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@NotNull
private Vector2 getMouseInput() {
	if(Gdx.input.isTouched()) {
		
		Vector2 mousePos = new Vector2(Gdx.input.getX(), Gdx.input.getY());
		mousePos.y = uiCamera.viewportHeight - mousePos.y; // origin is top left corner, so reverse Y dir
		
		Vector2 playerPos = mainPlayer.getBounds().getCenter(new Vector2());
		
		// Note: the camera pos is in the center of the screen.
		
		Vector3 playerScreenPos = camera.project(new Vector3(playerPos, 0));
		
		Vector2 mouseMove = new Vector2();
		mouseMove.x = mousePos.x - playerScreenPos.x;
		mouseMove.y = mousePos.y - playerScreenPos.y;
		//mouseMove.y -= GameCore.getGameScreen().getScreenHeight()/2;
		mouseMove.nor();
		
		return mouseMove;
	}
	
	return new Vector2();
}
 
開發者ID:chrisj42,項目名稱:miniventure,代碼行數:25,代碼來源:GameScreen.java

示例2: testSegment

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public boolean testSegment(RaycastResult out, Segment segment, float maxLambda) {
		Vector2 s = segment.p1;
		Vector2 r = tlR.get().set(segment.p2);
//		r.subLocal(s);
		r.sub(s);
		Vector2 d = tlD.get().set(p2);
//		d.subLocal(p1);
		d.sub(p1);
		Vector2 n = tlN.get();
		V2.crossToOut(d, 1.0f, n);
		Vector2 b = tlB.get();

		float k_slop = 100.0f * Settings.EPSILON;
		float denom = -V2.dot(r, n);

		// Cull back facing collision and ignore parallel segments.
		if (denom > k_slop){
			
			// Does the segment intersect the infinite line associated with this segment?
			b.set(s);
			b.sub(p1);
			float a = V2.dot(b, n);

			if (0.0f <= a && a <= maxLambda * denom){
				float mu2 = -r.x * b.y + r.y * b.x;

				// Does the segment intersect this segment?
				if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0f + k_slop)){
					a /= denom;
//					n.normalize();
					n.nor();
					out.lambda = a;
					out.normal.set(n);
					return true;
				}
			}
		}
		return false;
	}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:40,代碼來源:Segment.java

示例3: findCollision

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public boolean findCollision(Collision<Vector2> collision, Ray<Vector2> ray){
	Vector2 v = vectorCast(ray.start.x, ray.start.y, ray.end.x, ray.end.y);
	if(v == null) return false;
	collision.point = v;
	collision.normal = v.nor();
	return true;
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:9,代碼來源:Raycaster.java

示例4: faceEnemy

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void faceEnemy() {
Vector2 direction = new Vector2(getX() + 16 - target.getX()
	- Monster.REGION_WIDTH / 2f, getY() + 16 - target.getY()
	- Monster.REGION_HEIGHT / 2f);
direction.nor();

setRotation((float) Math.toDegrees(Math
	.atan2(-direction.x, direction.y)));
   }
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:10,代碼來源:Weapon.java

示例5: projectSegment

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public Range projectSegment(Vector2 onto) {
    // create new range or use an recycled range
    Range range = RangePool.create();

    // normailize vector
    onto.nor();

    // calculate min and max value with dot product
    float min = onto.dot(point1);
    float max = onto.dot(point2);
    range.set(min, max);

    return range;
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:15,代碼來源:Segment.java

示例6: checkInput

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void checkInput(float delta, @NotNull Vector2 mouseInput) {
	// checks for keyboard input to move the player.
	// getDeltaTime() returns the time passed between the last and the current frame in seconds.
	int speed = Tile.SIZE * 5; // this is technically in units/second.
	Vector2 movement = new Vector2();
	if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) movement.x--;
	if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) movement.x++;
	if(Gdx.input.isKeyPressed(Input.Keys.UP)) movement.y++;
	if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) movement.y--;
	
	movement.nor();
	
	movement.add(mouseInput);
	movement.nor();
	
	movement.scl(speed * delta);
	
	move(movement.x, movement.y);
	
	if(pressingKey(Input.Keys.Q)) cycleHeldItem(false);
	if(pressingKey(Input.Keys.E)) cycleHeldItem(true);
	
	if(pressingKey(Input.Keys.C))
		attack();
	else if(pressingKey(Input.Keys.V))
		interact();
	
	heldItem = heldItem == null ? null : heldItem.consume();
}
 
開發者ID:chrisj42,項目名稱:miniventure,代碼行數:30,代碼來源:Player.java


注:本文中的com.badlogic.gdx.math.Vector2.nor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。