public Vector2f getUV(int x, int y, Vector2f store, Vector2f offset, float offsetAmount, int totalSize) { float offsetX = offset.x + (offsetAmount * 1.0f); float offsetY = -offset.y + (offsetAmount * 1.0f);//note the -, we flip the tex coords store.set((((float) x) + offsetX) / (float) (totalSize - 1), // calculates percentage of texture here (((float) y) + offsetY) / (float) (totalSize - 1)); return store; }
/** * Set the distance from the eye where the shadows will be rendered default * value is dynamically computed to the shadow casters/receivers union bound * zFar, capped to view frustum far value. * * @param zFar the zFar values that override the computed one */ public void setShadowZExtend(float zFar) { if (fadeInfo != null) { fadeInfo.set(zFar - fadeLength, 1f / fadeLength); } this.zFarOverride = zFar; }
/** * Flips UV coordinates. * @param u * indicates if U coords should be flipped * @param v * indicates if V coords should be flipped */ public void flipUV(boolean u, boolean v) { if (faceUVCoords != null) { for (Entry<String, List<Vector2f>> entry : faceUVCoords.entrySet()) { for (Vector2f uv : entry.getValue()) { uv.set(u ? 1 - uv.x : uv.x, v ? 1 - uv.y : uv.y); } } } }
/** * Callback from RawInputListener. Do not use. */ @Override public void onMouseButtonEvent(MouseButtonEvent evt) { if (!eventsPermitted) { throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time."); } //updating cursor pos on click, so that non android touch events can properly update cursor position. cursorPos.set(evt.getX(), evt.getY()); inputQueue.add(evt); }
/** * Callback from RawInputListener. Do not use. */ @Override public void onTouchEvent(TouchEvent evt) { if (!eventsPermitted) { throw new UnsupportedOperationException("TouchInput has raised an event at an illegal time."); } cursorPos.set(evt.getX(), evt.getY()); inputQueue.add(evt); } }
/** * Set the distance from the eye where the shadows will be rendered default * value is dynamically computed to the shadow casters/receivers union bound * zFar, capped to view frustum far value. * * @param zFar the zFar values that override the computed one */ public void setShadowZExtend(float zFar) { this.zFarOverride = zFar; if(zFarOverride == 0){ fadeInfo = null; frustumCam = null; }else{ if (fadeInfo != null) { fadeInfo.set(zFarOverride - fadeLength, 1f / fadeLength); } if(frustumCam == null && viewPort != null){ initFrustumCam(); } } }
/** * Set the distance from the eye where the shadows will be rendered default * value is dynamically computed to the shadow casters/receivers union bound * zFar, capped to view frustum far value. * * @param zFar the zFar values that override the computed one */ public void setShadowZExtend(float zFar) { this.zFarOverride = zFar; if(zFarOverride == 0){ fadeInfo = null; frustumCam = null; }else{ if (fadeInfo != null) { fadeInfo.set(zFarOverride - fadeLength, 1f / fadeLength); } if(frustumCam == null && viewPort != null){ initFrustumCam(); } } }
public Vector2f getTex(float x, float z, Vector2f store) { if (x < 0 || z < 0 || x >= size || z >= size) { store.set(Vector2f.ZERO); return store; } int idx = (int) (z * size + x); return store.set(getMesh().getFloatBuffer(Type.TexCoord).get(idx*2), getMesh().getFloatBuffer(Type.TexCoord).get(idx*2+1) ); }
@Override public Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis) { int axisIndex = forAxis.getValue(); temp2Axis.set(lastCallAxis[axisIndex]); lastCallAxis[axisIndex].set(getAxis(controllerIndex, forAxis)); if( (temp2Axis.x != 0f || temp2Axis.y != 0f) && (lastCallAxis[axisIndex].x != 0f || lastCallAxis[axisIndex].y != 0f) ) { temp2Axis.subtractLocal(lastCallAxis[axisIndex]); } else { // move made from rest, don't count as a delta move temp2Axis.x = 0f; temp2Axis.y = 0f; } return temp2Axis; }
@Override public Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis) { int axisIndex = forAxis.getValue(); temp2Axis.set(lastCallAxis[axisIndex]); lastCallAxis[axisIndex].set(getAxis(controllerIndex, forAxis)); if ((temp2Axis.x != 0f || temp2Axis.y != 0f) && (lastCallAxis[axisIndex].x != 0f || lastCallAxis[axisIndex].y != 0f)) { temp2Axis.subtractLocal(lastCallAxis[axisIndex]); } else { // move made from rest, don't count as a delta move temp2Axis.x = 0f; temp2Axis.y = 0f; } return temp2Axis; }
@Override public Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis) { int axisIndex = forAxis.getValue(); temp2Axis.set(lastCallAxis[axisIndex]); lastCallAxis[axisIndex].set(getAxis(controllerIndex, forAxis)); if( (temp2Axis.x != 0f || temp2Axis.y != 0f) && (lastCallAxis[axisIndex].x != 0f || lastCallAxis[axisIndex].y != 0f) ) { temp2Axis.subtractLocal(lastCallAxis[axisIndex]); } else { // move made from rest, don't count as a delta move temp2Axis.x = 0f; temp2Axis.y = 0f; } return temp2Axis; }
public Vector2f getUV(int x, int y, Vector2f store){ store.set( (float)x / (float)getWidth(), (float)y / (float)getHeight() ); return store; }
/** * Callback from RawInputListener. Do not use. * * @param evt event to add to the input queue (not null) */ @Override public void onMouseMotionEvent(MouseMotionEvent evt) { /* * If events aren't allowed, the event may be a "first mouse event" * triggered by the constructor setting the mouse listener. * In that case, use the event to initialize the cursor position, * but don't queue it for further processing. * This is part of the fix for issue #792. */ cursorPos.set(evt.getX(), evt.getY()); if (eventsPermitted) { inputQueue.add(evt); } }
/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ public Vector2f getWayPointIndexForDistance(float distance, Vector2f store) { float sum = 0; if(spline.getTotalLength() == 0){ store.set(0, 0); return store; } distance = distance % spline.getTotalLength(); int i = 0; for (Float len : spline.getSegmentsLength()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }
public void actionMove(int pointerId, long time, float x, float y) { float jmeX = iosInput.getJmeX(x); float jmeY = iosInput.invertY(iosInput.getJmeY(y)); Vector2f lastPos = lastPositions.get(pointerId); if (lastPos == null) { lastPos = new Vector2f(jmeX, jmeY); lastPositions.put(pointerId, lastPos); } float dX = jmeX - lastPos.x; float dY = jmeY - lastPos.y; if (dX != 0 || dY != 0) { TouchEvent touch = iosInput.getFreeTouchEvent(); touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY); touch.setPointerId(pointerId); touch.setTime(time); touch.setPressure(1.0f); //touch.setPressure(event.getPressure(p)); lastPos.set(jmeX, jmeY); processEvent(touch); } }
/** * Get the triangle that the point is on. * * @param x coordinate in local space to the geomap * @param z coordinate in local space to the geomap * @return triangle in local space to the geomap */ protected Triangle getTriangleAtPoint(float x, float z) { Triangle[] triangles = getGridTrianglesAtPoint(x, z); if (triangles == null) { //System.out.println("x,z: " + x + "," + z); return null; } Vector2f point = new Vector2f(x, z); Vector2f t1 = new Vector2f(triangles[0].get1().x, triangles[0].get1().z); Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z); Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[0]; } t1.set(triangles[1].get1().x, triangles[1].get1().z); t1.set(triangles[1].get2().x, triangles[1].get2().z); t1.set(triangles[1].get3().x, triangles[1].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[1]; } return null; }
case Vector2: if (this.value != null) { ((Vector2f) this.value).set(Vector2f.ZERO);
touchEvent.setTime(event.getEventTime()); touchEvent.setPressure(event.getPressure(p)); lastPos.set(jmeX, jmeY);