use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.
the class SubFlameWFFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
int iter = 0;
final int MAX_ITER = 1000;
if (p.isInfinite() || p.isNaN()) {
prefuseIter(pContext);
}
while (xf != null) {
if (++iter > MAX_ITER) {
return;
}
xf = xf.getNextAppliedXFormTable()[pContext.random(Constants.NEXT_APPLIED_XFORM_TABLE_SIZE)];
if (xf == null) {
return;
}
// double parentColor = pAffineTP.color;
a.clear();
v.clear();
xf.transformPoint(pContext, a, v, p, p);
if (xf.getDrawMode() == DrawMode.HIDDEN)
continue;
else if ((xf.getDrawMode() == DrawMode.OPAQUE) && (pContext.random() > xf.getOpacity()))
continue;
Layer layer = flame.getFirstLayer();
List<XForm> finalXForms = layer.getFinalXForms();
if (finalXForms.size() > 0) {
finalXForms.get(0).transformPoint(pContext, pAffineTP, pVarTP, p, q);
for (int i = 1; i < finalXForms.size(); i++) {
finalXForms.get(i).transformPoint(pContext, pAffineTP, pVarTP, q, q);
}
} else {
q.assign(p);
}
// pVarTP.color -= 1.0;
break;
}
if (!q.doHide) {
pVarTP.doHide = false;
pVarTP.x += q.x + offset_x;
pVarTP.y += q.y + offset_y;
pVarTP.z += q.z + offset_z + colorscale_z * q.color;
if (color_mode != CM_OFF) {
if (q.rgbColor) {
pVarTP.rgbColor = true;
pVarTP.redColor = q.redColor;
pVarTP.greenColor = q.greenColor;
pVarTP.blueColor = q.blueColor;
}
switch(color_mode) {
case CM_DIRECT:
pVarTP.color = q.color;
break;
case CM_RED:
pVarTP.color = pVarTP.redColor / 255.0;
break;
case CM_GREEN:
pVarTP.color = pVarTP.greenColor / 255.0;
break;
case CM_BLUE:
pVarTP.color = pVarTP.blueColor / 255.0;
break;
case CM_BRIGHTNESS:
pVarTP.color = (0.2990 * pVarTP.redColor + 0.5880 * pVarTP.greenColor + 0.1130 * pVarTP.blueColor) / 255.0;
break;
}
}
} else {
pVarTP.doHide = true;
}
}
use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.
the class SuperShape3DFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
// SuperShape3d by David Young, http://fractal-resources.deviantart.com/gallery/24660058#/d1o8z8x
double rho1 = pContext.random() * rho_pi;
double phi1 = pContext.random() * phi_pi;
int p = (int) fmod(pContext.random(Integer.MAX_VALUE), 2);
if (p == 1) {
phi1 = (-phi1);
}
double sinr = sin(rho1);
double cosr = cos(rho1);
double sinp = sin(phi1);
double cosp = cos(phi1);
double msinr, mcosr;
{
double a = m4_1 * rho1;
msinr = sin(a);
mcosr = cos(a);
}
double msinp, mcosp;
{
double a = m4_2 * phi1;
msinp = sin(a);
mcosp = cos(a);
}
double pr1 = an2_1 * pow(fabs(mcosr), n2_1) + bn3_1 * pow(fabs(msinr), n3_1);
double pr2 = an2_2 * pow(fabs(mcosp), n2_2) + bn3_2 * pow(fabs(msinp), n3_2);
double r1 = pow(pr1, n1n_1) + spiral * rho1;
double r2 = pow(pr2, n1n_2);
if (toroidmap == 1) {
pVarTP.x += pAmount * cosr * (r1 + r2 * cosp);
pVarTP.y += pAmount * sinr * (r1 + r2 * cosp);
pVarTP.z += pAmount * r2 * sinp;
} else {
pVarTP.x += pAmount * r1 * cosr * r2 * cosp;
pVarTP.y += pAmount * r1 * sinr * r2 * cosp;
pVarTP.z += pAmount * r2 * sinp;
}
}
use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.
the class ScramblyFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
/* scrambly by dark-beam, http://dark-beam.deviantart.com/art/Scrambly-463910011 */
double Vx = pAffineTP.x;
double Vy = pAffineTP.y;
int Ix;
int Iy;
int swp;
Vx += _mzcella;
Vy += _mzcella;
Vx *= _cellainv;
Vy *= _cellainv;
Ix = (int) floor(Vx);
Iy = (int) floor(Vy);
if (_current_l <= 0 || Ix < 0 || Ix >= _current_l || Iy < 0 || Iy >= _current_l) {
pVarTP.x += pAmount * pAffineTP.x;
pVarTP.y += pAmount * pAffineTP.y;
} else {
Vx -= Ix;
Vy -= Iy;
// randomizing int parts:
swp = Ix + _current_l * Iy;
swp = (int) _mx_rd[swp];
Iy = swp / _current_l;
Ix = swp % _current_l;
// add int parts to fractional:
Vx += Ix;
Vy += Iy;
Vx *= _cella;
Vy *= _cella;
Vx -= _mzcella;
Vy -= _mzcella;
pVarTP.x += pAmount * Vx;
pVarTP.y += pAmount * Vy;
}
if (pContext.isPreserveZCoordinate()) {
pVarTP.z += pAmount * pAffineTP.z;
}
}
use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.
the class SphereNjaFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
/* Description:
The transform creates a sphere by converting the x and y values to a radius,
which becomes "t" for a parametric equation.
*/
// Initial coordinates
XYZPoint ini = new XYZPoint();
ini.x = pAffineTP.x;
ini.y = pAffineTP.y;
ini.z = pAffineTP.z;
ini.x -= shift_x;
ini.y -= shift_y;
// ini.z -= shift_z;
ini.invalidate();
/* Convert x and y of point to parametric space,
noting they are the radius outward in real space. */
double t = ini.getPrecalcSqrt() / stretch - M_PI / 2;
// circular curve, expanded by pAmount
// * ini.getPrecalcSqrt();
double r = cos(t) * pAmount;
// * ini.getPrecalcSqrt();
double z = sin(t) * pAmount;
// Convert parametric space (2D) back to real space (3D)
/* A new coordinate equals the new factor times a unit vector in the
direction of the coordinate of interest. */
pVarTP.x += r * (ini.x / ini.getPrecalcSqrt());
pVarTP.y += r * (ini.y / ini.getPrecalcSqrt());
pVarTP.z += z;
{
// (this should cause positive z values to curl inside the sphere)
/* Treating z as a vector that is split into two components, one being
an x-component of parametric space which becomes a new radius for
real space, taking into account conversion through unit vectors */
pVarTP.x += r * ini.z * (ini.x / ini.getPrecalcSqrt());
pVarTP.y += r * ini.z * (ini.y / ini.getPrecalcSqrt());
/* The z-component is a normalized value from the parametric space y
(which is real space z), taking into account the amount that went into
the x component. */
pVarTP.z += ini.z * z / (r * r + z * z);
}
pVarTP.x += shift_x;
pVarTP.y += shift_y;
// pVarTP.z += shift_z;
}
use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.
the class AbstractOBJMeshWFFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
if (mesh == null || mesh.getFaceCount() == 0) {
return;
}
Face f = mesh.getFace(pContext.random(mesh.getFaceCount()));
Vertex rawP1 = mesh.getVertex(f.v1);
Vertex rawP2 = mesh.getVertex(f.v2);
Vertex rawP3 = mesh.getVertex(f.v3);
if ((colorMapHolder.isActive() || displacementMapHolder.isActive()) && rawP1 instanceof VertexWithUV) {
VertexWithUV p1 = transform((VertexWithUV) rawP1);
VertexWithUV p2 = transform((VertexWithUV) rawP2);
VertexWithUV p3 = transform((VertexWithUV) rawP3);
// uniform sampling: http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
double sqrt_r1 = MathLib.sqrt(pContext.random());
double r2 = pContext.random();
double a = 1.0 - sqrt_r1;
double b = sqrt_r1 * (1.0 - r2);
double c = r2 * sqrt_r1;
double dx = a * p1.x + b * p2.x + c * p3.x;
double dy = a * p1.y + b * p2.y + c * p3.y;
double dz = a * p1.z + b * p2.z + c * p3.z;
pVarTP.x += pAmount * dx;
pVarTP.y += pAmount * dy;
pVarTP.z += pAmount * dz;
double u = a * p1.u + b * p2.u + c * p3.u;
double v = a * p1.v + b * p2.v + c * p3.v;
if (colorMapHolder.isActive()) {
double iu = GfxMathLib.clamp(u * (colorMapHolder.getColorMapWidth() - 1.0), 0.0, colorMapHolder.getColorMapWidth() - 1.0);
double iv = GfxMathLib.clamp(colorMapHolder.getColorMapHeight() - 1.0 - v * (colorMapHolder.getColorMapHeight() - 1.0), 0, colorMapHolder.getColorMapHeight() - 1.0);
int ix = (int) MathLib.trunc(iu);
int iy = (int) MathLib.trunc(iv);
colorMapHolder.applyImageColor(pVarTP, ix, iy, iu, iv);
pVarTP.color = uvColorMapper.getUVColorIdx(Tools.FTOI(pVarTP.redColor), Tools.FTOI(pVarTP.greenColor), Tools.FTOI(pVarTP.blueColor));
}
if (displacementMapHolder.isActive()) {
VectorD av = new VectorD(p2.x - p1.x, p2.y - p1.y, p2.y - p1.y);
VectorD bv = new VectorD(p3.x - p1.x, p3.y - p1.y, p3.y - p1.y);
VectorD n = VectorD.cross(av, bv);
n.normalize();
double iu = GfxMathLib.clamp(u * (displacementMapHolder.getDisplacementMapWidth() - 1.0), 0.0, displacementMapHolder.getDisplacementMapWidth() - 1.0);
double iv = GfxMathLib.clamp(displacementMapHolder.getDisplacementMapHeight() - 1.0 - v * (displacementMapHolder.getDisplacementMapHeight() - 1.0), 0, displacementMapHolder.getDisplacementMapHeight() - 1.0);
int ix = (int) MathLib.trunc(iu);
int iy = (int) MathLib.trunc(iv);
double d = displacementMapHolder.calculateImageDisplacement(ix, iy, iu, iv) * _displ_amount;
pVarTP.x += pAmount * n.x * d;
pVarTP.y += pAmount * n.y * d;
pVarTP.z += pAmount * n.z * d;
}
} else {
Vertex p1 = transform(rawP1);
Vertex p2 = transform(rawP2);
Vertex p3 = transform(rawP3);
// uniform sampling: http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
double sqrt_r1 = MathLib.sqrt(pContext.random());
double r2 = pContext.random();
double a = 1.0 - sqrt_r1;
double b = sqrt_r1 * (1.0 - r2);
double c = r2 * sqrt_r1;
double dx = a * p1.x + b * p2.x + c * p3.x;
double dy = a * p1.y + b * p2.y + c * p3.y;
double dz = a * p1.z + b * p2.z + c * p3.z;
pVarTP.x += pAmount * dx;
pVarTP.y += pAmount * dy;
pVarTP.z += pAmount * dz;
}
if (receive_only_shadows == 1) {
pVarTP.receiveOnlyShadows = true;
}
}
Aggregations