Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
trans_update.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Move an element from the server by changing only its transformation.
4///
5/// One box stands still. Every 1.5 s the other is moved by SetTransMatrix(),
6/// which streams only the new matrix. The client moves the object it already
7/// has and rebuilds no geometry.
8///
9/// \macro_code
10///
11/// \author Matevz Tadel
12
13#include <ROOT/REveManager.hxx>
14#include <ROOT/REveScene.hxx>
15#include <ROOT/REveBox.hxx>
16#include <ROOT/REveTrans.hxx>
17
18#include <TTimer.h>
19#include <TMath.h>
20
21using namespace ROOT::Experimental;
22
23class REveTransMover : public TTimer {
24 // clang-format off
25 REveElement *fEl{nullptr};
26 int fStep{0};
27 // clang-format on
28
29public:
30 REveTransMover(REveElement *el, Long_t ms) : TTimer(ms, kTRUE), fEl(el) {}
31
32 Bool_t Notify() override
33 {
35
36 REveTrans t;
37 t.SetPos(30.0 * TMath::Sin(0.4 * fStep), 0.0, 0.0);
38 fEl->SetTransMatrix(t.Array()); // a transformation-only change
39
40 ++fStep;
41 Reset();
42 return kTRUE;
43 }
44};
45
46static REveBox *make_box(const char *name, Color_t col, Float_t a, Float_t z)
47{
48 auto b = new REveBox(name);
49 b->SetMainColor(col);
50 b->SetMainTransparency(0);
51
52 // clang-format off
53 b->SetVertex(0, -a, -a, z - a); b->SetVertex(1, -a, a, z - a);
54 b->SetVertex(2, a, a, z - a); b->SetVertex(3, a, -a, z - a);
55 b->SetVertex(4, -a, -a, z + a); b->SetVertex(5, -a, a, z + a);
56 b->SetVertex(6, a, a, z + a); b->SetVertex(7, a, -a, z + a);
57 // clang-format on
58
59 return b;
60}
61
62void trans_update()
63{
64 auto eveMng = REveManager::Create();
65 eveMng->AllowMultipleRemoteConnections(false, false);
66
67 auto still = make_box("Still", kCyan, 10, -20);
68 eveMng->GetEventScene()->AddElement(still);
69
70 auto mover = make_box("Mover", kMagenta, 10, 20);
71 // Give the box a transformation from the start, so the first stream already
72 // carries its matrix.
73 mover->InitMainTrans();
74 eveMng->GetEventScene()->AddElement(mover);
75
76 eveMng->Show();
77
78 (new REveTransMover(mover, 1500))->TurnOn();
79}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
short Color_t
Color number (short)
Definition RtypesCore.h:100
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kMagenta
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:142
3D box with arbitrary vertices (cuboid).
Base class for REveUtil visualization elements, providing hierarchy management, rendering control and...
RAII guard for locking Eve manager (ctor) and processing changes (dtor).
REveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:162
Bool_t Notify() override
Notify when timer times out.
Definition TTimer.cxx:148
Namespace for ROOT features in testing.
Definition TROOT.h:100
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:601