Commit 75eba236 authored by BrutPitt's avatar BrutPitt
Browse files

ver 1.6.0 WiP - reorganize attractorsBase (h/cpp) files : move polynomial...

ver 1.6.0 WiP - reorganize attractorsBase (h/cpp) files : move polynomial class attractors, in separate files
parent d8ce17b6
//------------------------------------------------------------------------------
// Copyright (c) 2018-2020 Michele Morrone
// All rights reserved.
//
// https://michelemorrone.eu - https://BrutPitt.com
//
// twitter: https://twitter.com/BrutPitt - github: https://github.com/BrutPitt
//
// mailto:brutpitt@gmail.com - mailto:me@michelemorrone.eu
//
// This software is distributed under the terms of the BSD 2-Clause license
//------------------------------------------------------------------------------
#include "glWindow.h"
// Polynomial power of N
////////////////////////////////////////////////////////////////////////////
void PowerN3D::Step(vec4 &v, vec4 &vp)
{
elv[0] = vec3(1.f);
for(int i=1; i<=order; i++) elv[i] = elv[i-1] * (vec3)v;
auto itCf = cf.begin();
for(int x=order-1; x>=0; x--)
for(int y=order-1; y>=0; y--)
for(int z=order-1; z>=0; z--)
if(x+y+z <= order) *itCf++ = elv[x].x * elv[y].y * elv[z].z;
*itCf++ = elv[order].x;
*itCf++ = elv[order].y;
*itCf++ = elv[order].z;
vec3 vt(0.f);
itCf = cf.begin();
for(auto &it : kVal) vt += (vec3)it * *itCf++;
vp = vec4(vt, 0.f);
}
void tetrahedronGaussMap::Step(vec4 &v, vec4 &vp)
{
const float rnd = fastPrng64.xoroshiro128p_VNI<float>();
if(rnd<.2) {
const float x2 = v.x*v.x, y2 = v.y*v.y;
const float coeff = 1.f / (1.f+x2+y2);
vp = vec3(2.f*v.x, 2.f*v.y, 1.f-x2-y2) * coeff + (vec3)kVal[0];
} else if(rnd<.4) {
const float z2 = v.z*v.z, y2 = v.y*v.y;
const float coeff = 1.f / (1.f+z2+y2);
vp = vec3(1.f-z2-y2, 2.f*v.y, 2.f*v.z) * coeff + (vec3)kVal[1];
} else if(rnd<.6) {
const float x2 = v.x*v.x, z2 = v.z*v.z;
const float coeff = 1.f / (1.f+x2+z2);
vp = vec3(2.f*v.x, 1.f-x2-z2, 2.f*v.z) * coeff + (vec3)kVal[2];
} else if(rnd<.8) {
vp = v * .5;
} else {
vp = v * .5 + kVal[3];
}
}
// Polynomial attractors
////////////////////////////////////////////////////////////////////////////
void PolynomialA::Step(vec4 &v, vec4 &vp)
{ vp = vec3(v.y - v.y*v.z, v.z - v.x*v.z, v.x - v.x*v.y) + (vec3) kVal[0]; }
////////////////////////////////////////////////////////////////////////////
void PolynomialB::Step(vec4 &v, vec4 &vp)
{ vp = vec3(v.y-v.z*(kVal[1].x+v.y), v.z-v.x*(kVal[1].y+v.z), v.x-v.y*(kVal[1].z+v.x)) + (vec3) kVal[0]; }
////////////////////////////////////////////////////////////////////////////
void PolynomialC::Step(vec4 &v, vec4 &vp)
{
vp.x = kVal[0].x +v.x*(kVal[1].x +kVal[2].x *v.x+kVal[3].x *v.y)+v.y*(kVal[4].x+kVal[5].x*v.y);
vp.y = kVal[0].y +v.y*(kVal[1].y +kVal[2].y *v.y+kVal[3].y *v.z)+v.z*(kVal[4].y+kVal[5].y*v.z);
vp.z = kVal[0].z +v.z*(kVal[1].z +kVal[2].z *v.z+kVal[3].z *v.x)+v.x*(kVal[4].z+kVal[5].z*v.x);
}
////////////////////////////////////////////////////////////////////////////
void PolynomialABS::Step(vec4 &v, vec4 &vp)
{
vp.x = kVal[0].x + kVal[1].x*v.x + kVal[2].x*v.y + kVal[3].x*v.z + kVal[4].x*abs(v.x) + kVal[5].x*abs(v.y) +kVal[6].x*abs(v.z);
vp.y = kVal[0].y + kVal[1].y*v.x + kVal[2].y*v.y + kVal[3].y*v.z + kVal[4].y*abs(v.x) + kVal[5].y*abs(v.y) +kVal[6].y*abs(v.z);
vp.z = kVal[0].z + kVal[1].z*v.x + kVal[2].z*v.y + kVal[3].z*v.z + kVal[4].z*abs(v.x) + kVal[5].z*abs(v.y) +kVal[6].z*abs(v.z);
}
////////////////////////////////////////////////////////////////////////////
void PolynomialPow::Step(vec4 &v, vec4 &vp)
{
vp.x = kVal[0].x + kVal[1].x*v.x + kVal[2].x*v.y + kVal[3].x*v.z + kVal[4].x*abs(v.x) + kVal[5].x*abs(v.y) +kVal[6].x*pow(abs(v.z),kVal[7].x);
vp.y = kVal[0].y + kVal[1].y*v.x + kVal[2].y*v.y + kVal[3].y*v.z + kVal[4].y*abs(v.x) + kVal[5].y*abs(v.y) +kVal[6].y*pow(abs(v.z),kVal[7].y);
vp.z = kVal[0].z + kVal[1].z*v.x + kVal[2].z*v.y + kVal[3].z*v.z + kVal[4].z*abs(v.x) + kVal[5].z*abs(v.y) +kVal[6].z*pow(abs(v.z),kVal[7].z);
}
////////////////////////////////////////////////////////////////////////////
void PolynomialSin::Step(vec4 &v, vec4 &vp)
{
vp.x = kVal[0].x + kVal[1].x*v.x + kVal[2].x*v.y + kVal[3].x*v.z + kVal[4].x*sin(kVal[5].x*v.x) + kVal[6].x*sin(kVal[7].x*v.y) +kVal[8].x*sin(kVal[9].x*v.z);
vp.y = kVal[0].y + kVal[1].y*v.x + kVal[2].y*v.y + kVal[3].y*v.z + kVal[4].y*sin(kVal[5].y*v.x) + kVal[6].y*sin(kVal[7].y*v.y) +kVal[8].y*sin(kVal[9].y*v.z);
vp.z = kVal[0].z + kVal[1].z*v.x + kVal[2].z*v.y + kVal[3].z*v.z + kVal[4].z*sin(kVal[5].z*v.x) + kVal[6].z*sin(kVal[7].z*v.y) +kVal[8].z*sin(kVal[9].z*v.z);
}
//------------------------------------------------------------------------------
// Copyright (c) 2018-2020 Michele Morrone
// All rights reserved.
//
// https://michelemorrone.eu - https://BrutPitt.com
//
// twitter: https://twitter.com/BrutPitt - github: https://github.com/BrutPitt
//
// mailto:brutpitt@gmail.com - mailto:me@michelemorrone.eu
//
// This software is distributed under the terms of the BSD 2-Clause license
//------------------------------------------------------------------------------
#pragma once
// Polynomial power of N
////////////////////////////////////////////////////////////////////////////
class PowerN3D : public attractorVectorK
{
public:
PowerN3D() {
stepFn = (stepPtrFn) &PowerN3D::Step;
tmpOrder = order = 2;
vMin = 0.0; vMax = 0.0; kMin = -1.25; kMax = 1.25;
m_POV = vec3( 0.f, 0, 7.f);
resetData();
}
void Step(vec4 &v, vec4 &vp);
void startData();
void searchAttractor() { searchLyapunov(); }
void initStep() {
resetQueue();
resetData();
if(nCoeff!=kVal.size()) assert("mismatch loaded size!!");
Insert(vVal[0]);
stabilize(STABILIZE_DIM);
}
// Personal vals
///////////////////////////////////////
void saveAdditionalData(Config &cfg);
void loadAdditionalData(Config &cfg);
void additionalDataCtrls();
// SetOrder
///////////////////////////////////////
void setOrder(const int n)
{
tmpOrder = order = n;
resetData();
kVal.resize(nCoeff);
newRandomValues();
resetQueue();
Insert(vVal[0]);
searchAttractor();
}
void newRandomValues()
{
for(int i=0; i<nCoeff; i++)
kVal[i] = vec4(RANDOM(kMin,kMax),RANDOM(kMin,kMax),RANDOM(kMin,kMax),0.f);
vVal[0] = vec4(RANDOM(vMin,vMax),RANDOM(vMin,vMax),RANDOM(vMin,vMax),0.f);
}
private:
int getNumCoeff(int o) { return (o+1) * (o+2) * (o+3) / 6; }
int getNumCoeff() { return getNumCoeff(order); }
void resetData() {
nCoeff = getNumCoeff();
elv.resize(order+1);
cf.resize(nCoeff);
}
vector<vec3> elv;
vector<float> cf;
int nCoeff;
int order, tmpOrder;
};
// Polynomial attractors
////////////////////////////////////////////////////////////////////////////
class PolynomialBase : public attractorVectorK
{
public:
PolynomialBase() {
vMin = 0.0; vMax = 0.0; kMin = -1.0; kMax = 1.0;
m_POV = vec3( 0.f, 0, 7.f);
}
protected:
virtual void searchAttractor() { searchLyapunov(); }
};
/////////////////////////////////////////////////
class PolynomialA : public PolynomialBase
{
public:
PolynomialA() { stepFn = (stepPtrFn) &PolynomialA::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
/*
void newRandomValues ()
{
float val=.23+(float)rand()/(float)RAND_MAX*.1f;
//float val=1.55f+(float)rand()/(float)RAND_MAX*.2f;
int j=rand()%3;
kVal[j]=val;
kVal[(j+1)%3]=(float)rand()/(float)RAND_MAX*2.f;
kVal[(j+2)%3]=3.f-kVal[j]-kVal[(j+1)%3];
}*/
};
/////////////////////////////////////////////////
class PolynomialB : public PolynomialBase
{
public:
PolynomialB() { stepFn = (stepPtrFn) &PolynomialB::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
};
/////////////////////////////////////////////////
class PolynomialC : public PolynomialBase
{
public:
PolynomialC() { stepFn = (stepPtrFn) &PolynomialC::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
};
/////////////////////////////////////////////////
class PolynomialABS : public PolynomialBase
{
public:
PolynomialABS() { stepFn = (stepPtrFn) &PolynomialABS::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
};
/////////////////////////////////////////////////
class PolynomialPow : public PolynomialBase
{
public:
PolynomialPow() { stepFn = (stepPtrFn) &PolynomialPow::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
};
/////////////////////////////////////////////////
class PolynomialSin : public PolynomialBase
{
public:
PolynomialSin() { stepFn = (stepPtrFn) &PolynomialSin::Step; }
protected:
void Step(vec4 &v, vec4 &vp);
void startData();
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment