To create an image, you need (as in real life):
Constructing a Scene is simple:
Scene World;This defines a Scene object called
World. Class Scene is defined in 3D/Scene.hpp, don't forget to include this header file. You may now add objects and light sources to the scene.
Any object has to be given a Material. The Material must therefore be defined before an object can be defined:
Construction of a Material is quite a complex thing, since the Material parameters determine the sort of material, like plastic, metal, glass, air, clouds, and even more. At this stage, only the simplest case will be explained, the case of a non-transparent plastic medium. For simplicity, this kind of material is predefined and reuse is easy, the mere required parameter is the Material color:
Material Red ( rgb_real(1,0,0) );This defines a Material object called
Red, the color for diffuse reflection is set to (red=1.0, green=0.0, blue=0.0). The rest of the Material parameters are taken from the Material structure pointed to by Material*Materials_default, which is initialized at program start with some plastic material.
Class Material is defined in <3D/Material.hpp>, don't forget to include this header file.
Now back to the objects. There are many kinds of objects, the definitions of objects in the Light C++ library may be found in 3D/objects/. The simplest object is the Sphere, defined in <3D/objects/Sphere.hpp>, it requires a Material structure, the center point and the radius of the sphere:
Sphere Centralsphere( Red, vector3(0,0,0), 0.1 );The newly defined object may now be added to the Scene:
World.add(Centralsphere);Hereby the object is made part of the Scene.
To see the objects, we need some light. Various basic light sources are predefined in <3D/Lights.hpp>, e.g. a light source at infinite distance, shining in the given color from the given direction:
InfiniteLight Lsinf( rgb_real(1.,1.,1.), vector3(0,0,1));This makes a white light source at infinite distance shining from above downwards. To make the light source part of the Scene, it has to be switched on within the World object:
Lsinf.On(World);
Light sources and objects may only be part of one scene. If there exists more than one scene and a light source or an object is added to one scene, it will be deleted from a previous scene.
Construction the camera requires the position of the observer and the view point:
vector3 Observer(1,-1,0); vector3 Viewpoint(0,0,0);
Camera Kamera(Observer, Viewpoint);The Camera provides some more properties, which are not explained here.
A Camera's Frame may be constructed by a predefined way of command line arguments:
main(int argc,const char*argv[])
{
...
Camera::Frame frame(argc,argv);
... }
How to construct your own lens?
include <3D/Scene.hpp> include <3D/Material.hpp> include <3D/objects/Sphere.hpp> include <3D/Lights.hpp> include <3D/Camera.hpp>
main(int argc,const char*argv[])
{
Scene World;
Material Red ( rgb_real(1,0,0) );
Sphere Centralsphere( Red, vector3(0,0,0), 0.1 ); World.add(Centralsphere);
InfiniteLight Lsinf( rgb_real(1.,1.,1.), vector3(0,0,1)); Lsinf.On(World);
vector3 Observer(1,-1,0); vector3 Viewpoint(0,0,0);
Camera Kamera(Observer, Viewpoint); Camera::Frame frame(argc,argv); Standardobjektiv Stdlens(40);
Kamera.use(Stdlens); Kamera.expose(World,frame);
return 0; }
main 300x300 main.jpg
1.5.6