• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SteeringBehavior类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SteeringBehavior类属于com.badlogic.gdx.ai.steer包,在下文中一共展示了SteeringBehavior类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: calculateRealSteering

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的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


示例2: getTarget

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public static SteerLocation getTarget(SteeringBehavior behavior){
    SteerLocation targetL = null;
    if(behavior instanceof Face) targetL = (SteerLocation)((Face) behavior).getTarget();
    else if(behavior instanceof Arrive) targetL = (SteerLocation)((Arrive) behavior).getTarget();
    else if(behavior instanceof Seek) targetL = (SteerLocation)((Seek) behavior).getTarget();
    return targetL;
}
 
开发者ID:unlimitedggames,项目名称:gdxjam-ugg,代码行数:8,代码来源:BehaviorUtils.java


示例3: createSquad

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public static Entity createSquad (Vector2 position, Faction faction) {
	Entity entity = builder.createEntity(EntityCategory.SQUAD, position).physicsBody(BodyType.DynamicBody).circleSensor(30.0f)
		.faction(faction).target().filter(EntityCategory.SQUAD, 0, EntityCategory.SQUAD | EntityCategory.RESOURCE)
		.steeringBehavior().stateMachine().getWithoutAdding();

	SteerableComponent steerable = engine.createComponent(SteerableComponent.class).init(
		Components.PHYSICS.get(entity).getBody(), 30.0f);
	SquadComponent squadComp = engine.createComponent(SquadComponent.class).init(steerable);
	squadComp.targetLocation.getPosition().set(position);
	entity.add(squadComp);

	// A good rule of thumb is to make the maximum speed of the formation
	// around
	// half that of the members. We also give the anchor point far less
	// acceleration.
	steerable.setMaxLinearSpeed(SteerableComponent.MAX_LINEAR_SPEED / 2);
	steerable.setMaxLinearAcceleration(SteerableComponent.MAX_LINEAR_ACCELERATION / 10);

	Arrive<Vector2> arriveSB = new Arrive<Vector2>(steerable).setTarget(squadComp.targetLocation).setTimeToTarget(0.001f)
		.setDecelerationRadius(2f).setArrivalTolerance(0.0001f);
	SteeringBehavior<Vector2> sb = arriveSB;
	
	RadiusProximity<Vector2> proximity = new RadiusProximity<Vector2>(steerable, squadComp.friendlyAgents, 3.0f);
	Separation<Vector2> separationSB = new Separation<Vector2>(steerable, proximity);

	BlendedSteering<Vector2> blendedSteering = new BlendedSteering<Vector2>(steerable) //
		.setLimiter(NullLimiter.NEUTRAL_LIMITER) //
		.add(separationSB, 10000f)
		.add(arriveSB, 0.5f);
	sb = blendedSteering;
	Components.FSM.get(entity).changeState(SquadComponent.DEFAULT_STATE);

	Components.STEERING_BEHAVIOR.get(entity).setBehavior(sb);

	entity.add(steerable);

	engine.addEntity(entity);
	return entity;
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:40,代码来源:EntityFactory.java


示例4: remove

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
/** Removes a steering behavior from the list.
 * @param behavior the steering behavior to remove */
public void remove (SteeringBehavior<T> behavior) {
	for (int i = 0; i < list.size; i++) {
		if(list.get(i).behavior == behavior) {
			list.removeIndex(i);
			return;
		}
	}
}
 
开发者ID:libgdx,项目名称:gdx-ai,代码行数:11,代码来源:BlendedSteering.java


示例5: setBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public void setBehavior(SteeringBehavior<Vector2> behavior) {
    this.behavior = behavior;
}
 
开发者ID:MSLacerda,项目名称:DarkDay,代码行数:4,代码来源:B2dSteeringEntity.java


示例6: getBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public SteeringBehavior<Vector2> getBehavior() {
    return behavior;
}
 
开发者ID:MSLacerda,项目名称:DarkDay,代码行数:4,代码来源:B2dSteeringEntity.java


示例7: getBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public <T extends SteeringBehavior> SteeringBehavior getBehavior(Class<T> behaviorClass){
    return cachedBehaviors.get(behaviorClass);
}
 
开发者ID:unlimitedggames,项目名称:gdxjam-ugg,代码行数:4,代码来源:GameEntity.java


示例8: cacheBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public GameEntity cacheBehavior(SteeringBehavior behavior){
    if(behavior == null) return this;
    this.cachedBehaviors.put(behavior.getClass(), behavior);
    return this;
}
 
开发者ID:unlimitedggames,项目名称:gdxjam-ugg,代码行数:6,代码来源:GameEntity.java


示例9: getSteeringBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public SteeringBehavior<Vector2> getSteeringBehavior() {
	return steeringBehavior;
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:4,代码来源:Agent.java


示例10: setSteeringBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
	this.steeringBehavior = steeringBehavior;
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:4,代码来源:Agent.java


示例11: BehaviorAndWeight

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public BehaviorAndWeight (SteeringBehavior<T> behavior, float weight) {
	this.behavior = behavior;
	this.weight = weight;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:5,代码来源:BlendedSteering.java


示例12: getBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public SteeringBehavior<T> getBehavior () {
	return behavior;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:4,代码来源:BlendedSteering.java


示例13: setBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public void setBehavior (SteeringBehavior<T> behavior) {
	this.behavior = behavior;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:4,代码来源:BlendedSteering.java


示例14: add

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
/** Adds the specified behavior to the priority list.
 * @param behavior the behavior to add
 * @return this behavior for chaining. */
public PrioritySteering<T> add (SteeringBehavior<T> behavior) {
	behaviors.add(behavior);
	return this;
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:8,代码来源:PrioritySteering.java


示例15: getSteeringBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public SteeringBehavior<Vector2> getSteeringBehavior() {
    return steeringBehavior;
}
 
开发者ID:yichen0831,项目名称:Pacman_libGdx,代码行数:4,代码来源:GhostAI.java


示例16: setSteeringBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
    this.steeringBehavior = steeringBehavior;
}
 
开发者ID:yichen0831,项目名称:Pacman_libGdx,代码行数:4,代码来源:GhostAI.java


示例17: getSteeringBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
@Override
public SteeringBehavior<Vector3> getSteeringBehavior() {
	return prioritySteering;
}
 
开发者ID:jsjolund,项目名称:GdxDemo3D,代码行数:5,代码来源:CollisionAvoidanceSteererBase.java


示例18: processEntity

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
	SteeringBehavior<Vector2> behavior = Components.STEERING_BEHAVIOR.get(entity).getBehavior();
	SteerableComponent steerable = Components.STEERABLE.get(entity);
	
	if(behavior == null) return;
	if(steerable.getBody() == null) return;	//We shouldn't need this
	behavior.calculateSteering(steeringOutput);
	boolean anyAccelerations = false;
	Body body = steerable.getBody();
	
	if (!steeringOutput.linear.isZero()) {
		Vector2 force = steeringOutput.linear.scl(deltaTime);
		body.applyForceToCenter(force, true);
		anyAccelerations = true;
	}

	
	// Update orientation and angular velocity
	if (steerable.isIndependentFacing()) {
		if (steeringOutput.angular != 0) {
			body.applyTorque(steeringOutput.angular * deltaTime, true);
			anyAccelerations = true;
		}
	}
	
	else {
		// If we haven't got any velocity, then we can do nothing.
		Vector2 linVel = body.getLinearVelocity();
		if (!linVel.isZero(steerable.getZeroLinearSpeedThreshold())) {
			float newOrientation = steerable.vectorToAngle(linVel);
			body.setAngularVelocity((newOrientation - steerable.getAngularVelocity()) * deltaTime); // this is superfluous if independentFacing is always true
			body.setTransform(body.getPosition(), newOrientation);
		}
	}

	if (anyAccelerations) {
		// Cap the linear speed
		Vector2 velocity = body.getLinearVelocity();
		float currentSpeedSquare = velocity.len2();
		float maxLinearSpeed = steerable.getMaxLinearSpeed();
		if (currentSpeedSquare > maxLinearSpeed * maxLinearSpeed) {
			body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float)Math.sqrt(currentSpeedSquare)));
		}

		// Cap the angular speed
		float maxAngVelocity = steerable.getMaxAngularSpeed();
		if (body.getAngularVelocity() > maxAngVelocity) {
			body.setAngularVelocity(maxAngVelocity);
		}
	}
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:53,代码来源:SteeringSystem.java


示例19: init

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public SteeringBehaviorComponent init (SteeringBehavior<Vector2> behavior) {
	setBehavior(behavior);
	return this;
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:5,代码来源:SteeringBehaviorComponent.java


示例20: setBehavior

import com.badlogic.gdx.ai.steer.SteeringBehavior; //导入依赖的package包/类
public void setBehavior (SteeringBehavior<Vector2> behavior) {
	this.behavior = behavior;
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:4,代码来源:SteeringBehaviorComponent.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IntegrationContextUtils类代码示例发布时间:2022-05-22
下一篇:
Java Int2LongMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap