public void input() { float sensitivity = 0.5f; float movAmt = (float) (10 * Time.getDelta()); // float rotAmt = (float)(100 * Time.getDelta()); if (Input.getKey(GLFW.GLFW_KEY_ESCAPE)) { Input.showCursor(true); mouseLocked = false; } if (Input.getMouseDown(0)) { Input.setMousePosition(Window.getCenterPoint()); Input.showCursor(false); mouseLocked = true; } if (Input.getKey(GLFW.GLFW_KEY_W)) move(getForward(), movAmt); if (Input.getKey(GLFW.GLFW_KEY_S)) move(getForward(), -movAmt); if (Input.getKey(GLFW.GLFW_KEY_A)) move(getLeft(), movAmt); if (Input.getKey(GLFW.GLFW_KEY_D)) move(getRight(), movAmt); if (mouseLocked) { Vector2f deltaPos = Input.getMousePosition().sub(Window.getCenterPoint()); boolean rotY = deltaPos.getX() != 0; boolean rotX = deltaPos.getY() != 0; if (rotY) rotateY(deltaPos.getX() * sensitivity); if (rotX) rotateX(-deltaPos.getY() * sensitivity); if (rotY || rotX) Input.setMousePosition(new Vector2f(Window.getWidth() / 2, Window.getHeight() / 2)); } }
/** * Transform a Vector by a matrix and return the result in a destination vector. * * @param left The left matrix * @param right The right vector * @param dest The destination vector, or null if a new one is to be created * @return the destination vector */ public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) { if (dest == null) dest = new Vector2f(); float x = left.m00 * right.x + left.m10 * right.y; float y = left.m01 * right.x + left.m11 * right.y; dest.x = x; dest.y = y; return dest; }
@Override public TbtQuad clone() { TbtQuad result = (TbtQuad) super.deepClone(); result.size = size.clone(); result.imageSize = imageSize.clone(); result.horzFolds = horzFolds.clone(); result.vertFolds = vertFolds.clone(); result.horzTexCoords = horzTexCoords.clone(); result.vertTexCoords = vertTexCoords.clone(); return result; }
public Cameor2D(GLGraphics glGraphics, float frumHeigh, float frumWidth) { this.FrumHeigh = frumHeigh; this.FrumWidth = frumWidth; glGraphics = this.glGraphics; postion.setVector2f(frumWidth / 2, frumHeigh / 2); this.zoom = 1; }
public void updateSize(float width, float height) { if (size.x == width && size.y == height) return; // Put back the size adjustment we made in the first place horzFolds[1] -= size.x - imageSize.x; vertFolds[1] -= size.y - imageSize.y; size.set(width, height); // Adjust the middle fold for the new size horzFolds[1] += size.x - imageSize.x; vertFolds[1] += size.y - imageSize.y; refreshGeometry(); }
public Vector2f div(Vector2f v) { return new Vector2f(this.x / v.getX(), this.y / v.getY()); }
public Vector2f mult(Vector2f v) { return new Vector2f(this.x * v.getX(), this.y * v.getY()); }
public Vector2f sub(Vector2f v) { return new Vector2f(this.x - v.getX(), this.y - v.getY()); }
public Vector2f add(Vector2f v) { return new Vector2f(this.x + v.getX(), this.y + v.getY()); }
public float dot(Vector2f v) { return (v.getX() * this.x + v.getY() * this.x); }
/** * Multiplies this matrix with the vector and returns the resulting vector. * * @param v The vector to multiply this matrix with from the right hand side. * @return The result of the multiplication. */ public Vector2f multiply(Vector2f v) { float x = m00 * v.x() + m01 * v.y(); float y = m10 * v.x() + m11 * v.y(); return new Vector2f(x, y); }
public Vector2f add(Vector2f r) { return new Vector2f(x + r.getX(), y + r.getY()); }
/** * Translates this matrix with the specified vector. * * @param vec2 - the vector to translate with * @return this matrix instance */ public Matrix4f translate(Vector2f vec2) { return translate(new Vector3f(vec2.getX(), vec2.getY(), 0)); }
/** * Scales this matrix with the specified vector. * * @param scale - the vector to scale with * @return this matrix instance */ public Matrix4f scale(Vector2f scale) { matrix[0 + 0 * 4] *= scale.getX(); matrix[1 + 1 * 4] *= scale.getY(); return this; }
public Vector2f div(Vector2f r) { return new Vector2f(x / r.getX(), y / r.getY()); }
public Vector2f mul(Vector2f r) { return new Vector2f(x * r.getX(), y * r.getY()); }
public Vector2f sub(Vector2f r) { return new Vector2f(x - r.getX(), y - r.getY()); }
public static void setMousePosition(Vector2f pos) { Mouse.setCursorPosition((int) pos.getX(), (int) pos.getY()); }
/** * 将触摸屏幕的点转换为当前视图下的坐标 * * @param touch */ public void touchToWorld(Vector2f touch) { touch.x = (touch.x / glGraphics.getWidth()) * FrumWidth * zoom; touch.y = (touch.y / glGraphics.getHeight()) * FrumHeigh * zoom; // 在当前坐标系下的坐标 touch.add(postion).sub(FrumWidth * zoom / 2, FrumHeigh * zoom / 2); }
public float dot(Vector2f r) { return x * r.getX() + y * r.getY(); }