本文整理汇总了Java中javax.vecmath.Vector2d.add方法的典型用法代码示例。如果您正苦于以下问题:Java Vector2d.add方法的具体用法?Java Vector2d.add怎么用?Java Vector2d.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.vecmath.Vector2d
的用法示例。
在下文中一共展示了Vector2d.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjacentDist
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public double adjacentDist(Line l, Point2d pt) {
Vector2d v1 = new Vector2d(l.end);
v1.sub(l.start);
Vector2d v2 = new Vector2d(pt);
v2.sub(l.start);
double param = v2.dot(v1) / v1.length();
if ( param < 0 || param > v1.length() )
return Double.MAX_VALUE;
v1.normalize();
v1.scale( param );
v1.add( l.start );
return new Point2d (v1).distance(pt);
}
示例2: project
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public static Point2d project(Line l, Point2d pt) {
Vector2d v1 = new Vector2d(l.end);
v1.sub(l.start);
Vector2d v2 = new Vector2d(pt);
v2.sub(l.start);
double param = v2.dot(v1) / v1.length();
if (param < 0 || param > v1.length())
return null;
v1.normalize();
v1.scale(param);
v1.add(l.start);
return new Point2d(v1);
}
示例3: refereeTriesToKeepSurvey
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public void refereeTriesToKeepSurvey(SBProtocolMessage message){
int refereeThrow1 = actor.getMatch().d6.throwDie();
int refereeThrow2 = actor.getMatch().d6.throwDie();
if(refereeThrow1 == refereeThrow2){
if(actor.isHoldingBall()){
actor.invokeSetIsHoldingBall(false);
Vector2d newBallPos = new Vector2d(actor.getPos());
newBallPos.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(newBallPos);
}
actor.invokeClearPosition();
actor.invokeSetRedCard(true);
int actingUserIndex = -1;
if(actor.getMatch().getTeam(0) == actor.getTeam()){
actingUserIndex = 0;
}else if(actor.getMatch().getTeam(1) == actor.getTeam()){
actingUserIndex = 1;
}
((ServerMatch)actor.getMatch()).endTurn(actingUserIndex);
sendMessageShowMe(actor.toString(), "This stupid referee sent me of the pitch!");
returnSuccessMessage(message, SBProtocolMessage.WORKD_PLAYER_HAS_BEEN_SENT_OFF_THE_PITCH_BY_REFEREE);
}
}
示例4: beingTackled
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
protected boolean beingTackled(SBProtocolMessage message, int i, PitchField... path){
if (actor.isHoldingBall()) {
returnSuccessMessage(message, SBProtocolMessage.WORKD_YOU_HAVE_LOST_YOUR_BALLS);
}
//player gets tackled, he falls down and its no longer your turn
sendMessageShowMe(actor.toString(), "Dammit, I was tackled!");
((RuleBlock) actor.getRule(1)).playerDown(message, actor, RuleBlock.YOU_SUCK);
actor.invokeSetRemainingBe(0);
returnSuccessMessage(message, SBProtocolMessage.WORKD_YOU_ARE_TACKLED);
actor.getMatch().sendPlayer(actor);
if(path[i].getPos().equals(actor.getMatch().getPitch().getBallPos())){
Vector2d newBallPos = new Vector2d(actor.getMatch().getPitch().getBallPos());
newBallPos.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(newBallPos);
}
return false;
}
示例5: faildToPickUpBall
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
protected boolean faildToPickUpBall(SBProtocolMessage message){
returnSuccessMessage(message, SBProtocolMessage.WORKD_FAILED_PICK_UP_BALL);
Vector2d newBallPos = new Vector2d(actor.getMatch().getPitch().getBallPos());
newBallPos.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(newBallPos);
((ServerMatch)actor.getMatch()).endTurn(message);
return false;
}
示例6: notWellThrown
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
* where lands the ball if he doesnt pass the target
* @param targetField the target field
*/
protected void notWellThrown(Vector2d targetField, SBProtocolMessage message){
Vector2d failField=new Vector2d(targetField);
failField.add(actor.getMatch().scatter());
failField.add(actor.getMatch().scatter());
failField.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(failField);
returnSuccessMessage(message, SBProtocolMessage.WORKD_NOT_WELL_THROWN);
}
示例7: apply
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
* main method for pushing
* @param message SBProtocolMessage
* @param defender the player who is going to be pushed
*/
public void apply(SBProtocolMessage message, Player defender, PitchField defenderField, UUID pushChooser, Player playerBackingUp, Vector2d posToBackup) {
if(defender.invokeGetPlayerCondition() == PlayerCondition.DEAD
|| defender.invokeGetPlayerCondition() == PlayerCondition.INJURED
|| defender.invokeGetPlayerCondition() == PlayerCondition.KO
|| defender.getPosition() == Pitch.THE_VOID){
((RulePush)playerBackingUp.getRule(2)).backUp(posToBackup, message, playerBackingUp);
}else if(pushPossible(actor.getPosition(), defenderField)){
((ServerMatch) getMatch()).setCurrentActorWaitingForAnswer(actor);
((ServerMatch) getMatch()).setCurrentDefenderWaitingForAnswer(defender);
((ServerMatch) getMatch()).setCurrentPusherWaitingForAnswer(playerBackingUp);
((ServerMatch) getMatch()).setCurrentBackUpPosWaitingForAnswer(posToBackup);
SBProtocolParameterArray parameters = new SBProtocolParameterArray();
parameters.addParameter(new SBProtocolParameter(SBProtocolMessage.EVENT_API_FIELD));
parameters.addParameter(new SBProtocolParameter("$push"));
Vector<Vector2d> pushPossibilities = pushDirections(actor.getPosition(), defenderField);
for(Vector2d direction: pushPossibilities){
Vector2d destinationField = new Vector2d(direction);
destinationField.add(defenderField.getPos());
parameters.addParameter(new SBProtocolParameter((int)destinationField.x + ""));
parameters.addParameter(new SBProtocolParameter((int)destinationField.y + ""));
}
SBProtocolMessage messageToSend = new SBProtocolMessage(actor.getMatch().getParent().getUID(), SBProtocolCommand.EVENT, parameters);
getMatch().sendMessage(pushChooser, messageToSend);
actor.getMatch().setGamePhase(5);
}else{
returnFailureMessage(message, SBProtocolMessage.FAILD_PUSHING_NOT_POSSIBLE);
}
}
示例8: getShortestPath
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
* Liefert den kuerzesten Pfad von einem bestimmten Punkt aus zum Ziel
*
* @param from
* Startpunkt in weltkoordinaten
* @return Liste der Turningpoints (Gitterkoordinaten!!!)
*/
public Vector<TurningPoint> getShortestPath(Vector2d from) {
Vector2d f = new Vector2d(from);
f.scale(1 / blockSizeInM);
TurningPoint start = new TurningPoint(f);
if (finishPositions.size() == 0) {
return null;
}
Iterator<Vector2d> it = finishPositions.iterator();
double dist = java.lang.Double.MAX_VALUE;
Vector<TurningPoint> shortestPath = null;
while (it.hasNext()) {
Vector2d fin = new Vector2d(it.next());
fin.add(new Vector2d(0.5, 0.5));
TurningPoint finish = new TurningPoint(fin);
Vector<TurningPoint> tmpShortestPath = start.getShortestPathTo(finish, getFlatParcours());
double tmpDist = TurningPoint.getLengthOfPath(tmpShortestPath);
if (tmpDist < dist) {
shortestPath = tmpShortestPath;
dist = tmpDist;
}
}
// finde die kuerzeste Verbindung
return shortestPath;
}
示例9: updateMarkers
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public void updateMarkers( Bar b )
{
for (Marker m : b.mould.getAnchorsReadOnly( b.start, b.end ) )
{
Vector2d dir = new Vector2d (b.end);
dir.sub(b.start);
dir.scale( Mathz.clamp( weights.get (b), 0.1, 0.9 ) );
dir.add(b.start);
m.set( dir );
m.bar = b;
}
}
示例10: add
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
private void add(List<Marker> out, Point2d relStart, Point2d relEnd, Bar b, boolean rel)
{
Vector2d delta = new Vector2d(relEnd);
delta.sub(relStart);
for (PMarker pm : generators)
{
if (pm.rel == rel)
{
Vector2d d2 = new Vector2d(delta);
d2.scale(pm.param);
d2.add(relStart);
Marker o = new Marker();
o.bar = b;
o.set(d2);
if (b != null)
{
o.bar = b;
}
out.add(o);
o.generator = pm;
}
}
}
示例11: createDormerWindowsFor
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public void createDormerWindowsFor(Bar b, double desiredSpacing )
{
b.mould.clear();
double length = b.length();
int count = (int)(length /desiredSpacing);
double delta = length / (count+1.);
Vector2d v = new Vector2d (b.end);
v.sub(b.start);
v.normalize();
v.scale(delta);
for (int i = 1; i <= count; i++)
{
Vector2d loc = new Vector2d (v);
loc.scale(i);
loc.add(b.start);
Marker m = new Marker();
m.set(loc);
m.bar = b;
b.mould.create(m, null);
Marker profM = profileMarkers.get( profiles.get(b));
if (profM != null) {
Ship.Instance instance = ns.newInstance();
instance.anchors = new Anchor[]{new Anchor(m.generator, profM.generator)};
}
}
}
示例12: scatterBallAround
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
protected void scatterBallAround(int actingUserIndex){
Vector2d newBallPos = new Vector2d(actor.getMatch().getPitch().getBallPos());
newBallPos.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(newBallPos);
sendMessage(actor.getMatch().getUser(actingUserIndex), SBProtocolCommand.EVENT, SBProtocolMessage.EVENT_BALL_NOT_CATCHED);
}
示例13: chosenDirection
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
* tests weather the chosen direction to push your enemy is legal and then moves (or not)
* @param defender the pushed person
* @param message SBProtocolMessage
* @param answer SBProtocolMessage
*/
public boolean chosenDirection(Player defender, SBProtocolMessage message, SBProtocolMessage answer, Player playerBackingUp, Vector2d posToBackUp){
Vector2d actorField = new Vector2d(actor.getPos());
Vector2d defenderField = new Vector2d(defender.getPos());
Vector2d direction = new Vector2d(defenderField);
direction.sub(actorField);
Vector2d newDefenderField = new Vector2d(defenderField);
int x;
int y;
try{
x = Integer.parseInt(answer.getParameterContent(2));
y = Integer.parseInt(answer.getParameterContent(3));
}
catch(NumberFormatException e){
returnFailureMessage(message, SBProtocolMessage.FAILD_RECEIVED_WRONG_GAME_DATA);
return false;
}
Vector2d walk = new Vector2d(x,y);
walk.sub(defenderField);
if(pushPossible(actor.getPosition(), defender.getPosition(), walk)){
newDefenderField.add(walk);
}else{
returnFailureMessage(message, SBProtocolMessage.FAILD_WRONG_DIRECTION);
getMatch().sendMessage(actor.getTeam().getCoach().getUID(), message);
return true;
}
if(!(actor.getMatch().getPitch().isOnField(newDefenderField))){
crowdBeatsUpPlayer(defender);
returnSuccessMessage(message, SBProtocolMessage.WORKD_DEFENDER_PUSHED);
actor.getMatch().setGamePhase(3);
pushAllWaitingPlayers(message);
((RulePush)playerBackingUp.getRule(2)).backUp(posToBackUp, message, playerBackingUp);
}else if(actor.getMatch().getPitch().getFields()[(int)newDefenderField.x][(int)newDefenderField.y].getPlayer() == null){
//liegt der ball auf dem feld? -> scatter
if (getMatch().getPitch().getBallPos().x == (int)newDefenderField.x && getMatch().getPitch().getBallPos().y == (int)newDefenderField.y){
Vector2d newBallPos = new Vector2d (actor.getMatch().getPitch().getBallPos());
newBallPos.add(actor.getMatch().scatter());
actor.getMatch().getPitch().setBallPos(newBallPos);
}
((ServerMatch)actor.getMatch()).addCurrentPlayersBeingPushed(defender);
((ServerMatch)actor.getMatch()).addCurrentPlayerPositionsBeingPushed(newDefenderField);
pushAllWaitingPlayers(message);
actor.getMatch().setGamePhase(3);
((RulePush)playerBackingUp.getRule(2)).backUp(posToBackUp, message, playerBackingUp);
}else{
Player newDefender = actor.getMatch().getPitch().getFields()[(int)newDefenderField.x][(int)newDefenderField.y].getPlayer();
((ServerMatch)getMatch()).addCurrentHighlitedFields(newDefender.getPos());
((RuleBlock)actor.getRule(1)).sendHighlightFields(((ServerMatch)getMatch()).getCurrentHighlitedFields());
((ServerMatch)actor.getMatch()).addCurrentPlayersBeingPushed(defender);
((ServerMatch)actor.getMatch()).addCurrentPlayerPositionsBeingPushed(newDefenderField);
((RulePush)defender.getRule(2)).apply(message, newDefender, newDefender.getPosition(), answer.getUID(), playerBackingUp, posToBackUp);
returnSuccessMessage(message, SBProtocolMessage.WORKD_DEFENDER_PUSHED, "NEXT PUSH?");
return true;
}
return true;
}
示例14: returnLineTo
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
* gibt einen Polygonzug der mit Breite und einer Spitze versehen Linie von
* this zu p2 zurueck, zur Weiterverwendung in createLine()
*
* @param p2
* @return {x1,y1,z1,x2,y2,z2,...,x6,y6,z6}
*/
float[] returnLineTo(TurningPoint p2) {
Vector2d offset = new Vector2d(0.5, 0.5);
Vector2d length = new Vector2d(p2.pos);
length.sub(this.pos);
Vector2d halfWidth = new Vector2d(-length.y, length.x);
halfWidth.normalize();
halfWidth.scale(lineWidth / 2);
Vector2d corner = new Vector2d(this.pos);
// corner.add(new Vector2d(0.5,0.5));
corner.sub(halfWidth);
corner.sub(offset);
float[] polygon = new float[18];
polygon[0] = (float) corner.x;
polygon[1] = (float) corner.y;
polygon[2] = height;
corner.add(length);
polygon[3] = (float) corner.x;
polygon[4] = (float) corner.y;
polygon[5] = height;
corner.add(halfWidth);
corner.add(halfWidth);
polygon[6] = (float) corner.x;
polygon[7] = (float) corner.y;
polygon[8] = height;
corner.sub(length);
polygon[9] = (float) corner.x;
polygon[10] = (float) corner.y;
polygon[11] = height;
corner.sub(halfWidth);
Vector2d head = new Vector2d(length);
head.normalize();
head.scale(-lineWidth / 2);
corner.add(head);
polygon[12] = (float) corner.x;
polygon[13] = (float) corner.y;
polygon[14] = height;
corner.sub(halfWidth);
corner.sub(head);
polygon[15] = (float) corner.x;
polygon[16] = (float) corner.y;
polygon[17] = height;
return polygon;
}
示例15: setPlan
import javax.vecmath.Vector2d; //导入方法依赖的package包/类
private void setPlan(Marker planC, double distance, Marker planM) {
// we always trail by 1 frame, but this can't really be helped.
Bar bar = planC.bar;
// Loop<Bar> loop = null;
// Loopable<Bar> able = null;
LoopLoopable<Bar>
cAble = Siteplan.instance.plan.points.find( bar ),
mAble = Siteplan.instance.plan.points.find( planM.bar );
if ( cAble == null || mAble == null )
return; // didn't find marker on main plan. give up.
// remove plan marker from old location
Object generator = planM.bar.mould.remove( planM );
// anchors may have re-genereated. grab the most recent location
planC = refresh (planC, cAble );
// planM = refresh (planM, mAble);
// Object generator = mAble.loopable.get().mould.remove( planM );
// move plan marker - find correct bar by subtracting from desired distance
double leftInBar;
Loopable<Bar> able = cAble.loopable;
if ( distance > 0 )
{
leftInBar = planC.distance( able.get().end );
do
if ( leftInBar > distance )
{
leftInBar -= distance;
break;
}
else
{
distance -= leftInBar;
able = able.getNext();
leftInBar = able.get().length();
}
while ( true );
}
else
{
distance = -distance;
leftInBar = planC.distance( able.get().start );
do
if ( leftInBar > distance )
{
leftInBar -= distance;
leftInBar = able.get().length() - leftInBar;
break;
}
else
{
distance -= leftInBar;
able = able.getPrev();
leftInBar = able.get().length();
}
while ( true );
}
planM.bar = able.get();
// calculate position as distance from end
Vector2d dir = new Vector2d (planM.bar.end );
dir.sub( planM.bar.start );
dir.normalize();
dir.scale( -leftInBar );
dir.add( planM.bar.end );
planM.set( dir );
planM.bar.mould.create( planM, generator );
}