Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches

Detailed Description

Move an element from the server by changing only its transformation.

One box stands still in the centre. Four boxes go round a square about it, a step every 200 ms, each moved by SetTransMatrix(), which streams only the new matrix. The client moves the objects it already has and rebuilds no geometry.

#include <ROOT/REveBox.hxx>
#include <TTimer.h>
#include <TMath.h>
#include <vector>
using namespace ROOT::Experimental;
/// Position (`x`, `y`) at `s` along the perimeter of a square of half-side
/// `a`, s in [0, 4) going counter-clockwise from the corner (a, -a).
static void square_pos(Double_t s, Double_t a, Double_t &x, Double_t &y)
{
const Double_t f = 2 * a * (s - TMath::Floor(s)) - a; // -a .. a along the side
switch (Int_t(TMath::Floor(s)) % 4) {
case 0:
x = a;
y = f;
break;
case 1:
x = -f;
y = a;
break;
case 2:
x = -a;
y = -f;
break;
default:
x = f;
y = -a;
break;
}
}
class REveTransMover : public TTimer {
// clang-format off
std::vector<REveElement*> fEls;
int fStep{0};
// clang-format on
public:
REveTransMover(std::vector<REveElement *> els, Long_t ms) : TTimer(ms, kTRUE), fEls(std::move(els)) {}
Bool_t Notify() override
{
for (size_t i = 0; i < fEls.size(); ++i) {
square_pos(0.02 * fStep + i, 40, x, y);
t.SetPos(0.0, y, x); // in the yz plane, which faces the default camera
fEls[i]->SetTransMatrix(t.Array()); // a transformation-only change
}
++fStep;
Reset();
return kTRUE;
}
};
static REveBox *make_box(const char *name, Color_t col, Float_t a, Float_t z)
{
auto b = new REveBox(name);
b->SetMainColor(col);
b->SetMainTransparency(0);
// clang-format off
b->SetVertex(0, -a, -a, z - a); b->SetVertex(1, -a, a, z - a);
b->SetVertex(2, a, a, z - a); b->SetVertex(3, a, -a, z - a);
b->SetVertex(4, -a, -a, z + a); b->SetVertex(5, -a, a, z + a);
b->SetVertex(6, a, a, z + a); b->SetVertex(7, a, -a, z + a);
// clang-format on
return b;
}
void trans_update()
{
auto eveMng = REveManager::Create();
eveMng->AllowMultipleRemoteConnections(false, false);
auto still = make_box("Still", kCyan, 10, 0);
eveMng->GetEventScene()->AddElement(still);
const Color_t colors[] = {kMagenta, kOrange, kGreen + 1, kBlue};
std::vector<REveElement *> movers;
for (int i = 0; i < 4; ++i) {
auto mover = make_box(Form("Mover %d", i), colors[i], 6, 0);
// Give the box a transformation from the start, so the first stream
// already carries its matrix.
mover->InitMainTrans();
eveMng->GetEventScene()->AddElement(mover);
movers.push_back(mover);
}
eveMng->Show();
auto timer = new REveTransMover(movers, 200);
timer->Notify();
timer->TurnOn();
}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
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
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kOrange
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:142
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
3D box with arbitrary vertices (cuboid).
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
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:693
Author
Matevz Tadel

Definition in file trans_update.C.