本文整理汇总了Java中com.jme.math.Vector3f.addLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.addLocal方法的具体用法?Java Vector3f.addLocal怎么用?Java Vector3f.addLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.addLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTetrahedronProperties
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* The centroid of a tetrahedron (or any other simplex) is just the average of each point.
* The volume of the tetrahedron is given by this formula, where a, b, c and d are the four vertices, in any order:
* V = abs[(a-d) dot ((b-d)cross(c-d))]/6
*
* See:
* http://en.wikipedia.org/wiki/Tetrahedron
* http://en.wikipedia.org/wiki/Centroid
* @param v1
* @param v2
* @param v3
* @param v4
* @param store
* @return
*/
private float getTetrahedronProperties(Vector3f v1, Vector3f v2,Vector3f v3,Vector3f v4, Vector3f store)
{
_aMinusD.set(v1).subtractLocal(v4);
_bMinusD.set(v2).subtractLocal(v4);
_cMinusD.set(v3).subtractLocal(v4);
Vector3f crossProduct = _bMinusD.crossLocal(_cMinusD);
float volume = FastMath.abs(_aMinusD.dot(crossProduct))/6f;
store.set(v1);
store.addLocal(v2);
store.addLocal(v3);
store.addLocal(v4);
store.divideLocal(4);
if (debugMode)
drawTetrahedron(v1.subtract(object.getSpatial().getWorldTranslation()),v2.subtract(object.getSpatial().getWorldTranslation()),v3.subtract(object.getSpatial().getWorldTranslation()),v4.subtract(object.getSpatial().getWorldTranslation()));
return volume;
}
示例2: getGotoLocation
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private CellTransform getGotoLocation(Cell cell) {
// get the bounds of the cell we are going to
BoundingVolume bv = cell.getWorldBounds();
if (isLarge(bv)) {
// if the cell is big, go to the center rather than very
// far away
return cell.getWorldTransform();
}
// use the view properties to calculate the idea distance away
ViewProperties vp = ViewManager.getViewManager().getViewProperties();
float fov = vp.getFieldOfView();
float min = vp.getFrontClip();
float max = 30f;
float distance = CellPlacementUtils.getDistance(bv, fov, min, max);
// calculate the look vector to this cell -- we only care about the y axis
// rotation
Quaternion rotation = cell.getWorldTransform().getRotation(null);
Vector3f lookVec = CellPlacementUtils.getLookDirection(rotation, null);
// translate into a quaternion using lookAt
Quaternion look = new Quaternion();
look.lookAt(lookVec.negate(), Vector3f.UNIT_Y);
// find the origin by translating the look vector
Vector3f origin = lookVec.mult(distance);
origin.addLocal(cell.getWorldTransform().getTranslation(null));
return new CellTransform(look, origin);
}
示例3: transform
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Transform the vector ret by this transform. ret is modified and returned.
* @param ret
*/
public Vector3f transform(Vector3f ret) {
ret.multLocal(scale);
rotation.multLocal(ret);
ret.addLocal(translation);
return ret;
}
示例4: setNormalData
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
*
* <code>setNormalData</code> defines the normals of each face of the
* tetrahedron.
*
*/
private void setNormalData() {
FloatBuffer norms = BufferUtils.createVector3Buffer(12);
//for each side, to get the normal of that side, average its vertices, subtract the center from that average, and normalize
Vector3f[][] sides = new Vector3f[4][];
sides[0] = new Vector3f[]{vertices[0], vertices[1],vertices[2]};
sides[1] = new Vector3f[]{vertices[0], vertices[1],vertices[3]};
sides[2] = new Vector3f[]{vertices[0], vertices[2],vertices[3]};
sides[3] = new Vector3f[]{vertices[1], vertices[2],vertices[3]};
for (int i = 0; i < sides.length;i++)
{
Vector3f centerOfSide = new Vector3f();
for (Vector3f vertex:sides[i])
{
centerOfSide.addLocal(vertex);
}
centerOfSide.divideLocal(sides[i].length);
centerOfSide.subtractLocal(center);//this is now the normal of this side
centerOfSide.normalizeLocal();
for (int e = 0;e <sides[i].length;e++)
{//Put these normals into the buffer
norms.put(centerOfSide.x).put(centerOfSide.y).put(centerOfSide.z);
}
}
norms.rewind();
TriangleBatch batch = getBatch(0);
batch.setNormalBuffer(norms);
}
示例5: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
meshCollision = physicsNode.createMesh("cylMesh");
Vector3f scale = new Vector3f(physicsModel.getLocalScale());
physicsModel.getLocalScale().multLocal(1f);
physicsModel.updateWorldData();
meshCollision.copyFrom((TriMesh) ((SpatialModel)physicsModel).getSpatial());
physicsModel.getLocalScale().set(scale);
physicsModel.updateWorldData();
//and construct physics
meshCollision.getLocalTranslation().set(physicsModel.getLocalTranslation());
meshCollision.getLocalRotation().set(physicsModel.getLocalRotation());
// collision.getLocalScale().set(shared.getLocalScale());
// meshCollision.setIsCollidable(false);
meshCollision.setMaterial(getMaterial());
//meshCollision.setMaterial(MaterialWrapper.WEIGHTLESS);
physicsNode.attachChild(meshCollision);
OdePhysicsComponent comp = new OdePhysicsComponent(meshCollision,physicsModel);
comp.setMass( meshCollision.getVolume() * this.getMaterial().getDensity());
components.add(comp);
Vector3f cm = new Vector3f(0,-interpreter.getHeight()/4f,0);
interpreter.getLocalRotation().multLocal(cm);
cm.addLocal(interpreter.getLocalTranslation());
store.set(cm);
return meshCollision.getVolume() * this.getMaterial().getDensity();
}
示例6: intersectPairWithPlane
import com.jme.math.Vector3f; //导入方法依赖的package包/类
protected static boolean intersectPairWithPlane(Plane p, Vector3f p1, Vector3f p2, Vector3f store, boolean allowIntersectionOutsidePoints)
{
_tempIntersect.set(p2).subtractLocal(p1);
_tempIntersect.normalizeLocal();
Vector3f direction = _tempIntersect;
Vector3f origin = p1;
float denominator = p.getNormal().dot(direction);
if (denominator > -FastMath.FLT_EPSILON && denominator < FastMath.FLT_EPSILON)
return false; // coplanar
float numerator = -(p.getNormal().dot(origin) + p.getConstant());
float ratio = numerator / denominator;
if (Float.isInfinite(ratio))
return false;
//if (ratio < FastMath.FLT_EPSILON)
// return false; // intersects behind p1
store.set(direction).multLocal(ratio);
store.addLocal(origin);
if (!allowIntersectionOutsidePoints)
{
float length = store.dot(p.getNormal());
float p1Length = p.getNormal().dot(p1);
float p2Length = p.getNormal().dot(p2);
if (length >( p1Length > p2Length ? p1Length:p2Length ))
return false;
else if (length <( p1Length < p2Length ? p1Length:p2Length ))
return false;
}
return true;
}
示例7: calculateCenter
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void calculateCenter()
{
center = new Vector3f();
//average the 4 points to get the center
for (Vector3f vertex:vertices)
{
center.addLocal(vertex);
}
center.divideLocal(vertices.length);
}
示例8: calcOffsetStackTransform
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private CellTransform calcOffsetStackTransform () {
CellTransform transform = new CellTransform(null, null);
// Uses: parent, pixelScale, size, offset, ortho
Vector3f offsetTranslation = calcOffsetTranslation();
// Uses: type
Vector3f stackTranslation = calcStackTranslation();
offsetTranslation.addLocal(stackTranslation);
// TODO: HACK: Part 3 of 4 temporary workaround for 951
offsetTranslation.addLocal(new Vector3f(0f, 0f, hackZEpsilon));
transform.setTranslation(offsetTranslation);
return transform;
}
示例9: run
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void run() {
while (!done) {
long newTime = System.currentTimeMillis();
float timeScale = 0.001f;
float deltaTime = (newTime - oldTime) * timeScale;
logger.finest("oldTime " + oldTime + " newTime " + newTime
+ " deltaTime " + deltaTime);
oldTime = newTime;
if (deltaTime <= 0.0) {
sleep(40);
continue;
}
//Difference between where we are and where we want to be.
Vector3f positionError = new Vector3f(targetPosition);
positionError.subtractLocal(currentPosition);
if (positionError.length() < EPSILON) {
logger.fine("Orb reached target position.");
if (listener != null) {
listener.targetReached(currentPosition);
}
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
}
}
continue;
}
Vector3f springForce = new Vector3f(positionError);
springForce.multLocal(SPRING);
Vector3f dampingForce = new Vector3f(oldVelocity);
dampingForce.multLocal(DAMPING * -1.0f);
Vector3f netAcceleration = new Vector3f(springForce);
netAcceleration.addLocal(springForce);
netAcceleration.addLocal(dampingForce);
netAcceleration.multLocal(1.0f / MASS);
Vector3f aIntegration = new Vector3f(netAcceleration);
aIntegration.multLocal(0.5f * deltaTime * deltaTime);
Vector3f vIntegration = new Vector3f(oldVelocity);
vIntegration.multLocal(deltaTime);
Vector3f jump = new Vector3f();
jump.addLocal(aIntegration);
jump.addLocal(vIntegration);
//Speed limiter
float newVelocity = jump.length() / deltaTime;
if (newVelocity > MAX_SPEED) {
jump.normalizeLocal();
jump.multLocal(MAX_SPEED * deltaTime);
}
jump.multLocal(1.0f/deltaTime);
oldVelocity = jump;
move(jump);
sleep(40);
}
}
示例10: update
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void update(Vector3f tIn, Quaternion rIn) {
translation.set(tIn);
rotation.set(rIn);
viewRot.set(rotation);
viewTranslation.set(translation);
Vector3f cameraTrans = rotation.mult(offset);
// System.out.println("Camera trans "+cameraTrans );
translation.addLocal(cameraTrans);
// handle camera collision
if (COLLISION_GLOBAL_ENABLE && (collisionEnabled || collisionCheck)) {
Vector3f dir = new Vector3f(translation);
Vector3f target = new Vector3f(tIn);
target.addLocal(0, DEFAULT_OFFSET.y, 0);
dir.subtractLocal(target).normalizeLocal();
Ray ray = new Ray(target, dir);
PickInfo info = collisionSys.pickAllWorldRay(ray, true, false,
false, cameraComp);
for (int i = 0; i < info.size(); i++) {
// find the next picked object
PickDetails details = info.get(i);
// if the distance is less than the minimum, try the next
// info
if (details.getDistance() < MIN_DISTANCE) {
continue;
}
// if we are performing a collision check, see if the
// camera is closer than the collision
if (collisionCheck) {
if (target.distance(translation) <= details.getDistance()) {
// camera is closer than the nearest collision,
// re-enable collision
collisionEnabled = true;
}
// only check the first collision
break;
}
// if the collision is farther than where the camera would
// have been positioned or outside of range, we can stop and
// leave the camera as is
if (details.getDistance() >= MAX_DISTANCE ||
details.getDistance() >= target.distance(translation))
{
break;
}
// if we made it here, the collision is within range. Move
// the camera to the collision point
translation.set(details.getPosition());
break;
}
// we have checked the collision status -- don't check again until
// the user zooms in
collisionCheck = false;
}
rotation.lookAt(rotation.mult(cameraLook), yUp);
commitRequired=true;
}
示例11: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
if (controllable == null)
return from;
if (point == RADIUS)
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue()).divideLocal(2f);
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
from = controllable.getParent().localToWorld(from,from);
return from;
}else
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
Vector3f scale = controllable.getLocalScale();
if (!controllable.getLocalRotation().equals(compareRotation))
{
compareRotation = new Quaternion().set(controllable.getLocalRotation());
cacheRotation = controllable.getLocalRotation().inverse();
localDirection = compareRotation.mult(point.direction);
orientation.updateOrientation();
}
Vector3f bottom = controllable.getLocalTranslation().subtract(compareRotation.mult(scale.mult(point.direction)).multLocal(0.5f*point.flip));
from.subtractLocal(bottom);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit);//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue());
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit);//Have to account for control distance...
from.addLocal(bottom);
from = controllable.getParent().localToWorld(from,from);
return from;
}
}
示例12: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
if (controllable == null)
return from;
if (type == AxlePosition.RADIAL_LEFT || type == AxlePosition.RADIAL_RIGHT)
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue()).divideLocal(2f);
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
from = controllable.getParent().localToWorld(from,from);
return from;
}else
{
/*Vector3f axis = new Vector3f( type == CapsulePosition.LENGTH_RIGHT? Vector3f.UNIT_X:Vector3f.UNIT_X.mult(-1f));
controllable.getParent().updateWorldData();
controllable.updateWorldData();
controllable.getParent().updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
// Vector3f bottom = controllable.getParent().getLocalTranslation().subtract(axis.mult(controllable.getInterpreter().getHeight())).multLocal(0.5f));
// controllable.getParent().getWorldRotation().multLocal(axis);
from.subtractLocal(axis.divideLocal(2f));
from.subtractLocal(getControlDistance());//Have to account for control distance...
from.divideLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
//Vector3f orig = new Vector3f(from);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
// orig.subtractLocal(orig)
from.multLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
from.addLocal(getControlDistance());//Have to account for control distance...
from.addLocal(axis);
System.out.println(from);
from = controllable.getParent().localToWorld(from,from);*/
return from;
}
}
示例13: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
if (controllable == null)
return from;
if (point == RADIUS)
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue()).divideLocal(2f);
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
from = controllable.getParent().localToWorld(from,from);
return from;
}else
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
Vector3f scale = controllable.getLocalScale();
Vector3f bottom = controllable.getLocalTranslation().subtract(controllable.getLocalRotation().mult(scale.mult(point.direction)).multLocal(0.5f*point.flip));
from.subtractLocal(bottom);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit);//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue());
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit);//Have to account for control distance...
from.addLocal(bottom);
from = controllable.getParent().localToWorld(from,from);
return from;
}
}
示例14: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
if (controllable == null)
return from;
from = controllable.getRelativeFromWorld(from, from);
Vector3f scale = controllable.getLocalScale();
Vector3f bottom = controllable.getLocalTranslation().subtract(scale.mult(point.direction).multLocal(0.5f*point.flip));
from.subtractLocal(bottom);
// Quaternion rotation = controllable.getWorldRotation();
// Vector3f origin = controllable.getWorldTranslation() ;
//from.subtractLocal(origin);
cacheUnit.set(getControlDistance());
//rotation.multLocal(cacheUnit);
from.subtractLocal(cacheUnit);//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue());
//rotation.multLocal(cacheUnit);
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
//rotation.multLocal(cacheUnit);
from.addLocal(cacheUnit);//Have to account for control distance...
//from.addLocal(origin);
from.addLocal(bottom);
from = controllable.getWorldFromRelative(from, from);
return from;
}
示例15: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
if (controllable == null)
return from;
if(type == BallSocketPosition.BALL_RADIAL || type == BallSocketPosition.JOINT_RADIAL)
{
controllable.getParent().updateWorldData();
controllable.updateWorldData();
from = controllable.getParent().worldToLocal(from,from);
cacheUnit.set(getControlDistance());
from.subtractLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
cacheUnit.set(ActionToolSettings.getInstance().getGridUnits().getValue()).divideLocal(2f);
from.divideLocal(cacheUnit);
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(cacheUnit);
cacheUnit.set(getControlDistance());
from.addLocal(cacheUnit.divideLocal(2f));//Have to account for control distance...
from = controllable.getParent().localToWorld(from,from);
return from;
}else{
return from;
/*Vector3f pos = controllable.getRelativeFromWorld(from, new Vector3f());
// System.out.println(pos);
//pos.subtractLocal(ActionToolSettings.getInstance().getGridOrigin().getValue());
pos.divideLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
pos.x = Math.round(pos.x);
pos.y = Math.round(pos.y);
pos.z = Math.round(pos.z);
pos.multLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
return controllable.getWorldFromRelative(pos, from);*/
}
}