Class TRayCollision

Unit

Declaration

type TRayCollision = class(specialize TStructList<TRayCollisionNode>)

Description

Represents a ray collision with TCastleTransform (TCastleTransform that may have parents).

We advise to access the useful information using only the Transform or Info methods or read Distance field.

Everything else is somewhat internal information and things get complicated if you try to make sense of it. It's a TODO: to maybe deprecate this structure in favor of something simpler.

The full description is that this is a list, from the innermost TCastleTransform that was hit by the ray, to the root of the TCastleTransform tree. The First item is the collision information with the final TCastleTransform. The rest of items are parent, grandparent etc. of this TCastleTransform object (so it is a path within TCastleViewport.Items hierarchy tree).

But be aware that CGE uses some internal TCastleTransform instances. E.g. TCastleBox, TCastleTiledMap have internal TCastleScene instances. These internal components are marked with csTransient flag in ComponentState.

We, again, advise to not iterate over this list or access e.g. first item directly. Use only Transform or Info methods or read Distance field! Things are simple then.

This is never an empty list when returned by RayCollision.

Hierarchy

Overview

Fields

Public Distance: Single;

Methods

Public function IndexOfItem(const Item: TCastleTransform): Integer; overload;
Public function IndexOfItem(const ItemClass: TCastleTransformClass): Integer; overload;
Public function Transform: TCastleTransform;
Public function Info(out HitInfo: TRayCollisionNode): Boolean;

Description

Fields

Public Distance: Single;

Distance, in world coordinate system, from the current camera to the picked point. The suggested usage is to decide if player is close enough to reach the 3D object — for example, you may not want to allow player to open a door by clicking on it from a far distance.

If the ray hit empty space, the distance is MaxSingle. Such case may occur because, once TCastleTransform handles TCastleTransform.PointingDevicePress, we make sure to inform it about PointingDeviceMove and PointingDeviceRelease, regardless if ray still hits this TCastleTransform instance.

Methods

Public function IndexOfItem(const Item: TCastleTransform): Integer; overload;

Index of node with given Item, -1 if none.

Public function IndexOfItem(const ItemClass: TCastleTransformClass): Integer; overload;

Index of node with given ItemClass, -1 if none.

Public function Transform: TCastleTransform;

TCastleTransform that was hit by given ray.

To be precise, this returns the inner-most TCastleTransform in the TCastleTransform tree, except it doesn't return internal TCastleTransform (that has csTransient flag is ComponentState). This way it doesn't return internal components, like internal TCastleScene inside TCastleBox or TCastleTiledMap.

Returns Nil if nothing was hit (Count is zero).

Public function Info(out HitInfo: TRayCollisionNode): Boolean;

Returns information about what was hit by given ray.

To be precise, this returns the first TRayCollisionNode on the list except it doesn't return TRayCollisionNode that relates to internal TCastleTransform (that has csTransient flag is ComponentState). This way it doesn't return internal components, like internal TCastleScene inside TCastleBox or TCastleTiledMap.

Returns False if nothing was hit (Count is zero), HitInfo is undefined in this case.


Generated by PasDoc 0.16.0-snapshot.