Navigation: Scripting Reference Manual > Functions & Subroutines > GetRaySurfaceNormal

 

GetRaySurfaceNormal

 

Contact Us: fredsupport@photonengr.com

 

Description

For the last surface a ray intersected, this command retrieves the vector normal to the surface at the ray's intersection coordinates.  Depending on the number of rays traced, it may be necessary to dimension ray index and ray counter variables as data type Huge_ instead of Long.  Please see Multi-threaded Raytracing for more information.

 

Syntax

GetRaySurfaceNormal idx, u, v, w

 

Parameters

idx As Long (or Huge_)

The index of the ray in the buffer.

 

u As Double

Returns the X component of the ray's surface normal vector in global coordinates.

 

v As Double

Returns the Y component of the ray's surface normal vector in global coordinates.

 

w As Double

Returns the Z component of the ray's surface normal vector in global coordinates

 

Remarks

This subroutine retrieves the vector normal to the last surface a particular ray touched. If there is a problem the subroutine sets an error and returns without modifying the parameters.

 

Note that this vector is NOT normalized, i.e., u2 + v2 + w2 ≠ 1. To determine the normalized vector (u', w', v'),

 

u'=u/Sqr(u2 + v2 + w2), v'=v/Sqr(u2 + v2 + w2), w'=w/Sqr(u2 + v2 + w2)

 

Examples

The following script loops over rays in the ray buffer and prints out the surface normal in the global coordinate system and in the local coordinate system of a designated surface.

 

Sub Main

 

          Dim ray As T_RAY

          Dim ii As Long, surfNode As Long

          Dim success As Boolean

          Dim u As Double, v As Double, w As Double

 

          ClearOutputWindow

 

          'surface whose local coordinate system is used

          surfNode = FindFullName( "Geometry.hemisphere.Hemisphere Inner Wall" )

 

          'setup output header information

          Print "Ray ID";

          Print "U";

          Print "V";

          Print "W"

          'start looping over rays

          success = GetFirstRay( ii, ray )

          While success

                    'surface normal in global coordinates

                    GetRaySurfaceNormal ii, u, v, w

                    Print ii;

                    Print u;

                    Print v;

                    Print w;

                    Print "(Global Coordinates)"

                    'transform normal into local coordinate system

                    TransformDirection -1, surfNode, u, v, w

                    Print Chr(9) & u;

                    Print v;

                    Print w;

                    Print "(Local Coordinates)"

                    success = GetNextRay( ii, ray )

          Wend

End Sub 

 

See Also

GetRayDirection

GetRayPower

Raydata GetSet

 

 

 

 

 

Copyright © Photon Engineering, LLC