use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class ArcballCamera method initialize.
private void initialize() {
mStartFOV = mFieldOfView;
mLookAtEnabled = true;
setLookAt(0, 0, 0);
mEmpty = new Object3D();
mScratchMatrix = new Matrix4();
mScratchVector = new Vector3();
mCameraStartPos = new Vector3();
mPrevSphereCoord = new Vector3();
mCurrSphereCoord = new Vector3();
mPrevScreenCoord = new Vector2();
mCurrScreenCoord = new Vector2();
mStartOrientation = new Quaternion();
mCurrentOrientation = new Quaternion();
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class CatmullRomCurve3D method reparametrizeForUniformDistribution.
/**
* Creates a curve with uniformly distributed points. Please note that this might alter the shape of the curve
* slightly. The higher the resolution, the more closely it will resemble to original curve. You'd typically want to
* use this for smooth animations with constant speeds.
*
* <pre>
* <code>
* myCurve.reparametrizeForUniformDistribution(myCurve.getPoints().size() * 4);
* </code>
* </pre>
*
* @param resolution
*/
public void reparametrizeForUniformDistribution(int resolution) {
double curveLength = getLength(resolution * 100);
// -- get the length between each new point
double segmentDistance = curveLength / resolution;
double numSegments = mSegmentLengths.length;
List<Vector3> newPoints = Collections.synchronizedList(new CopyOnWriteArrayList<Vector3>());
// -- add first control point
newPoints.add(mPoints.get(0));
// -- add first point
Vector3 point = new Vector3();
calculatePoint(point, 0);
newPoints.add(point);
double currentLength = 0;
for (int i = 1; i < numSegments; i++) {
currentLength += mSegmentLengths[i];
if (currentLength >= segmentDistance) {
point = new Vector3();
calculatePoint(point, (double) i / (double) (numSegments - 1));
newPoints.add(point);
currentLength = 0;
}
}
// -- add last point
point = new Vector3();
calculatePoint(point, 1);
newPoints.add(point);
// -- add last control point
newPoints.add(mPoints.get(mPoints.size() - 1));
// -- scale control point 1
Vector3 controlPoint = Vector3.subtractAndCreate(mPoints.get(1), mPoints.get(0));
double oldDistance = mPoints.get(1).distanceTo(mPoints.get(2));
double newDistance = newPoints.get(1).distanceTo(newPoints.get(2));
controlPoint.multiply(newDistance / oldDistance);
newPoints.set(0, Vector3.subtractAndCreate(mPoints.get(1), controlPoint));
// -- scale control point 2
controlPoint = Vector3.subtractAndCreate(mPoints.get(mPoints.size() - 2), mPoints.get(mPoints.size() - 1));
oldDistance = mPoints.get(mPoints.size() - 2).distanceTo(mPoints.get(mPoints.size() - 3));
newDistance = newPoints.get(newPoints.size() - 2).distanceTo(newPoints.get(newPoints.size() - 3));
controlPoint.multiply(newDistance / oldDistance);
newPoints.set(newPoints.size() - 1, Vector3.subtractAndCreate(mPoints.get(mPoints.size() - 2), controlPoint));
mPoints = newPoints;
mNumPoints = mPoints.size();
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class SVGPath method inspectValues.
private void inspectValues(CompoundCurve3D bezierPath, String values) {
String[] vals = values.split(",");
Vector3 c, p, cp1, cp2;
if (vals.length == 0)
throw new RuntimeException("Empty values found.");
switch(mCurrentCommand) {
case MOVE_TO:
c = new Vector3(Double.parseDouble(vals[0]), -Double.parseDouble(vals[1]), 0);
p = mCurrentCommandIsRelative ? c.addAndSet(mPreviousPoint, c) : c;
break;
case VERTICAL:
c = new Vector3(0, -Double.parseDouble(vals[0]), 0);
if (mCurrentCommandIsRelative)
p = c.addAndSet(mPreviousPoint, c);
else {
c.x = mPreviousPoint.x;
p = c;
}
bezierPath.addCurve(new LinearBezierCurve3D(mPreviousPoint.clone(), p));
break;
case HORIZONTAL:
c = new Vector3(Double.parseDouble(vals[0]), 0, 0);
if (mCurrentCommandIsRelative)
p = c.addAndSet(mPreviousPoint, c);
else {
c.y = mPreviousPoint.y;
p = c;
}
bezierPath.addCurve(new LinearBezierCurve3D(mPreviousPoint.clone(), p));
break;
case CURVE_TO:
c = new Vector3(Double.parseDouble(vals[4]), -Double.parseDouble(vals[5]), 0);
p = mCurrentCommandIsRelative ? c.addAndSet(mPreviousPoint, c) : c;
cp1 = new Vector3(Double.parseDouble(vals[0]), -Double.parseDouble(vals[1]), 0);
if (mCurrentCommandIsRelative)
cp1.add(mPreviousPoint);
cp2 = new Vector3(Double.parseDouble(vals[2]), -Double.parseDouble(vals[3]), 0);
if (mCurrentCommandIsRelative)
cp2.add(mPreviousPoint);
mPreviousControlPoint.setAll(cp2);
bezierPath.addCurve(new CubicBezierCurve3D(mPreviousPoint.clone(), cp1, cp2, p));
break;
case SMOOTH_CURVE_TO:
c = new Vector3(Double.parseDouble(vals[2]), -Double.parseDouble(vals[3]), 0);
p = mCurrentCommandIsRelative ? c.addAndSet(mPreviousPoint, c) : c;
cp1 = reflect(mPreviousControlPoint, mPreviousPoint);
cp2 = new Vector3(Double.parseDouble(vals[0]), -Double.parseDouble(vals[1]), 0);
if (mCurrentCommandIsRelative)
cp2.add(mPreviousPoint);
bezierPath.addCurve(new CubicBezierCurve3D(mPreviousPoint.clone(), cp1, cp2, p));
break;
case LINE_TO:
c = new Vector3(Double.parseDouble(vals[0]), -Double.parseDouble(vals[1]), 0);
p = mCurrentCommandIsRelative ? c.addAndSet(mPreviousPoint, c) : c;
bezierPath.addCurve(new LinearBezierCurve3D(mPreviousPoint.clone(), p));
break;
default:
return;
}
if (bezierPath.getNumCurves() == 0)
mStartPoint.setAll(p);
mPreviousPoint.setAll(p);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class DebugBoundingBox method updateBoundingBox.
public void updateBoundingBox(BoundingBox boundingBox) {
if (mBBoxVertices == null) {
mBBoxVertices = new Vector3[8];
mPoints = new Stack<>();
for (int i = 0; i < 16; i++) {
mPoints.push(new Vector3());
if (i < 8)
mBBoxVertices[i] = new Vector3();
}
init(true);
getGeometry().changeBufferUsage(mGeometry.getVertexBufferInfo(), GLES20.GL_DYNAMIC_DRAW);
setMaterial(new Material());
}
updateBox(boundingBox);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class DebugCamera method updateFrustum.
public void updateFrustum() {
mCamera.setProjectionMatrix(mRenderer.getOverrideViewportWidth(), mRenderer.getOverrideViewportHeight());
if (mPoints == null) {
if (!mCamera.isInitialized()) {
return;
}
mPoints = new Stack<>();
mFrustumCornersTransformed = new Vector3[8];
for (int i = 0; i < 16; i++) {
if (i < 8)
mFrustumCornersTransformed[i] = new Vector3();
mPoints.push(new Vector3());
}
init(true);
getGeometry().changeBufferUsage(mGeometry.getVertexBufferInfo(), GLES20.GL_DYNAMIC_DRAW);
setMaterial(mMaterial);
}
mCamera.getFrustumCorners(mFrustumCornersTransformed, true, true);
FloatBuffer b = mGeometry.getVertices();
int index = 0;
addVertexToBuffer(b, index++, mFrustumCornersTransformed[0]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[1]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[2]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[3]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[0]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[4]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[5]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[1]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[5]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[6]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[2]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[6]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[7]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[3]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[7]);
addVertexToBuffer(b, index++, mFrustumCornersTransformed[4]);
mGeometry.changeBufferData(mGeometry.getVertexBufferInfo(), mGeometry.getVertices(), 0);
}
Aggregations