Property | Defined By | ||
---|---|---|---|
dir : Vector3D
Defines the directional vector of the Ray object
| Ray | ||
orig : Vector3D
Defines the origin point of the Ray object
| Ray | ||
planeNormal : Vector3D [read-only]
Defines the directional normal of the Ray object
| Ray |
Method | Defined By | ||
---|---|---|---|
Ray() | Ray | ||
getRayToSphereIntersection(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Number, bNearest:Boolean = true, bNormal:Boolean = false, outVector3D:Vector3D = null):Vector3D
Returns a Vector3D where the ray intersects a sphere. | Ray | ||
getRayToTriangleIntersection(p0:Vector3D, p1:Vector3D, v0:Vector3D, v1:Vector3D, v2:Vector3D, outVector3D:Vector3D = null):Vector3D
Returns a Vector3D where the ray intersects a plane inside a triangle
Returns null if no hit is found. | Ray | ||
intersectsSphere(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Number):Boolean
Checks if a ray intersects a sphere. | Ray |
dir | property |
dir:Vector3D
Defines the directional vector of the Ray object
public function get dir():Vector3D
public function set dir(value:Vector3D):void
orig | property |
orig:Vector3D
Defines the origin point of the Ray object
public function get orig():Vector3D
public function set orig(value:Vector3D):void
planeNormal | property |
planeNormal:Vector3D
[read-only] Defines the directional normal of the Ray object
public function get planeNormal():Vector3D
Ray | () | Constructor |
public function Ray()
getRayToSphereIntersection | () | method |
public function getRayToSphereIntersection(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Number, bNearest:Boolean = true, bNormal:Boolean = false, outVector3D:Vector3D = null):Vector3D
Returns a Vector3D where the ray intersects a sphere. Return null if the ray misses the sphere param pOrig Vector3D. The origin of the ray. param dir Vector3D. The direction of the ray. param sPos Vector3D. The position of the sphere. param radius Number. The radius of the sphere. param bNearest [optional] Boolean. If the ray traverses the sphere and if true the returned hit is the nearest to ray origin. Default is true. param bNormal [optional] Boolean. If the returned vector is the normal of the hitpoint. Default is false.
Parameters
pOrig:Vector3D | |
dir:Vector3D | |
sPos:Vector3D | |
radius:Number | |
bNearest:Boolean (default = true )
| |
bNormal:Boolean (default = false )
| |
outVector3D:Vector3D (default = null )
|
Vector3D — 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);
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 | () | method |
public function getRayToTriangleIntersection(p0:Vector3D, p1:Vector3D, v0:Vector3D, v1:Vector3D, v2:Vector3D, outVector3D:Vector3D = null):Vector3D
Returns a Vector3D where the ray intersects a plane inside a triangle Returns null if no hit is found. param p0 Vector3D. The origin of the ray. param p1 Vector3D. The end of the ray. param v0 Vector3D. The first scenespace vertex of the face. param v1 Vector3D. The second scenespace vertex of the face. param v2 Vector3D. The third scenespace vertex of the face. param 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. view.camera.x = 100; view.camera.y = 100; view.camera.z = 500; var v0:Vector3D = new Vector3D(-200, 100, 60); var v1:Vector3D = new Vector3D(200, 100, 60); var v2:Vector3D = new Vector3D(0, -200, 60); var dest: Vector3D = new Vector3D(0, 0, 0); var intersect:Vector3D = _ray.getRayToTriangleIntersection(_view.camera.position, dest, v0, v1, v2 ); trace("intersect ray: "+intersect);
Parameters
p0:Vector3D | |
p1:Vector3D | |
v0:Vector3D | |
v1:Vector3D | |
v2:Vector3D | |
outVector3D:Vector3D (default = null )
|
Vector3D — Vector3D The intersection point
|
intersectsSphere | () | method |
public function intersectsSphere(pOrig:Vector3D, dir:Vector3D, sPos:Vector3D, radius:Number):Boolean
Checks if a ray intersects a sphere. param pOrig Vector3D. The origin vector of the ray. param dir Vector3D. The normalized direction vector of the ray. param sPos Vector3D. The position of the sphere. param radius Number. The radius of the sphere.
Parameters
pOrig:Vector3D | |
dir:Vector3D | |
sPos:Vector3D | |
radius:Number |
Boolean — Boolean If the ray intersects the sphere
|