📄 cscene.java
字号:
int cosY = vy > 0 ? sin : -sin;
int sinY = vy > 0 ? cos : -cos;
int collidingVelocity = (def.abs(vx) * sinX + def.abs(vy) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity = (def.abs(vx) * cosX + def.abs(vy) * cosY)
/ def.VALUE_MULTIPLE_TEN;
// silent thing`s velocity after collision
int sCollidedVelocity = 2 * mm * collidingVelocity / (mm + ms);
cosY = sCollidedVelocity > 0 ? -sin : sin;
sinY = sCollidedVelocity > 0 ? cos : -cos;
v[0] = def.abs(sCollidedVelocity) * cosY / def.VALUE_MULTIPLE_TEN; //09-20 Milo the Y < 0 problem...
v[1] = def.abs(sCollidedVelocity) * sinY / def.VALUE_MULTIPLE_TEN;
// moving thing's velocity after collisoin
int mCollidedVelocity = (mm - ms) * collidingVelocity / (mm + ms);
cosX = excursionVelocity > 0 ? cos : -cos;
sinX = excursionVelocity > 0 ? sin : -sin;
cosY = mCollidedVelocity > 0 ? -sin : sin;
sinY = mCollidedVelocity > 0 ? cos : -cos;
v[2] = (def.abs(excursionVelocity) * cosX + def.abs(mCollidedVelocity)
* cosY)
/ def.VALUE_MULTIPLE_TEN;
v[3] = (def.abs(excursionVelocity) * sinX + def.abs(mCollidedVelocity)
* sinY)
/ def.VALUE_MULTIPLE_TEN;
return v;
}
/**
* deal with such situation that two balls collided, one moving, the other still
*
* @param x the x weight of the vector which stands for that of the connected line between the centers of both balls
* @param y the y weight of the vector
* @param vx the velocity in x direction of the moving ball
* @param vy the velocity in y direction of the moving ball
* @param mm the mass of the moving ball
* @param ms the mass of the still ball
* @return int[4] v, v[0] and v[1] stand for the velocitys in x, y direction of the still ball after collision <p>
* v[2] and v[3] stand for the velocitys of the moving ball after collision
*/
private static int[] collisionBallWithStillTenpin(int x, int y, int vx, int vy,
int mm, int ms) {
int[] v = new int[4];
int angleC;
if (x != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * y / x));
angleC = def.convertInto360(x, y, angleC) - 900;
if (angleC < 0) {
angleC += 3600;
}
}
else {
angleC = y >= 0 ? 0 : 1800;
}
int angle = def.abs( (angleC / 900 % 2 == 0 ? 0 : 900) - angleC % 900);
int cos = def.cos(angle);
if (def.abs(angleC) > 900 && def.abs(angleC) < 2700) {
cos = -cos;
}
int sin = def.sin(angle);
if (def.abs(angleC) > 1800 && def.abs(angleC) < 3600) {
sin = -sin;
}
int cosX = vx > 0 ? cos : -cos;
int sinX = vx > 0 ? -sin : sin;
int cosY = vy > 0 ? sin : -sin;
int sinY = vy > 0 ? cos : -cos;
int collidingVelocity = (def.abs(vx) * sinX + def.abs(vy) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity = (def.abs(vx) * cosX + def.abs(vy) * cosY)
/ def.VALUE_MULTIPLE_TEN;
// silent thing`s velocity after collision
int sCollidedVelocity = 2 * mm * collidingVelocity / (mm + ms);
cosY = sCollidedVelocity > 0 ? -sin : sin;
sinY = sCollidedVelocity > 0 ? cos : -cos;
v[0] = def.abs(sCollidedVelocity) * cosY / def.VALUE_MULTIPLE_TEN; //09-20 Milo the Y < 0 problem...
v[1] = def.abs(sCollidedVelocity) * sinY / def.VALUE_MULTIPLE_TEN;
// moving thing's velocity after collisoin
int mCollidedVelocity = (mm - ms) * collidingVelocity / (mm + ms);
cosX = excursionVelocity > 0 ? cos : -cos;
sinX = excursionVelocity > 0 ? sin : -sin;
cosY = mCollidedVelocity > 0 ? -sin : sin;
sinY = mCollidedVelocity > 0 ? cos : -cos;
/*v[2] = (def.abs(excursionVelocity) * cosX + def.abs(mCollidedVelocity)
* cosY)
/ def.VALUE_MULTIPLE_TEN;
v[3] = (def.abs(excursionVelocity) * sinX + def.abs(mCollidedVelocity)
* sinY)
/ def.VALUE_MULTIPLE_TEN;*/
v[2] = vx;
v[3] = vy;
return v;
}
//
/**
* deal with such situation that two balls collided, one moving, the other still
*
* @param x the x weight of the vector which stands for that of the connected line between the centers of both balls
* @param y the y weight of the vector
* @param vx the velocity in x direction of the moving ball
* @param vy the velocity in y direction of the moving ball
* @param mm the mass of the moving ball
* @param ms the mass of the still ball
* @return int[4] v, v[0] and v[1] stand for the velocitys in x, y direction of the still ball after collision <p>
* v[2] and v[3] stand for the velocitys of the moving ball after collision
*/
private static int[] collisionMoving(int x, int y, int vx0, int vy0,
int vx1, int vy1, int mm, int ms) {
int[] v = new int[4];
int angleC;
if (x != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * y / x));
angleC = def.convertInto360(x, y, angleC) - 900;
if (angleC < 0) {
angleC += 3600;
}
}
else {
angleC = y >= 0 ? 0 : 1800;
}
int angle = def.abs( (angleC / 900 % 2 == 0 ? 0 : 900) - angleC % 900);
int cos = def.cos(angle);
if (def.abs(angleC) > 900 && def.abs(angleC) < 2700) {
cos = -cos;
}
int sin = def.sin(angle);
if (def.abs(angleC) > 1800 && def.abs(angleC) < 3600) {
sin = -sin;
}
//calculating moving velocity
int cosX = vx0 > 0 ? cos : -cos;
int sinX = vx0 > 0 ? -sin : sin;
int cosY = vy0 > 0 ? sin : -sin;
int sinY = vy0 > 0 ? cos : -cos;
//here 9/02
int collidingVelocity0 = (def.abs(vx0) * sinX + def.abs(vy0) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity0 = (def.abs(vx0) * cosX + def.abs(vy0) * cosY)
/ def.VALUE_MULTIPLE_TEN;
int collidingVelocity1 = (def.abs(vx1) * sinX + def.abs(vy1) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity1 = (def.abs(vx1) * cosX + def.abs(vy1) * cosY)
/ def.VALUE_MULTIPLE_TEN;
// silent thing`s velocity after collision
int sCollidedVelocity0 = ( (collidingVelocity0 * (mm - ms)) +
(2 * ms * collidingVelocity1))
/ (mm + ms);
cosY = sCollidedVelocity0 > 0 ? -sin : sin;
sinY = sCollidedVelocity0 > 0 ? cos : -cos;
v[2] = def.abs(sCollidedVelocity0) * cosY / def.VALUE_MULTIPLE_TEN;
v[3] = def.abs(sCollidedVelocity0) * sinY / def.VALUE_MULTIPLE_TEN;
cosX = excursionVelocity0 > 0 ? cos : -cos;
sinX = excursionVelocity0 > 0 ? sin : -sin;
v[2] += (def.abs(excursionVelocity0) * cosX) / def.VALUE_MULTIPLE_TEN;
v[3] += (def.abs(excursionVelocity0) * sinX) / def.VALUE_MULTIPLE_TEN;
int sCollidedVelocity1 = ( (collidingVelocity1 * (ms - mm)) +
(2 * mm * collidingVelocity0))
/ (mm + ms);
cosY = sCollidedVelocity1 > 0 ? -sin : sin;
sinY = sCollidedVelocity1 > 0 ? cos : -cos;
v[0] = def.abs(sCollidedVelocity1) * cosY / def.VALUE_MULTIPLE_TEN;
v[1] = def.abs(sCollidedVelocity1) * sinY / def.VALUE_MULTIPLE_TEN;
cosX = excursionVelocity1 > 0 ? cos : -cos;
sinX = excursionVelocity1 > 0 ? sin : -sin;
v[0] += (def.abs(excursionVelocity1) * cosX) / def.VALUE_MULTIPLE_TEN;
v[1] += (def.abs(excursionVelocity1) * sinX) / def.VALUE_MULTIPLE_TEN;
return v;
}
//milo 10-09
private static int[] collisionBallWithMovingTenpin(int collisionStatus, int x,
int y, int vx0, int vy0, int vx1, int vy1, int mm, int ms) {
int[] v = new int[4];
int angleC;
if(collisionStatus == def.TENPIN_NORMAL_COLLISION || collisionStatus == def.TENPIN_HEAVY_ROTATED_COLLISION)
{
if (x != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * y / x));
angleC = def.convertInto360(x, y, angleC) - 900;
if (angleC < 0) {
angleC += 3600;
}
}
else {
angleC = y >= 0 ? 0 : 1800;
}
int angle = def.abs( (angleC / 900 % 2 == 0 ? 0 : 900) - angleC % 900);
int cos = def.cos(angle);
if (def.abs(angleC) > 900 && def.abs(angleC) < 2700) {
cos = -cos;
}
int sin = def.sin(angle);
if (def.abs(angleC) > 1800 && def.abs(angleC) < 3600) {
sin = -sin;
}
//calculating moving velocity
int cosX = vx0 > 0 ? cos : -cos;
int sinX = vx0 > 0 ? -sin : sin;
int cosY = vy0 > 0 ? sin : -sin;
int sinY = vy0 > 0 ? cos : -cos;
//here 9/02
int collidingVelocity0 = (def.abs(vx0) * sinX + def.abs(vy0) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity0 = (def.abs(vx0) * cosX + def.abs(vy0) * cosY)
/ def.VALUE_MULTIPLE_TEN;
int collidingVelocity1 = (def.abs(vx1) * sinX + def.abs(vy1) * sinY)
/ def.VALUE_MULTIPLE_TEN;
int excursionVelocity1 = (def.abs(vx1) * cosX + def.abs(vy1) * cosY)
/ def.VALUE_MULTIPLE_TEN;
// silent thing`s velocity after collision
int sCollidedVelocity0 = ( (collidingVelocity0 * (mm - ms)) +
(2 * ms * collidingVelocity1))
/ (mm + ms);
cosY = sCollidedVelocity0 > 0 ? -sin : sin;
sinY = sCollidedVelocity0 > 0 ? cos : -cos;
v[2] = def.abs(sCollidedVelocity0) * cosY / def.VALUE_MULTIPLE_TEN;
v[3] = def.abs(sCollidedVelocity0) * sinY / def.VALUE_MULTIPLE_TEN;
cosX = excursionVelocity0 > 0 ? cos : -cos;
sinX = excursionVelocity0 > 0 ? sin : -sin;
//v[2] += (def.abs(excursionVelocity0) * cosX) / def.VALUE_MULTIPLE_TEN;
//v[3] += (def.abs(excursionVelocity0) * sinX) / def.VALUE_MULTIPLE_TEN;
v[2] = vx0; // added by Milo 10-10
v[3] = vy0;
int sCollidedVelocity1 = ( (collidingVelocity1 * (ms - mm)) +
(2 * mm * collidingVelocity0)) / (mm + ms);
cosY = sCollidedVelocity1 > 0 ? -sin : sin;
sinY = sCollidedVelocity1 > 0 ? cos : -cos;
v[0] = def.abs(sCollidedVelocity1) * cosY / def.VALUE_MULTIPLE_TEN;
v[1] = def.abs(sCollidedVelocity1) * sinY / def.VALUE_MULTIPLE_TEN;
cosX = excursionVelocity1 > 0 ? cos : -cos;
sinX = excursionVelocity1 > 0 ? sin : -sin;
v[0] += (def.abs(excursionVelocity1) * cosX) / def.VALUE_MULTIPLE_TEN;
v[1] += (def.abs(excursionVelocity1) * sinX) / def.VALUE_MULTIPLE_TEN;
}
else //rotated collsion
{
if (collisionStatus == def.TENPIN_LOW_ROTATED_COLLISION) {
v[0] = vx1;
v[1] = vy1;
v[2] = vx0;
v[3] = vy0;
}
}
return v;
}
/**
* judge if the collisioin will happen
*
* @param x0 x coordinate of the moving object
* @param y0 y coordinate of the moving object
* @param vx the X velocity of the moving object
* @param vy the Y velocity of the moving object
* @param x1 x coordinate of the still object
* @param y1 y coordinate of the still object
* @param r0 the radius of the moving object
* @param r1 the radius of the still object
* @return int[4] result, result[0]is 1 if the collision happens, or result[0] is 0; <p>
* result[1] and result[2] means the x, y coordinate of the moving object when the collision happens <p>
* result[3] means the tangent degree of the collision
* result[4] means which part of still tenpin was collised
*/
private int[] isTenpinStillCollision(int pin1, int pin2){
int r0 = CTenpin.TENPIN_RADIUS;
int r1 = r0;
int vx = m_tenpin[pin1].m_tenpinVelocity[0];
int vy = m_tenpin[pin1].m_tenpinVelocity[1];
int[] result = new int[5];
for (int i = 0; i < 5; i++) {
result[i] = 0;
}
//result[0] = def.TENPIN_WITHOUT_COLLISION;
try{
int x0 = m_tenpin[pin1].m_tenpinPosition[0];
int y0 = m_tenpin[pin1].m_tenpinPosition[1];
int z0 = m_tenpin[pin1].m_tenpinPosition[2];
int x1 = m_tenpin[pin2].m_tenpinPosition[0]; //still tenpin
int y1 = m_tenpin[pin2].m_tenpinPosition[1];
int z1 = m_tenpin[pin2].m_tenpinPosition[2];
int tempCos;
int tempSin;
m_tenpin[pin1].m_tenpinAngle[2]%= 3600;
if (m_tenpin[pin1].m_tenpinAngle[2] > 900 &&
m_tenpin[pin1].m_tenpinAngle[2] < 1800) {
tempCos = -def.cos(1800 - m_tenpin[pin1].m_tenpinAngle[2]);
tempSin = def.sin(1800 - m_tenpin[pin1].m_tenpinAngle[2]);
}
else if (m_tenpin[pin1].m_tenpinAngle[2] > 1800 &&
m_tenpin[pin1].m_tenpinAngle[2] < 2700) {
tempCos = def.cos(2700 - m_tenpin[pin1].m_tenpinAngle[2]);
tempSin = -def.sin(2700 - m_tenpin[pin1].m_tenpinAngle[2]);
}
else if (m_tenpin[pin1].m_tenpinAngle[2] > 2700 &&
m_tenpin[pin1].m_tenpinAngle[2] < 3600) {
tempCos = -def.cos(3600 - m_tenpin[pin1].m_tenpinAngle[2]);
tempSin = -def.sin(3600 - m_tenpin[pin1].m_tenpinAngle[2]);
}
else {
tempCos = def.cos(m_tenpin[pin1].m_tenpinAngle[2]);
tempSin = def.sin(m_tenpin[pin1].m_tenpinAngle[2]);
}
int[] newStillPosition = new int[3];
newStillPosition[0] = x0 +
(tempCos * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
newStillPosition[1] = y0 +
(tempSin * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
newStillPosition[2] = z0 +
(def.cos(m_tenpin[pin1].m_tenpinAngle[0]) * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
/*int dis0 = def.distanceP2L(x1, y1, z1, x1, y1, z1 + CTenpin.TENPIN_HEIGHT,
x0, y0, z0);
int dis1 = def.distanceP2L(x1, y1, z1, x1, y1, z1 + CTenpin.TENPIN_HEIGHT,
newStillPosition[0], newStillPosition[1],
newStillPosition[2]);*/
int dis0 = def.distanceP2P(x1, y1, x0, y0);
int dis1 = def.distanceP2P(x1, y1, newStillPosition[0], newStillPosition[1]);
//int disTemp = def.distanceP2L(x0 + vx, y0 + vy, z0, newStillPosition[0] +vx,newStillPosition[1] + vy, newStillPosition[2], x1, y1, z1);
int disTemp = def.distanceP2L(x0 + vx, y0 + vy, newStillPosition[0] +vx,newStillPosition[1] + vy, x1, y1); //Chaneged by Milo 10-12
//think about /3 distance head collision 10-13
int tempZ = dis0 < dis1 ? z0 : newStillPosition[2];
boolean isCollision = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -