本文整理匯總了Java中javax.vecmath.Vector3d.angle方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector3d.angle方法的具體用法?Java Vector3d.angle怎麽用?Java Vector3d.angle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.vecmath.Vector3d
的用法示例。
在下文中一共展示了Vector3d.angle方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: computeFrontCollisionVector
import javax.vecmath.Vector3d; //導入方法依賴的package包/類
/**If it's really the front collision, the "mirror vector" is returned. Otherwise the unchanged parameter normal is returned.*/
private Vector3d computeFrontCollisionVector(Vector3d normal) {
Vector3d av = botself.getVelocity().getVector3d();
Vector3d result = new Vector3d(normal.x, normal.y, 0);
Vector3d negativeActual = new Vector3d(-av.x, -av.y, 0);
if (SteeringManager.DEBUG) System.out.println("Angle "+SteeringTools.radiansToDegrees(normal.angle(negativeActual)));
if (result.angle(negativeActual) <= Math.PI/2) {
boolean turnLeft;
if (result.angle(negativeActual) == 0) {
turnLeft = random.nextBoolean();
} else {
turnLeft = SteeringTools.pointIsLeftFromTheVector(av, result);
}
Vector3d turn = SteeringTools.getTurningVector2(av, turnLeft); //Tady se původně používal getTurningVector1.
turn.normalize();
turn.scale(0.5); //Aby neměl rotační vektor tak velký vliv.
result.add(turn);
result.normalize();
if (SteeringManager.DEBUG) System.out.println("Obstacle avoidance front collision: turn left "+turnLeft);
}
return result;
}
示例2: goRoundPartner
import javax.vecmath.Vector3d; //導入方法依賴的package包/類
private Vector3d goRoundPartner(Player player) {
Vector3d result = new Vector3d(0,0,0);
Location myActualLocation = botself.getLocation();
Vector3d myVelocity = botself.getVelocity().getVector3d();
Location hisActualLocation = player.getLocation();
Vector3d hisVelocity = player.getVelocity().getVector3d();
Location myNextLocation = null;
Location hisNextLocation = null;
double collisionTime = -1;
for(int t=0;t <= projection*TICK_PARTS;t++){
double time = ((double)t)/TICK_PARTS;
myNextLocation = getLocationAfterTime(myActualLocation, myVelocity, time);
hisNextLocation = getLocationAfterTime(hisActualLocation, hisVelocity, time);
if (myNextLocation.getDistance(hisNextLocation) <= distanceFromOtherPeople) {
collisionTime = time;
break;
}
}
if (collisionTime != -1) { //Za dobu collisionTime bychom se přiblížili příliš blízko.
double ourNextDistance = myNextLocation.getDistance(hisNextLocation);
Vector3d myNextLocationToHis = new Vector3d(hisNextLocation.x - myNextLocation.x, hisNextLocation.y - myNextLocation.y, hisNextLocation.z - myNextLocation.z);
double ourNextAngle = myNextLocationToHis.angle(myVelocity);
Vector3d turningVector;
double koefA, koefB;
boolean turnLeft;
/*Teď podle toho, zda bude v danou chvíli druhý bot od nás napravo či nalevo, zatočíme na danou stranu.
A podle toho, jak dalekood sebe budeme a za jak dlouho to je, bude síla velká.*/
if (ourNextAngle == 0) {
turnLeft = random.nextBoolean();
if (SteeringManager.DEBUG) {
System.out.println("Partner exactly front collision. "+turnLeft);
}
koefA = 1;
koefB = getKoefB(collisionTime);
} else {
koefA = getKoefA(ourNextAngle, ourNextDistance);
koefB = getKoefB(collisionTime);
turnLeft = !SteeringTools.pointIsLeftFromTheVector(myVelocity, myNextLocationToHis);
if (SteeringManager.DEBUG) System.out.println("Partner nearly front collision. " + turnLeft);
if (SteeringManager.DEBUG) System.out.println("Distance " + ourNextDistance + " koefA " + koefA + " koefB " + koefB);
}
turningVector = SteeringTools.getTurningVector2(botself.getVelocity().getVector3d(), turnLeft);
turningVector.normalize();
turningVector.scale(2*repulsiveForce * koefA * koefB);
if (SteeringManager.DEBUG) System.out.println("Turning vector " + turningVector.length());
result.add(turningVector);
}
return result;
}
示例3: lookAt
import javax.vecmath.Vector3d; //導入方法依賴的package包/類
/**
* Set the viewpoint so it looks at specified location.
* Set new center and update up angle.
* @param location location that should be in the middle of screen
* @param axis x = 0, y = 1, z = 2, which axis is up direction?
* @param upFlag is up at positive infinity of the axis (true) or negative infinity (false);
*/
public void lookAt(Location location, int axis, boolean upFlag) {
System.out.println("Look at target: " + location);
Vector3d newEye2Center = new Vector3d();
newEye2Center.x = location.x - eye.x;
newEye2Center.y = location.y - eye.y;
newEye2Center.z = location.z - eye.z;
Vector3d currentEye2Center = new Vector3d(
getEye2Center().x,
getEye2Center().y,
getEye2Center().z
);
double angle = currentEye2Center.angle(newEye2Center);
System.out.println("Angle " + angle + " " + angle*180/Math.PI);
/* Vector3d upVec;
double upDir = upFlag ? 1: -1;
center = new Location(location);
switch (axis) {
case 0:
upVec = new Vector3d(upDir, 0, 0);
break;
case 1:
upVec = new Vector3d(0, upDir, 0);
break;
case 2:
upVec = new Vector3d(0, 0, upDir);
break;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
Location eye2CenterLoc = getEye2Center();
Vector3d eye2Center = new Vector3d();
eye2Center.x = eye2CenterLoc.x;
eye2Center.y = eye2CenterLoc.y;
eye2Center.z = eye2CenterLoc.z;
eye2Center.normalize();
// from look direction and up vector compute "right" vector
Vector3d right = new Vector3d();
right.cross(eye2Center, upVec);
up.cross(right, eye2Center);
emitChangedViewport();*/
}