本文整理汇总了C++中VRTransformPtr类的典型用法代码示例。如果您正苦于以下问题:C++ VRTransformPtr类的具体用法?C++ VRTransformPtr怎么用?C++ VRTransformPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VRTransformPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadXYZ
void OSG::loadXYZ(string path, VRTransformPtr res) {
cout << "load xyz pointcloud " << path << endl;
res->setName(path);
try {
VRGeoData data;
vector<float> vertex = vector<float>(6);
int i=0;
ifstream file(path);
while (file >> vertex[i]) {
i++;
if (i >= 6) {
i = 0;
data.pushVert(Pnt3d(vertex[0], vertex[1], vertex[2]), Vec3d(0,1,0), Color3f(vertex[3]/255.0, vertex[4]/255.0, vertex[5]/255.0));
data.pushPoint();
}
}
if (data.size()) {
cout << " assemble geometry.. " << endl;
auto geo = data.asGeometry("points");
res->addChild(geo);
}
}
catch (std::exception& ex) { cerr << "Got an std::exception, what=" << ex.what() << endl; return; }
catch (...) { cerr << "Got an unknown exception" << endl; return; }
}
示例2: VRFrame
void VRRecorder::capture() {
auto v = view.lock();
if (!v) {
v = VRSetup::getCurrent()->getView(viewID);
view = v;
}
if (!v) return;
if (frameLimitReached()) return;
//int ts = VRGlobals::get()->CURRENT_FRAME;
VRFrame* f = new VRFrame();
captures.push_back(f);
f->capture = v->grab();
f->timestamp = getTime()*1e-3;
VRTransformPtr t = v->getCamera();
if (t == 0) return;
f->f = t->getFrom();
f->a = t->getAt();
f->u = t->getUp();
f->width = f->capture->getImage()->getWidth();
f->height = f->capture->getImage()->getHeight();
if (!frame) initFrame();
f->transcode(frame, codec_context, sws_context, captures.size()-1);
}
示例3: setTransform
void VRRecorder::setTransform(VRTransformPtr t, int f) {
if (f >= (int)captures.size() || f < 0) return;
VRFrame* fr = captures[f];
cout << "setTransform " << t->getName() << " " << fr->f << endl;
t->setFrom(fr->f);
t->setAt(fr->a);
t->setUp(fr->u);
}
示例4: FContainer
shared_ptr<FContainer> FLogistics::addContainer(VRTransformPtr t) {
if (t == 0) return 0;
auto c = shared_ptr<FContainer>(new FContainer());
t = static_pointer_cast<VRTransform>(t->duplicate(true));
t->setVisible(true);
t->setPersistency(0);
c->setTransformation(t);
objects[c->getID()] = c;
return c;
}
示例5: fillContainer
void FLogistics::fillContainer(shared_ptr<FContainer> c, int N, VRTransformPtr t) {
for (int i=0; i<N; i++) {
auto p = addProduct();
t = static_pointer_cast<VRTransform>(t->duplicate(true));
t->setVisible(true);
t->setPersistency(0);
p->setTransformation(t);
c->add( p );
}
}
示例6: update
void VRSnappingEngine::update() {
for (auto dev : VRSetupManager::getCurrent()->getDevices()) { // get dragged objects
VRTransformPtr obj = dev.second->getDraggedObject();
VRTransformPtr gobj = dev.second->getDraggedGhost();
if (obj == 0 || gobj == 0) continue;
if (objects.count(obj) == 0) continue;
Matrix m = gobj->getWorldMatrix();
Vec3f p = Vec3f(m[3]);
bool lastEvent = event->snap;
event->snap = 0;
for (auto ri : rules) {
Rule* r = ri.second;
if (r->csys == obj) continue;
if (anchors.count(obj)) {
for (auto a : anchors[obj]) {
Matrix maL = a->getMatrix();
Matrix maW = m; maW.mult(maL);
Vec3f pa = Vec3f(maW[3]);
Vec3f paL = r->local( Vec3f(maW[3]) );
Vec3f psnap = r->getSnapPoint(pa);
float D = (psnap-paL).length(); // check distance
//cout << "dist " << D << " " << pa[1] << " " << paL[1] << " " << psnap[1] << endl;
if (!r->inRange(D)) continue;
r->snap(m);
maL.invert();
m.mult(maL);
event->set(obj, r->csys, m, dev.second, 1);
break;
}
} else {
Vec3f p2 = r->getSnapPoint(p);
float D = (p2-p).length(); // check distance
if (!r->inRange(D)) continue;
r->snap(m);
event->set(obj, r->csys, m, dev.second, 1);
}
}
obj->setWorldMatrix(m);
if (lastEvent != event->snap) {
if (event->snap) snapSignal->trigger<EventSnap>(event);
else if (obj == event->o1) snapSignal->trigger<EventSnap>(event);
}
}
// update geo
if (!hintGeo->isVisible()) return;
}
示例7: apply
// called from VRTransform::apply_constraints
void VRConstraint::apply(VRTransformPtr obj, VRObjectPtr parent, bool force) {
if (!active || obj->getPhysics()->isPhysicalized()) return;
auto now = VRGlobals::CURRENT_FRAME;
if (apply_time_stamp == now && !force) return;
apply_time_stamp = now;
if (local) parent = obj->getParent(true);
if (auto r = Referential.lock()) parent = r;
Matrix4d J;
if (parent) J = parent->getMatrixTo(obj);
else J = obj->getWorldMatrix();
J.mult(refMatrixB);
J.multLeft(refMatrixAI);
for (int i=0; i<3; i++) { // translation
if (min[i] > max[i]) continue; // free
if (min[i] > J[3][i]) J[3][i] = min[i]; // lower bound
if (max[i] < J[3][i]) J[3][i] = max[i]; // upper bound
}
Vec3d angles = VRTransform::computeEulerAngles(J);
auto sign = [](float a) {
return a<0?-1:1;
};
// TODO: this is not correct, for example [180, 20, 180], corresponds to [0, 160, 0], and not [0, 20, 0] !!
// this tries to fix it somewhat, but its not clean!
if ( abs(angles[0]) > Pi*0.5 && abs(angles[2]) > Pi*0.5) {
angles[0] -= sign(angles[0])*Pi;
angles[2] -= sign(angles[2])*Pi;
angles[1] = Pi - angles[1];
}
Vec3d angleDiff;
for (int i=3; i<6; i++) { // rotation
if (min[i] > max[i]) continue; // free
float a = angles[i-3];
float d1 = min[i]-a; while(d1 > Pi) d1 -= 2*Pi; while(d1 < -Pi) d1 += 2*Pi;
float d2 = max[i]-a; while(d2 > Pi) d2 -= 2*Pi; while(d2 < -Pi) d2 += 2*Pi;
if (d1 > 0 && abs(d1) <= abs(d2)) angleDiff[i-3] = d1; // lower bound
if (d2 < 0 && abs(d2) <= abs(d1)) angleDiff[i-3] = d2; // upper bound
}
VRTransform::applyEulerAngles(J, angles + angleDiff);
J.multLeft(refMatrixA);
J.mult(refMatrixBI);
obj->setMatrixTo(J, parent);
}
示例8: addPoint
int path::addPoint(VRTransformPtr t) {
OSG::Matrix m = t->getWorldMatrix();
Vec3f p = Vec3f(m[3]);
Vec3f d = Vec3f(m[2]);
Vec3f u = Vec3f(m[1]);
pnt pn(p, d, Vec3f(1,1,1), u);
points.push_back(pn);
return points.size() - 1;
}
示例9: getTransformation
bool FObject::move(OSG::PathPtr p, float dx) {
VRTransformPtr trans = getTransformation();
if (trans == 0) return true;
bool done = false;
t += dx;
if (t >= 1) { t = 1; done = true; }
Matrix4d m;
Vec3d dir, up, pos;
pos = p->getPosition(t);
p->getOrientation(t, dir, up);
MatrixLookAt( m, pos, pos+dir, up );
trans->setWorldMatrix(m);
if (done) t = 0;
return done;
}
示例10: loadGeometry
PyObject* VRScriptManager::loadGeometry(VRScriptManager* self, PyObject *args, PyObject *kwargs) {
const char* path = "";
int ignoreCache = 0;
const char* preset = "OSG";
const char* parent = "";
const char* kwlist[] = {"path", "cached", "preset", "parent", NULL};
string format = "s|iss:loadGeometry";
if (! PyArg_ParseTupleAndKeywords(args, kwargs, format.c_str(), (char**)kwlist, &path, &ignoreCache, &preset, &parent)) return NULL;
VRObjectPtr prnt = VRSceneManager::getCurrent()->getRoot()->find( parent );
VRTransformPtr obj = VRImport::get()->load( path, prnt, ignoreCache, preset);
if (obj == 0) {
VRGuiManager::get()->printInfo("Warning: " + string(path) + " not loaded!\n");
Py_RETURN_NONE;
}
obj->setPersistency(0);
return VRPyTypeCaster::cast(obj);
}
示例11: VRFrame
void VRRecorder::capture() {
auto v = view.lock();
if (!v) {
v = VRSetupManager::getCurrent()->getView(viewID);
view = v;
}
if (!v) return;
if (frameLimitReached()) return;
//int ts = VRGlobals::get()->CURRENT_FRAME;
VRFrame* f = new VRFrame();
captures.push_back(f);
f->capture = v->grab();
f->timestamp = glutGet(GLUT_ELAPSED_TIME);
VRTransformPtr t = v->getCamera();
if (t == 0) return;
f->f = t->getFrom();
f->a = t->getAt();
f->u = t->getUp();
}
示例12: setClipPlane
void VRMaterial::setClipPlane(bool active, Vec4f equation, VRTransformPtr beacon) {
for (int i=0; i<getNPasses(); i++) {
auto md = mats[i];
if (md->clipChunk == 0) {
md->clipChunk = ClipPlaneChunk::create();
md->mat->addChunk(md->clipChunk);
}
md->clipChunk->setEquation(equation);
md->clipChunk->setEnable (active);
if (beacon) md->clipChunk->setBeacon(beacon->getNode());
}
}
示例13: attachTransform
void virtuose::attachTransform(VRTransformPtr trans)
{
if(vc == 0) return;
isAttached = true;
attached = trans;
VRPhysics* o = trans->getPhysics();
btMatrix3x3 t = o->getInertiaTensor();
float inertia[9] {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
Matrix3ToArray(t,inertia);
cout<<"\n "<<"\n "<<inertia[0] << " " <<inertia[1] << " " <<inertia[2] << "\n "<<inertia[3] << " " <<inertia[4] << " " <<inertia[5] << "\n "<<inertia[6] << " " <<inertia[7] <<" " << inertia[8]<<"\n ";
CHECK(virtAttachVO(vc, o->getMass(), inertia));
}
示例14: attachTransform
void virtuose::attachTransform(VRTransformPtr trans) {
//if(!connected()) return;
isAttached = true;
attached = trans;
VRPhysics* o = trans->getPhysics();
btMatrix3x3 t = o->getInertiaTensor();
Vec9 inertia;
Matrix3ToArray(t,inertia.data);
print(inertia, 9);
//cout<<"\n virtuose::attachTransform:\n " << inertia[0] << " " <<inertia[1] << " " <<inertia[2] << "\n "<<inertia[3] << " " <<inertia[4] << " " <<inertia[5] << "\n "<<inertia[6] << " " <<inertia[7] <<" " << inertia[8]<<"\n ";
cout<<"\n virtuose::attachTransform:\n ";
interface.setObject<Vec9>("inertia", inertia);
interface.setObject<float>("mass", o->getMass());
interface.setObject<bool>("doAttach", true);
//CHECK(virtAttachVO(vc, o->getMass(), inertia));
}
示例15: loadVtk_old
void loadVtk_old(string path, VRTransformPtr res) {
cout << "load VTK file " << path << endl;
ifstream file(path.c_str());
string line;
auto next = [&]() -> string& {
getline(file, line);
return line;
};
VTKProject project;
project.version = splitString( next() )[4];
project.title = next();
project.format = next();
project.dataset = splitString( next() )[1];
VRGeoData geo; // build geometry
if (project.dataset == "STRUCTURED_POINTS") {
auto r = splitString( next() ); Vec3i dims = toValue<Vec3i>( r[1] + " " + r[2] + " " + r[3] );
r = splitString( next() ); Vec3d p0 = toValue<Vec3d>( r[1] + " " + r[2] + " " + r[3] );
r = splitString( next() ); Vec3d d = toValue<Vec3d>( r[1] + " " + r[2] + " " + r[3] );
for (int k=0; k<dims[2]; k++) {
for (int j=0; j<dims[1]; j++) {
for (int i=0; i<dims[0]; i++) {
geo.pushVert(p0 + Vec3d(d[0]*i, d[1]*j, d[2]*k) );
geo.pushPoint();
}
}
}
}
if (project.dataset == "STRUCTURED_GRID") {
auto r = splitString( next() ); Vec3i dims = toValue<Vec3i>( r[1] + " " + r[2] + " " + r[3] );
r = splitString( next() ); int N = toInt(r[1]); string type = r[2]; // points
vector<Vec3d> points;
for (int i=0; i<N; i++) {
Vec3d p = toValue<Vec3d>( next() );
points.push_back(p);
geo.pushVert(p);
geo.pushPoint();
}
}
if (project.dataset == "RECTILINEAR_GRID") {
;
}
if (project.dataset == "UNSTRUCTURED_GRID") {
;
}
if (project.dataset == "POLYDATA") {
auto r = splitString( next() ); int N = toInt(r[1]); string type = r[2]; // points
for (int i=0; i<N; i++) geo.pushVert( toValue<Vec3d>( next() ) );
while (next() != "") {
r = splitString( line );
string type = r[0];
N = toInt(r[1]);
//int size = toInt(r[2]);
for (int i=0; i<N; i++) { // for each primitive
r = splitString( next() );
int Ni = toInt(r[0]); // length of primitive
cout << line << " " << Ni << endl;
//if (Ni == 2) geo.pushLine(toInt(r[1]), toInt(r[2]));
if (Ni == 3) geo.pushTri(toInt(r[1]), toInt(r[2]), toInt(r[3]));
if (Ni == 4) geo.pushQuad(toInt(r[1]), toInt(r[2]), toInt(r[3]), toInt(r[4]));
}
}
}
if (project.dataset == "FIELD") {
;
}
// parsing finished
cout << project.toString() << endl;
file.close();
auto m = VRMaterial::create(project.title + "_mat");
m->setLit(0);
m->setDiffuse(Color3f(0.3,0.7,1.0));
VRGeometryPtr g = geo.asGeometry(project.title);
g->setMaterial(m);
//g->updateNormals();
res->addChild( g );
}