Standard
Class Standard_MappingShapeSphere

Object
  extended by common:Generic
      extended by common:MappingShape
          extended by Standard:Standard_MappingShapeSphere

class 
MappingShape:Standard_MappingShapeSphere

Implements the Sphere shape with radius 0.5 from 3D Mapping in Standard.uxf.


Ultra Fractal Source

Toggle UF Source Code Display

 class Standard_MappingShapeSphere(common.ulb:MappingShape) {
 ; Implements the Sphere shape with radius 0.5 from 3D Mapping in Standard.uxf.
 public:
   bool func GetTextureCoordinates(float sx, float sy, float sz, float dx, \
                                   float dy, float dz, complex &result)
     ; This must be solved:
     ; [ sx ]          [ dx ]   [ x ]
     ; [ sy ] + lambda [ dy ] = [ y ]
     ; [ sz ]          [ dz ]   [ z ]
     ; and
     ; x^2 + y^2 + z^2 = radius^2
 
     float lambda
     float a = sqr(dx) + sqr(dy) + sqr(dz)
     float b = 2 * sx * dx + 2 * sy * dy + 2 * sz * dz
     float c = sqr(sx) + sqr(sy) + sqr(sz) - 0.25
     float d = sqr(b) - 4 * a * c
 
     if d < 0
       ; No roots exist.
       return false
     else
       ; One or two roots: select smallest.
       if a > 0
         lambda = (-b - sqrt(d)) / (2 * a)
       else
         lambda = (-b + sqrt(d)) / (2 * a)
       endif
 
       if lambda <= 0
         ; Intersection point is behind the screen.
         return false
       else
         float x = sx + lambda * dx
         float y = sy + lambda * dy
         float z = sz + lambda * dz
 
         if z == 0
           if x > 0
             result = 2
           else
             result = -2
           endif
         else
           result = (4 / #pi) * atan(x / abs(z))
         endif
 
         result = result + flip((4 / #pi) * atan(y / sqrt(sqr(x) + sqr(z))))
         return true
       endif
     endif
   endfunc
 
 default:
   title = "Sphere"
 }
 


Constructor Summary
Standard_MappingShapeSphere()
           
 
Method Summary
 boolean GetTextureCoordinates(float sx, float sy, float sz, float dx, float dy, float dz, complex result)
          GetTextureCoordinates tests a ray against the mapping shape.
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

Standard_MappingShapeSphere

public Standard_MappingShapeSphere()
Method Detail

GetTextureCoordinates

public boolean GetTextureCoordinates(float sx,
                                     float sy,
                                     float sz,
                                     float dx,
                                     float dy,
                                     float dz,
                                     complex result)
Description copied from class: MappingShape
GetTextureCoordinates tests a ray against the mapping shape. If the ray intersects the shape, it returns true, and returns the coordinates of the point on the shape that intersects the ray in the result argument. If the shape does not intersect the ray, returns false.

A concrete shape descendant should override this function to define the mapping shape.

The ray is defined as:
[ sx ] [ dx ]
[ sy ] + lambda [ dy ]
[ sz ] [ dz ]

Overrides:
GetTextureCoordinates in class MappingShape
Parameters:
sx - X coordinate of point in space that the ray passes through.
sy - Y coordinate of point in space that the ray passes through.
sz - Z coordinate of point in space that the ray passes through.
dx - Relative movement of the line along the X axis.
dy - Relative movement of the line along the Y axis.
dz - Relative movement of the line along the Z axis.
result - Receives the texture coordinates if the function returns true.
Returns:
True if the ray intersects the shape, false otherwise.