本文整理匯總了Java中processing.core.PConstants.PI屬性的典型用法代碼示例。如果您正苦於以下問題:Java PConstants.PI屬性的具體用法?Java PConstants.PI怎麽用?Java PConstants.PI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類processing.core.PConstants
的用法示例。
在下文中一共展示了PConstants.PI屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: angleBetween
/**
* ( begin auto-generated from PVector_angleBetween.xml )
*
* Calculates and returns the angle (in radians) between two vectors.
*
* ( end auto-generated )
*
* @webref pvector:method
* @usage web_application
* @param v1 the x, y, and z components of a PVector
* @param v2 the x, y, and z components of a PVector
* @brief Calculate and return the angle between two vectors
*/
static public float angleBetween(PVector v1, PVector v2) {
// We get NaN if we pass in a zero vector which can cause problems
// Zero seems like a reasonable angle between a (0,0,0) vector and something else
if (v1.x == 0 && v1.y == 0 && v1.z == 0 ) return 0.0f;
if (v2.x == 0 && v2.y == 0 && v2.z == 0 ) return 0.0f;
double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
// This should be a number between -1 and 1, since it's "normalized"
double amt = dot / (v1mag * v2mag);
// But if it's not due to rounding error, then we need to fix it
// http://code.google.com/p/processing/issues/detail?id=340
// Otherwise if outside the range, acos() will return NaN
// http://www.cppreference.com/wiki/c/math/acos
if (amt <= -1) {
return PConstants.PI;
} else if (amt >= 1) {
// http://code.google.com/p/processing/issues/detail?id=435
return 0;
}
return (float) Math.acos(amt);
}
示例2: drawProgressBar
/**
* This function draws the progress bar graphical
* component of the popup.
*/
private void drawProgressBar()
{
//draw progress bar
window.noFill();
window.strokeWeight(3);
turn = (int)(System.currentTimeMillis() - poisonStamp) / 1000;
for(int x = 0; x < 3; ++x)
{
window.stroke(randomColours[randomIndex[x]][0],
randomColours[randomIndex[x]][1],
randomColours[randomIndex[x]][2]);
//arcs 1
if(x >= turn)
{
if(x == turn)
currentVel[x] -= 5.0f;
if(currentVel[x] < maxVel)
currentVel[x] = maxVel;
float angle = PConstants.PI * 2 * (float)(System.currentTimeMillis() - poisonStamp) / currentVel[x];
float radius = (barRadius + (10 * x)) * (1 - (x == turn ? ((float)(System.currentTimeMillis() - poisonStamp) % (Settings.commandWaitTime / 3) / (float)(Settings.commandWaitTime / 3)) : 0));
window.arc(window.width / 2, (window.height / 2) + 60,
radius,
radius,
x % 2 == 0 ? (float)((-PConstants.PI / 6.0) + angle) : (float)((-PConstants.PI / 6.0) - angle),
x % 2 == 0 ? (float)((PConstants.PI / 6.0) + angle) : (float)((PConstants.PI / 6.0) - angle));
window.arc(window.width / 2, (window.height / 2) + 60,
radius,
radius,
x % 2 == 0 ? (float)((-PConstants.PI / 6.0) + angle + PConstants.PI) : (float)((-PConstants.PI / 6.0) - angle - PConstants.PI),
x % 2 == 0 ? (float)((PConstants.PI / 6.0) + angle + PConstants.PI) : (float)((PConstants.PI / 6.0) - angle - PConstants.PI));
}
}
window.strokeWeight(1);
}
示例3: mouseEvent
public void mouseEvent(processing.event.MouseEvent event) {
switch (event.getAction()) {
case MouseEvent.DRAG:
//Calc distance dragged
float dx = prevX - event.getX();
float dy = prevY - event.getY();
if (_parent.mouseButton == PConstants.LEFT
&& !event.isControlDown()) {
//Rotation about the z-axis, on the graph not world axis.
PVector relX = VectorUtils.rotateArbitaryAxis(getRelativePosition(),
new PVector(0, 1, 0), -dx * PConstants.PI / 100);
_position = PVector.add(relX, _lookat);
float dAngle = dy * PConstants.PI / 100;
PVector r = getRelativePosition();
//The next sections is slightly tricky, to get a better understanding
//render the vector A in the draw routine below, this shows the axis
//the camera is rotated about.
//now need to get an axis to rotate about that will allow
//the camera to orbit over the top and bottom of lookat point
A = new PVector(0, 0, 1);
//now we get the angle between the z axis and the r vector projected
//into the x-z plane only so no y comp and add 90deg
float angle = (float) Math.atan2(r.x, r.z) + PConstants.PI / 2;
//now rotate the axis A so it is orthogonal to r
A = VectorUtils.rotateArbitaryAxis(A, new PVector(0, 1, 0), angle);
//As we now have an axis that is always orthogonal to our relative
//position going through the lookat point, we rotate the camera
//position around it.
PVector relY = VectorUtils.rotateArbitaryAxis(r, A, dAngle);
//Strange things happen when the new relative position gets to 0,0,0 and flips
//to the other side, the scene flips the z and x axis(comment out this check
//to see) so basically we dont want to apply any changes if the sign has changed
if (Math.signum(r.x) == Math.signum(relY.x)
&& Math.signum(r.z) == Math.signum(relY.z)) {
_position = PVector.add(relY, _lookat);
}
}
if (_parent.mouseButton == PConstants.RIGHT
|| (_parent.mouseButton == PConstants.LEFT && event.isControlDown())) {
PVector newPos = PVector.add(_position, PVector.mult(getEyeVector(), dy * 20));
PVector relPos = PVector.sub(newPos, _lookat);
if (relPos.mag() < _nearLimit || relPos.mag() > _farLimit) {
newPos = _position;
}
_position = newPos;
}
prevX = event.getX();
prevY = event.getY();
break;
case MouseEvent.MOVE:
//Keep track of previous mouse pos
//so a distance dragged can be calculated
prevX = event.getX();
prevY = event.getY();
break;
}
}