本文整理汇总了Java中com.jme.math.Vector3f.length方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.length方法的具体用法?Java Vector3f.length怎么用?Java Vector3f.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.length方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: applyLinearFriction
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void applyLinearFriction(IFluidRegion region, float submergedRadius, BoundingSphere bound, float tpf)
{
Vector3f linearFriction;
linearFriction = getPhysicsNode().getLinearVelocity(_frictionStore);
float velocity = linearFriction.length();
linearFriction.normalizeLocal();
applyLinearFrictionToVector(velocity, linearFriction, region, submergedRadius, bound, tpf);
}
示例3: applyLimitedForce
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* It is necessary to limit the amount of acceleration that any object can undergo; otherwise very light objects can behave erraticly.
* @param object
* @param force
* @param position
*/
public static void applyLimitedForce(BuoyantObject object, Vector3f force, Vector3f position)
{
float mass = object.getCollisionGeometry().getVolume() *object.getCollisionGeometry().getMaterial().getDensity();
//Limit the force being applied
float magnitude = force.length();
if (magnitude/mass>MAX_LINEAR_ACCELERATION)
{
float factor = (mass*MAX_LINEAR_ACCELERATION)/magnitude;
force.multLocal(factor);
}
object.getPhysicsNode().addForce(force, position);
}
示例4: applyLimitedTorque
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* It is necessary to limit the amount of acceleration that any object can undergo; otherwise very light objects can behave erraticly.
* @param object
* @param torque
*/
public static void applyLimitedTorque(BuoyantObject object, Vector3f torque)
{
float mass =object.getCollisionGeometry().getVolume() *object.getCollisionGeometry().getMaterial().getDensity();
//Limit the torque being applied
float magnitude = torque.length();
if (magnitude/mass>MAX_ANGULAR_ACCELERATION)
{
float factor = (mass*MAX_ANGULAR_ACCELERATION)/magnitude;
torque.multLocal(factor);
}
object.getPhysicsNode().addTorque(torque);
}
示例5: commitEvent
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public void commitEvent(Event event) {
// Fetch and cast some event objects
MouseEvent3D mouseEvent = (MouseEvent3D)event;
MouseEvent awtMouseEvent = (MouseEvent)mouseEvent.getAwtEvent();
// Figure out where the initial mouse button press happened and
// store the initial position. We also store the center of the
// affordance.
if (event instanceof MouseButtonEvent3D) {
MouseButtonEvent3D be = (MouseButtonEvent3D)event;
if (be.isPressed() && be.getButton() == ButtonId.BUTTON1) {
// Figure out where the button press is in screen and world
// coordinates. Also fetch the current rotation for cell.
MouseEvent awtButtonEvent = (MouseEvent)be.getAwtEvent();
dragStartScreen = new Point(awtButtonEvent.getX(), awtButtonEvent.getY());
dragStartWorld = be.getIntersectionPointWorld();
// Figure out the world coordinates of the center of the
// affordance.
Entity entity = event.getEntity();
RenderComponent rc = (RenderComponent)entity.getComponent(RenderComponent.class);
Vector3f centerWorld = rc.getSceneRoot().getWorldTranslation();
// Compute the vector from the starting point of the drag
// to the center of the affordance in world coordinates.
dragStartVectorWorld = dragStartWorld.subtract(centerWorld);
dragStartRadius = dragStartVectorWorld.length();
// Show the resize label, make sure we do this in an
// AWT Event Thread
showResizeLabel(awtMouseEvent);
// Tell the listeners that a resizing has started
fireResizingStarted();
} else if (be.isReleased() == true) {
// Hide the resize label, make sure we do this in an
// AWT Event Thread
hideResizeLabel();
}
return;
}
// If not a drag motion, just return, we don't care about the event
if (!(event instanceof MouseDraggedEvent3D)) {
return;
}
// Get the vector of the drag motion from the initial starting
// point in world coordinates.
MouseDraggedEvent3D dragEvent = (MouseDraggedEvent3D) event;
Vector3f dragWorld = dragEvent.getDragVectorWorld(dragStartWorld,
dragStartScreen, new Vector3f());
// Figure out what the vector is of the current drag location in
// world coodinates. This gives a vector from the center of the
// affordance. We just take the vector (from the center) of the
// start of the drag and add the bit we dragged the mouse. Also
// compute the length of this radius
Vector3f dragEndVectorWorld = dragStartVectorWorld.add(dragWorld);
float dragEndRadius = dragEndVectorWorld.length();
// Take the ratio of the radius between the start and the end. That
// will give us the amount to scale the cell
float scale = dragEndRadius / dragStartRadius;
// Update the resize label, make sure we do this in an AWT Event
// Thread
updateResizeLabel(scale, awtMouseEvent);
// Rotate the object along the defined axis and angle.
fireResizingChanged(scale);
}
示例6: 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);
}
}
示例7: cameraTest
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void cameraTest(Thing th, Node scene) {
try {
//direction from the camera to the thing
// Vector3f direction = th.shape.getLocalTranslation().subtract(e.rcnEven.getCameraNode().getLocalTranslation()).normalizeLocal();
Vector3f direction = th.shape.getLocalTranslation().subtract(wEnv.getRobotCamera(0).getCameraNode().getLocalTranslation()).normalizeLocal();
// check if thing is within the camera view
// Vector3f difference =e.rcnEven.getCameraNode().getLocalRotation().getRotationColumn(2).subtract(direction);
Vector3f difference = wEnv.getRobotCamera(0).getCameraNode().getLocalRotation().getRotationColumn(2).subtract(direction);
if (difference.length() > 0.5f) {
// 2 == 180�
// 1 == 90�
// 0.5 == 45�
// not in camera field of view
//System.out.println("!!!!! Food " + wEnv.getOpool().indexOf(th) + "is NOT in view");
return;
}
Ray ray = new Ray(wEnv.getRobotCamera(0).getCameraNode().getLocalTranslation(), direction);
PickResults results = new BoundingPickResults();
//results.clear();
results.setCheckDistance(true);
scene.findPick(ray, results);
if (results.getNumber() > 0) {
for (int it = 0; it < results.getNumber(); it++) {
Node geom = results.getPickData(it).getTargetMesh().getParent();
// if (containsNode(geom, e.rcnEven.getCameraNode())) {
if (containsNode(geom, wEnv.getRobotCamera(0).getCameraNode())) {
// oops, ignore that
continue;
}
if (containsNode(geom, (wEnv.getCpool().get(wEnv.getCamera(0))).shape)) { //@@@@ attention for camera index
// oops, ignore that
continue;
}
if (containsNode(geom, th.shape)) {
// got our target
//System.out.println("!!!!! I see food: " + e.opool.indexOf(th));
break;
} else {
// our ray hit something else than the food
//System.out.println("!!!!! Food " + e.opool.indexOf(th) + " is OCCLUDED!!!!");
//String na = new String();
Node aux = results.getPickData(it).getTargetMesh().getParent();
do {
//na = aux.getName();
//if(aux.getParent() != null)aux = aux.getParent();
if (aux.getParent() != null) {
aux = aux.getParent();
}
} while (aux.getParent() != rootNode);
break;
}
}
}
} catch (Exception ev) {
log.severe("cameraTest error...");
ev.printStackTrace();
}
}
示例8: getVolumeAndCentroid
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public float getVolumeAndCentroid(IFluidRegion region, Vector3f gravityUnit, Vector3f store) {
BoundingSphere bound;
try{
bound = getCustomWorldBound();
}catch(ClassCastException e)
{
throw new BoundClassException(e.getMessage());
}
Plane waterPlane = _plane;
waterPlane.getNormal().set(gravityUnit);
waterPlane.setConstant(region.getFluidHeight());
float radius = bound.getRadius();
Vector3f center = bound.getCenter(_temp3);
//move the center down along gravity by the amount radius
//intersect the line center, gravity unit with the plane
Vector3f intersect = _temp;
boolean result = intersectLineWithPlane(waterPlane, center, gravityUnit, true, intersect);
if (!result)
return 0;
float height;//height here is relative to center, not to the end of the sphere.
intersect.subtractLocal(center);
store.set(center);
if ((height = intersect.length())>=radius)
{
if (intersect.dot(gravityUnit)>0)
return 0;
else
return super.getVolume();//the entire volume is submerged
}
height *= -FastMath.sign( intersect.dot(gravityUnit));//get the sign of the intersection relative to the opposite of gravity's vector
float totalVolume = 4f/3f * FastMath.PI * FastMath.pow(bound.radius, 3);
float volumeBelowSurface = volumeOfPartialSphere(radius, height,-radius);
// intersect.normalizeLocal();
centroidOfPartialSphere(radius,-height, -radius,volumeBelowSurface,gravityUnit,store);//invert this to get the centroid below surface
store.addLocal(center);
float ratio = volumeBelowSurface/totalVolume;
return super.getVolume()*ratio;
}
示例9: applyFriction
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void applyFriction(IFluidRegion region, Vector3f gravityUnit, float tpf) {
BoundingSphere bound;
try{
bound = getCustomWorldBound();
}catch(ClassCastException e)
{
throw new BoundClassException(e.getMessage());
}
Plane waterPlane = _plane;
waterPlane.getNormal().set(gravityUnit);
waterPlane.setConstant(region.getFluidHeight());
float radius = bound.getRadius();
Vector3f center = bound.getCenter(_temp3);
//move the center down along gravity by the amount radius
//intersect the line center, gravity unit with the plane
Vector3f intersect = _temp;
boolean result = intersectLineWithPlane(waterPlane, center, gravityUnit, true, intersect);
if (!result)
return;
float height;//height here is relative to center, not to the end of the sphere.
intersect.subtractLocal(center);
if ((height = intersect.length())>=radius)
{
if (intersect.dot(gravityUnit)>0)
return;
else
height = radius;
}
height *= -FastMath.sign( intersect.dot(gravityUnit));//get the sign of the intersection relative to the opposite of gravity's vector
float submergedRadius = radius;
if (height < 0)
submergedRadius = FastMath.sqrt(radius*radius - height * height);
applyLinearFriction(region,submergedRadius,bound, tpf);
applyRotationalFriction(region,bound,tpf);
}
示例10: pointLineDistance
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Calculates the distance of a point from a line.
* <p><code>
* x1----------------------------x2 <br>
* | <br>
* | distance <br>
* | <br>
* point <br>
* </code>
* <p>
* The formula is <br>
* <code>
* d = |(x2-x1) x (x1-p)| <br>
* ------------------ <br>
* |x2-x1| <br>
* </code>
*
* Where p=point, lineStart=x1, lineEnd=x2
*
*/
public static float pointLineDistance( final Vector3f lineStart,
final Vector3f lineEnd,
final Vector3f point ) {
Vector3f a = new Vector3f(lineEnd);
a.subtract(lineStart);
Vector3f b = new Vector3f(lineStart);
b.subtract(point);
Vector3f cross = new Vector3f();
cross.cross(a,b);
return cross.length()/a.length();
}