vtrans.cpp
An example scenery demonstrating the `retransformation' feature. For any object or object group a procedure may be specified, which virtually recreates and transforms the object/group multiple times. Like twins of order n, the same object appears n times. However, it exists only once in memory, and any changes to this true objects are directly and immediatly reflected to all virtual copies. All the virtual copies can only differ by the degrees of freedom which are provided by the Transformation class. This may however be sufficient, and arbitrarily complex retransformation functions, like one mimifying a helix or even an
L-system, are possible.
#include <3D/Material.hpp>
#include <3D/Lights.hpp>
#include <3D/Scene.hpp>
#include <3D/Camera.hpp>
#include <3D/objects/Sphere.hpp>
#include <3D/objects/planeobjs.hpp>
#include <wb/options.hpp>
#include <wb/Parameters.hpp>
#ifdef STARS
#include <3D/scenery/sao.hpp>
#endif
int Ridx=0;
using namespace Lux;
using namespace wb;
int helix(int t,Transformation&T,const ObjectBase&)
{
const int Kugels=300;
if (t>Kugels) return 0;
const double Omega=M_PI/(2.6/3.*Kugels), omega=M_PI/11,
R=10*(1-Ridx/30.0),
r=1;
double Phi=Omega*t, phi=omega*t;
double Ro=3./(3.+Phi);
T.Obj_to_World=rotx(-Phi)*scale(vector3(Ro,Ro,Ro));
Ro*=R;
vector3 S(r*sin(phi),r*cos(phi),0);
S*=T.Obj_to_World;
T.Translation=vector3(-Phi,Ro*cos(Phi),Ro*sin(Phi)+(R-Ro)*.75)+S;
T.invertflag=1;
return 1;
}
int main(int argc,const char*argv[])
{
if (print_help(argc, argv) )
return 0;
Parameters Params(argc, argv);
vector3 Standpunkt(-3,20,.1),
Blickpunkt(-1,0,5);
Scene Welt;
#ifdef STARS
Sky The_Night;
Welt.defBackground(The_Night);
#endif
Material s1 = Material::gold, s2 = Material::gold, s3 = Material::gold;
s2.diffuse = rgb_real(.9,.2,.5);
s3.diffuse = rgb_real(.3,.9,.3);
double Kr=.2;
Sphere K1(vector3(0,0,+.3),Kr,s1),
K2(vector3(0,0,-.3),Kr,s2),
K3(vector3(0,0,0) ,1.4*Kr,s3);
K1.name="Goldige Kugel";
K2.name="Rotviolette Kugel";
K3.name="Flachkugel";
K3.trans().scale(vector3(1,1,.4));
Spherical_Objectgroup Kvirtual(K2.M,2*(K1.M.z+Kr));
Kvirtual.add(K2).add(K3).add(K1);
Kvirtual.name = "Virtuelles Kugelgebilde";
Welt.add(Kvirtual);
Kvirtual.trans();
Kvirtual.retransform=helix;
Material Matt = Material::matt;
Plane E1(Matt,vector3(0,0,-1), vector3(0,0,1));
E1.name="Schiefe Ebene";
Welt.add(E1);
InfiniteLight Ls(3*rgb_real(1,1,1),vector3(-2,1,4));
Ls.On(Welt);
AmbientLight Himmelslicht(.5*rgb_real(0.2,0.3,0.4));
Himmelslicht.On(Welt);
Camera Kamera(Standpunkt, Blickpunkt);
Standardobjektiv Stdlens(60);
Kamera.use(Stdlens);
Option R(argc,argv,"R",0,30);
{
Ridx = R();
Kamera.action(Welt, Params["Camera::"] );
}
return 0;
}