meer.cpp

A scenery demonstrating the Ocean waves, embedded in some atmospheric environment.

meer.jpg

Please have a look at Maritime Welt for more elaborated simulations (independent of Light++!).

#include <stdio.h>
#include <3D/Objectlight.hpp>
#include <3D/objects/Quader.hpp>
#include <3D/Camera.hpp>
#include <3D/Scene.hpp>
#include <3D/Material.hpp>
#include <3D/Lights.hpp>
#include <wb/options.hpp>
#include <3D/scenery/atmosphere.hpp>
#include <3D/scenery/ocean_waves.hpp>
#include <3D/objects/HField.hpp>
#include <3D/noise.hpp>
#include <wb/Parameters.hpp>


using namespace wb;
using namespace Lux;

class   Ocean : public HField
{
        Ocean_waves     Waves;
        /*
                Resulting waves are normalized to have heights within [0,1]
         */
        
public: Ocean(MaterialBase&S, int exp2=9,
             double fieldsize=1<<6,
             double theta0 = 10*M_PI/180,
             double thetaexp=40);
};

Ocean::Ocean(MaterialBase&S, int exp2, double fieldsize, double theta0,
             double thetaexp)
:HField(S, (float*)-1, 1<<exp2, 1<<exp2,
        vector2(0, 0), vector2(fieldsize,fieldsize),
        20 /* Periodicity */
        ),
 Waves(1<<exp2, theta0, thetaexp, true /*fixed structure per field*/,
        16,1, 1.0)
{
        f = Waves.data;
        find_minmax();
}


struct  VNoiseMaterial : public MaterialBase
{
        Material&myMaterial;
        vector3 Scale;
        double  Amplitude;

        VNoiseMaterial(Material&matter, double A)
        : myMaterial(matter), Scale(1,1,1), Amplitude(A)
        {}
        
        Material &operator ()(double t, const vector3 &P,vector3 &n,double r)
        {
        Material&m =  myMaterial(t,P,n,r);
        vector3 Ncrd = div(P,Scale);
                Ncrd.x -= 6*t;Ncrd.y -= 15*t;
                Ncrd.z += 1e2*t;
                n += Amplitude*dNoise( Ncrd);
                n.unit();
                return m;
        }

        Material&Pure_material() { return myMaterial; }


        bool is2D() const
        {       return myMaterial.is2D();       }


        bool isTransparent() const
        {       return myMaterial.isTransparent(); }
        
};



int main(int argc,const char*argv[])
{

        if (print_help(argc, argv) )
                return 0;

Parameters Params(argc, argv);

double  sonne_altitude =  70, sonne_azimuth  = 270;

        sonne_altitude = 1;

double  Standhoehe = 3;

        sonne_altitude = doption(argc,argv,"alt",sonne_altitude);
        sonne_azimuth  = doption(argc,argv,"azim",sonne_azimuth);
        Standhoehe     = doption(argc,argv,"mm",Standhoehe);

vector3 Standpunkt(-2, 0,Standhoehe + doption(argc,argv,"z",0));
vector3 Blickpunkt( 0, 0,Standhoehe);

        option(argc,argv,"view",Blickpunkt.z);

Camera  Kamera(Standpunkt,Blickpunkt);

int     vangle = 50;
        option(argc,argv,"angle",vangle);

Standardobjektiv  Stdlens(vangle);

        Kamera.use(Stdlens);

Scene   Welt;

const   double  Erdradius = 6350000.0;    // 6350 km
const   vector3 Erdmitte(0,0,-Erdradius);

Material  Grund = Material::weiss;
Material  Erde = option(argc,argv,"antarctica") ? Material::weiss : Material::water;

//      printf("Constructing the Ocean..."); fflush(stdout);
//
//Ocean Meer(Erde,ioption(argc,argv,"n",9));
//      puts("done.");                       fflush(stdout);



Sphere  Meeresboden(Erdmitte,Erdradius-10,Grund);

Material myWater = Material::water;
VNoiseMaterial vnm(myWater, doption(argc,argv,"ampl", 0.2) );
        vnm.Scale = voption(argc,argv, "waves", vector3(7,25,1) );

//Sphere        VMeer(Erdmitte,Erdradius, myWater);
Sphere  VMeer(Erdmitte,Erdradius, vnm);

//      Welt.add(Meer,"Das Meer");
        Welt.add(VMeer,"Das Meer");
        Welt.add(Meeresboden,"Meeresboden");

Atmosphere  atm(Meeresboden, doption(argc,argv,"density",1.6e-6) );

        if (!option(argc,argv,"noatm"))
                Welt.add(atm);

        atm.Luft.optical_depth = ioption(argc,argv,"steps",-7);


Amun_Re Sonne(sonne_altitude*M_PI/180,sonne_azimuth*M_PI/180);
        Welt.add(Sonne);

        Kamera.Exposure_time = 4.0;
        //Kamera.IntensityMode = Camera::ARC_TAN;
        Kamera.infmap(true);
        option(argc,argv,"time",Kamera.Exposure_time);

        Kamera.action(Welt, Params["Camera::"] );

        return 0;
}

Generated on Wed Jun 17 20:00:14 2009 for Light++ by  doxygen 1.5.6