Standard
Class Standard_MappingShapeEgg
Object
common:Generic
common:MappingShape
Standard:Standard_MappingShapeEgg
class
- MappingShape:Standard_MappingShapeEgg
Implements the Egg shape (radius 0.5..0.667) from 3D Mapping in Standard.uxf.
Ultra Fractal Source
Toggle UF Source Code Display
class Standard_MappingShapeEgg(common.ulb:MappingShape) {
; Implements the Egg shape (radius 0.5..0.667) 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
; 1) x^2 + (6/7 * y)^2 + z^2 = radius^2
; or
; 2) x^2 + (24/35 * y)^2 + z^2 - radius^2
;
; If y > 0, equation 2 is the right one, otherwise equation 1.
float lambda
float x = 0
float y = 0
float z = 0
float x1 = 0
float y1 = 0
float z1 = 0
float x2 = 0
float y2 = 0
float z2 = 0
bool solid = false
bool solid1 = false
bool solid2 = false
; First perform hit test for equation 1; store coordinates
; in (x1, y1, z1)
sy = sy * 6/7
dy = dy * 6/7
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.
solid1 = true
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.
solid1 = true
else
x1 = sx + lambda * dx
y1 = sy + lambda * dy
z1 = sz + lambda * dz
endif
endif
; Now perform hit test for equation 2; store coordinates
; in (x2, y2, z2)
sy = sy * 4/5
dy = dy * 4/5
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.
solid2 = true
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.
solid2 = true
else
x2 = sx + lambda * dx
y2 = sy + lambda * dy
z2 = sz + lambda * dz
endif
endif
; Now select proper coordinates (either set 1 or set 2)
if solid1
if y2 < 0
solid = true
else
x = x2
y = y2
z = z2
solid = solid2
endif
else
if y2 > 0
x = x2
y = y2
z = z2
else
x = x1
y = y1
z = z1
endif
endif
if !solid
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
else
return false
endif
endfunc
default:
title = "Egg"
}
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 Object |
|
Standard_MappingShapeEgg
public Standard_MappingShapeEgg()
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.