本文整理汇总了Java中org.rajawali3d.math.vector.Vector3.subtractAndCreate方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3.subtractAndCreate方法的具体用法?Java Vector3.subtractAndCreate怎么用?Java Vector3.subtractAndCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rajawali3d.math.vector.Vector3
的用法示例。
在下文中一共展示了Vector3.subtractAndCreate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersectRayPlane
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
/**
* Intersects a ray defined by a start and end point and a {@link Plane}.
* @param rayStart Startpoint of the ray
* @param rayEnd Endpoint of the ray
* @param plane The plane
* @param hitPoint The intersection point (optional)
* @return True if there is an intersection, false otherwise.
*/
public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) {
Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart);
double denorm = rayDir.dot(plane.getNormal());
if (denorm != 0) {
double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm;
if (t < 0) return false;
if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t));
return true;
} else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) {
if (hitPoint != null) hitPoint.setAll(rayStart);
return true;
} else {
return false;
}
}
示例2: ASpiral3D
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
/**
* Constructs a {@link ArchimedeanSpiral3D} with the specified parameters.
*
* @param density {@code double} Factor which determines how tightly the spiral is curled.
* @param start {@link Vector3} The point where the spiral should start from.
* @param normal {@link Vector3} The normal vector of the plane the spiral is in. This is assumed to be
* orthogonal to the vector formed from the start to the origin.
* @param spiralIn {@code boolean} True if the spiral should move from the staring point in. False to move from starting point out.
*/
public ASpiral3D(double density, Vector3 start, Vector3 normal, boolean spiralIn) {
// Store the provided initial conditions
mSpiralIn = spiralIn;
mDensity = density;
mStart = Vector3.subtractAndCreate(start, Vector3.ZERO);
mUp = normal.clone();
// Calculate the remaining conditions
mCalculateTangents = false;
// Create the initial tangent vector
mCurrentTangent = Vector3.crossAndCreate(mStart, mUp);
// The initial rotation is 0 radians about the up axis
mRotation = new Quaternion(mUp, 0);
}
示例3: createLightViewProjectionMatrix
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
private Matrix4 createLightViewProjectionMatrix(DirectionalLight light) {
//
// -- Get the frustum corners in world space
//
mCamera.getFrustumCorners(mFrustumCorners, true);
//
// -- Get the frustum centroid
//
mFrustumCentroid.setAll(0, 0, 0);
for(int i=0; i<8; i++)
mFrustumCentroid.add(mFrustumCorners[i]);
mFrustumCentroid.divide(8.0);
//
// --
//
BoundingBox lightBox = new BoundingBox(mFrustumCorners);
double distance = mFrustumCentroid.distanceTo(lightBox.getMin());
Vector3 lightDirection = light.getDirectionVector().clone();
lightDirection.normalize();
Vector3 lightPosition = Vector3.subtractAndCreate(mFrustumCentroid, Vector3.multiplyAndCreate(lightDirection, distance));
//
// --
//
mLightViewMatrix.setToLookAt(lightPosition, mFrustumCentroid, Vector3.Y);
for(int i=0; i<8; i++)
mFrustumCorners[i].multiply(mLightViewMatrix);
BoundingBox b = new BoundingBox(mFrustumCorners);
mLightProjectionMatrix.setToOrthographic(b.getMin().x, b.getMax().x, b.getMin().y, b.getMax().y, -b.getMax().z, -b.getMin().z);
mLightModelViewProjectionMatrix.setAll(mLightProjectionMatrix);
mLightModelViewProjectionMatrix.multiply(mLightViewMatrix);
return mLightModelViewProjectionMatrix;
}
示例4: applyTransformation
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
@Override
protected void applyTransformation() {
if (mDiffPosition == null)
mDiffPosition = Vector3.subtractAndCreate(mToPosition, mFromPosition);
mMultipliedPosition.scaleAndSet(mDiffPosition, mInterpolatedTime);
mAddedPosition.addAndSet(mFromPosition, mMultipliedPosition);
mTransformable3D.setPosition(mAddedPosition);
}
示例5: applyTransformation
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
@Override
protected void applyTransformation() {
if (mDiffScale == null)
mDiffScale = Vector3.subtractAndCreate(mToScale, mFromScale);
mMultipliedScale.scaleAndSet(mDiffScale, mInterpolatedTime);
mAddedScale.addAndSet(mFromScale, mMultipliedScale);
mTransformable3D.setScale(mAddedScale);
}
示例6: calculateFaceNormal
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
private Vector3 calculateFaceNormal(int[] vertexIDs) {
ArrayList<Vector3> vertices = mVertices.get(mObjects);
Vector3 v1 = vertices.get(vertexIDs[0]);
Vector3 v2 = vertices.get(vertexIDs[2]);
Vector3 v3 = vertices.get(vertexIDs[1]);
Vector3 vector1 = Vector3.subtractAndCreate(v2, v1);
Vector3 vector2 = Vector3.subtractAndCreate(v3, v1);
Vector3 normal = Vector3.crossAndCreate(vector1, vector2);
normal.normalize();
return normal;
}
示例7: calculateChildSideLengths
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
/**
* Calculates the side lengths that child nodes
* of this node should have.
*/
protected void calculateChildSideLengths() {
//Determine the distance on each axis
Vector3 temp = Vector3.subtractAndCreate(mTransformedMax, mTransformedMin);
temp.multiply(0.5f); //Divide it in half
float overlap = 1.0f + mOverlap/100.0f;
temp.multiply(overlap);
temp.absoluteValue();
mChildLengths.setAll(temp);
}
示例8: intersectRayTriangle
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
/**
* Intersects a ray defined by a start and end point and a triangle.
* @param rayStart Startpoint of the ray
* @param rayEnd Endpoint of the ray
* @param t1 The first vertex of the triangle
* @param t2 The second vertex of the triangle
* @param t3 The third vertex of the triangle
* @param hitPoint The intersection point (optional)
* @return True if there is an intersection, false otherwise.
*/
public static boolean intersectRayTriangle(Vector3 rayStart, Vector3 rayEnd, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 hitPoint) {
Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart);
rayDir.normalize();
p.set(t1, t2, t3);
if (!intersectRayPlane(rayStart, rayEnd, p, i)) return false;
v0.subtractAndSet(t3, t1);
v1.subtractAndSet(t2, t1);
v2.subtractAndSet(i, t1);
double dot00 = v0.dot(v0);
double dot01 = v0.dot(v1);
double dot02 = v0.dot(v2);
double dot11 = v1.dot(v1);
double dot12 = v1.dot(v2);
double denom = dot00 * dot11 - dot01 * dot01;
if (denom == 0) return false;
double u = (dot11 * dot02 - dot01 * dot12) / denom;
double v = (dot00 * dot12 - dot01 * dot02) / denom;
if (u >= 0 && v >= 0 && u + v <= 1) {
if (hitPoint != null) hitPoint.setAll(i);
return true;
} else
return false;
}
示例9: createLightViewProjectionMatrix
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
private Matrix4 createLightViewProjectionMatrix(DirectionalLight light) {
//
// -- Get the frustum corners in world space
//
mCamera.getFrustumCorners(mFrustumCorners, true);
//
// -- Get the frustum centroid
//
mFrustumCentroid.setAll(0, 0, 0);
for(int i=0; i<8; i++)
mFrustumCentroid.add(mFrustumCorners[i]);
mFrustumCentroid.divide(8.0);
//
// --
//
BoundingBox lightBox = new BoundingBox(mFrustumCorners);
double distance = mFrustumCentroid.distanceTo(lightBox.getMin());
Vector3 lightDirection = light.getDirectionVector().clone();
lightDirection.normalize();
Vector3 lightPosition = Vector3.subtractAndCreate(mFrustumCentroid, Vector3.multiplyAndCreate(lightDirection, distance));
//
// --
//
mLightViewMatrix.setToLookAt(lightPosition, mFrustumCentroid, Vector3.Y);
for(int i=0; i<8; i++)
mFrustumCorners[i].multiply(mLightViewMatrix);
BoundingBox b = new BoundingBox(mFrustumCorners);
mLightProjectionMatrix.setToOrthographic(b.getMin().x, b.getMax().x, b.getMin().y, b.getMax().y, -b.getMax().z, -b.getMin().z);
mLightModelViewProjectionMatrix.setAll(mLightProjectionMatrix);
mLightModelViewProjectionMatrix.multiply(mLightViewMatrix);
return mLightModelViewProjectionMatrix;
}
示例10: calculateNormals
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
public float[] calculateNormals(int[] indices) {
float[] vertices = new float[mGeometry.getVertices().capacity()];
mGeometry.getVertices().get(vertices).position(0);
float[] faceNormals = new float[indices.length];
float[] vertNormals = new float[vertices.length];
int numIndices = indices.length;
int numVertices = vertices.length;
int id1, id2, id3, vid1, vid2, vid3;
Vector3 v1 = new Vector3();
Vector3 v2 = new Vector3();
Vector3 v3 = new Vector3();
Vector3 normal = new Vector3();
// -- calculate face normals
for(int i=0; i<numIndices; i+=3) {
id1 = indices[i];
id2 = indices[i+1];
id3 = indices[i+2];
vid1 = id1 * 3;
vid2 = id2 * 3;
vid3 = id3 * 3;
v1.setAll(vertices[vid1], vertices[vid1+1], vertices[vid1+2]);
v2.setAll(vertices[vid2], vertices[vid2+1], vertices[vid2+2]);
v3.setAll(vertices[vid3], vertices[vid3+1], vertices[vid3+2]);
Vector3 vector1 = Vector3.subtractAndCreate(v2, v1);
Vector3 vector2 = Vector3.subtractAndCreate(v3, v1);
normal = Vector3.crossAndCreate(vector1, vector2);
normal.normalize();
faceNormals[i] = (float) normal.x;
faceNormals[i+1] = (float) normal.y;
faceNormals[i+2] = (float) normal.z;
}
// -- calculate vertex normals
Vector3 vertexNormal = new Vector3();
for(int i=0; i<numVertices; i+=3) {
int vIndex = i / 3;
vertexNormal.setAll(0, 0, 0);
for(int j=0; j<numIndices; j+=3)
{
id1 = indices[j];
id2 = indices[j+1];
id3 = indices[j+2];
if(id1 == vIndex || id2 == vIndex || id3 == vIndex) {
vertexNormal.add(faceNormals[j], faceNormals[j+1], faceNormals[j+2]);
}
}
vertexNormal.normalize();
vertNormals[i] = (float) vertexNormal.x;
vertNormals[i+1] = (float) vertexNormal.y;
vertNormals[i+2] = (float) vertexNormal.z;
}
//mGeometry.setNormals(vertNormals);
faceNormals = null;
v1 = null;
v2 = null;
v3 = null;
return vertNormals;
}
示例11: grow
import org.rajawali3d.math.vector.Vector3; //导入方法依赖的package包/类
/**
* Grows the tree.
*/
protected void grow() {
RajLog.d("[" + this.getClass().getName() + "] Growing tree: " + this);
Vector3 min = new Vector3(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
Vector3 max = new Vector3(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE);
//Get a full list of all the members, including members in the children
ArrayList<IGraphNodeMember> members = getAllMembersRecursively(true);
int members_count = members.size();
for (int i = 0; i < members_count; ++i) {
IBoundingVolume volume = members.get(i).getTransformedBoundingVolume();
Vector3 test_against_min = null;
Vector3 test_against_max = null;
if (volume == null) {
ATransformable3D object = (ATransformable3D) members.get(i);
test_against_min = object.getPosition();
test_against_max = test_against_min;
} else {
if (volume instanceof BoundingBox) {
BoundingBox bb = (BoundingBox) volume;
test_against_min = bb.getTransformedMin();
test_against_max = bb.getTransformedMax();
} else if (volume instanceof BoundingSphere) {
BoundingSphere bs = (BoundingSphere) volume;
Vector3 bs_position = bs.getPosition();
double radius = bs.getScaledRadius();
Vector3 rad = new Vector3();
rad.setAll(radius, radius, radius);
test_against_min = Vector3.subtractAndCreate(bs_position, rad);
test_against_max = Vector3.addAndCreate(bs_position, rad);
} else {
RajLog.e("[" + this.getClass().getName() + "] Received a bounding box of unknown type.");
throw new IllegalArgumentException("Received a bounding box of unknown type.");
}
}
if (test_against_min != null && test_against_max != null) {
if(test_against_min.x < min.x) min.x = test_against_min.x;
if(test_against_min.y < min.y) min.y = test_against_min.y;
if(test_against_min.z < min.z) min.z = test_against_min.z;
if(test_against_max.x > max.x) max.x = test_against_max.x;
if(test_against_max.y > max.y) max.y = test_against_max.y;
if(test_against_max.z > max.z) max.z = test_against_max.z;
}
}
mMin.setAll(min);
mMax.setAll(max);
mTransformedMin.setAll(min);
mTransformedMax.setAll(max);
calculatePoints();
calculateChildSideLengths();
if (mSplit) {
for (int i = 0; i < CHILD_COUNT; ++i) {
((Octree) mChildren[i]).setChildRegion(i, mChildLengths);
}
}
for (int i = 0; i < members_count; ++i) {
internalAddObject(members.get(i));
}
}