本文整理汇总了Java中com.jme.math.Vector3f.dot方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.dot方法的具体用法?Java Vector3f.dot怎么用?Java Vector3f.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.dot方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCurrentPlacemark
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Returns a Placemark that represents the current position of the avatar.
*/
private Placemark getCurrentPlacemark(ServerSessionManager sessionManager) {
// Fetch the current translation of the avatar and the (x, y, z) of its
// position
ViewManager manager = ViewManager.getViewManager();
ViewCell viewCell = manager.getPrimaryViewCell();
CellTransform viewTransform = viewCell.getWorldTransform();
Vector3f location = viewTransform.getTranslation(null);
float x = location.x;
float y = location.y;
float z = location.z;
// Find out what the URL to the server is
String url = sessionManager.getServerURL();
// Compute the current look angle, as degrees from the +x axis, ignoring
// any look in the y-axis.
Quaternion viewRotation = viewTransform.getRotation(null);
Vector3f v1 = new Vector3f(0, 0, 1);
Vector3f normal = new Vector3f(0, 1, 0);
Vector3f v2 = viewRotation.mult(v1);
v2.normalizeLocal();
// Compute the signed angle between v1 and v2. We do this with the
// following formula: angle = atan2(normal dot (v1 cross v2), v1 dot v2)
float dotProduct = v1.dot(v2);
Vector3f crossProduct = v1.cross(v2);
float lookAngle = (float) Math.atan2(normal.dot(crossProduct), dotProduct);
lookAngle = (float) Math.toDegrees(lookAngle);
return new Placemark("", url, x, y, z, lookAngle);
}
示例3: 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();
}
示例4: isBelowWater
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Test if a vector (in world coordinates) is under water
* @param region
* @param vector
* @param gravityUnit
* @return Less than 0 if under water
*/
protected static float isBelowWater(IFluidRegion region, Vector3f vector, Vector3f gravityUnit)
{
float fluidHeight = region.getFluidHeight();
float gravityDistance = -gravityUnit.dot(vector);
//gravity distance is the height of the object, relative to the direction of gravity
return gravityDistance - fluidHeight;
}
示例5: 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;
}
示例6: move
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
protected void move(ControllableCylinder toControl, Vector3f position) {
if (toControl == null )
return;
if (!toControl.getLocalRotation().equals(compareRotation))
{
compareRotation = new Quaternion().set(toControl.getLocalRotation());
cacheRotation = toControl.getLocalRotation().inverse();
localDirection = compareRotation.mult(point.direction);
orientation.updateOrientation();
}
Vector3f scale = toControl.getLocalScale();
Vector3f old = new Vector3f(scale);
Vector3f pos = new Vector3f( position);
float stretch;
Vector3f bottom = toControl.getLocalTranslation().subtract(compareRotation.mult(scale.mult(point.direction)).multLocal(0.5f*point.flip));
if (point != RADIUS)
pos.subtractLocal(bottom);
//stretch= Math.abs((pos.dot(point.direction)- CONTROL_DISTANCE*point.flip) );
stretch= pos.dot(localDirection)*point.flip - CONTROL_DISTANCE;
if (stretch < MIN_THICKNESS/2f)
stretch = MIN_THICKNESS/2f;
Vector3f mod = new Vector3f();
if (point==RADIUS)
{
stretch = controllable.getValidatedScale(stretch,RADIUS);
mod.set(1,1,0);
mod.multLocal(stretch);
scale.multLocal(new Vector3f(0,0,1)).addLocal(mod.multLocal(2f));
}else
{
if (point == CylinderPoint.LEFT)
stretch = controllable.getValidatedScale(stretch,CylinderPoint.LEFT);
else if (point == CylinderPoint.RIGHT)
stretch = controllable.getValidatedScale(stretch,CylinderPoint.RIGHT);
mod.set(point.direction);
mod.multLocal(stretch);
scale.multLocal(point.inverse).addLocal(mod);//.add(0f,+CONTROL_DISTANCE/2f,0f));
toControl.getLocalTranslation().addLocal(toControl.getLocalRotation().mult(scale.subtract(old)).divideLocal(2f).multLocal(point.flip));
}
toControl.updateModel();
if (point==RADIUS)
{
this.updatePosition();
}else
{
if (super.siblings != null)
{
for (ControlPoint control:siblings)
control.updatePosition();
}else
this.updatePosition();
}
}
示例7: 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;
}
示例8: 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);
}
示例9: buildSegments
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Build trapezoids for each face of the object, representing the portion that is submerged
* @param region
* @param gravityUnit
* @return
*/
private ArrayList<LinePair>[] buildSegments(IFluidRegion region, Vector3f gravityUnit)
{
ArrayList<LinePair>[] linePairs = _segments;
ArrayList<LinePair>[] segments = _returnSegments;
OrientedBoundingBox bound = object.getCustomWorldBound();
object.getPhysicsNode().updateWorldVectors();
Vector3f physicsNodeCenter = object.getPhysicsNode().getWorldTranslation();
boolean flip = false;
// flip = true;
// getSegmentFromRegionAndBound(region,bound,Y_AXIS, flip, physicsNodeCenter,gravityUnit, linePairs[0]);
// segments[0] = (linePairs[0]);//for testing
// drawLineSegments(segments[0], object.getPhysicsNode().getWorldTranslation());
for (int i = 0; i<6;i++)
{
int axis = AXIS[i/2];
if( getSegmentFromRegionAndBound(region,bound,axis, flip,physicsNodeCenter, gravityUnit, linePairs[i]))
{
segments[i] = linePairs[i];
}else
{
//if the trapezoid if fully submerged, include it.
//otherwise, set it to null
LinePair segment= linePairs[i].get(0);//test any one of the pairs in this segment
//check if the pair's translation is greater than or lower than the fluid height
Vector3f height = _heightTest;
height.set( segment.getXAxis()).multLocal(segment.start).addLocal(segment.getTranslation()).addLocal(object.getPhysicsNode().getWorldTranslation());
if (-height.dot(gravityUnit)<=region.getFluidHeight())
{
segments[i] = linePairs[i];
}else
segments[i]=null;
}
flip = ! flip;
}
return segments;
}
示例10: move
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
protected void move(ControllableSphere toControl, Vector3f position) {
if (toControl == null )
return;
Vector3f pos = position;
//this.getParent().worldToLocal(moveTo, pos);
Vector3f scale = toControl.getLocalScale();
float stretch;
if (point == SPHERE)
stretch= pos.dot(new Vector3f(1,0,0)) - CONTROL_DISTANCE;
else
stretch= pos.dot(point.direction) - CONTROL_DISTANCE;
if (stretch < MIN_THICKNESS)
stretch = MIN_THICKNESS;
Vector3f mod = new Vector3f();
mod.set(point.direction);
mod.multLocal(stretch);
scale.multLocal(point.inverse).addLocal(mod.multLocal(2f));
toControl.updateModel();
this.updatePosition();
}
示例11: applyRotationalFriction
import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void applyRotationalFriction(ArrayList<LinePair>[] segments, IFluidRegion region, Vector3f gravityUnit, float tpf)
{
//Planning to use the slanted trapezoid integration to apply only the force appropriate for the area involved
//NOTE: currently, all the solutions assume x moves along the width of the trapezoid. This is ok for linear friction, but for rotational friction that only works for half the cases. Have to solve again from along y.
object.rotationNode.detachAllChildren();
Vector3f omega = _temp;
//NOTE: Angular velocity is NOT given in local terms; for example, if the physics node has an initial rotation, applying the same angular velocity will cause it to rotate in the same way relative to the world, regardless of the initial rotation.
omega=(object.getPhysicsNode().getAngularVelocity(omega));
object.linearNode.detachAllChildren();
for (ArrayList<LinePair> segmentSet:segments)
{
//for each line segment, the velocity is the component of velocity in the direction of its normal
if(segmentSet == null)
continue;
float omegaX = omega.dot(segmentSet.get(0).getYAxis());//this is intentionally compared to the Y axis, not the X axis
float omegaY = omega.dot(segmentSet.get(0).getXAxis());
applyRotationalFrictionToSegments(segmentSet, region, omegaX,object.dragCoefficient, tpf);
//The bottom line is always the last added to the line's children
ArrayList<LinePair> inverseSet = invertLinePairSet(segmentSet);
//drawLineSegments(inverseSet, object.getPhysicsNode().getWorldTranslation());
applyRotationalFrictionToSegments(inverseSet, region, omegaY, object.dragCoefficient, tpf);
applyRotationalSkinDragToSegments(inverseSet, region, omega.dot(segmentSet.get(0).getNormal()), tpf);
}
}
示例12: move
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
protected void move(ControllableTube toControl, Vector3f position) {
if (toControl == null )
return;
Vector3f localDirection = toControl.getLocalRotation().mult(point.direction);
Vector3f scale = toControl.getLocalScale();
Vector3f old = new Vector3f(scale);
Vector3f pos = new Vector3f( position);
float stretch;
Vector3f bottom = toControl.getLocalTranslation().subtract(toControl.getLocalRotation().mult(scale.mult(point.direction)).multLocal(0.5f*point.flip));
if (point != RADIUS)
pos.subtractLocal(bottom);
//stretch= Math.abs((pos.dot(point.direction)- CONTROL_DISTANCE*point.flip) );
stretch= pos.dot(localDirection)*point.flip - CONTROL_DISTANCE;
if (stretch < MIN_THICKNESS/2f)
stretch = MIN_THICKNESS/2f;
Vector3f mod = new Vector3f();
if (point==RADIUS)
{
toControl.setOuterRadius(stretch);
}else if (point==INNER_RADIUS)
{
// stretch = controllable.getValidatedScale(stretch,INNER_RADIUS);
toControl.setInnerRadius(stretch);
}else
{
float oldHeight = toControl.getHeight();
toControl.setHeight(stretch);
mod.set(point.direction);
mod.multLocal((stretch -oldHeight)*point.flip*.5f) ;
toControl.getWorldRotation().multLocal(mod);
toControl.setLocalTranslation(toControl.getWorldTranslation().add(mod));
}
toControl.updateModel();
{
if (super.siblings != null)
{
for (ControlPoint control:siblings)
control.updatePosition();
}else
this.updatePosition();
}
}