当前位置: 首页>>代码示例>>Java>>正文


Java Vector3f.normalizeLocal方法代码示例

本文整理汇总了Java中com.jme.math.Vector3f.normalizeLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.normalizeLocal方法的具体用法?Java Vector3f.normalizeLocal怎么用?Java Vector3f.normalizeLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme.math.Vector3f的用法示例。


在下文中一共展示了Vector3f.normalizeLocal方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:36,代码来源:PlacemarkPlugin.java

示例2: 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();
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:14,代码来源:CellTransform.java

示例3: strongLocalNormalize

import com.jme.math.Vector3f; //导入方法依赖的package包/类
private void strongLocalNormalize(Vector3f vector)
{
	vector.normalizeLocal();
	if(Math.abs(vector.x)<=STRONG_EPSILON)
		vector.x = 0f;
	if(Math.abs(vector.y) <= STRONG_EPSILON)
		vector.y = 0f;
	if(Math.abs(vector.z) <= STRONG_EPSILON)
		vector.z = 0f;
	vector.normalizeLocal();
}
 
开发者ID:sambayless,项目名称:golems,代码行数:12,代码来源:OdeMultimeter.java

示例4: project

import com.jme.math.Vector3f; //导入方法依赖的package包/类
/**
 * Project a vector onto a plane (define by the normal Normal)
 * Inputs are assumed to be normalized. If the normal equals the vector (or very nearly does), return false, and set store to zero.
 * @param vector
 * @param normal
 * @param store The (normalized) projection
 * @return
 */
private boolean project(Vector3f vector, Vector3f normal, Vector3f store) {
	//take the zero vector, project it into the plane, and normalize
	//A || B = B x (AxB / |B|) / |B| projection of a vector A onto a plane with normal B. NOTE: division happens AFTER crossing
	//See: http://www.euclideanspace.com/maths/geometry/elements/plane/lineOnPlane/index.htm
	//assuming normalized inputs, we can skip some steps...
	
	if(normal.distanceSquared(vector)<FastMath.FLT_EPSILON)
	{
		store.zero();
		return false;
	}
	else
	{
			store.set(vector);
			store.crossLocal(normal);
			normal.cross(store,store);
			if(store.lengthSquared()<=FastMath.FLT_EPSILON)
			{
				store.zero();
				return false;
			}
			store.normalizeLocal();
			return true;
	}
//	worldZeroVector =(orientation.getDirection().cross( worldZeroVector));//.cross(orientation.getDirection()));
//	worldZeroVector.set( orientation.getDirection().cross(worldZeroVector.cross(orientation.getDirection()))).normalizeLocal();

}
 
开发者ID:sambayless,项目名称:golems,代码行数:37,代码来源:OrientingNode.java

示例5: 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);
}
 
开发者ID:sambayless,项目名称:golems,代码行数:10,代码来源:BuoyantSphere.java

示例6: 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);
}
 
开发者ID:sambayless,项目名称:golems,代码行数:41,代码来源:Tetrahedron.java

示例7: 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);
}
   }
 
开发者ID:josmas,项目名称:openwonderland,代码行数:73,代码来源:FollowMe.java

示例8: mouseMovementAction

import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void mouseMovementAction(Vector2f mousePos, boolean left,
		boolean right) {

	if (left)
	{
		if (GeneralSettings.getInstance().getCameraZoom().isValue())
		{
			float distY =  mousePos.y-initialMouse.y ;
	
			float dist = FastMath.sqr(distY)/5000f;
			if (FastMath.abs(dist)>5f)
				dist = 5f;
			
			dist*= FastMath.sign(distY);
		
			zoomVelocity = dist;
			cameraVelocity.zero();
		}else
		{
			
			cameraVelocity.set(StateManager.getCameraManager().getCameraRotation().mult(new Vector3f(-(initialMouse.x-mousePos.x)/50f, (StateManager.IS_AWT_MOUSE?1:-1) *(initialMouse.y-mousePos.y)/50f, 0)));
			zoomVelocity = 0;
		}
		
		//might switch to a 45 perspective up/down movement later
	}
	if (right)
	{		

	
		 velocity = new Vector2f(mousePos.x - initialMouse.x,(StateManager.IS_AWT_MOUSE?1:-1) *(mousePos.y -initialMouse.y));
		
		Vector3f dir = StateManager.getCameraManager().getCameraRotation().mult(StateManager.getCameraManager().getCameraPosition());
		dir.normalizeLocal();
		//this has probably been 90 degrees off...

		xVelocity = (velocity.x*velocity.x)/(7000f);
	//	System.out.print(xVelocity);
		if (xVelocity*approxTime>	MAX_ROTATION)
			xVelocity = MAX_ROTATION/approxTime;
		
		yVelocity = (velocity.y*velocity.y)/(7000f) ;
		if (yVelocity*approxTime>	MAX_ROTATION)
			yVelocity = MAX_ROTATION/approxTime;
		//System.out.println("\t" + xVelocity);
		rotationXVelocity.fromAngleAxis(Math.signum(velocity.x) * xVelocity*approxTime, xAxis);
		negativeRotationXVelocity.fromAngleAxis(-Math.signum(velocity.x) * xVelocity*approxTime, xAxis);
		velocityY =Math.signum(velocity.y)*yVelocity*approxTime;
		//rotationVelocity.multLocal(new Quaternion().fromAngleAxis(Math.signum(velocity.y)*yVelocity*approxTime, yAxis));
		
		
		
	}
}
 
开发者ID:sambayless,项目名称:golems,代码行数:55,代码来源:CameraTool.java

示例9: mouseMovementAction

import com.jme.math.Vector3f; //导入方法依赖的package包/类
public void mouseMovementAction(Vector2f mousePos, boolean left,
		boolean right) {

	if (left)
	{
		if (GeneralSettings.getInstance().getCameraZoom().isValue())
		{
			float distY =  mousePos.y-initialMouse.y ;
	
			float dist = FastMath.sqr(distY)/5000f;
			if (FastMath.abs(dist)>5f)
				dist = 5f;
			
			dist*= FastMath.sign(distY);
			
			zoomVelocity = dist;
			cameraVelocity.zero();
		}else
		{
			cameraVelocity.set(StateManager.getCameraManager().getCameraRotation().mult(new Vector3f(-(initialMouse.x-mousePos.x)/50f, (StateManager.IS_AWT_MOUSE?1:-1) *(initialMouse.y-mousePos.y)/50f, 0)));
			zoomVelocity = 0;
		}
		
		//might switch to a 45 perspective up/down movement later
	}
	if (right)
	{		
		
	
		 velocity = new Vector2f(mousePos.x - initialMouse.x,(StateManager.IS_AWT_MOUSE?1:-1) *(mousePos.y -initialMouse.y));
		
		Vector3f dir = StateManager.getCameraManager().getCameraRotation().mult(StateManager.getCameraManager().getCameraPosition());
		dir.normalizeLocal();
		//this has probably been 90 degrees off...

		xVelocity = (velocity.x*velocity.x)/(7000f);
	//	System.out.print(xVelocity);
		if (xVelocity*approxTime>	MAX_ROTATION)
			xVelocity = MAX_ROTATION/approxTime;
		
		yVelocity = (velocity.y*velocity.y)/(7000f) ;
		if (yVelocity*approxTime>	MAX_ROTATION)
			yVelocity = MAX_ROTATION/approxTime;
		//System.out.println("\t" + xVelocity);
		rotationXVelocity.fromAngleAxis(Math.signum(velocity.x) * xVelocity*approxTime, xAxis);
		negativeRotationXVelocity.fromAngleAxis(-Math.signum(velocity.x) * xVelocity*approxTime, xAxis);
		velocityY =Math.signum(velocity.y)*yVelocity*approxTime;
		//rotationVelocity.multLocal(new Quaternion().fromAngleAxis(Math.signum(velocity.y)*yVelocity*approxTime, yAxis));
		
	}
}
 
开发者ID:sambayless,项目名称:golems,代码行数:52,代码来源:CameraSelectionTool.java

示例10: makeStaticJoint

import com.jme.math.Vector3f; //导入方法依赖的package包/类
private static void makeStaticJoint(DynamicPhysicsNode physicsNode, PhysicsCollisionGeometry axle,PhysicsCollisionGeometry staticAxle, boolean useLeft,Vector3f hingeCenter, boolean universal, OdePhysicsEnvironment compiledEnvironment)
{

	Joint joint = physicsNode.getSpace().createJoint();//this already is set, but for clarity its here too
	compiledEnvironment.setJointStatic(staticAxle.getPhysicsNode(),joint);
        

	joint.setCollisionEnabled(true);
	

	physicsNode.updateWorldVectors();
	
	axle.updateWorldVectors();
	staticAxle.updateWorldVectors();
	
	Vector3f localNormal = new Vector3f(0,1,0);
	Vector3f normal = axle.getWorldRotation().mult(localNormal);
	normal.normalizeLocal();
	
	Vector3f pos1 = new Vector3f().set(axle.getWorldTranslation());//this wont work if, for instance, these aren't yet attached to their world...
	

	Vector3f pos2 = new Vector3f().set(staticAxle.getWorldTranslation());

	Vector3f dif = pos1.subtract(pos2, new Vector3f());
	dif.normalizeLocal();
	
       joint.attach(physicsNode) ;
       
       joint.setAnchor(new Vector3f(hingeCenter)); //the anchor has to be set at the center of the SECOND node
	
       
       RotationalJointAxis axis1 = joint.createRotationalAxis();	     
       //node.axis1.setDirection( dif.cross(normal) );
       axis1.setDirection(axle.getWorldRotation().mult(new Vector3f(0,0,1)));
       
       RotationalJointAxis axis2 = joint.createRotationalAxis();	     
       axis2.setDirection( axle.getWorldRotation().mult(new Vector3f(0,1,0)) );
       axis2.setRelativeToSecondObject(true);
       if(!universal){
       RotationalJointAxis axis3 = joint.createRotationalAxis();	     
       axis3.setDirection( axle.getWorldRotation().mult(new Vector3f(1,0,0)) );
       axis3.setRelativeToSecondObject(true);
       }
}
 
开发者ID:sambayless,项目名称:golems,代码行数:46,代码来源:OdeBallAndSocketStructure.java

示例11: makeStaticJoint

import com.jme.math.Vector3f; //导入方法依赖的package包/类
private   RotationalJointAxis makeStaticJoint(final DynamicPhysicsNode physicsNode, final PhysicsCollisionGeometry axle,PhysicsCollisionGeometry staticAxle, boolean leftDynamic,OdePhysicsEnvironment compiledEnvironment)
{
	
	Joint joint = physicsNode.getSpace().createJoint();//this already is set, but for clarity its here too
	  compiledEnvironment.setJointStatic(staticAxle.getPhysicsNode(),joint);
	joint.setCollisionEnabled(true);
	

	physicsNode.updateWorldVectors();
	
	axle.updateWorldVectors();
	staticAxle.updateWorldVectors();

	Vector3f localNormal = new Vector3f(0,1,0);
	Vector3f normal = axle.getWorldRotation().mult(localNormal);
	normal.normalizeLocal();

       joint.attach(physicsNode) ;
       
     
       
       Vector3f offSet = new Vector3f().set(axle.getLocalTranslation());//passes through center of node
       
       joint.setAnchor(physicsNode.localToWorld(offSet, offSet)); //the anchor has to be set at the center of the SECOND node
	
       
      final RotationalJointAxis axis = joint.createRotationalAxis();	
    
       if(leftDynamic)
       {
       	axis.setDirection( axle.getWorldRotation().mult(Vector3f.UNIT_Z.mult(-1f)) );//if there is rotation, this might be messed...
       }else{
       	  axis.setDirection( axle.getWorldRotation().mult(Vector3f.UNIT_Z) );//if there is rotation, this might be messed...
       }
     //  System.out.println(axle.getWorldRotation().mult(Vector3f.UNIT_Z));
       motorCallback = new MotorCallback()
       {

		
		public void setAvailableAcceleration(float amount) {
			
			axis.setAvailableAcceleration(amount);
		}

		
		public void setDesiredVelocity(float amount) {
			axis.setDesiredVelocity(amount);
		}

		
		public float getVelocity() {
			return axis.getVelocity();
		}

		
		public float getPosition() {
			return axis.getPosition();
		}

		
		public void applyForce(float force) {
			Vector3f forceVector = axis.getDirection(new Vector3f()).multLocal(-force);
			physicsNode.addForce(forceVector, axle.getLocalTranslation());
		}

		
		public void applyTorque(float torque, float time) {
			Vector3f forceVector = axis.getDirection(new Vector3f()).multLocal(torque);
			physicsNode.addTorque(forceVector);
		}

       };
       
       return axis;
}
 
开发者ID:sambayless,项目名称:golems,代码行数:76,代码来源:OdeAxleStructure.java


注:本文中的com.jme.math.Vector3f.normalizeLocal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。