Constructor
Variables
Methods
getRayToSphereIntersection(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Float, bNearest:Bool = true, bNormal:Bool = false, ?outVector3D:Vector3D):Vector3D
Returns a Vector3D where the ray intersects a sphere. Return null if the ray misses the sphere
Parameters:
pOrig | Vector3D. The origin of the ray. |
|---|---|
dir | Vector3D. The direction of the ray. |
sPos | Vector3D. The position of the sphere. |
radius | Number. The radius of the sphere. |
bNearest | [optional] Boolean. If the ray traverses the sphere and if true the returned hit is the nearest to ray origin. Default is true. |
bNormal | [optional] Boolean. If the returned vector is the normal of the hitpoint. Default is false. |
Returns:
Vector3D The intersection vector3D or the normal vector3D of the hitpoint. Default is false. example of a ray triggered from mouse
var pMouse:Vector3D = _view.unproject(_view.mouseX, _view.mouseY, 1);
var cam:Vector3D = _view.camera.position;
var dir:Vector3D = new Vector3D( pMouse.x-cam.x, pMouse.y-cam.y, pMouse.z-cam.z);
dir.normalize();
var spherePosition:Vector3D = new Vector3D(200, 200, 200);
//hittest
trace("Ray intersects sphere :"+ _ray.intersectsSphere(pMouse, dir, spherePosition, 500) );
var sintersect:Vector3D = _ray.getRayToSphereIntersection(pMouse, dir, spherePosition, 500, true, false);
if sintersect == null no hit, else sintersect = intersection vector3d or the normal of the intersection
getRayToTriangleIntersection(p0:Vector3D, p1:Vector3D, v0:Vector3D, v1:Vector3D, v2:Vector3D, ?outVector3D:Vector3D):Vector3D
Returns a Vector3D where the ray intersects a plane inside a triangle Returns null if no hit is found.
Parameters:
p0 | Vector3D. The origin of the ray. |
|---|---|
p1 | Vector3D. The end of the ray. |
v0 | Vector3D. The first scenespace vertex of the face. |
v1 | Vector3D. The second scenespace vertex of the face. |
v2 | Vector3D. The third scenespace vertex of the face. |
outVector3D | Vector3D. Optional user defined Vector3D returned with result values example: fire a ray from camera position to 0,0,0 and test if it hits the triangle. |
Returns:
Vector3D The intersection point
intersectsSphere(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Float):Bool
Checks if a ray intersects a sphere.
Parameters:
pOrig | Vector3D. The origin vector of the ray. |
|---|---|
dir | Vector3D. The normalized direction vector of the ray. |
sPos | Vector3D. The position of the sphere. |
radius | Number. The radius of the sphere. |
Returns:
Boolean If the ray intersects the sphere