Java源码示例:com.jme3.util.TempVars
示例1
/**
* <code>rotateUpTo</code> is a utility function that alters the
* local rotation to point the Y axis in the direction given by newUp.
*
* @param newUp
* the up vector to use - assumed to be a unit vector.
*/
public void rotateUpTo(Vector3f newUp) {
TempVars vars = TempVars.get();
Vector3f compVecA = vars.vect1;
Quaternion q = vars.quat1;
// First figure out the current up vector.
Vector3f upY = compVecA.set(Vector3f.UNIT_Y);
Quaternion rot = localTransform.getRotation();
rot.multLocal(upY);
// get angle between vectors
float angle = upY.angleBetween(newUp);
// figure out rotation axis by taking cross product
Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal();
// Build a rotation quat and apply current local rotation.
q.fromAngleNormalAxis(angle, rotAxis);
q.mult(rot, rot);
vars.release();
setTransformRefresh();
}
示例2
@Override
public void simpleUpdate(float tpf) {
area.setCenter(ln.getLocalTranslation());
area.setRotation(ln.getLocalRotation());
TempVars vars = TempVars.get();
boolean intersectBox = area.intersectsBox(aabb, vars);
boolean intersectFrustum = area.intersectsFrustum(frustumCam, vars);
boolean intersectSphere = area.intersectsSphere(sphere, vars);
vars.release();
boolean intersect = intersectBox || intersectFrustum || intersectSphere;
areaGeom.getMaterial().setColor("Color", intersect ? ColorRGBA.Green : ColorRGBA.White);
sphereGeom.getMaterial().setColor("Color", intersectSphere ? ColorRGBA.Cyan : ColorRGBA.White);
frustumGeom.getMaterial().setColor("Color", intersectFrustum ? ColorRGBA.Cyan : ColorRGBA.White);
aabbGeom.getMaterial().setColor("Color", intersectBox ? ColorRGBA.Cyan : ColorRGBA.White);
}
示例3
@Override
public void simpleUpdate(float tpf) {
TempVars vars = TempVars.get();
boolean intersect = spotLight.intersectsFrustum(frustumCam, vars);
if (intersect) {
geom.getMaterial().setColor("Diffuse", ColorRGBA.Green);
} else {
geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
}
Vector3f farPoint = vars.vect1.set(spotLight.getPosition()).addLocal(vars.vect2.set(spotLight.getDirection()).multLocal(spotLight.getSpotRange()));
//computing the radius of the base disc
float farRadius = (spotLight.getSpotRange() / FastMath.cos(spotLight.getSpotOuterAngle())) * FastMath.sin(spotLight.getSpotOuterAngle());
//computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
Vector3f perpDirection = vars.vect2.set(spotLight.getDirection()).crossLocal(frustumCam.getWorldPlane(3).getNormal()).normalizeLocal().crossLocal(spotLight.getDirection());
//projecting the far point on the base disc perimeter
Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
vars.release();
// boxGeo.setLocalTranslation(spotLight.getPosition());
// boxGeo.setLocalTranslation(projectedPoint);
}
示例4
private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf, int componentSize) {
TempVars vars = TempVars.get();
Vector3f pos = vars.vect1;
// offset is given in element units
// convert to be in component units
offset *= componentSize;
for (int i = 0; i < inBuf.limit() / componentSize; i++) {
pos.x = inBuf.get(i * componentSize);
pos.y = inBuf.get(i * componentSize + 1);
pos.z = inBuf.get(i * componentSize + 2);
outBuf.put(offset + i * componentSize, pos.x);
outBuf.put(offset + i * componentSize + 1, pos.y);
outBuf.put(offset + i * componentSize + 2, pos.z);
}
vars.release();
}
示例5
private BoundingBox createBox(int l, int r) {
TempVars vars = TempVars.get();
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f v1 = vars.vect3,
v2 = vars.vect4,
v3 = vars.vect5;
for (int i = l; i <= r; i++) {
getTriangle(i, v1, v2, v3);
BoundingBox.checkMinMax(min, max, v1);
BoundingBox.checkMinMax(min, max, v2);
BoundingBox.checkMinMax(min, max, v3);
}
BoundingBox bbox = new BoundingBox(min, max);
vars.release();
return bbox;
}
示例6
/**
* <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix
* data.
*
* @param fb
* the buffer to fill, starting at current position. Must have
* room for 16 more floats.
* @param columnMajor
* if true, this buffer should be filled with column major data,
* otherwise it will be filled row major.
* @return matrix data as a FloatBuffer. (position is advanced by 16 and any
* limit set is not changed).
*/
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
// if (columnMajor) {
// fb.put(m00).put(m10).put(m20).put(m30);
// fb.put(m01).put(m11).put(m21).put(m31);
// fb.put(m02).put(m12).put(m22).put(m32);
// fb.put(m03).put(m13).put(m23).put(m33);
// } else {
// fb.put(m00).put(m01).put(m02).put(m03);
// fb.put(m10).put(m11).put(m12).put(m13);
// fb.put(m20).put(m21).put(m22).put(m23);
// fb.put(m30).put(m31).put(m32).put(m33);
// }
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 16);
vars.release();
return fb;
}
示例7
/**
* <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix
* data.
*
* @param fb
* the buffer to fill, starting at current position. Must have
* room for 9 more floats.
* @param columnMajor
* true → column-major order, false → row-major order
* @return matrix data as a FloatBuffer. (position is advanced by 9 and any
* limit set is not changed).
*/
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
// if (columnMajor){
// fb.put(m00).put(m10).put(m20);
// fb.put(m01).put(m11).put(m21);
// fb.put(m02).put(m12).put(m22);
// }else{
// fb.put(m00).put(m01).put(m02);
// fb.put(m10).put(m11).put(m12);
// fb.put(m20).put(m21).put(m22);
// }
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 9);
vars.release();
return fb;
}
示例8
/**
*
* @param viewCam
* @return true if intersects
*/
@Override
protected boolean checkCulling(Camera viewCam) {
if (light == null) {
return false;
}
Camera cam = viewCam;
if(frustumCam != null){
cam = frustumCam;
cam.setLocation(viewCam.getLocation());
cam.setRotation(viewCam.getRotation());
}
TempVars vars = TempVars.get();
boolean intersects = light.intersectsFrustum(cam,vars);
vars.release();
return intersects;
}
示例9
/**
* <code>rotateUpTo</code> is a utility function that alters the
* local rotation to point the Y axis in the direction given by newUp.
*
* @param newUp
* the up vector to use - assumed to be a unit vector.
*/
public void rotateUpTo(Vector3f newUp) {
TempVars vars = TempVars.get();
Vector3f compVecA = vars.vect1;
Quaternion q = vars.quat1;
// First figure out the current up vector.
Vector3f upY = compVecA.set(Vector3f.UNIT_Y);
Quaternion rot = localTransform.getRotation();
rot.multLocal(upY);
// get angle between vectors
float angle = upY.angleBetween(newUp);
// figure out rotation axis by taking cross product
Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal();
// Build a rotation quat and apply current local rotation.
q.fromAngleNormalAxis(angle, rotAxis);
q.mult(rot, rot);
vars.release();
setTransformRefresh();
}
示例10
/**
* Callback from Control.render(), do not use.
*
* @param rm
* @param vp
*/
private void renderFromControl(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
if (meshType == ParticleMesh.Type.Point) {
float C = cam.getProjectionMatrix().m00;
C *= cam.getWidth() * 0.5f;
// send attenuation params
this.getMaterial().setFloat("Quadratic", C);
}
Matrix3f inverseRotation = Matrix3f.IDENTITY;
TempVars vars = null;
if (!worldSpace) {
vars = TempVars.get();
inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
}
particleMesh.updateParticleData(particles, cam, inverseRotation);
if (!worldSpace) {
vars.release();
}
}
示例11
/**
* Internal use only
*
* @see Track#setTime(float, float, com.jme3.animation.AnimControl,
* com.jme3.animation.AnimChannel, com.jme3.util.TempVars)
*/
@Override
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
if (time >= length) {
return;
}
if (!initialized) {
control.addListener(new OnEndListener());
initialized = true;
}
if (!started && time >= startOffset) {
started = true;
audio.playInstance();
}
}
示例12
@Override
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
// TODO: When MeshControl is created, it will gather targets
// list automatically which is then retrieved here.
/*
Mesh target = targets[targetMeshIndex];
if (time < times[0]) {
applyFrame(target, 0, weight);
} else if (time > times[times.length - 1]) {
applyFrame(target, times.length - 1, weight);
} else {
int startFrame = 0;
for (int i = 0; i < times.length; i++) {
if (times[i] < time) {
startFrame = i;
}
}
int endFrame = startFrame + 1;
float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);
applyFrame(target, startFrame, blend * weight);
applyFrame(target, endFrame, (1f - blend) * weight);
}
*/
}
示例13
/**
* Compute bounds from an array of points
* @param pts
* @param mat
* @return a new BoundingBox
*/
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) {
Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
TempVars vars = TempVars.get();
Vector3f temp = vars.vect1;
for (int i = 0; i < pts.length; i++) {
float w = mat.multProj(pts[i], temp);
temp.x /= w;
temp.y /= w;
// Why was this commented out?
temp.z /= w;
min.minLocal(temp);
max.maxLocal(temp);
}
vars.release();
Vector3f center = min.add(max).multLocal(0.5f);
Vector3f extent = max.subtract(min).multLocal(0.5f);
//Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned
return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f);
}
示例14
/**
* Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }.
* This will require a localized transform update for this geometry.
*/
public void computeWorldMatrix() {
// Force a local update of the geometry's transform
checkDoTransformUpdate();
// Compute the cached world matrix
cachedWorldMat.loadIdentity();
if (ignoreTransform) {
return;
}
cachedWorldMat.setRotationQuaternion(worldTransform.getRotation());
cachedWorldMat.setTranslation(worldTransform.getTranslation());
TempVars vars = TempVars.get();
Matrix4f scaleMat = vars.tempMat4;
scaleMat.loadIdentity();
scaleMat.scale(worldTransform.getScale());
cachedWorldMat.multLocal(scaleMat);
vars.release();
}
示例15
/**
* Callback from Control.render(), do not use.
*
* @param rm
* @param vp
*/
private void renderFromControl(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
if (meshType == ParticleMesh.Type.Point) {
float C = cam.getProjectionMatrix().m00;
C *= cam.getWidth() * 0.5f;
// send attenuation params
this.getMaterial().setFloat("Quadratic", C);
}
Matrix3f inverseRotation = Matrix3f.IDENTITY;
TempVars vars = null;
if (!worldSpace) {
vars = TempVars.get();
inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
}
particleMesh.updateParticleData(particles, cam, inverseRotation);
if (!worldSpace) {
vars.release();
}
}
示例16
/**
* Instantly emits available particles, up to num.
*/
public void emitParticles(int num) {
// Force world transform to update
this.getWorldTransform();
TempVars vars = TempVars.get();
BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
Vector3f min = vars.vect1;
Vector3f max = vars.vect2;
bbox.getMin(min);
bbox.getMax(max);
if (!Vector3f.isValidVector(min)) {
min.set(Vector3f.POSITIVE_INFINITY);
}
if (!Vector3f.isValidVector(max)) {
max.set(Vector3f.NEGATIVE_INFINITY);
}
for(int i=0;i<num;i++) {
if( emitParticle(min, max) == null ) break;
}
bbox.setMinMax(min, max);
this.setBoundRefresh();
vars.release();
}
示例17
/**
* Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians),
* (aka pitch, yaw, roll) in the local coordinate space.
*
* @return The spatial on which this method is called, e.g <code>this</code>.
*/
public Spatial rotate(float xAngle, float yAngle, float zAngle) {
TempVars vars = TempVars.get();
Quaternion q = vars.quat1;
q.fromAngles(xAngle, yAngle, zAngle);
rotate(q);
vars.release();
return this;
}
示例18
public static void recursiveMethod(int recurse) {
TempVars vars = TempVars.get();
{
vars.vect1.set(0.1f, 0.2f, 0.3f);
if (recurse < 4) {
recursiveMethod(recurse + 1);
}
sumCompute.addLocal(vars.vect1);
}
vars.release();
}
示例19
public static void methodThatUsesTempVars() {
TempVars vars = TempVars.get();
{
vars.vect1.set(0.1f, 0.2f, 0.3f);
sumCompute.addLocal(vars.vect1);
}
vars.release();
}
示例20
/**
* Create a debug spatial from the specified collision shape.
* <p>
* This is mostly used internally. To attach a debug shape to a physics
* object, call <code>attachDebugShape(AssetManager manager);</code> on it.
*
* @param collisionShape the shape to visualize (may be null, unaffected)
* @return a new tree of geometries, or null
*/
public static Spatial getDebugShape(CollisionShape collisionShape) {
if (collisionShape == null) {
return null;
}
Spatial debugShape;
if (collisionShape instanceof CompoundCollisionShape) {
CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
List<ChildCollisionShape> children = shape.getChildren();
Node node = new Node("DebugShapeNode");
for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) {
ChildCollisionShape childCollisionShape = it.next();
CollisionShape ccollisionShape = childCollisionShape.shape;
Geometry geometry = createDebugShape(ccollisionShape);
// apply translation
geometry.setLocalTranslation(childCollisionShape.location);
// apply rotation
TempVars vars = TempVars.get();
Matrix3f tempRot = vars.tempMat3;
tempRot.set(geometry.getLocalRotation());
childCollisionShape.rotation.mult(tempRot, tempRot);
geometry.setLocalRotation(tempRot);
vars.release();
node.attachChild(geometry);
}
debugShape = node;
} else {
debugShape = createDebugShape(collisionShape);
}
if (debugShape == null) {
return null;
}
debugShape.updateGeometricState();
return debugShape;
}
示例21
/**
* Update this control in IK mode, based on IK targets.
*
* @param tpf the time interval between frames (in seconds, ≥0)
*/
private void ikUpdate(float tpf){
TempVars vars = TempVars.get();
Quaternion tmpRot1 = vars.quat1;
Quaternion[] tmpRot2 = new Quaternion[]{vars.quat2, new Quaternion()};
Iterator<String> it = ikTargets.keySet().iterator();
float distance;
Bone bone;
String boneName;
while (it.hasNext()) {
boneName = it.next();
bone = boneLinks.get(boneName).bone;
if (!bone.hasUserControl()) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
continue;
}
distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
if (distance < IKThreshold) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
continue;
}
int depth = 0;
int maxDepth = ikChainDepth.get(bone.getName());
updateBone(boneLinks.get(bone.getName()), tpf * FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
Vector3f position = vars.vect1;
for (PhysicsBoneLink link : boneLinks.values()) {
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
示例22
private int collideWithRay(Ray ray) {
TempVars vars = TempVars.get();
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(
center);
float a = diff.dot(diff) - (getRadius() * getRadius());
float a1, discr;
if (a <= 0.0) {
// inside sphere
vars.release();
return 1;
}
a1 = ray.direction.dot(diff);
vars.release();
if (a1 >= 0.0) {
return 0;
}
discr = a1 * a1 - a;
if (discr < 0.0) {
return 0;
} else if (discr >= FastMath.ZERO_TOLERANCE) {
return 2;
}
return 1;
}
示例23
/**
* Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the
* character motion will only be powered by physics else, the character will
* be animated by the keyframe animation, but will be able to physically
* interact with its physics environment
*
* @param mode an enum value (not null)
*/
protected void setMode(Mode mode) {
this.mode = mode;
AnimControl animControl = targetModel.getControl(AnimControl.class);
animControl.setEnabled(mode == Mode.Kinematic);
baseRigidBody.setKinematic(mode == Mode.Kinematic);
if (mode != Mode.IK) {
TempVars vars = TempVars.get();
for (PhysicsBoneLink link : boneLinks.values()) {
link.rigidBody.setKinematic(mode == Mode.Kinematic);
if (mode == Mode.Ragdoll) {
Quaternion tmpRot1 = vars.quat1;
Vector3f position = vars.vect1;
//making sure that the ragdoll is at the correct place.
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
if(mode != Mode.IK){
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
}
}
}
示例24
/**
* Smoothly blend from Ragdoll mode to Kinematic mode This is useful to
* blend ragdoll actual position to a keyframe animation for example
*
* @param blendTime the blending time between ragdoll to anim.
*/
public void blendToKinematicMode(float blendTime) {
if (mode == Mode.Kinematic) {
return;
}
blendedControl = true;
this.blendTime = blendTime;
mode = Mode.Kinematic;
AnimControl animControl = targetModel.getControl(AnimControl.class);
animControl.setEnabled(true);
TempVars vars = TempVars.get();
for (PhysicsBoneLink link : boneLinks.values()) {
Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
Vector3f position = vars.vect1;
targetModel.getWorldTransform().transformInverseVector(p, position);
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
Quaternion q2 = vars.quat1;
Quaternion q3 = vars.quat2;
q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
q2.normalizeLocal();
link.startBlendingPos.set(position);
link.startBlendingRot.set(q2);
link.rigidBody.setKinematic(true);
}
vars.release();
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, false);
}
blendStart = 0;
}
示例25
public OccludersExtractor(Matrix4f vpm, int cc, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) {
viewProjMatrix = vpm;
casterCount = cc;
splitBB = sBB;
casterBB = cBB;
splitOccluders = sOCC;
vars = v;
}
示例26
/**
* This method works similar to Camera.lookAt but where lookAt sets the
* priority on the direction, this method sets the priority on the up vector
* so that the result direction vector and rotation is guaranteed to be
* perpendicular to the up vector.
*
* @param rotation The rotation to set the result on or null to create a new
* Quaternion, this will be set to the new "z-forward" rotation if not null
* @param direction The direction to base the new look direction on, will be
* set to the new direction
* @param worldUpVector The up vector to use, the result direction will be
* perpendicular to this
*/
protected final void calculateNewForward(Quaternion rotation, Vector3f direction, Vector3f worldUpVector) {
if (direction == null) {
return;
}
TempVars vars = TempVars.get();
Vector3f newLeft = vars.vect1;
Vector3f newLeftNegate = vars.vect2;
newLeft.set(worldUpVector).crossLocal(direction).normalizeLocal();
if (newLeft.equals(Vector3f.ZERO)) {
if (direction.x != 0) {
newLeft.set(direction.y, -direction.x, 0f).normalizeLocal();
} else {
newLeft.set(0f, direction.z, -direction.y).normalizeLocal();
}
logger.log(Level.INFO, "Zero left for direction {0}, up {1}", new Object[]{direction, worldUpVector});
}
newLeftNegate.set(newLeft).negateLocal();
direction.set(worldUpVector).crossLocal(newLeftNegate).normalizeLocal();
if (direction.equals(Vector3f.ZERO)) {
direction.set(Vector3f.UNIT_Z);
logger.log(Level.INFO, "Zero left for left {0}, up {1}", new Object[]{newLeft, worldUpVector});
}
if (rotation != null) {
rotation.fromAxes(newLeft, worldUpVector, direction);
}
vars.release();
}
示例27
public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam){
TempVars vars = TempVars.get();
//Temp vects for reflection cam orientation calculation
Vector3f sceneTarget = vars.vect1;
Vector3f reflectDirection = vars.vect2;
Vector3f reflectUp = vars.vect3;
Vector3f reflectLeft = vars.vect4;
Vector3f camLoc = vars.vect5;
camLoc = plane.reflect(sceneCam.getLocation(), camLoc);
reflectionCam.setLocation(camLoc);
reflectionCam.setFrustum(sceneCam.getFrustumNear(),
sceneCam.getFrustumFar(),
sceneCam.getFrustumLeft(),
sceneCam.getFrustumRight(),
sceneCam.getFrustumTop(),
sceneCam.getFrustumBottom());
reflectionCam.setParallelProjection(sceneCam.isParallelProjection());
sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6));
reflectDirection = plane.reflect(sceneTarget, reflectDirection);
reflectDirection.subtractLocal(camLoc);
sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6));
reflectUp = plane.reflect(sceneTarget, reflectUp);
reflectUp.subtractLocal(camLoc);
sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6));
reflectLeft = plane.reflect(sceneTarget, reflectLeft);
reflectLeft.subtractLocal(camLoc);
reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection);
vars.release();
}
示例28
/**
* <code>computeFromTris</code> creates a new Bounding Box from a given
* set of triangles. It is used in OBBTree calculations.
*
* @param tris
* @param start
* @param end
*/
public void computeFromTris(Triangle[] tris, int start, int end) {
if (end - start <= 0) {
return;
}
TempVars vars = TempVars.get();
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY,
Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f point;
for (int i = start; i < end; i++) {
point = tris[i].get(0);
checkMinMax(min, max, point);
point = tris[i].get(1);
checkMinMax(min, max, point);
point = tris[i].get(2);
checkMinMax(min, max, point);
}
center.set(min.addLocal(max));
center.multLocal(0.5f);
xExtent = max.x - center.x;
yExtent = max.y - center.y;
zExtent = max.z - center.z;
vars.release();
}
示例29
private int collideWithRay(Ray r,
Matrix4f worldMatrix,
BoundingVolume worldBound,
CollisionResults results) {
TempVars vars = TempVars.get();
try {
CollisionResults boundResults = vars.collisionResults;
boundResults.clear();
worldBound.collideWith(r, boundResults);
if (boundResults.size() > 0) {
float tMin = boundResults.getClosestCollision().getDistance();
float tMax = boundResults.getFarthestCollision().getDistance();
if (tMax <= 0) {
tMax = Float.POSITIVE_INFINITY;
} else if (tMin == tMax) {
tMin = 0;
}
if (tMin <= 0) {
tMin = 0;
}
if (r.getLimit() < Float.POSITIVE_INFINITY) {
tMax = Math.min(tMax, r.getLimit());
if (tMin > tMax){
return 0;
}
}
// return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
}
return 0;
} finally {
vars.release();
}
}
示例30
public void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left) {
TempVars vars = TempVars.get();
try {
Vector3f fwdVector = vars.vect1.set(direction);
Vector3f leftVector = vars.vect2.set(fwdVector).crossLocal(up);
Vector3f upVector = vars.vect3.set(leftVector).crossLocal(fwdVector);
m00 = leftVector.x;
m01 = leftVector.y;
m02 = leftVector.z;
m03 = -leftVector.dot(location);
m10 = upVector.x;
m11 = upVector.y;
m12 = upVector.z;
m13 = -upVector.dot(location);
m20 = -fwdVector.x;
m21 = -fwdVector.y;
m22 = -fwdVector.z;
m23 = fwdVector.dot(location);
m30 = 0f;
m31 = 0f;
m32 = 0f;
m33 = 1f;
} finally {
vars.release();
}
}