本文整理汇总了Java中com.jme.math.Vector3f.set方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.set方法的具体用法?Java Vector3f.set怎么用?Java Vector3f.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.set方法的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: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
jointCollision=physicsNode.createCylinder("joint");
jointCollision.getLocalTranslation().set(jointModel.getLocalTranslation());
jointCollision.getLocalScale().set(jointModel.getLocalScale());
jointCollision.getLocalScale().x/=2f;
jointCollision.getLocalScale().y/=2f;
jointCollision.getLocalRotation().set(jointModel.getLocalRotation());
jointCollision.setIsCollidable(false);
jointCollision.setMaterial(getMaterial());
physicsNode.attachChild(jointCollision);
jointCollision.updateWorldVectors();
store.set(jointCollision.getLocalTranslation());
OdePhysicsComponent jointComp = new OdePhysicsComponent(jointCollision,jointModel);
jointComp.setMass( jointCollision.getVolume()*getMaterial().getDensity());
components.add(jointComp);
return jointCollision.getVolume()*getMaterial().getDensity();
}
示例3: getCameraPosition
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Returns the current camera position (in world coordinates).
* <br>
* INTERNAL ONLY.
*/
@InternalAPI
public Vector3f getCameraPosition (Vector3f ret) {
synchronized (cameraLock) {
if (ret == null) {
return new Vector3f(cameraPositionWorld);
}
ret.set(cameraPositionWorld);
return ret;
}
}
示例4: toEuler
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Converts the Matrix into Euler angles (roll, pitch, yaw )
*/
public static void toEuler( Matrix3f matrix, Vector3f euler ) {
Vector3f v3d = new Vector3f();
Vector3f zAxis = new Vector3f( 0, 0, -1 );
Vector3f yAxis = new Vector3f( 0, 1, 0 );
Vector3f xAxis = new Vector3f( 1, 0, 0 );
v3d.set( xAxis );
matrix.mult( v3d, v3d );
v3d.x = Math.abs( v3d.x );
v3d.z = 0;
v3d.normalize();
euler.x = xAxis.angleBetween( v3d );
v3d.set( yAxis );
matrix.mult( v3d, v3d );
v3d.z = Math.abs( v3d.z );
v3d.x = 0;
v3d.normalize();
euler.y = yAxis.angleBetween( v3d );
v3d.set( zAxis );
matrix.mult( v3d, v3d );
v3d.y = 0;
v3d.normalize();
euler.z = zAxis.angleBetween( v3d );
if (v3d.x<0)
euler.z = FastMath.TWO_PI-euler.z;
}
示例5: getLookAt
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Return the position and current look direction
* @param position
* @param look
*/
public void getLookAt(Vector3f position, Vector3f look) {
position.set(0,0,0);
transform(position);
look.set(0,0,1);
transform(look);
look.normalizeLocal();
}
示例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: getNaturalTranslation
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public Vector3f getNaturalTranslation(boolean forLeft) {
Vector3f store = new Vector3f();
if (forLeft)
{
return store.set(-0.6f, 0, 0);
}else
{
return store.set(0.6f, 0, 0);
}
}
示例8: getNaturalTranslation
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public Vector3f getNaturalTranslation(boolean forLeft) {
Vector3f store = new Vector3f();
if (forLeft)
{
return store.set(0.5f, 0, 0);
}else
{
return store.set(-0.25f, 0, 0);
}
}
示例9: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
float radius = interpreter.getLeftRadius();
float length = interpreter.getLeftLength();
{
jointCollision=physicsNode.createCylinder("joint");
jointCollision.getLocalTranslation().set(jointModel.getLocalTranslation());
jointCollision.getLocalScale().z= interpreter.getLeftLength()- INNER_DISTANCE;
jointCollision.getLocalScale().x= radius;
jointCollision.getLocalScale().y= radius;
jointCollision.getLocalRotation().set(jointModel.getLocalRotation());
// jointCollision.getLocalRotation().multLocal(new Quaternion().fromAngleNormalAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
jointCollision.setIsCollidable(false);
jointCollision.setMaterial(getMaterial());
physicsNode.attachChild(jointCollision);
}
jointCollision.updateWorldVectors();
store.set(jointCollision.getLocalTranslation());
OdePhysicsComponent jointComp = new OdePhysicsComponent(jointCollision,jointModel);
jointComp.setMass( jointCollision.getVolume()*getMaterial().getDensity());
components.add(jointComp);
return jointCollision.getVolume()*getMaterial().getDensity();
}
示例10: resolveUnderwaterVolume_4Similar
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Helper method to perform an efficient tetrahedralization of the volume under the water, to determine exactly its volume and centroid.
* @param underWaterIndices
* @param vertices
* @param waterPlane
* @param store
* @return
*/
private float resolveUnderwaterVolume_4Similar(int[] underWaterIndices, Vector3f[] vertices, Plane waterPlane, Vector3f store)
{
boolean result = true;
//move the corresponding vertices from the set to intersect the water
//this is the condition where 4 vertices on the same plane are under water; to find out which axis that plane is on:
int axis = getSharedAxis(underWaterIndices[0], underWaterIndices[1]);
axis &= getSharedAxis(underWaterIndices[1], underWaterIndices[2]);
axis &= getSharedAxis(underWaterIndices[2], underWaterIndices[3]);
Vector3f[] pairs = new Vector3f[4];
Vector3f[] originals = new Vector3f[4];
pairs[0] = _temp0;
pairs[1] = _temp1;
pairs[2] = _temp2;
pairs[3] = _temp3;
for (int i = 0; i < underWaterIndices.length;i++)
{
int currentVertex = underWaterIndices[i];
originals[i] = vertices[currentVertex];
pairs[i].set( getNeighbour(axis, currentVertex,vertices));
result &= intersectPairWithPlane(waterPlane,originals[i],pairs[i],pairs[i], true);//vertices[currentVertex],vertices[vertexChange],vertices[vertexChange]);
}
if (!result)//This shouldn't ever occur
return -1;
Vector3f curPos = _tempVector;
//create the corresponding tetrahedra
float volume = getTetrahedronProperties(originals[0],originals[1],originals[2],pairs[2],curPos);
store.set(curPos.multLocal(volume));
float totalVolume = volume;
volume = getTetrahedronProperties(originals[2],originals[3],originals[1],pairs[2],curPos);
store.addLocal(curPos.multLocal(volume));
totalVolume += volume;
volume = getTetrahedronProperties(originals[1],originals[3],pairs[3],pairs[2],curPos);
store.addLocal(curPos.multLocal(volume));
totalVolume += volume;
volume = getTetrahedronProperties(originals[1],originals[0],pairs[3],pairs[1],curPos);
store.addLocal(curPos.multLocal(volume));
totalVolume += volume;
volume = getTetrahedronProperties(originals[0],pairs[2],pairs[3],pairs[1],curPos);
store.addLocal(curPos.multLocal(volume));
totalVolume += volume;
volume = getTetrahedronProperties(originals[0],pairs[2],pairs[1],pairs[0],curPos);
store.addLocal(curPos.multLocal(volume));
totalVolume += volume;
store.divideLocal(totalVolume);
return totalVolume;
}
示例11: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
float radius = interpreter.getRadius();
float height = interpreter.getHeight();
if (height>0f)
{
collision=physicsNode.createCapsule("Capsule");
//and construct physics
collision.getLocalTranslation().set(physicsModel.getLocalTranslation());
collision.getLocalRotation().set(physicsModel.getLocalRotation());
collision.getLocalRotation().multLocal(new Quaternion().fromAngleAxis(FastMath.HALF_PI,Vector3f.UNIT_Y));
collision.getLocalScale().set(physicsModel.getCyl().getLocalScale());
collision.getLocalScale().x/=2f;
collision.getLocalScale().y/=2f;
}else//this is actually a sphere
{
collision = physicsNode.createSphere("CapsuleSphere");
collision.getLocalTranslation().set(physicsModel.getLocalTranslation());
// collision.getLocalRotation().set(capsuleModel.getLocalRotation());
collision.getLocalScale().set(radius,radius,radius);
}
collision.setIsCollidable(false);
collision.setMaterial(this.getMaterial());
physicsNode.attachChild(collision);
store.set(collision.getLocalTranslation());
collision.updateWorldVectors();//note: it is critical to update world scale before calculating the volume!
OdePhysicsComponent comp = new OdePhysicsComponent(collision,physicsModel);
comp.setMass( collision.getVolume() * this.getMaterial().getDensity());
components.add(comp);
return collision.getVolume() * this.getMaterial().getDensity();
}
示例12: 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;
}
示例13: giveSpatialAway
import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
* Give the supplied spatial to another node, preserving the world vectors (scale, translation, rotation) of the node
* @param toGive
* @param receive
*/
public static void giveSpatialAway(Spatial toGive, Node receive)
{
//Node oldParent = toGive.getParent();
Quaternion worldOriginalRotation = new Quaternion();
Quaternion checkRotationTemp = new Quaternion();
Vector3f worldTranslationTemp = new Vector3f();
Quaternion worldRotationTemp = new Quaternion();
toGive.updateWorldVectors();
worldTranslationTemp.set(toGive.getWorldTranslation());
worldOriginalRotation.set (toGive.getWorldRotation());
// Vector3f axis = new Vector3f();
// System.out.println(":" + toGive);
// System.out.println("pre angle: " + toGive.getWorldRotation().toAngleAxis(axis) + "\t" + axis);
receive.updateWorldVectors();
checkRotationTemp.set(receive.getWorldRotation());
(worldRotationTemp.set(checkRotationTemp)).inverseLocal();
/* if (!checkRotationTemp.equals(receive.getWorldRotation()))//only update if neccesary
{
checkRotationTemp.set(receive.getWorldRotation());
(worldRotationTemp.set(checkRotationTemp)).inverseLocal();//cache this for efficiency
}//if this right?? yes*/
//why would this be called twice for a single collision? possibly because the node is first added to a new group (Wasn't previously in one) then combined
// StateManager.getGame().lock();
// try{
receive.attachChild(toGive);//attach all of this object's children to the collision object
// }finally
// {
// StateManager.getGame().unlock();
// }
//(this automatically removes the child from their previous node)
// toGive.updateWorldVectors();//parent is already in sync w/ world
toGive.getLocalRotation().set( worldRotationTemp).multLocal(worldOriginalRotation) ;//worldOriginalRotation.multLocal(worldRotationTemp));//rotate the object to exactly counter the world rotation of the parent object, then rotate it forwards again to its original world rotation
//receive.updateWorldVectors();
toGive.getLocalTranslation().set(receive.worldToLocal(worldTranslationTemp, worldTranslationTemp));
toGive.updateWorldVectors();
// ConstructorTool.updateToWorld(toGive);
//the angle is the same, but the axis is different!
// System.out.println("post angle: " + toGive.getWorldRotation().toAngleAxis(axis) + "\t" + axis);
}
示例14: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
jointCollision=physicsNode.createCylinder("joint");
jointCollision.getLocalTranslation().set(jointModel.getLocalTranslation());
jointCollision.getLocalScale().set(jointModel.getLocalScale());
jointCollision.getLocalScale().x/=2f;
jointCollision.getLocalScale().y/=2f;
jointCollision.getLocalRotation().set(jointModel.getLocalRotation());
jointCollision.setIsCollidable(false);
jointCollision.setMaterial(getMaterial());
physicsNode.attachChild(jointCollision);
jointCollision.updateWorldVectors();
OdePhysicsComponent jointComp = new OdePhysicsComponent(jointCollision,jointModel);
jointComp.setMass( jointCollision.getVolume()*getMaterial().getDensity());
components.add(jointComp);
if(isBearing)
{
jointBearingCollision=physicsNode.createCylinder("joint");
jointBearingCollision.getLocalTranslation().set(jointBearingModel.getLocalTranslation());
jointBearingCollision.getLocalScale().set(jointBearingModel.getLocalScale());
jointBearingCollision.getLocalScale().x/=2f;
jointBearingCollision.getLocalScale().y/=2f;
jointBearingCollision.getLocalRotation().set(jointBearingModel.getLocalRotation());
jointBearingCollision.setIsCollidable(false);
jointBearingCollision.setMaterial(getMaterial());
physicsNode.attachChild(jointBearingCollision);
jointBearingCollision.updateWorldVectors();
float rightMass = jointCollision.getVolume()*getMaterial().getDensity();
float bearingMass = jointBearingCollision.getVolume()*getMaterial().getDensity();
store.set(jointCollision.getLocalTranslation()).multLocal(rightMass).addLocal(jointBearingCollision.getLocalTranslation().mult(bearingMass)).divideLocal(bearingMass+rightMass);
OdePhysicsComponent bearingComp = new OdePhysicsComponent(jointBearingCollision,jointBearingModel);
bearingComp.setMass( jointBearingCollision.getVolume()*getMaterial().getDensity());
components.add(bearingComp);
return rightMass+bearingMass;
}else{
store.set(jointCollision.getLocalTranslation());
return jointCollision.getVolume()*getMaterial().getDensity();
}
}
示例15: buildCollisionGeometries
import com.jme.math.Vector3f; //导入方法依赖的package包/类
@Override
public float buildCollisionGeometries(PhysicsNode physicsNode,Collection<PhysicsComponent> components,
Vector3f store) {
cylCollision = physicsNode.createCylinder("cylinder");
cylCollision.getLocalTranslation().set(interpreter.getLocalTranslation());
cylCollision.getLocalRotation().multLocal(new Quaternion().fromAngleNormalAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
cylCollision.getLocalRotation().multLocal(interpreter.getLocalRotation());
cylCollision.getLocalRotation().set(getParentRotation().mult(cylCollision.getLocalRotation()));
getParentRotation().multLocal(cylCollision.getLocalTranslation());
cylCollision.getLocalTranslation().addLocal(getParentTranslation());
cylCollision.getLocalScale().set(interpreter.getRadius(),interpreter.getRadius(),interpreter.getHeight());
cylCollision.setIsCollidable(false);
cylCollision.setMaterial(Material.GHOST);
PhysicsSpatialMonitor.getInstance().registerGhost(cylCollision);
cylCollision.updateWorldVectors();
/*float radius = cylCollision.getLocalScale().x;
float length = cylCollision.getLocalScale().z;
//Build an aserisk down the middle of the cylinder, out of boxes, to act as the inner, backup cylinder.
//its radius will be 90% of the actual radius.
{
float numberOfBoxes = 8;
float boxRadius = radius * 0.96f;
float boxLength = length * 0.96f;
float theta = FastMath.PI/numberOfBoxes;
float halfWidth = FastMath.sin(theta/2f)*boxRadius;
float boxHeight =FastMath.sqrt( boxRadius*boxRadius - halfWidth*halfWidth) * 2f;
float boxWidth = halfWidth*2f;
for (int i = 0 ;i< numberOfBoxes;i++)
{
//create the box, then rotate it into position
PhysicsBox box = physicsNode.createBox("CylinderAsterisk" + i);
box.getLocalScale().set(boxHeight ,boxWidth ,boxLength);
box.getLocalTranslation().set(cylCollision.getLocalTranslation());
Quaternion boxRotation = new Quaternion().fromAngleNormalAxis(theta*i,Vector3f.UNIT_Z);
box.getLocalRotation().set(cylCollision.getLocalRotation());
// box.getLocalRotation().multLocal(new Quaternion().fromAngleNormalAxis(FastMath.HALF_PI,Vector3f.UNIT_Y));
box.getLocalRotation().multLocal(boxRotation);
box.setIsCollidable(false);
// box.setMaterial(this.getMaterial());
physicsNode.attachChild(box);
physicsNode.updateWorldVectors();
box.setMaterial(Material.GHOST);
PhysicsSpatialMonitor.getInstance().registerGhost(box);
// box.getLocalRotation().multLocal(cylCollision.getLocalRotation());
}
}*/
OdePhysicsComponent comp = new OdePhysicsComponent(cylCollision,null);
comp.setMass( 0f);
components.add(comp);
physicsNode.attachChild(cylCollision);
cylCollision.updateWorldVectors();//note: it is critical to update world scale before calculating the volume!
store.set(cylCollision.getLocalTranslation());
return 0;
}