reb
Class RaytraceGeneric

Object
  extended by common:Generic
      extended by reb:RaytraceGeneric
Direct Known Subclasses:
RaytraceSphere

class 
Generic:RaytraceGeneric

The generic class sets up lights and the viewpoint. Objects are to be set up in the descendants.


Ultra Fractal Source

Toggle UF Source Code Display

 Class RaytraceGeneric(common.ulb:Generic) {
 ; The generic class sets up lights and the viewpoint. Objects are to be
 ; set up in the descendants.
 
 public:
   import "common.ulb"
 ;  import "reb.ulb"
 
   func RaytraceGeneric(Generic pparent)
     Init()
   endfunc
 
 
   ; Call Init() in the global section
   func Init()
     ; create the lights and light vectors
     ; create the objects, including surface and transparency characteristics
     ;   1. textures, patterns, images, refractive index
     ;   2. spheres, planes, 3D fractals
     lar = new VectorArray(@nlight)
     int i = 0
     float vd = 0
     float litex = 0
     complex lite = 0
     float litez = 0
     while i < @nlight
       if i >= 0
         litex = (@lightx-@pointx)
         litey = -(@lighty-@pointy)
         litez = @lightz+@pointz
         lite = litex + flip(litey)
         vd = sqrt(|lite|+litez^2)
         lite = lite/vd
         litez = litez/vd
         lar.m_elements[i] = new Vector(real(lite), imag(lite), litez, 0)
         spec[0] = @spec1
         shiny[0] = @shiny1
         sbright[0] = @sbright1
       endif
       if i >= 1
         litex = (@lightx2-@pointx2)
         litey = -(@lighty2-@pointy2)
         litez = @lightz2+@pointz2
         lite = litex + flip(litey)
         vd = sqrt(|lite|+litez^2)
         lite = lite/vd
         litez = litez/vd
         lar.m_elements[i] = new Vector(real(lite), imag(lite), litez, 0)
         spec[1] = @spec2
         shiny[1] = @shiny2
         sbright[1] = @sbright2
       endif
       if i >= 2
         litex = (@lightx3-@pointx3)
         litey = -(@lighty3-@pointy3)
         litez = @lightz3+@pointz3
         lite = litex + flip(litey)
         vd = sqrt(|lite|+litez^2)
         lite = lite/vd
         litez = litez/vd
         lar.m_elements[i] = new Vector(real(lite), imag(lite), litez, 0)
         spec[2] = @spec3
         shiny[2] = @shiny3
         sbright[2] = @sbright3
       endif
       if i >= 3
         litex = (@lightx4-@pointx4)
         litey = -(@lighty4-@pointy4)
         litez = @lightz4+@pointz4
         lite = litex + flip(litey)
         vd = sqrt(|lite|+litez^2)
         lite = lite/vd
         litez = litez/vd
         lar.m_elements[i] = new Vector(real(lite), imag(lite), litez, 0)
         spec[3] = @spec4
         shiny[3] = @shiny4
         sbright[3] = @sbright4
       endif
       if i >= 4
         litex = (@lightx5-@pointx5)
         litey = -(@lighty5-@pointy5)
         litez = @lightz5+@pointz5
         lite = litex + flip(litey)
         vd = sqrt(|lite|+litez^2)
         lite = lite/vd
         litez = litez/vd
         lar.m_elements[i] = new Vector(real(lite), imag(lite), litez, 0)
         spec[4] = @spec5
         shiny[4] = @shiny5
         sbright[4] = @sbright5
       endif
       i = i + 1
     endwhile
     i = 0
     regress = 0
     int j = 0
     while i < 10
       diffuse[i] = 0
       while j < 5
         specular[i,j] = 0
         j = j + 1
       endwhile
       si[i] = 0
       i = i + 1
     endwhile
   endfunc
 
   ; call ViewPoint() in the init section
   func ViewPoint()
     ; create camera, view screen and view vector
     ; initialize zero and infinite distances
      ; setup to allow transforms
       float asp = #height/#width
      float xcrd = real(#screenpixel)
      float ycrd = imag(#screenpixel)
      ; generate the x and y location in the image
      float dxx = (real(#pixel)-real(#center))*(#width)/4*#magn
      float dyy = (imag(#pixel)-imag(#center))*(#width)/4*#magn
      float transx = (#width)*0.5;
      float transy = (#height)*0.5;
      float cosan = cos(#angle);
      float sinan = sin(#angle);
      xcrd = transx + (dxx*cosan + dyy*sinan)
      ycrd = transy + (dxx*sinan - dyy*cosan)
 
     float vd = 0
     float cx = 0
     float cy = 0
     float cz = @cameraz
     cx = cx - (0.5-xcrd/#width)*2 + real(#center)*#magn/2
     cy = cy - (0.5-ycrd/#height)*asp*2 - imag(#center)*#magn/2
     complex cam = cx + flip(cy)
     float vd = 1/sqrt(|cam|+cz^2)
     cam = cam*vd
     float camz = cz*vd
     view = new Vector(real(cam),imag(cam),camz,0)
     origin = new Vector(0,0,-@cameraz,0)
   endfunc
 
 ;-------------------------------------------------
 ; Function to determine object intersections with rays
 ; The maximum recursion level is currently set to 10
 ; @param origin = ray origin as a vector
 ; @param ray = ray as a vector
 ; @param regress = regression level
 ; @param rsi = object index - passed back from recursion
 ; @param dif = diffuse lighting parameter - passed back from recursion
 ; @param sbr = specular lighting paramer - passed back from recursion
 ; @param scolor = color of the intersected object
 ;------------------------------------------------
   ; Call Intersect() after viewpoint
   bool func Intersect(Vector origin, Vector ray, int ®ress, int &rsi, \
                  float &dif, float &sbr, color &scolor)
     return false
   endfunc
 
 
   ; call result() in the final section
   color func Result()
     color return_color = rgba(0.5,0.5,0.5,1)
     return return_color
   endfunc
 
   Vector view
   Vector origin
   float diffuse[10]
   float specular[10,5]
   int si[10]
   int regress
   color spec[5]
   color speccol[10,5]
 protected:
   VectorArray lar
   float shiny[5]
   float sbright[5]
 
 default:
   int param v_raytracegeneric
     caption = "Version (Raytrace Generic)"
     default = 100
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_raytracegeneric < 100
   endparam
   heading
     text = "This is the camera (viewpoint) distance from the view plane. The \
             view plane is the computer screen. Positive distances are in the \
             direction of the screen."
   endheading
   float param cameraz
     caption = "Camera Distance"
     default = -10
   endparam
   heading
     caption = "Light parameters"
     expanded = false
   endheading
   int param nlight
     caption = "Number of Lights"
     default = 1
     min = 1
     max = 5
   endparam
   heading
     text = "  Light Origin"
   endheading
   color param spec1
     caption = "Specular color"
     default = rgba(1,1,1,1)
   endparam
   float param sbright1
     caption = "Specular brightness"
     default = 0.7
     min = 0
     max = 1
   endparam
   float param shiny1
     caption = "Shininess"
     default = 100.0
   endparam
   float param lightx
     caption = "       X"
     default = 5
   endparam
   float param lighty
     caption = "       Y"
     default = 5
   endparam
   float param lightz
     caption = "       Z"
     default = 10
   endparam
   heading
     text = "  Light Point At"
   endheading
   float param pointx
     caption = "       X"
     default = 0.0
   endparam
   float param pointy
     caption = "       Y"
     default = 0.0
   endparam
   float param pointz
     caption = "       Z"
     default = 0.0
   endparam
   heading
     text = "Light #2"
     visible = @nlight > 1
   endheading
   heading
     text = "  Light Origin #2"
     visible = @nlight > 1
   endheading
   color param spec2
     caption = "Specular color"
     default = rgba(1,1,1,1)
     visible = @nlight > 1
   endparam
   float param sbright2
     caption = "Specular brightness"
     default = 0.7
     min = 0
     max = 1
     visible = @nlight > 1
   endparam
   float param shiny2
     caption = "Shininess"
     default = 100.0
     visible = @nlight > 1
   endparam
   float param lightx2
     caption = "       X"
     default = 5.0
     visible = @nlight > 1
   endparam
   float param lighty2
     caption = "       Y"
     default = 0.0
     visible = @nlight > 1
   endparam
   float param lightz2
     caption = "       Z"
     default = 10
     visible = @nlight > 1
   endparam
   heading
     text = "  Light Point At #2"
     visible = @nlight > 1
   endheading
   float param pointx2
     caption = "       X"
     default = 0.0
     visible = @nlight > 1
   endparam
   float param pointy2
     caption = "       Y"
     default = 0.0
     visible = @nlight > 1
   endparam
   float param pointz2
     caption = "       Z"
     default = 0.0
     visible = @nlight > 1
   endparam
   heading
     text = "Light #3"
     visible = @nlight > 2
   endheading
   heading
     text = "  Light Origin #3"
     visible = @nlight > 2
   endheading
   color param spec3
     caption = "Specular color"
     default = rgba(1,1,1,1)
     visible = @nlight > 2
   endparam
   float param sbright3
     caption = "Specular brightness"
     default = 0.7
     min = 0
     max = 1
     visible = @nlight > 2
   endparam
   float param shiny3
     caption = "Shininess"
     default = 100.0
     visible = @nlight > 2
   endparam
   float param lightx3
     caption = "       X"
     default = -2
     visible = @nlight > 2
   endparam
   float param lighty3
     caption = "       Y"
     default = 5
     visible = @nlight > 2
   endparam
   float param lightz3
     caption = "       Z"
     default = 10
     visible = @nlight > 2
   endparam
   heading
     text = "  Light Point At #3"
     visible = @nlight > 2
   endheading
   float param pointx3
     caption = "       X"
     default = 0.0
     visible = @nlight > 2
   endparam
   float param pointy3
     caption = "       Y"
     default = 0.0
     visible = @nlight > 2
   endparam
   float param pointz3
     caption = "       Z"
     default = 0.0
     visible = @nlight > 2
   endparam
   heading
     text = "Light #4"
     visible = @nlight > 3
   endheading
   heading
     text = "  Light Origin #4"
     visible = @nlight > 3
   endheading
   color param spec4
     caption = "Specular color"
     default = rgba(1,1,1,1)
     visible = @nlight > 3
   endparam
   float param sbright4
     caption = "Specular brightness"
     default = 0.7
     min = 0
     max = 1
     visible = @nlight > 3
   endparam
   float param shiny4
     caption = "Shininess"
     default = 100.0
     visible = @nlight > 3
   endparam
   float param lightx4
     caption = "       X"
     default = -5
     visible = @nlight > 3
   endparam
   float param lighty4
     caption = "       Y"
     default = -5
     visible = @nlight > 3
   endparam
   float param lightz4
     caption = "       Z"
     default = 10
     visible = @nlight > 3
   endparam
   heading
     text = "  Light Point At #4"
     visible = @nlight > 3
   endheading
   float param pointx4
     caption = "       X"
     default = 0.0
     visible = @nlight > 3
   endparam
   float param pointy4
     caption = "       Y"
     default = 0.0
     visible = @nlight > 3
   endparam
   float param pointz4
     caption = "       Z"
     default = 0.0
     visible = @nlight > 3
   endparam
   heading
     text = "Light #5"
     visible = @nlight > 4
   endheading
   heading
     text = "  Light Origin #5"
     visible = @nlight > 4
   endheading
   color param spec5
     caption = "Specular color"
     default = rgba(1,1,1,1)
     visible = @nlight > 4
   endparam
   float param sbright5
     caption = "Specular brightness"
     default = 0.7
     min = 0
     max = 1
     visible = @nlight > 4
   endparam
   float param shiny5
     caption = "Shininess"
     default = 100.0
     visible = @nlight > 4
   endparam
   float param lightx5
     caption = "       X"
     default = -2
     visible = @nlight > 4
   endparam
   float param lighty5
     caption = "       Y"
     default = -3
     visible = @nlight > 4
   endparam
   float param lightz5
     caption = "       Z"
     default = 10
     visible = @nlight > 4
   endparam
   heading
     text = "  Light Point At #5"
     visible = @nlight > 4
   endheading
   float param pointx5
     caption = "       X"
     default = 0.0
     visible = @nlight > 4
   endparam
   float param pointy5
     caption = "       Y"
     default = 0.0
     visible = @nlight > 4
   endparam
   float param pointz5
     caption = "       Z"
     default = 0.0
     visible = @nlight > 4
   endparam
 }
 


Constructor Summary
RaytraceGeneric()
           
RaytraceGeneric(Generic pparent)
          import "reb.ulb"
 
Method Summary
 void Init()
          Call Init() in the global section
 boolean Intersect(Vector origin, Vector ray, int regress, int rsi, float dif, float sbr, color scolor)
          Function to determine object intersections with rays The maximum recursion level is currently set to 10
 color Result()
          call result() in the final section
 void ViewPoint()
          call ViewPoint() in the init section
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

RaytraceGeneric

public RaytraceGeneric(Generic pparent)
import "reb.ulb"


RaytraceGeneric

public RaytraceGeneric()
Method Detail

Init

public void Init()
Call Init() in the global section


ViewPoint

public void ViewPoint()
call ViewPoint() in the init section


Intersect

public boolean Intersect(Vector origin,
                         Vector ray,
                         int regress,
                         int rsi,
                         float dif,
                         float sbr,
                         color scolor)
Function to determine object intersections with rays The maximum recursion level is currently set to 10

Parameters:
origin - = ray origin as a vector
ray - = ray as a vector
regress - = regression level
rsi - = object index - passed back from recursion
dif - = diffuse lighting parameter - passed back from recursion
sbr - = specular lighting paramer - passed back from recursion
scolor - = color of the intersected object Call Intersect() after viewpoint

Result

public color Result()
call result() in the final section