Refine search
/** Return center point's rectangle * @param point0 * @param point1 * @param point2 * @return the center point */ private static Vector3 centerPoint (Vector3 point0, Vector3 point1, Vector3 point2) { tmpV0.set(point1).sub(point0).scl(0.5f); tmpV1.set(point0).add(tmpV0); tmpV0.set(point2).sub(point1).scl(0.5f); return tmpV1.add(tmpV0); } }
/** Returns whether the given line segment intersects the given circle. * @param start The start point of the line segment * @param end The end point of the line segment * @param center The center of the circle * @param squareRadius The squared radius of the circle * @return Whether the line segment and the circle intersect */ public static boolean intersectSegmentCircle (Vector2 start, Vector2 end, Vector2 center, float squareRadius) { tmp.set(end.x - start.x, end.y - start.y, 0); tmp1.set(center.x - start.x, center.y - start.y, 0); float l = tmp.len(); float u = tmp1.dot(tmp.nor()); if (u <= 0) { tmp2.set(start.x, start.y, 0); } else if (u >= l) { tmp2.set(end.x, end.y, 0); } else { tmp3.set(tmp.scl(u)); // remember tmp is already normalized tmp2.set(tmp3.x + start.x, tmp3.y + start.y, 0); } float x = center.x - tmp2.x; float y = center.y - tmp2.y; return x * x + y * y <= squareRadius; }
/** Sets the plane normal and distance to the origin based on the three given points which are considered to be on the plane. * The normal is calculated via a cross product between (point1-point2)x(point2-point3) * * @param point1 * @param point2 * @param point3 */ public void set (Vector3 point1, Vector3 point2, Vector3 point3) { normal.set(point1).sub(point2).crs(point2.x-point3.x, point2.y-point3.y, point2.z-point3.z).nor(); d = -point1.dot(normal); }
/** Multiplies the ray by the given matrix. Use this to transform a ray into another coordinate system. * * @param matrix The matrix * @return This ray for chaining. */ public Ray mul (Matrix4 matrix) { tmp.set(origin).add(direction); tmp.mul(matrix); origin.mul(matrix); direction.set(tmp.sub(origin)); return this; }
/** Averages the given transforms and stores the result in this matrix. Translations and scales are lerped while rotations are * slerped. Does not destroy the data contained in t. * @param t List of transforms * @return This matrix for chaining */ public Matrix4 avg (Matrix4[] t) { final float w = 1.0f / t.length; tmpVec.set(t[0].getScale(tmpUp).scl(w)); quat.set(t[0].getRotation(quat2).exp(w)); tmpForward.set(t[0].getTranslation(tmpUp).scl(w)); for (int i = 1; i < t.length; i++) { tmpVec.add(t[i].getScale(tmpUp).scl(w)); quat.mul(t[i].getRotation(quat2).exp(w)); tmpForward.add(t[i].getTranslation(tmpUp).scl(w)); } quat.nor(); setToScaling(tmpVec); rotate(quat); setTranslation(tmpForward); return this; }
/** Sets the rotation of this decal based on the (normalized) direction and up vector. * @param dir the direction vector * @param up the up vector */ public void setRotation (Vector3 dir, Vector3 up) { tmp.set(up).crs(dir).nor(); tmp2.set(dir).crs(tmp).nor(); rotation.setFromAxes(tmp.x, tmp2.x, dir.x, tmp.y, tmp2.y, dir.y, tmp.z, tmp2.z, dir.z); updated = false; }
@Override public boolean touchDown (int screenX, int screenY, int pointer, int button) { boolean result = false; if (button == Buttons.LEFT) { Ray ray = camera.getPickRay(screenX, screenY); tmpV1.set(ray.direction).scl(10f).add(ray.origin); ClosestRayResultCallback cb = new ClosestRayResultCallback(ray.origin, tmpV1); world.collisionWorld.rayTest(ray.origin, tmpV1, cb); if (cb.hasHit()) { btRigidBody body = (btRigidBody)(cb.getCollisionObject()); if (body != null && !body.isStaticObject() && !body.isKinematicObject()) { pickedBody = body; body.setActivationState(Collision.DISABLE_DEACTIVATION); cb.getHitPointWorld(tmpV); tmpV.mul(body.getCenterOfMassTransform().inv()); pickConstraint = new btPoint2PointConstraint(body, tmpV); btConstraintSetting setting = pickConstraint.getSetting(); setting.setImpulseClamp(30f); setting.setTau(0.001f); pickConstraint.setSetting(setting); ((btDynamicsWorld)world.collisionWorld).addConstraint(pickConstraint); pickDistance = tmpV1.sub(camera.position).len(); result = true; } } cb.dispose(); } return result ? result : super.touchDown(screenX, screenY, pointer, button); }
/** Returns the endpoint given the distance. This is calculated as startpoint + distance * direction. * @param out The vector to set to the result * @param distance The distance from the end point to the start point. * @return The out param */ public Vector3 getEndPoint (final Vector3 out, final float distance) { return out.set(direction).scl(distance).add(origin); }
/** Averages the given transform with this one and stores the result in this matrix. Translations and scales are lerped while * rotations are slerped. * @param other The other transform * @param w Weight of this transform; weight of the other transform is (1 - w) * @return This matrix for chaining */ public Matrix4 avg (Matrix4 other, float w) { getScale(tmpVec); other.getScale(tmpForward); getRotation(quat); other.getRotation(quat2); getTranslation(tmpUp); other.getTranslation(right); setToScaling(tmpVec.scl(w).add(tmpForward.scl(1 - w))); rotate(quat.slerp(quat2, 1 - w)); setTranslation(tmpUp.scl(w).add(right.scl(1 - w))); return this; }
public Matrix4 calculateParallaxMatrix (float parallaxX, float parallaxY) { update(); tmp.set(position); tmp.x *= parallaxX; tmp.y *= parallaxY; parallaxView.setToLookAt(tmp, tmp2.set(tmp).add(direction), up); parallaxCombined.set(projection); Matrix4.mul(parallaxCombined.val, parallaxView.val); return parallaxCombined; } }
/** Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then * recalculating the up vector via a cross product between right and direction. */ public void normalizeUp () { tmpVec.set(direction).crs(up).nor(); up.set(tmpVec).crs(direction).nor(); }
private Vector3 getTranslation (Matrix4 worldTransform, Vector3 center, Vector3 output) { if (center.isZero()) worldTransform.getTranslation(output); else if (!worldTransform.hasRotationOrScaling()) worldTransform.getTranslation(output).add(center); else output.set(center).mul(worldTransform); return output; }
/** Sets this matrix to a look at matrix with the given position, target and up vector. * * @param position the position * @param target the target * @param up the up vector * @return This matrix */ public Matrix4 setToLookAt (Vector3 position, Vector3 target, Vector3 up) { tmpVec.set(target).sub(position); setToLookAt(tmpVec, up); this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z)); return this; }
@Override protected void onLoaded () { super.onLoaded(); BoundingBox bounds = instances.get(0).calculateBoundingBox(new BoundingBox()); bounds.getCenter(center); radius = bounds.getDimensions(tmpV).len() * .5f; pointLight.position.set(0, radius, 0).add(transformedCenter.set(center).mul(transform)); pointLight.intensity = radius * radius; ((ColorAttribute)pLight.material.get(ColorAttribute.Diffuse)).color.set(pointLight.color); final float s = 0.2f * radius; pLight.worldTransform.setToScaling(s, s, s); }
@Override public boolean touchDragged (int screenX, int screenY, int pointer) { float deltaX = -Gdx.input.getDeltaX() * degreesPerPixel; float deltaY = -Gdx.input.getDeltaY() * degreesPerPixel; camera.direction.rotate(camera.up, deltaX); tmp.set(camera.direction).crs(camera.up).nor(); camera.direction.rotate(tmp, deltaY); // camera.up.rotate(tmp, deltaY); return true; }
public Vector3 getPositionAt (Vector3 out, int x, int y) { final float dx = (float)x / (float)(width - 1); final float dy = (float)y / (float)(height - 1); final float a = data[y * width + x]; out.set(corner00).lerp(corner10, dx).lerp(tmpV1.set(corner01).lerp(corner11, dx), dy); out.add(tmpV1.set(magnitude).scl(a)); return out; }
@Override public boolean touchDragged (int x, int y, int pointer) { camera.unproject(curr.set(x, y, 0)); if (!(last.x == -1 && last.y == -1 && last.z == -1)) { camera.unproject(delta.set(last.x, last.y, 0)); delta.sub(curr); camera.position.add(delta.x, delta.y, 0); } last.set(x, y, 0); return false; }