7
« on: January 27, 2015, 06:17:12 am »
I have done it,may be someone need?
In my project it was worked perfect.
public boolean AABBIntersectsAABB(Object3D obj1,Object3D obj2, Update_trackandcar update,World world)
{
SimpleVector obj1_0=this.new_getworldspacebounds(obj1)[0];
SimpleVector obj1_1=this.new_getworldspacebounds(obj1)[1];
SimpleVector obj1_2=this.new_getworldspacebounds(obj1)[2];
SimpleVector obj1_3=this.new_getworldspacebounds(obj1)[3];
SimpleVector obj2_0=this.new_getworldspacebounds(obj2)[0];
SimpleVector obj2_1=this.new_getworldspacebounds(obj2)[1];
SimpleVector obj2_2=this.new_getworldspacebounds(obj2)[2];
SimpleVector obj2_3=this.new_getworldspacebounds(obj2)[3];
SimpleVector obj1_front=new SimpleVector(obj1_0.x-obj1_3.x,0,obj1_0.z-obj1_3.z);
SimpleVector obj1_left=new SimpleVector(obj1_0.x-obj1_1.x,0,obj1_0.z-obj1_1.z);
SimpleVector obj2_front=new SimpleVector(obj2_0.x-obj2_3.x,0,obj2_0.z-obj2_3.z);
SimpleVector obj2_left=new SimpleVector(obj2_0.x-obj2_1.x,0,obj2_0.z-obj2_1.z);
obj1_front.normalize();
obj1_left.normalize();
obj2_front.normalize();
obj2_left.normalize();
float distance1_z0=obj1_0.calcDot(obj1_front);
float distance1_z1=obj1_1.calcDot(obj1_front);
float distance1_z2=obj1_2.calcDot(obj1_front);
float distance1_z3=obj1_3.calcDot(obj1_front);
float distance1_z00=obj1_0.calcDot(obj2_front);
float distance1_z01=obj1_1.calcDot(obj2_front);
float distance1_z02=obj1_2.calcDot(obj2_front);
float distance1_z03=obj1_3.calcDot(obj2_front);
float distance1_x0=obj1_0.calcDot(obj1_left);
float distance1_x1=obj1_1.calcDot(obj1_left);
float distance1_x2=obj1_2.calcDot(obj1_left);
float distance1_x3=obj1_3.calcDot(obj1_left);
float distance1_x00=obj1_0.calcDot(obj2_left);
float distance1_x01=obj1_1.calcDot(obj2_left);
float distance1_x02=obj1_2.calcDot(obj2_left);
float distance1_x03=obj1_3.calcDot(obj2_left);
float[] distance1_z=new float[4];
distance1_z[0]=distance1_z0;
distance1_z[1]=distance1_z1;
distance1_z[2]=distance1_z2;
distance1_z[3]=distance1_z3;
float[] distance1_z_00=new float[4];
distance1_z_00[0]=distance1_z00;
distance1_z_00[1]=distance1_z01;
distance1_z_00[2]=distance1_z02;
distance1_z_00[3]=distance1_z03;
float[] distance1_x=new float[4];
distance1_x[0]=distance1_x0;
distance1_x[1]=distance1_x1;
distance1_x[2]=distance1_x2;
distance1_x[3]=distance1_x3;
float[] distance1_x_00=new float[4];
distance1_x_00[0]=distance1_x00;
distance1_x_00[1]=distance1_x01;
distance1_x_00[2]=distance1_x02;
distance1_x_00[3]=distance1_x03;
float distance2_z0=obj2_0.calcDot(obj1_front);
float distance2_z1=obj2_1.calcDot(obj1_front);
float distance2_z2=obj2_2.calcDot(obj1_front);
float distance2_z3=obj2_3.calcDot(obj1_front);
float distance2_z00=obj2_0.calcDot(obj2_front);
float distance2_z01=obj2_1.calcDot(obj2_front);
float distance2_z02=obj2_2.calcDot(obj2_front);
float distance2_z03=obj2_3.calcDot(obj2_front);
float distance2_x0=obj2_0.calcDot(obj1_left);
float distance2_x1=obj2_1.calcDot(obj1_left);
float distance2_x2=obj2_2.calcDot(obj1_left);
float distance2_x3=obj2_3.calcDot(obj1_left);
float distance2_x00=obj2_0.calcDot(obj2_left);
float distance2_x01=obj2_1.calcDot(obj2_left);
float distance2_x02=obj2_2.calcDot(obj2_left);
float distance2_x03=obj2_3.calcDot(obj2_left);
float[] distance2_z=new float[4];
distance2_z[0]=distance2_z0;
distance2_z[1]=distance2_z1;
distance2_z[2]=distance2_z2;
distance2_z[3]=distance2_z3;
float[] distance2_z_00=new float[4];
distance2_z_00[0]=distance2_z00;
distance2_z_00[1]=distance2_z01;
distance2_z_00[2]=distance2_z02;
distance2_z_00[3]=distance2_z03;
float[] distance2_x=new float[4];
distance2_x[0]=distance2_x0;
distance2_x[1]=distance2_x1;
distance2_x[2]=distance2_x2;
distance2_x[3]=distance2_x3;
float[] distance2_x_00=new float[4];
distance2_x_00[0]=distance2_x00;
distance2_x_00[1]=distance2_x01;
distance2_x_00[2]=distance2_x02;
distance2_x_00[3]=distance2_x03;
this.sort(distance1_x);
this.sort(distance1_z);
this.sort(distance2_x);
this.sort(distance2_z);
this.sort(distance1_x_00);
this.sort(distance1_z_00);
this.sort(distance2_x_00);
this.sort(distance2_z_00);
if(
(distance1_x[0]>distance2_x[3])
||
(distance1_x[3]<distance2_x[0])
||
(distance1_z[0]>distance2_z[3])
||
(distance1_z[3]<distance2_z[0])
||
(distance1_x_00[0]>distance2_x_00[3])
||
(distance1_x_00[3]<distance2_x_00[0])
||
(distance1_z_00[0]>distance2_z_00[3])
||
(distance1_z_00[3]<distance2_z_00[0])
)
{return false;}
else return true;
}