So here it is guys ,after several hours the last night and some more like these a few couples of months ago i finaly manages to write a correct code to perform Ray-Triangle intersection test using ray.getIntersect() ,method.I think it is pointless to explain why you would wish to perform such kind of test ( especially for those who develop FPS games) .So here is how this should be done(for any question on implementation you van ask me):
private function RayFaceTest():Vector3D{
var intersectVector:Vector3D;
var ray:Ray=new Ray();
for(var i:int=0;i<_objB.faces.length;++i){
var p0:Vector3D=_objB.sceneTransform.transformVector(_objB.faces[i].vertices[0].position);
var p1:Vector3D=_objB.sceneTransform.transformVector(_objB.faces[i].vertices[1].position);
var p2:Vector3D=_objB.sceneTransform.transformVector(_objB.faces[i].vertices[2].position);
ray.orig=_objA.position;
var dd:Vector3D=new Vector3D(0,400,0);
var dird:Vector3D=_objA.transform.transformVector(dd);
ray.dir=dird;
rayDebug(ray.orig,ray.dir);
intersectVector=ray.getIntersect(ray.orig,ray.dir,p0,p1,p2);
if(intersectVector){
break;
}
}
return intersectVector;
}
Explanation:
_objA and _objB are two spheres which have the same Z position. _objA is movable by keyboard input.We draw a ray from the center of sphere _objA in the direction of its local Y with the arbitrary length ( I set to 400).So basically when you rotate _objA around Z the ray direction transforms according to local _objA Y direction.We test the ray hits against the triangles of _objB sphere. Notice that right after for loop start we convert each face 3 vertices coords from obj local space into scene spaceNot doing so you will never get intersection(actually this was my pitfall ).Then we cast the ray passing into getIntersect() ray origin,ray direction vectors ,and 3 vertex vectors for the currently tested triangle.
If the intersection occurs intersectVector returns the coords of the hit otherwise it is null.If it is not null we break fro the loop in order to return the hit to the function and start the iteration again.This is it .I hope it was usefull . :))
--
Michael Ivanov ,Programmer
Neurotech Solutions Ltd.
Flex|Air |3D|Unity|
www.neurotechresearch.comhttp://blog.alladvanced.net
http://www.meetup.com/GO3D-Games-Opensource-3D/Tel:054-4962254
explo...@gmail.comte...@neurotech.co.il