Record TTriangle
Unit
Declaration
type TTriangle = record
Description
Triangle in 3D. This object should always be initialized by Init, and updated only by it's methods (never modify fields of this object directly).
Overview
Fields
Local: TTriangleGeometry; 

World: TTriangleGeometry; 

InternalShape: TObject; 

MailboxSavedTag: TMailboxTag; 

MailboxIsIntersection: boolean; 

MailboxIntersection: TVector3; 

MailboxIntersectionDistance: Single; 

Normal: TTriangle3; 

TexCoord: TTriangle4; 

Face: TFaceIndex; 
Methods
procedure Init(AShape: TObject; const ATriangle: TTriangle3; const ANormal: TTriangle3; const ATexCoord: TTriangle4; const AFace: TFaceIndex); 

function SegmentDirCollision( out Intersection: TVector3; out IntersectionDistance: Single; const Segment0, SegmentVector: TVector3; const SegmentTag: TMailboxTag): boolean; 

function RayCollision( out Intersection: TVector3; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3; const RayTag: TMailboxTag): boolean; 

function ITexCoord(const Point: TVector3): TVector4; 

function ITexCoord2D(const Point: TVector3): TVector2; 

function INormal(const Point: TVector3): TVector3; 

function INormalCore(const Point: TVector3): TVector3; 
Description
Fields
Local: TTriangleGeometry; 

Geometry of this item. We need two geometry descriptions:

World: TTriangleGeometry; 

Geometry of this item. We need two geometry descriptions:

InternalShape: TObject; 

Shape containing this triangle. This is always an instance of TShape class, but due to unit dependencies it cannot be declared as such here. Use CastleShapes unit to have a "record helper" method that returns a Shape as TShape instance. 
MailboxSavedTag: TMailboxTag; 

Tag of an object (like a ray or a line segment) for which we have saved an intersection result. Intersection result is in MailboxIsIntersection, MailboxIntersection, MailboxIntersectionDistance. To make things correct, we obviously assume that every segment and ray have different tags. Also, tag 1 is reserved. In practice, we simply initialize History: a naive implementation at the beginning was not using tags, instead I had MailboxState (empty, ray or segment) and I was storing ray/line vectors (2 TVector3 values). This had much larger size (6 * SizeOf(Single) + SizeOf(enum) = 28 bytes) than tag, which is important (3D models have easily thousands of TTriangle). And it took longer to compare and assign, so it was working much slower. 
MailboxIsIntersection: boolean; 

This item has no description. 
MailboxIntersection: TVector3; 

This item has no description. 
MailboxIntersectionDistance: Single; 

This item has no description. 
Normal: TTriangle3; 

Normal vectors, at each triangle vertex. 
TexCoord: TTriangle4; 

Texture coordinates, for each triangle point. Each texture coordinate is a 4D vector, since we may have 3D textures referenced by 4D (homogeneous) coordinates. For normal 2D textures, you can simply take the first 2 components of the vector, and ignore the remaining 2 components. The 3th component is always 0 if was not specified (if model had only 2D texture coords). The 4th component is always 1 if was not specified (if model had only 2D or 3D texture coords). In case of multitexturing, this describes coordinates of the first texture unit. In case no texture is defined, this is undefined. 
Face: TFaceIndex; 

The indexes of this 
Methods
procedure Init(AShape: TObject; const ATriangle: TTriangle3; const ANormal: TTriangle3; const ATexCoord: TTriangle4; const AFace: TFaceIndex); 

Initialize new triangle. Given ATriangle must satisfy ATriangle.IsValid. 
function SegmentDirCollision( out Intersection: TVector3; out IntersectionDistance: Single; const Segment0, SegmentVector: TVector3; const SegmentTag: TMailboxTag): boolean; 

Check collisions between TTriangle and ray/segment. Always use these routines to check for collisions, to use mailboxes if possible. Mailboxes are used only if this was compiled with TRIANGLE_OCTREE_USE_MAILBOX defined. Increments TriangleCollisionTestsCounter if actual test was done (that is, if we couldn't use mailbox to get the result quickier). 
function RayCollision( out Intersection: TVector3; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3; const RayTag: TMailboxTag): boolean; 

This item has no description. 
function ITexCoord(const Point: TVector3): TVector4; 

For a given position (in world coordinates), return the texture coordinate at this point. It is an interpolated texture coordinate from our pervertex texture coordinates in TexCoord field. This assumes that Position actually lies within the triangle. The ITexCoord2D returns the same, but cut to the first 2 texture coordinate components. Usable for normal 2D textures. 
function ITexCoord2D(const Point: TVector3): TVector2; 

This item has no description. 
function INormal(const Point: TVector3): TVector3; 

For a given position (in world coordinates), return the smooth normal vector at this point. It is an interpolated normal from our pervertex normals in the Normal field, thus is supports also the case when you have smooth shading (normals change throughout the triangle). Like the Normal field, the returned vector is a normal vector in the local coordinates. Use TTriangleHelper.INormalWorldSpace to get a normal vector in scene coordinates. This assumes that Position actally lies within the triangle. 
function INormalCore(const Point: TVector3): TVector3; 

Like INormal, but not necessarily normalized. 
Generated by PasDoc 0.16.0.