📄 cscene.java
字号:
if (tempZ <= def.TENPIN_GRAVITY_CENTER * 2) {
if (disTemp <= (r0 + r1)) {
//collision with biggest one
if ((dis0-dis1) < CTenpin.TENPIN_HEIGHT / def.FALLING_VALUE )
{
result[0] = def.TENPIN_NORMAL_COLLISION;
isCollision = true;
result[4] = def.TENPIN_BIGGEST_PART;
}
else{
result[0] = def.TENPIN_HEAD_COLLISION;
result[4] = def.TENPIN_BIGGEST_PART;
}
}
}
else if (tempZ <= def.TENPIN_GRAVITY_CENTER * 4) {
if (disTemp <= (r0 + r1 / 2)) {
//collision with middle one
if ((dis0-dis1) < CTenpin.TENPIN_HEIGHT / def.FALLING_VALUE )
{
result[0] = def.TENPIN_NORMAL_COLLISION;
isCollision = true;
result[4] = def.TENPIN_MIDDLE_PART;
}
else {
result[0] = def.TENPIN_HEAD_COLLISION;
result[4] = def.TENPIN_MIDDLE_PART;
}
}
}
else if (tempZ <= CTenpin.TENPIN_HEIGHT) {
if (disTemp <= (r0 + r1 / 3)) {
//collision with smallest one
if ( (dis0 - dis1) < CTenpin.TENPIN_HEIGHT / def.FALLING_VALUE) {
result[0] = def.TENPIN_LOW_ROTATED_COLLISION;
isCollision = true;
result[4] = def.TENPIN_SMALLEST_PART;
}
else {
result[0] = def.TENPIN_HEAD_COLLISION;
result[4] = def.TENPIN_SMALLEST_PART;
}
}
}
else {
//without collision
result[0] = def.TENPIN_WITHOUT_COLLISION;
return result;
}
if (result[0] == def.TENPIN_HEAD_COLLISION) {
result[1] = x0;
result[2] = y0;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
return result;
}
if (isCollision == true) {
if (vx == 0 && vy == 0) {
result[0] = def.TENPIN_NORMAL_COLLISION;
result[1] = x0;
result[2] = y0;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
return result;
}
long a = (long) (y1 - y0) * vx * vy + (long) x1 * vx * vx
+ (long) x0 * vy * vy;
long b = (long) (x1 - x0) * vx * vy + (long) y1 * vy * vy
+ (long) y0 * vx * vx;
int c = vx * vx + vy * vy;
////System.out.println("a b c "+a+" "+b+" "+c);
int xplumb = (int) (a / c);
int yplumb = (int) (b / c);
//System.out.println("plumb: "+xplumb+" "+yplumb);
int dislev = def.sqrt( (r0 + r1) * (r0 + r1) - disTemp * disTemp);
//System.out.println("dislev: "+dislev);
int angleC;
if (vx != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * vy / vx));
}
else {
angleC = 900;
}
int cos = def.cos(angleC);
int sin = def.sin(angleC);
if (vy < 0) {
sin = -sin;
}
if (vx < 0) {
cos = -cos;
}
int rx = dislev * cos / def.VALUE_MULTIPLE_TEN;
int ry = dislev * sin / def.VALUE_MULTIPLE_TEN;
//System.out.println("rx ry: "+rx+" "+ry);
if ( (yplumb - ry > y0 && yplumb - ry > y0 + vy && yplumb + ry > y0 &&
yplumb
+ ry > y0 + vy)
|| (yplumb - ry < y0 && yplumb - ry < y0 + vy
&& yplumb + ry < y0 && yplumb + ry < y0 + vy)) {
result[0] = def.TENPIN_WITHOUT_COLLISION;
return result;
}
result[1] = xplumb - rx;
result[2] = yplumb - ry;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
}
return result;
}
catch (Exception ex){
System.out.println(ex.toString());
return result;
}
}
private int[] isTenpinDeadCollision(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[] newPin1Position = new int[2];
newPin1Position[0] = x0 +
(tempCos * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
newPin1Position[1] = y0 +
(tempSin * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
m_tenpin[pin2].m_tenpinAngle[2]%= 3600;
if (m_tenpin[pin2].m_tenpinAngle[2] > 900 &&
m_tenpin[pin2].m_tenpinAngle[2] < 1800) {
tempCos = -def.cos(1800 - m_tenpin[pin2].m_tenpinAngle[2]);
tempSin = def.sin(1800 - m_tenpin[pin2].m_tenpinAngle[2]);
}
else if (m_tenpin[pin2].m_tenpinAngle[2] > 1800 &&
m_tenpin[pin2].m_tenpinAngle[2] < 2700) {
tempCos = def.cos(2700 - m_tenpin[pin2].m_tenpinAngle[2]);
tempSin = -def.sin(2700 - m_tenpin[pin2].m_tenpinAngle[2]);
}
else if (m_tenpin[pin2].m_tenpinAngle[2] > 2700 &&
m_tenpin[pin2].m_tenpinAngle[2] < 3600) {
tempCos = -def.cos(3600 - m_tenpin[pin2].m_tenpinAngle[2]);
tempSin = -def.sin(3600 - m_tenpin[pin2].m_tenpinAngle[2]);
}
else {
tempCos = def.cos(m_tenpin[pin2].m_tenpinAngle[2]);
tempSin = def.sin(m_tenpin[pin2].m_tenpinAngle[2]);
}
int[] newPin2Position = new int[2];
newPin2Position[0] = x0 +
(tempCos * CTenpin.TENPIN_HEIGHT) /
def.VALUE_MULTIPLE_TEN;
newPin2Position[1] = y0 +
(tempSin * 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.distanceP2L(x1, y1,
newPin2Position[0], newPin2Position[1],
x0 + vx, y0 + vy);
int dis1 = def.distanceP2L(x1, y1,
newPin2Position[0], newPin2Position[1],
newPin1Position[0] + vx,
newPin1Position[1] + vy);
//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 disTemp = dis0 < dis1 ? dis0 : dis1;
boolean isCollision = false;
if (disTemp <= (r0 + r1)) {
//collision with smallest one
if ( (dis0 - dis1) < CTenpin.TENPIN_HEIGHT / def.FALLING_VALUE) {
result[0] = def.TENPIN_NORMAL_COLLISION;
isCollision = true;
result[4] = def.TENPIN_SMALLEST_PART;
}
else {
result[0] = def.TENPIN_HEAD_COLLISION;
result[4] = def.TENPIN_SMALLEST_PART;
}
}
else{
result[0] = def.TENPIN_WITHOUT_COLLISION;
return result;
}
if (result[0] == def.TENPIN_HEAD_COLLISION) {
result[1] = x0;
result[2] = y0;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
return result;
}
if (isCollision == true) {
if (vx == 0 && vy == 0) {
result[0] = def.TENPIN_NORMAL_COLLISION;
result[1] = x0;
result[2] = y0;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
return result;
}
long a = (long) (y1 - y0) * vx * vy + (long) x1 * vx * vx
+ (long) x0 * vy * vy;
long b = (long) (x1 - x0) * vx * vy + (long) y1 * vy * vy
+ (long) y0 * vx * vx;
int c = vx * vx + vy * vy;
////System.out.println("a b c "+a+" "+b+" "+c);
int xplumb = (int) (a / c);
int yplumb = (int) (b / c);
//System.out.println("plumb: "+xplumb+" "+yplumb);
int dislev = def.sqrt( (r0 + r1) * (r0 + r1) - disTemp * disTemp);
//System.out.println("dislev: "+dislev);
int angleC;
if (vx != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * vy / vx));
}
else {
angleC = 900;
}
int cos = def.cos(angleC);
int sin = def.sin(angleC);
if (vy < 0) {
sin = -sin;
}
if (vx < 0) {
cos = -cos;
}
int rx = dislev * cos / def.VALUE_MULTIPLE_TEN;
int ry = dislev * sin / def.VALUE_MULTIPLE_TEN;
//System.out.println("rx ry: "+rx+" "+ry);
if ( (yplumb - ry > y0 && yplumb - ry > y0 + vy && yplumb + ry > y0 &&
yplumb
+ ry > y0 + vy)
|| (yplumb - ry < y0 && yplumb - ry < y0 + vy
&& yplumb + ry < y0 && yplumb + ry < y0 + vy)) {
result[0] = def.TENPIN_WITHOUT_COLLISION;
return result;
}
result[1] = xplumb - rx;
result[2] = yplumb - ry;
result[3] = (r0 + r1 - disTemp) / def.DEFAULT_EXTEND;
}
return result;
}
catch (Exception ex){
System.out.println(ex.toString());
return result;
}
}
/**
* judge if the collisioin will happen
*
* @param x0 x coordinate of the moving object
* @param y0 y coordinate of the moving object
* @param vx0 the X velocity of the moving object
* @param vy0 the Y velocity of the moving object
* @param x1 x coordinate of the still object
* @param y1 y coordinate of the still object
* @param vx1 the X velocity of the other object
* @param vy1 the Y velocity of the other object
* @param r0 the radius of the moving object
* @param r1 the radius of the still object
* @return int[6] 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] and result[4] means the x, y coordinate of the other object when the collision happens <p>
* result[5] means the tangent degree of the collision
*/
private int[] isTenpinCollisionWithMovingTenpin(int pin1,int pin2){
int r0 = CTenpin.TENPIN_RADIUS;
int r1 = r0;
int vx0 = m_tenpin[pin1].m_tenpinVelocity[0];
int vy0 = m_tenpin[pin1].m_tenpinVelocity[1];
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 vx1 = m_tenpin[pin2].m_tenpinVelocity[0];
int vy1 = m_tenpin[pin2].m_tenpinVelocity[1];
int x1 = m_tenpin[pin2].m_tenpinPosition[0];
int y1 = m_tenpin[pin2].m_tenpinPosition[1];
int z1 = m_tenpin[pin2].m_tenpinPosition[2];
int[] re
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -