Public Member Functions

PolyVox::Raycast< VolumeType, VoxelType > Class Template Reference

The Raycast class can be used to find the fist filled voxel along a given path. More...

#include <Raycast.h>

Collaboration diagram for PolyVox::Raycast< VolumeType, VoxelType >:

List of all members.

Public Member Functions

 Raycast (VolumeType< VoxelType > *volData, const Vector3DFloat &v3dStart, const Vector3DFloat &v3dDirection, RaycastResult &result)
 Constructor.
void setStart (const Vector3DFloat &v3dStart)
 Sets the start position for the ray.
void setDirection (const Vector3DFloat &v3dDirection)
 Set the direction for the ray.
void execute ()
 Performs the raycast.

Detailed Description

template<template< typename > class VolumeType, typename VoxelType>
class PolyVox::Raycast< VolumeType, VoxelType >

The Raycast class can be used to find the fist filled voxel along a given path.

The principle behind raycasting is to fire a 'ray' through the volume and determine what (if anything) that ray hits. This simple test can be used for the purpose of picking, visibility checks, lighting calculations, or numerous other applications.

A ray is a stright line in space define by a start point and a direction vector. The length of the direction vector represents the length of the ray. When you call a Raycast object's execute() method it will iterate over each voxel which lies on the ray, starting from the defined start point. It will examine each voxel and terminate either when it encounters a solid voxel or when it reaches the end of the ray. If a solid voxel is encountered then its position is stored in the intersectionVoxel field of the RaycastResult structure and the intersectionFound flag is set to true, otherwise the intersectionFound flag is set to false.

The following code snippet shows how the class is used:

 Vector3DFloat start(rayOrigin.x(), rayOrigin.y(), rayOrigin.z());
 Vector3DFloat direction(rayDir.x(), rayDir.y(), rayDir.z());
 direction.normalise();
 direction *= 1000.0f; //Casts ray of length 1000
 
 RaycastResult raycastResult;
 Raycast<Material8> raycast(m_pPolyVoxVolume, start, direction, raycastResult);
 raycast.execute();
 
 if(raycastResult.foundIntersection)
 {
    //...
 }

Some further notes, the Raycast uses full 26-connectivity, which basically means it will examine every voxel the ray touches, even if it just passes through the corner. Also, it peforms a simple binary test against a voxel's threshold, rather than making use of it's density. Therefore it will work best in conjunction with one of the 'cubic' surace extractors. It's behaviour with the Marching Cubes surface extractor has not been tested yet.

Definition at line 87 of file Raycast.h.


Constructor & Destructor Documentation

template<template< typename > class VolumeType, typename VoxelType >
PolyVox::Raycast< VolumeType, VoxelType >::Raycast ( VolumeType< VoxelType > *  volData,
const Vector3DFloat v3dStart,
const Vector3DFloat v3dDirection,
RaycastResult result 
)

Constructor.

Builds a Raycast object.

Parameters:
volData A pointer to the volume through which the ray will be cast.
v3dStart The starting position of the ray.
v3dDirection The direction of the ray. The length of this vector also represents the length of the ray.
result An instance of RaycastResult in which the result will be stored.

Definition at line 35 of file Raycast.inl.


Member Function Documentation

template<template< typename > class VolumeType, typename VoxelType >
void PolyVox::Raycast< VolumeType, VoxelType >::execute ( void   ) 

Performs the raycast.

The result is stored in the RaycastResult instance which was passed to the constructor.

Definition at line 67 of file Raycast.inl.

Referenced by PolyVox::AmbientOcclusionCalculator< VolumeType, VoxelType >::execute().

Here is the call graph for this function:

template<template< typename > class VolumeType, typename VoxelType >
void PolyVox::Raycast< VolumeType, VoxelType >::setDirection ( const Vector3DFloat v3dDirection  ) 

Set the direction for the ray.

Parameters:
v3dDirection The direction of the ray. The length of this vector also represents the length of the ray.

Definition at line 58 of file Raycast.inl.

Referenced by PolyVox::AmbientOcclusionCalculator< VolumeType, VoxelType >::execute().

template<template< typename > class VolumeType, typename VoxelType >
void PolyVox::Raycast< VolumeType, VoxelType >::setStart ( const Vector3DFloat v3dStart  ) 

Sets the start position for the ray.

Parameters:
v3dStart The starting position of the ray.

Definition at line 48 of file Raycast.inl.

Referenced by PolyVox::AmbientOcclusionCalculator< VolumeType, VoxelType >::execute().


The documentation for this class was generated from the following files: