Object version of 3d-mapping in Standard.uxf.
General 3D perspective mapping. This transformations wraps a fractal on a 3D
shape.
The 3D transformations/formulas use the left-handed coordinate system, where
X points to the right, Y points up, and Z points into the screen. To
determine the direction of a rotation, hold your left hand such that your
thumb points into the direction of the axis around which the rotation takes
place, and then your curled fingers point into the direction of positive
rotation.
Rotation is performed first around the X axis, then around the Y axis, and
finally around the Z axis. Scaling must be done using UF's zooming feature.
Translation is performed after the rotation.
Any shape is supported via the MappingShape class.
class Standard_3DMapping(common.ulb:UserTransform) {
;
; Object version of 3d-mapping in Standard.uxf.
;
; General 3D perspective mapping. This transformations wraps a fractal on a 3D
; shape.
;
; The 3D transformations/formulas use the left-handed coordinate system, where
; X points to the right, Y points up, and Z points into the screen. To
; determine the direction of a rotation, hold your left hand such that your
; thumb points into the direction of the axis around which the rotation takes
; place, and then your curled fingers point into the direction of positive
; rotation.
;
; Rotation is performed first around the X axis, then around the Y axis, and
; finally around the Z axis. Scaling must be done using UF's zooming feature.
; Translation is performed after the rotation.
;
; Any shape is supported via the MappingShape class.
;
public:
func Standard_3DMapping(Generic pparent)
Transform(pparent)
fShape = new @shapeClass(this)
endfunc
complex func Iterate(complex pz)
; Construct a line from the current pixel on the screen through 3D space.
; The line is defined by (sx, sy, sz) + lambda * (dx, dy, dz) where
; lambda can be any real value > 0. So the line does not extend behind
; the screen.
float sx = -@transx
float sy = -@transy
float sz = -@transz
float dx = real(pz)
float dy = imag(pz)
float dz = 4
; Convert angles from degrees to radians.
float angx = (@rotx * #pi) / 180
float angy = (@roty * #pi) / 180
float angz = (@rotz * #pi) / 180
; Rotate the line according to the (rotx, roty, rotz) angle.
; Apply rotation around Z axis
float tt = cos(angz) * sy - sin(angz) * sx
sx = cos(angz) * sx + sin(angz) * sy
sy = tt
tt = cos(angz) * dy - sin(angz) * dx
dx = cos(angz) * dx + sin(angz) * dy
dy = tt
; Apply rotation around Y axis
tt = cos(angy) * sx - sin(angy) * sz
sz = cos(angy) * sz + sin(angy) * sx
sx = tt
tt = cos(angy) * dx - sin(angy) * dz
dz = cos(angy) * dz + sin(angy) * dx
dx = tt
; Apply rotation around X axis
tt = cos(angx) * sz - sin(angx) * sy
sy = cos(angx) * sy + sin(angx) * sz
sz = tt
tt = cos(angx) * dz - sin(angx) * dy
dy = cos(angx) * dy + sin(angx) * dz
dz = tt
; Now compute the intersection of the line with the shape, and return
; the intersection point (texture coordinates).
complex result
if fShape.GetTextureCoordinates(sx, sy, sz, dx, dy, dz, result)
return @fraccenter + \
result * exp(flip((@fracangle * #pi) / 180)) / @fracmagn
else
m_Solid = true
return pz
endif
endfunc
private:
MappingShape fShape
default:
title = "3D Mapping"
helpfile = "Uf*.chm"
helptopic = "Html/transformations/standard/3dmapping.html"
MappingShape param shapeClass
caption = "Shape"
default = Standard_MappingShapePlane
hint = "The fractal is mapped onto this shape."
endparam
param rotx
caption = "X Rotation"
default = 0.0
hint = "Rotation around the x-axis, in degrees. The x-axis points to \
the right. To determine the direction in which the rotation will \
take place, hold up your left hand with your thumb pointing to \
the right. Your (curled) fingers now indicate the direction of \
positive X rotation."
endparam
param roty
caption = "Y Rotation"
default = 0.0
hint = "Rotation around the y-axis, in degrees. The y-axis points \
upwards. To determine the direction in which the rotation will \
take place, hold up your left hand with your thumb pointing \
upwards. Your (curled) fingers now indicate the direction of \
positive Y rotation."
endparam
param rotz
caption = "Z Rotation"
default = 0.0
hint = "Rotation around the z-axis, in degrees. The z-axis points into \
the screen. To determine the direction in which the rotation will \
take place, hold up your left hand with your thumb pointing into \
the screen. Your (curled) fingers now indicate the direction of \
positive Z rotation."
endparam
param transx
caption = "X Translation"
default = 0.0
hint = "Translation along the x-axis. The x-axis points to the right, \
so increasing this value will move the fractal to the right, too."
endparam
param transy
caption = "Y Translation"
default = -0.5
hint = "Translation along the y-axis. The y-axis points upwards, \
so increasing this value will move the fractal upwards, too."
endparam
param transz
caption = "Z Translation"
default = 2.0
hint = "Translation along the z-axis. The z-axis points into the screen, \
so increasing this value will move the fractal away."
endparam
complex param fraccenter
caption = "Fractal Center"
default = #center
hint = "Center of the fractal image. Use here what you would \
normally enter in the Location tab."
endparam
float param fracmagn
caption = "Fractal Magnification"
default = #magn
exponential = true
hint = "Magnification of the fractal image. Use here what you would \
normally enter in the Location tab."
endparam
float param fracangle
caption = "Fractal Rotation"
default = #angle
hint = "Rotation angle (in degrees) of the fractal image. Use here \
what you would normally enter in the Location tab."
endparam
}