Package com.jme3.math
Class Ray
java.lang.Object
com.jme3.math.Ray
- All Implemented Interfaces:
- Collidable,- Savable,- Serializable,- Cloneable
Ray defines a line segment which has an origin and a direction.
 That is, a point and an infinite ray is cast from this point. The ray is
 defined by the following equation: 
 R(t) = origin + t*direction for t >= 0.
 - See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionclone()Create a copy of this ray.intcollideWith(Collidable other, CollisionResults results) Check collision with another Collidable.floatdistanceSquared(Vector3f point) Calculate the squared distance from this ray to the specified point.getDirectionretrieves the direction vector of the ray.floatgetLimit()getLimitreturns the limit of the ray, aka the length.getOriginretrieves the origin point of the ray.floatintersects(Vector3f v0, Vector3f v1, Vector3f v2) booleanintersectsWherePlane(Plane p, Vector3f loc) booleanintersectWhere(Triangle t, Vector3f loc) intersectWheredetermines if the Ray intersects a triangle.booleanintersectWhere(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f loc) intersectWheredetermines if the Ray intersects a triangle defined by the specified points and if so it stores the point of intersection in the given loc vector.booleanintersectWherePlanar(Triangle t, Vector3f loc) intersectWherePlanardetermines if the Ray intersects a triangle and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the triangle plane.booleanintersectWherePlanar(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f loc) intersectWherePlanardetermines if the Ray intersects a triangle defined by the specified points and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the triangle plane.booleanintersectWherePlanarQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f loc) intersectWherePlanardetermines if the Ray intersects a quad defined by the specified points and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the quad plane.voidread(JmeImporter importer) De-serialize this ray from the specified importer, for example when loading from a J3O file.voidCopies information from a source ray into this ray.voidsetDirection(Vector3f direction) setDirectionsets the direction vector of the ray.voidsetLimit(float limit) setLimitsets the limit of the ray.voidsetOriginsets the origin of the ray.toString()Represent this ray as a String.voidwrite(JmeExporter e) Serialize this ray to the specified exporter, for example when saving to a J3O file.
- 
Field Details- 
originThe ray's beginning point.
- 
directionThe direction of the ray.
- 
limitpublic float limitThe length of the ray (defaults to +Infinity).
 
- 
- 
Constructor Details- 
Raypublic Ray()Constructor instantiates a newRayobject. As default, the origin is (0,0,0) and the direction is (0,0,1).
- 
RayConstructor instantiates a newRayobject. The origin and direction are given.- Parameters:
- origin- the origin of the ray.
- direction- the direction the ray travels in.
 
 
- 
- 
Method Details- 
intersectWhereintersectWheredetermines if the Ray intersects a triangle. It then stores the point of intersection in the given loc vector- Parameters:
- t- the Triangle to test against.
- loc- storage vector to save the collision point in (if the ray collides)
- Returns:
- true if the ray collides.
 
- 
intersectWhereintersectWheredetermines if the Ray intersects a triangle defined by the specified points and if so it stores the point of intersection in the given loc vector.- Parameters:
- v0- first point of the triangle.
- v1- second point of the triangle.
- v2- third point of the triangle.
- loc- storage vector to save the collision point in (if the ray collides) if null, only boolean is calculated.
- Returns:
- true if the ray collides.
 
- 
intersectWherePlanarintersectWherePlanardetermines if the Ray intersects a triangle and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the triangle plane.- Parameters:
- t- the Triangle to test against.
- loc- storage vector to save the collision point in (if the ray collides) as t, u, v
- Returns:
- true if the ray collides.
 
- 
intersectWherePlanarintersectWherePlanardetermines if the Ray intersects a triangle defined by the specified points and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the triangle plane.- Parameters:
- v0- first point of the triangle.
- v1- second point of the triangle.
- v2- third point of the triangle.
- loc- storage vector to save the collision point in (if the ray collides) as t, u, v
- Returns:
- true if the ray collides.
 
- 
intersects
- 
intersectWherePlanarQuadintersectWherePlanardetermines if the Ray intersects a quad defined by the specified points and if so it stores the point of intersection in the given loc vector as t, u, v where t is the distance from the origin to the point of intersection and u,v is the intersection point in terms of the quad plane. One edge of the quad is [v0,v1], another one [v0,v2]. The behaviour thus is likeintersectWherePlanar(Vector3f, Vector3f, Vector3f, Vector3f)except for the extended area, which is equivalent to the union of the triangles [v0,v1,v2] and [-v0+v1+v2,v1,v2].- Parameters:
- v0- top left point of the quad.
- v1- top right point of the quad.
- v2- bottom left point of the quad.
- loc- storage vector to save the collision point in (if the ray collides) as t, u, v
- Returns:
- true if the ray collides with the quad.
 
- 
intersectsWherePlane- Parameters:
- p- the Plane to test for collision (not null, unaffected)
- loc- storage for the location of the intersection (not null, modified when returning true)
- Returns:
- true if the ray collides with the given Plane
 
- 
collideWithDescription copied from interface:CollidableCheck collision with another Collidable.- Specified by:
- collideWithin interface- Collidable
- Parameters:
- other- The object to check collision against
- results- Will contain the list of- CollisionResults.
- Returns:
- how many collisions were found between this and other
 
- 
distanceSquaredCalculate the squared distance from this ray to the specified point.- Parameters:
- point- location vector of the input point (not null, unaffected)
- Returns:
- the square of the minimum distance (≥0)
 
- 
getOrigingetOriginretrieves the origin point of the ray.- Returns:
- the origin of the ray.
 
- 
setOriginsetOriginsets the origin of the ray.- Parameters:
- origin- the origin of the ray.
 
- 
getLimitpublic float getLimit()getLimitreturns the limit of the ray, aka the length. If the limit is not infinity, then this ray is a line with lengthlimit.- Returns:
- the limit of the ray, aka the length.
 
- 
setLimitpublic void setLimit(float limit) setLimitsets the limit of the ray.- Parameters:
- limit- the limit of the ray.
- See Also:
 
- 
getDirectiongetDirectionretrieves the direction vector of the ray.- Returns:
- the direction of the ray.
 
- 
setDirectionsetDirectionsets the direction vector of the ray.- Parameters:
- direction- the direction of the ray.
 
- 
setCopies information from a source ray into this ray.- Parameters:
- source- the ray to copy information from
 
- 
toStringRepresent this ray as a String. The format is: Ray [Origin: (X.X, Y.Y, Z.Z), Direction: (X.X, Y.Y, Z.Z)]
- 
writeSerialize this ray to the specified exporter, for example when saving to a J3O file.- Specified by:
- writein interface- Savable
- Parameters:
- e- (not null)
- Throws:
- IOException- from the exporter
 
- 
readDe-serialize this ray from the specified importer, for example when loading from a J3O file.- Specified by:
- readin interface- Savable
- Parameters:
- importer- (not null)
- Throws:
- IOException- from the importer
 
- 
cloneCreate a copy of this ray.
 
-