本文整理汇总了Java中com.jme.math.Vector3f.subtractLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.subtractLocal方法的具体用法?Java Vector3f.subtractLocal怎么用?Java Vector3f.subtractLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.subtractLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcPlanarIntersection
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Calculates the point in world coordinates where the given ray intersects the "world plane"
* of this geometry. Returns null if the ray doesn't intersect the plane.
* <br><br>
* All inputs are in world coordinates.
* <br><br>
* @param ray The ray.
* @param planePoint A point on the plane.
* @param planeNormal The plane normal vector.
* @return The intersection point.
*/
protected Vector3f calcPlanarIntersection(Ray ray, Vector3f planePoint, Vector3f planeNormal) {
// Ray Equation is X = P + t * V
// Plane Equation is (X - P0) dot N = 0
//
// where
// X is a point on the ray
// P = Starting point for ray (ray.getOrigin())
// t = distance along ray to intersection point
// V = Direction vector of Ray (ray.getDirection())
// P0 = known point on plane (planePoint)
// N = Normal for plane (planeNormal)
//
// Combine equations to calculate t:
//
// t = [ (P0 - P) dot N ] / (V dot N)
//
// Then substitute t into the Ray Equation to get the intersection point.
//
// Source: Various: Lars Bishop book, Geometry Toolbox, Doug T.
Vector3f pointDiffVec = new Vector3f(planePoint);
pointDiffVec.subtractLocal(ray.getOrigin());
float numerator = planeNormal.dot(pointDiffVec);
float denominator = planeNormal.dot(ray.getDirection());
if (denominator == 0f) {
// No intersection
return null;
}
float t = numerator / denominator;
// Now plug t into the Ray Equation is X = P + t * V
Vector3f x = ray.getDirection().mult(t).add(ray.getOrigin());
return x;
}
示例2: setTargetPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void setTargetPosition(Vector3f targetPosition,
Quaternion rotation) {
this.targetPosition = targetPosition;
this.rotation = rotation;
oldTime = System.currentTimeMillis();
logger.finer("Set targetPosition " + targetPosition
+ " rotation " + rotation);
Vector3f positionError = new Vector3f(targetPosition);
positionError.subtractLocal(currentPosition);
float length = positionError.length();
logger.fine("current " + currentPosition + "target "
+ targetPosition + " error " + length);
if (length >= LONG_DISTANCE) {
// Get to LONG_DISTANCE away, then animate from there
Vector3f moveTo = new Vector3f(positionError);
moveTo.multLocal((length - LONG_DISTANCE) / length);
move(moveTo);
logger.fine("JUMP TO: " + currentPosition);
} else {
if (animate == false) {
move(positionError);
}
}
synchronized (this) {
notifyAll();
}
}
示例3: walkLoop
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Walk from the current location to the new location specified, and
* orient to the give look direction
* @param location
* @param lookDirection
* @param speed in meters/second
*/
void walkLoop(Vector3f[] locations, Vector3f lookDirection, float speed, int loopCount) {
this.speed = speed;
locationIndex = 0;
desiredLocations = locations;
desiredLoopCount = loopCount;
currentLoopCount = 0;
step = new Vector3f(desiredLocations[0]);
step.subtractLocal(currentLocation);
step.multLocal(speed / (1000f / sleepTime));
walking = true;
semaphore.release();
}
示例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: adjustToCenter
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void adjustToCenter()
{
calculateCenter();//calculate the center point of these vertices
for (Vector3f vertex:vertices)
vertex.subtractLocal(center);//move the vertices so the center will be at 0
center.zero();
}
示例6: move
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
protected void move (ControllableBox toControl, Vector3f moveTo)
{
if (toControl == null )
return;
toControl.signalMoved();
Vector3f scale = toControl.getLocalScale();
Vector3f old = new Vector3f(scale);
Vector3f pos = moveTo;
float stretch;
Vector3f bottom = toControl.getLocalTranslation().subtract(scale.mult(point.direction).multLocal(0.5f*point.flip));
pos.subtractLocal(bottom);
stretch= pos.dot(point.direction)*point.flip - CONTROL_DISTANCE;//*point.flip) );
if (stretch < MIN_THICKNESS/2f)
stretch = MIN_THICKNESS/2f;
Vector3f mod = new Vector3f();
mod.set(point.direction);
mod.multLocal(stretch);
scale.multLocal(point.inverse).addLocal(mod);//.add(0f,+CONTROL_DISTANCE/2f,0f));
toControl.getLocalTranslation().addLocal(scale.subtract(old).divideLocal(2f).multLocal(point.flip));
toControl.updateWorldData();
toControl.updateModel();
if (super.siblings != null)
{
for (ControlPoint<?> control:siblings)
control.updatePosition();
}else
this.updatePosition();
}
示例7: getRestrictedPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public Vector3f getRestrictedPosition(Vector3f from) {
//Get the closest grid node to the provided position;
from.subtractLocal(ActionToolSettings.getInstance().getGridOrigin().getValue());
from.divideLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
from.x = Math.round(from.x);
from.y = Math.round(from.y);
from.z = Math.round(from.z);
from.multLocal(ActionToolSettings.getInstance().getGridUnits().getValue());
return from;
}
示例8: deployToModule
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public DeployedModel deployToModule(File moduleRootDir, ImportedModel importedModel) throws IOException {
try {
String modelName = getFilename(importedModel.getOriginalURL().toURI().getPath());
HashMap<String, String> textureDeploymentMapping = new HashMap();
DeployedModel deployedModel = new DeployedModel(importedModel.getOriginalURL(), this);
LoaderData data = new LoaderData();
data.setDeployedTextures(textureDeploymentMapping);
data.setModelLoaderClassname(this.getClass().getName());
deployedModel.setLoaderData(data);
// TODO replace getName with getModuleName(moduleRootDir)
String moduleName = moduleRootDir.getName();
String targetDirName = moduleRootDir.getAbsolutePath()+File.separator+"art"+ File.separator + modelName;
File targetDir = new File(targetDirName);
targetDir.mkdirs();
// Must deploy textures before models so we have the deployment url mapping
deployTextures(targetDir, textureDeploymentMapping, importedModel);
ModelCellServerState cellSetup = new ModelCellServerState();
ModelCellComponentServerState setup = new ModelCellComponentServerState();
cellSetup.addComponentServerState(setup);
cellSetup.setName(importedModel.getWonderlandName());
BoundingVolume modelBounds = importedModel.getModelBG().getWorldBound();
float scale = scaleBounds(modelBounds);
modelBounds = modelBounds.transform(new Quaternion(), Vector3f.ZERO,
new Vector3f(scale, scale, scale));
cellSetup.setBoundingVolumeHint(new BoundingVolumeHint(false, modelBounds));
deployedModel.setModelBounds(modelBounds);
Vector3f offset = importedModel.getRootBG().getLocalTranslation();
PositionComponentServerState position = new PositionComponentServerState();
Vector3f boundsCenter = modelBounds.getCenter();
offset.subtractLocal(boundsCenter);
deployedModel.setModelTranslation(offset);
deployedModel.setModelRotation(importedModel.getModelBG().getLocalRotation());
deployedModel.setModelScale(importedModel.getModelBG().getLocalScale().multLocal(scale));
// System.err.println("BOUNDS CENTER "+boundsCenter);
// System.err.println("OFfset "+offset);
// System.err.println("Cell origin "+boundsCenter);
position.setTranslation(boundsCenter);
// The cell bounds already have the rotation and scale applied, so these
// values must not go in the Cell transform. Instead they go in the
// deployedModel so that the model is correctly oriented and thus
// matches the bounds in the cell.
// Center the worldBounds on the cell (ie 0,0,0)
BoundingVolume worldBounds = modelBounds.clone(null);
worldBounds.setCenter(new Vector3f(0,0,0));
position.setBounds(worldBounds);
cellSetup.addComponentServerState(position);
deployedModel.addCellServerState(cellSetup);
deployModels(targetDir,
moduleName,
deployedModel,
importedModel,
textureDeploymentMapping, setup);
return deployedModel;
} catch (URISyntaxException ex) {
Logger.getLogger(JmeColladaLoader.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
示例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: targetSwap
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void targetSwap(Vector3f oldVector, Vector3f newVector) {
oldVector.subtractLocal(newVector);
currentPosition.addLocal(oldVector);
setTargetPosition(new Vector3f());
}
示例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 (type == CapsulePosition.RADIAL_TOP || type == CapsulePosition.RADIAL_BOTTOM)
{
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;
}
}
示例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 (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;
}
}
示例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 (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;
}
}
示例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;
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;
}
}
示例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;
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;
}