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


Java SteeringAcceleration.setZero方法代码示例

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


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

示例1: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> blendedSteering) {
	// Clear the output to start with
	blendedSteering.setZero();

	// Go through all the behaviors
	int len = list.size;
	for (int i = 0; i < len; i++) {
		BehaviorAndWeight<T> bw = list.get(i);

		// Calculate the behavior's steering
		bw.behavior.calculateSteering(steering);

		// Scale and add the steering to the accumulator
		blendedSteering.mulAdd(steering, bw.weight);
	}

	Limiter actualLimiter = getActualLimiter();

	// Crop the result
	blendedSteering.linear.limit(actualLimiter.getMaxLinearAcceleration());
	if (blendedSteering.angular > actualLimiter.getMaxAngularAcceleration())
		blendedSteering.angular = actualLimiter.getMaxAngularAcceleration();

	return blendedSteering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:27,代码来源:BlendedSteering.java

示例2: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	// We'll need epsilon squared later.
	float epsilonSquared = epsilon * epsilon;

	// Go through the behaviors until one has a large enough acceleration
	int n = behaviors.size;
	selectedBehaviorIndex = -1;
	for (int i = 0; i < n; i++) {
		selectedBehaviorIndex = i;

		SteeringBehavior<T> behavior = behaviors.get(i);

		// Calculate the behavior's steering
		behavior.calculateSteering(steering);

		// If we're above the threshold return the current steering
		if (steering.calculateSquareMagnitude() > epsilonSquared) return steering;
	}

	// If we get here, it means that no behavior had a large enough acceleration,
	// so return the small acceleration from the final behavior or zero if there are
	// no behaviors in the list.
	return n > 0 ? steering : steering.setZero();
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:26,代码来源:PrioritySteering.java

示例3: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	steering.setZero();

	averageVelocity = steering.linear;

	int neighborCount = proximity.findNeighbors(this);

	if (neighborCount > 0) {
		// Average the accumulated velocities
		averageVelocity.scl(1f / neighborCount);

		// Match the average velocity.
		// Notice that steering.linear and averageVelocity are the same vector here.
		averageVelocity.sub(owner.getLinearVelocity()).limit(getActualLimiter().getMaxLinearAcceleration());
	}

	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:20,代码来源:Alignment.java

示例4: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<Vector2> calculateRealSteering(SteeringAcceleration<Vector2> steering) {
    targetPosition = owner.getPosition().x + ((wanderOrientation == 1)? 0.5f : -0.5f);
    if (!stopped) {
        if (Utils.randRange(0f, 1f) < 0.01f) {
            stopTime = Utils.randRange(minStopTime, maxStopTime);
            stopped = true;
        }
        return doSteering(steering);
    }
    else {
        currStopTime += Gdx.graphics.getDeltaTime();
        if (currStopTime >= stopTime) {
            stopped = false;
            currStopTime = 0;
            wanderOrientation = Utils.randRange(0, 1);
        }
        steering.setZero();
    }

    return steering;
}
 
开发者ID:ALPSquid,项目名称:0Bit-Engine,代码行数:23,代码来源:Wander2D.java

示例5: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<Vector2> calculateRealSteering(SteeringAcceleration<Vector2> steering) {
    if (!stopped) {
        if ((targetPosition == entity.getMinX() && owner.getPosition().x <= targetPosition + 0.1) ||
                (targetPosition == entity.getMaxX() && owner.getPosition().x >= targetPosition - 0.1)) {
            stopTime = Utils.randRange(minStopTime, maxStopTime);
            stopped = true;
        }
        return doSteering(steering);
    } else {
        currStopTime += Gdx.graphics.getDeltaTime();
        if (currStopTime >= stopTime) {
            stopped = false;
            currStopTime = 0;
            targetPosition = (targetPosition == entity.getMaxX()) ? entity.getMinX() : entity.getMaxX();
        }
        steering.setZero();
    }
    return steering;
}
 
开发者ID:ALPSquid,项目名称:0Bit-Engine,代码行数:21,代码来源:Patrol2D.java

示例6: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	T ownerPosition = owner.getPosition();
	float minDistanceSquare = Float.POSITIVE_INFINITY;

	// Get the updated rays
	Ray<T>[] inputRays = rayConfiguration.updateRays();

	// Process rays
	for (int i = 0; i < inputRays.length; i++) {
		// Find the collision with current ray
		boolean collided = raycastCollisionDetector.findCollision(outputCollision, inputRays[i]);

		if (collided) {
			float distanceSquare = ownerPosition.dst2(outputCollision.point);
			if (distanceSquare < minDistanceSquare) {
				minDistanceSquare = distanceSquare;
				// Swap collisions
				Collision<T> tmpCollision = outputCollision;
				outputCollision = minOutputCollision;
				minOutputCollision = tmpCollision;
			}
		}
	}

	// Return zero steering if no collision has occurred
	if (minDistanceSquare == Float.POSITIVE_INFINITY) return steering.setZero();

	// Calculate and seek the target position
	steering.linear.set(minOutputCollision.point)
		.mulAdd(minOutputCollision.normal, owner.getBoundingRadius() + distanceFromBoundary).sub(owner.getPosition()).nor()
		.scl(getActualLimiter().getMaxLinearAcceleration());

	// No angular acceleration
	steering.angular = 0;

	// Output steering acceleration
	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:40,代码来源:RaycastObstacleAvoidance.java

示例7: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	shortestTime = Float.POSITIVE_INFINITY;
	firstNeighbor = null;
	firstMinSeparation = 0;
	firstDistance = 0;
	relativePosition = steering.linear;

	// Take into consideration each neighbor to find the most imminent collision.
	int neighborCount = proximity.findNeighbors(this);

	// If we have no target, then return no steering acceleration
	//
	// NOTE: You might think that the condition below always evaluates to true since
	// firstNeighbor has been set to null when entering this method. In fact, we have just
	// executed findNeighbors(this) that has possibly set firstNeighbor to a non null value
	// through the method reportNeighbor defined below.
	if (neighborCount == 0 || firstNeighbor == null) return steering.setZero();

	// If we're going to hit exactly, or if we're already
	// colliding, then do the steering based on current position.
	if (firstMinSeparation <= 0 || firstDistance < owner.getBoundingRadius() + firstNeighbor.getBoundingRadius()) {
		relativePosition.set(firstNeighbor.getPosition()).sub(owner.getPosition());
	} else {
		// Otherwise calculate the future relative position
		relativePosition.set(firstRelativePosition).mulAdd(firstRelativeVelocity, shortestTime);
	}

	// Avoid the target
	// Notice that steerling.linear and relativePosition are the same vector
	relativePosition.nor().scl(-getActualLimiter().getMaxLinearAcceleration());

	// No angular acceleration
	steering.angular = 0f;

	// Output the steering
	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:39,代码来源:CollisionAvoidance.java

示例8: arrive

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
protected SteeringAcceleration<T> arrive (SteeringAcceleration<T> steering, T targetPosition) {
	// Get the direction and distance to the target
	T toTarget = steering.linear.set(targetPosition).sub(owner.getPosition());
	float distance = toTarget.len();

	// Check if we are there, return no steering
	if (distance <= arrivalTolerance) return steering.setZero();

	Limiter actualLimiter = getActualLimiter();
	// Go max speed
	float targetSpeed = actualLimiter.getMaxLinearSpeed();

	// If we are inside the slow down radius calculate a scaled speed
	if (distance <= decelerationRadius) targetSpeed *= distance / decelerationRadius;

	// Target velocity combines speed and direction
	T targetVelocity = toTarget.scl(targetSpeed / distance); // Optimized code for: toTarget.nor().scl(targetSpeed)

	// Acceleration tries to get to the target velocity without exceeding max acceleration
	// Notice that steering.linear and targetVelocity are the same vector
	targetVelocity.sub(owner.getLinearVelocity()).scl(1f / timeToTarget).limit(actualLimiter.getMaxLinearAcceleration());

	// No angular acceleration
	steering.angular = 0f;

	// Output the steering
	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:29,代码来源:Arrive.java

示例9: face

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
protected SteeringAcceleration<T> face (SteeringAcceleration<T> steering, T targetPosition) {
	// Get the direction to target
	T toTarget = steering.linear.set(targetPosition).sub(owner.getPosition());

	// Check for a zero direction, and return no steering if so
	if (toTarget.isZero(getActualLimiter().getZeroLinearSpeedThreshold())) return steering.setZero();

	// Calculate the orientation to face the target
	float orientation = owner.vectorToAngle(toTarget);

	// Delegate to ReachOrientation
	return reachOrientation(steering, orientation);
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:14,代码来源:Face.java

示例10: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	// Predictive or non-predictive behavior?
	T location = (predictionTime == 0) ?
	// Use the current position of the owner
	owner.getPosition()
		:
		// Calculate the predicted future position of the owner. We're reusing steering.linear here.
		steering.linear.set(owner.getPosition()).mulAdd(owner.getLinearVelocity(), predictionTime);

	// Retrieve the flow vector at the specified location
	T flowVector = flowField.lookup(location);
	
	// Clear both linear and angular components
	steering.setZero();

	if (flowVector != null && !flowVector.isZero()) {
		Limiter actualLimiter = getActualLimiter();

		// Calculate linear acceleration
		steering.linear.mulAdd(flowVector, actualLimiter.getMaxLinearSpeed()).sub(owner.getLinearVelocity())
			.limit(actualLimiter.getMaxLinearAcceleration());
	}

	// Output steering
	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:28,代码来源:FollowFlowField.java

示例11: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
public SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	// Check if we have a trajectory, and create one if not.
	if (target == null) {
		target = calculateTarget();
		callback.reportAchievability(isJumpAchievable);
	}

	// If the trajectory is zero, return no steering acceleration
	if (!isJumpAchievable) return steering.setZero();

	// Check if the owner has reached target position and velocity with acceptable tolerance
	if (owner.getPosition().epsilonEquals(target.getPosition(), takeoffPositionTolerance)) {
		if (DEBUG_ENABLED) GdxAI.getLogger().info("Jump", "Good position!!!");
		if (owner.getLinearVelocity().epsilonEquals(target.getLinearVelocity(), takeoffVelocityTolerance)) {
			if (DEBUG_ENABLED) GdxAI.getLogger().info("Jump", "Good Velocity!!!");
			isJumpAchievable = false;
			// Perform the jump, and return no steering (the owner is airborne, no need to steer).
			callback.takeoff(maxVerticalVelocity, airborneTime);
			return steering.setZero();
		} else {
			if (DEBUG_ENABLED)
				GdxAI.getLogger().info("Jump",
					"Bad Velocity: Speed diff. = "
						+ planarVelocity.set(target.getLinearVelocity()).sub(owner.getLinearVelocity()).len() + ", diff = ("
						+ planarVelocity + ")");
		}
	}

	// Delegate to MatchVelocity
	return super.calculateRealSteering(steering);
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:33,代码来源:Jump.java

示例12: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	// Check for a zero direction, and return no steering if so
	if (owner.getLinearVelocity().isZero(getActualLimiter().getZeroLinearSpeedThreshold())) return steering.setZero();

	// Calculate the orientation based on the velocity of the owner
	float orientation = owner.vectorToAngle(owner.getLinearVelocity());

	// Delegate to ReachOrientation
	return reachOrientation(steering, orientation);
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:12,代码来源:LookWhereYouAreGoing.java

示例13: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
	// Initialize member variables used by the callback
	this.distance2ToClosest = Float.POSITIVE_INFINITY;
	this.toObstacle = steering.linear;

	// Find neighbors (the obstacles) using this behavior as callback
	int neighborsCount = proximity.findNeighbors(this);

	// If no suitable obstacles found return no steering otherwise use Arrive on the hiding spot
	return neighborsCount == 0 ? steering.setZero() : arrive(steering, bestHidingSpot);
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:13,代码来源:Hide.java

示例14: reachOrientation

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
/** Produces a steering that tries to align the owner to the target orientation. This method is called by subclasses that want
 * to align to a certain orientation.
 * @param steering the steering to be calculated.
 * @param targetOrientation the target orientation you want to align to.
 * @return the calculated steering for chaining. */
protected SteeringAcceleration<T> reachOrientation (SteeringAcceleration<T> steering, float targetOrientation) {
	// Get the rotation direction to the target wrapped to the range [-PI, PI]
	float rotation = ArithmeticUtils.wrapAngleAroundZero(targetOrientation - owner.getOrientation());

	// Absolute rotation
	float rotationSize = rotation < 0f ? -rotation : rotation;

	// Check if we are there, return no steering
	if (rotationSize <= alignTolerance) return steering.setZero();

	Limiter actualLimiter = getActualLimiter();

	// Use maximum rotation
	float targetRotation = actualLimiter.getMaxAngularSpeed();

	// If we are inside the slow down radius, then calculate a scaled rotation
	if (rotationSize <= decelerationRadius) targetRotation *= rotationSize / decelerationRadius;

	// The final target rotation combines
	// speed (already in the variable) and direction
	targetRotation *= rotation / rotationSize;

	// Acceleration tries to get to the target rotation
	steering.angular = (targetRotation - owner.getAngularVelocity()) / timeToTarget;

	// Check if the absolute acceleration is too great
	float angularAcceleration = steering.angular < 0f ? -steering.angular : steering.angular;
	if (angularAcceleration > actualLimiter.getMaxAngularAcceleration())
		steering.angular *= actualLimiter.getMaxAngularAcceleration() / angularAcceleration;

	// No linear acceleration
	steering.linear.setZero();

	// Output the steering
	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:42,代码来源:ReachOrientation.java

示例15: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入方法依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {

	steering.setZero();

	centerOfMass = steering.linear;

	int neighborCount = proximity.findNeighbors(this);

	if (neighborCount > 0) {

		// The center of mass is the average of the sum of positions
		centerOfMass.scl(1f / neighborCount);

		// Now seek towards that position.
		centerOfMass.sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration());
	}

	return steering;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:21,代码来源:Cohesion.java


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