本文整理汇总了Java中javax.vecmath.Vector2d类的典型用法代码示例。如果您正苦于以下问题:Java Vector2d类的具体用法?Java Vector2d怎么用?Java Vector2d使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vector2d类属于javax.vecmath包,在下文中一共展示了Vector2d类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBehindBorder
import javax.vecmath.Vector2d; //导入依赖的package包/类
/**Returns true, if the agent overstepped the border of the nextLocation.*/
private boolean getBehindBorder() {
/* Vektory startA a endA (agent) určují úsečku "A" od previousLocation k lokaci agenta.*/
Vector2d startA = new Vector2d(previousLocation.x, previousLocation.y);
Vector2d endA = new Vector2d(botself.getLocation().x, botself.getLocation().y);
Vector2d directionA = new Vector2d(endA.x - startA.x, endA.y - startA.y);
/* Vektory startB a endB (border) určují přímku "B" prochízející nextLocation mající směr kolmý na spojnici nextLocation a previousLocation. Je to tedy jakási hranice
* a my zkoumáme, zda se agent dostal za tuto hranici.*/
Vector2d startB = new Vector2d(nextLocation.x, nextLocation.y);
Vector2d normalDirectionB = new Vector2d(nextLocation.x - previousLocation.x, nextLocation.y - previousLocation.y);
Vector2d directionB = new Vector2d(-normalDirectionB.y, normalDirectionB.x);
//Vector2d endB = new Vector2d(startB.x + directionB.x, startB.y + directionB.y);
Vector2d intersection = SteeringTools.getIntersection(startA, directionA, startB, directionB, SteeringTools.LineType.ABSCISSA, SteeringTools.LineType.STRAIGHT_LINE);
/*Pokud úsečka "A" protíná přímku "B" (intersection není null), agent se dostal za hranici a je třeba posunout následující bod na cestě.*/
if (SteeringManager.DEBUG) System.out.println("Jsme za hranicí "+(intersection != null)+" průsečík: "+intersection);
return (intersection != null);
}
示例2: 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);
}
示例3: gen
import javax.vecmath.Vector2d; //导入依赖的package包/类
@Override
public List<Point2d> gen(Vector2d left, Vector2d right) {
Point2d overhang = new Point2d(right);
overhang.scale(0.2);
Line l = new Line(new Point2d(), new Point2d(left));
Point2d r = l.project(overhang, false);
List<Point2d> out = new ArrayList<>();
out.add(new Point2d());
out.add(overhang);
out.add(r);
return out;
}
示例4: 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);
}
示例5: computeNormal
import javax.vecmath.Vector2d; //导入依赖的package包/类
private static Vector2d computeNormal(final Point2d prev, final Point2d current, final Point2d next, final Vector2d prevNormal) {
Vector2d normal = new Vector2d();
if (prev == null) {
normal.x = current.y - next.y;
normal.y = next.x - current.x;
} else if (next == null) {
normal.x = -current.y + prev.y;
normal.y = -prev.x + current.x;
} else {
normal.x = prev.y - next.y;
normal.y = next.x - prev.x;
}
// normalization if not null (Vector2d.normalize() method returns NaN if norm is 0!
double norm = Math.sqrt(normal.x * normal.x + normal.y * normal.y);
if (norm > 1.E-6) {
normal.x /= norm;
normal.y /= norm;
}
return normal;
}
示例6: finishEdge
import javax.vecmath.Vector2d; //导入依赖的package包/类
private void finishEdge(Parabola n) {
if (n.isLeaf) {
return;
}
double mx;
if (n.edge.direction.x > 0) {
mx = Math.max(width, n.edge.start.x + 10);
} else {
mx = Math.min(0, n.edge.start.x - 10);
}
Vector2d end = new Vector2d(mx, mx*n.edge.f + n.edge.g);
n.edge.end = end;
points.add(end);
finishEdge(n.left());
finishEdge(n.right());
}
示例7: checkHole
import javax.vecmath.Vector2d; //导入依赖的package包/类
/**
* Prueft, ob ein Punkt ueber einem Loch liegt
*
* @param pos
* @return true, wenn der Bot ueber dem loch steht
*/
public boolean checkHole(Point3d pos) {
if ((pos.x < 0) || (pos.y < 0) || (pos.x > dimX * blockSizeInM) || (pos.y > dimY * blockSizeInM)) {
return true;
}
Iterator it = holes.iterator();
while (it.hasNext()) {
Vector2f min = new Vector2f((Vector2d) it.next());
min.scale(blockSizeInM);
Vector2f max = new Vector2f(min);
max.add(new Vector2f(blockSizeInM, blockSizeInM));
if ((pos.x > min.x) && (pos.x < max.x) && (pos.y > min.y) && (pos.y < max.y)) {
return true;
}
}
return false;
}
示例8: drawChoiceAPI
import javax.vecmath.Vector2d; //导入依赖的package包/类
public void drawChoiceAPI(Graphics2D g, Player[] playerChoices) {
if(playerChoices != null) {
Player hoveringPlayer = getGameCanvas().getPitchMouseLogic().getHoveringPlayer();
for(Player player: playerChoices) {
Vector2d playerPos = player.getPos();
if(playerPos != null) {
if(hoveringPlayer != null && playerPos.equals(hoveringPlayer.getPos())) {
highlightField(g, playerPos.x, playerPos.y, SBColor.BLUE_BRIGHT_80);
drawBeacon(g, playerPos.x, playerPos.y, SBColor.BLUE_BRIGHT);
} else {
highlightField(g, playerPos.x, playerPos.y, SBColor.YELLOW_80);
}
}
}
}
}
示例9: drawFieldAPI
import javax.vecmath.Vector2d; //导入依赖的package包/类
public void drawFieldAPI(Graphics2D g, Vector2d[] fieldChoices) {
if(fieldChoices != null) {
for(Vector2d field: fieldChoices) {
double[] hoveringFieldCoords = getGameCanvas().getPitchMouseLogic().getMXY();
Vector2d hoveringField = new Vector2d(hoveringFieldCoords[0], hoveringFieldCoords[1]);
if(field != null) {
if(field.equals(hoveringField)) {
highlightField(g, field.x, field.y, SBColor.BLUE_BRIGHT_80);
drawBeacon(g, field.x, field.y, SBColor.BLUE_BRIGHT);
} else {
highlightField(g, field.x, field.y, SBColor.YELLOW_80);
}
}
}
}
}
示例10: drawBeacon
import javax.vecmath.Vector2d; //导入依赖的package包/类
private void drawBeacon(Graphics2D g2D, double x, double y, Color color, int a) {
g2D.setPaint(
new Color(color.getRed(),
color.getGreen(),
color.getBlue(),
(int) (a + 20 * Math.cos((double) getGameCanvas().timer * 3 /180*Math.PI)))
);
Vector2d pXYleft = posToDisp(new Vector2d(x * getPW() + getPW()/4, y * getPW() + getPW()/2)),
pXYright = posToDisp(new Vector2d(x * getPW() + 3*getPW()/4, y * getPW() + getPW()/2));
GeneralPath beacon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);
beacon.moveTo((pXYleft.x + pXYright.x) / 2, pXYleft.y - 1000);
beacon.lineTo(pXYright.x, pXYright.y);
beacon.lineTo(pXYleft.x, pXYleft.y);
beacon.closePath();
g2D.fill(beacon);
}
示例11: setMXY
import javax.vecmath.Vector2d; //导入依赖的package包/类
void setMXY(MouseEvent e) {
double xNew = e.getX(), yNew = e.getY();
Vector2d mXYNew = getGameCanvas().getGameRenderer().dispToPos(new Vector2d(xNew, yNew));
double mXNewTemp = mXYNew.x / getpW(),
mYNewTemp = mXYNew.y / getpH();
if(mXNewTemp < 0) mXNewTemp -= 1; // fix negative coordinates rounding error
if(mYNewTemp < 0) mYNewTemp -= 1; // "
int mXNew = (int) mXNewTemp,
mYNew = (int) mYNewTemp;
mXOld = mX;
mYOld = mY;
if(mXNew >= 0 && mXNew < Pitch.PITCH_LENGTH && mYNew >= 0 && mYNew < Pitch.PITCH_WIDTH) {
mX = mXNew;
mY = mYNew;
} else {
resetMXY();
}
}
示例12: halfTime
import javax.vecmath.Vector2d; //导入依赖的package包/类
private void halfTime() {
Vector<Player> playersOnThePitch = findPlayersOnThePitch();
clearAllPlayerPos();
getPitch().adjustBallPos(new Vector2d(-1, -1));
teamsSet[0] = false;
teamsSet[1] = false;
gamePhase = 1;
resetPlayerConditions();
checkForSwelteringHeat(playersOnThePitch);
sendGame();
checkForTeamCondition();
cleanPlayersAfterTouchdownOrHalfTime();
if(roundCount >= NUMBER_OF_ROUNDS_IN_GAME){
finishGame();
}else{
initiateTeamSetup(coaches[actingPlayer]);
}
}
示例13: isAdjacent
import javax.vecmath.Vector2d; //导入依赖的package包/类
/**
* Checks whether two field-positions are adjacent
* @param pos1 Position of the first Field (as a Vector 2d)
* @param pos2 Position of the second Field (as a Vector 2d)
* @return Boolean which is true if the two fields are adjacent and false if not
*/
public boolean isAdjacent(Vector2d pos1, Vector2d pos2){
try{
if(!(isOnField(pos1)) || !(isOnField(pos2))){
throw new SBOutOfFieldException("given position is not on the pitch");
}else{
for(PitchField f: getNeighbours(pos2)){
if(fields[(int)pos1.x][(int)pos1.y] == f){
return true;
}
}
return false;
}
}catch(SBOutOfFieldException e){
e.printStackTrace();
}
return false;
}
示例14: 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);
}
}
示例15: 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;
}