本文整理汇总了C++中TransformPtr::getMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ TransformPtr::getMatrix方法的具体用法?C++ TransformPtr::getMatrix怎么用?C++ TransformPtr::getMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransformPtr
的用法示例。
在下文中一共展示了TransformPtr::getMatrix方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display
// redraw the window
void display(void)
{
Profiler::the().StartProfile("Frame");
unsigned i;
for (i=0; i<numFirst; ++i) {
TransformPtr trf = TransformPtr::dcast(first->getChild(i)->getCore());
beginEditCP(trf);
trf->getMatrix()[3] += Vec4f((rand()/Real32(RAND_MAX)-0.5f),
(rand()/Real32(RAND_MAX)-0.5f),
(rand()/Real32(RAND_MAX)-0.5f), 0.0f);
endEditCP(trf);
}
for (i=0; i<numSecond; ++i) {
TransformPtr trf = TransformPtr::dcast(second->getChild(i)->getCore());
beginEditCP(trf);
trf->getMatrix()[3] += Vec4f((rand()/Real32(RAND_MAX)-0.5f),
(rand()/Real32(RAND_MAX)-0.5f),
(rand()/Real32(RAND_MAX)-0.5f), 0.0f);
endEditCP(trf);
}
bool result = all->apply(first, second);
OSGRAPIDCollision& col = (OSGRAPIDCollision&)all->getData();
SLOG << col.getNumContacts() << " contacts with "
<< col.getNumBVolTests() << " BVolTests/"
<< col.getNumMixedTests() << " MixedTests/"
<< col.getNumPrimTests() << " TriTests "
<< std::endl;
Profiler::the().EndProfile("Frame");
mgr->redraw();
}
示例2: keyPressed
virtual void keyPressed(const KeyEventPtr e)
{
if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_CONTROL)
{
TutorialWindowEventProducer->closeWindow();
}
switch(e->getKey())
{
case KeyEvent::KEY_S:
statFlag = !statFlag;
mgr->setStatistics(statFlag);
break;
case KeyEvent::KEY_EQUALS:
{
Vec3f Translation;
Quaternion Rotation;
Vec3f Scale;
Quaternion ScaleOrient;
Matrix ThePointLightMat = ThePointLightBeaconTransform->getMatrix();
ThePointLightMat.getTransform(Translation,Rotation,Scale,ScaleOrient);
Translation = Translation + Vec3f(0.0,10.0,0.0);
ThePointLightMat.setTranslate(Translation);
beginEditCP(ThePointLightBeaconTransform);
ThePointLightBeaconTransform->setMatrix(ThePointLightMat);
endEditCP(ThePointLightBeaconTransform);
}
break;
case KeyEvent::KEY_MINUS:
{
Vec3f Translation;
Quaternion Rotation;
Vec3f Scale;
Quaternion ScaleOrient;
Matrix ThePointLightMat = ThePointLightBeaconTransform->getMatrix();
ThePointLightMat.getTransform(Translation,Rotation,Scale,ScaleOrient);
Translation = Translation + Vec3f(0.0,-10.0,0.0);
ThePointLightMat.setTranslate(Translation);
beginEditCP(ThePointLightBeaconTransform);
ThePointLightBeaconTransform->setMatrix(ThePointLightMat);
endEditCP(ThePointLightBeaconTransform);
}
break;
case KeyEvent::KEY_T:
beginEditCP(TheBlinnMat, BlinnMaterial::DiffuseTextureFieldMask);
endEditCP(TheBlinnMat, BlinnMaterial::DiffuseTextureFieldMask);
break;
}
}
示例3: OnTrackingButtonReleased
void CFlystickTranslationResetTool::OnTrackingButtonReleased(Quaternion q, Vec3f position){
std::cout << "CFlystickTranslationResetTool::OnTrackingButtonReleased()" << std::endl;
if (! m_bToolActive){
std::cout << "tool is not active" << std::endl;
return;
}
if (m_posgPickedObjectNode == NullFC){
std::cout << "CFlystickTranslationResetTool: No object picked to reset translation" << std::endl;
return;
}
NodePtr parentingTransformNode = GetParentTransformNode(m_posgPickedObjectNode);
if (parentingTransformNode != NullFC){
std::cout << "CFlystickTranslationResetTool: Resetting translation!" << std::endl;
TransformPtr transform = TransformPtr::dcast(parentingTransformNode->getCore());
Matrix m = transform->getMatrix();
m.setTranslate(0.0, 0.0, 0.0);
beginEditCP(transform, Transform::MatrixFieldMask);{
transform->setMatrix(m);
};endEditCP(transform, Transform::MatrixFieldMask);
}else{
std::cout << "CFlystickTranslationResetTool: Found no parenting transform to reset!" << std::endl;
}
m_bToolActive = false;
}
示例4: update
virtual void update(const UpdateEventPtr e)
{
Real32 RotateRate(1.0f);
Matrix RotMat;
RotMat.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),RotateRate*e->getElapsedTime()));
Matrix NewMat(RootTransformCore->getMatrix());
NewMat.multLeft(RotMat);
beginEditCP(RootTransformCore, Transform::MatrixFieldMask);
RootTransformCore->setMatrix(NewMat);
endEditCP(RootTransformCore, Transform::MatrixFieldMask);
}
示例5: update
virtual void update(const UpdateEventPtr e)
{
RubberCamera->update(e->getElapsedTime());
float TranslateAmount(1.0f);
float RotateAmount(1.0f);
WindowEventProducerPtr TheEventProducer(WindowEventProducerPtr::dcast(e->getSource()));
if(TheEventProducer->getKeyState(KeyEvent::KEY_LEFT) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
TranslateTransform.setTranslate(-TranslateAmount*e->getElapsedTime(),0.0f,0.0f);
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
if(TheEventProducer->getKeyState(KeyEvent::KEY_RIGHT) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
TranslateTransform.setTranslate(TranslateAmount*e->getElapsedTime(),0.0f,0.0f);
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
if(TheEventProducer->getKeyState(KeyEvent::KEY_UP) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
TranslateTransform.setTranslate(0.0f,0.0f,-TranslateAmount*e->getElapsedTime());
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
if(TheEventProducer->getKeyState(KeyEvent::KEY_DOWN) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
TranslateTransform.setTranslate(0.0f,0.0f,TranslateAmount*e->getElapsedTime());
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
if(TheEventProducer->getKeyState(KeyEvent::KEY_A) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
//TranslateTransform.setTranslate(-TranslateAmount,0.0f,0.0f);
TranslateTransform.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), -RotateAmount*e->getElapsedTime()));
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
if(TheEventProducer->getKeyState(KeyEvent::KEY_D) == KeyEvent::KEY_STATE_DOWN)
{
Matrix TranslateTransform;
//TranslateTransform.setTranslate(TranslateAmount,0.0f,0.0f);
TranslateTransform.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), RotateAmount*e->getElapsedTime()));
Matrix NewTransform(BoxTransform->getMatrix());
NewTransform.mult(TranslateTransform);
beginEditCP(BoxTransform, Transform::MatrixFieldMask);
BoxTransform->setMatrix(NewTransform);
endEditCP(BoxTransform, Transform::MatrixFieldMask);
}
}
示例6: keyboard
//.........这里部分代码省略.........
{
osgdam = OpenSGDeformActionManager::GetInstance();
if(osgdam != 0)
{
gmtl::AABoxf aabb;
Pnt3f aabbMin, aabbMax;
#if OSG_MAJOR_VERSION >= 2
model->editVolume(true).getBounds(aabbMin, aabbMax);
#else
model->getVolume(true).getBounds(aabbMin, aabbMax);
#endif
for (int i = 0; i < 3; i++)
{
aabbMin[i] = aabbMin[i] - 1.0f;
aabbMax[i] = aabbMax[i]/2 + 1.0f;
}
aabb = gmtl::AABoxf(gmtl::Vec3f(aabbMin[0], aabbMin[1], aabbMin[2]),
gmtl::Vec3f(aabbMax[0], aabbMax[1], aabbMax[2]));
osgdam->insertLattice(model, 2, 2, 2, 3, true, aabb);
}
break;
}
case 'q':
{
NodePtr tmp = model;
while (tmp != NullFC)
{
TransformPtr tcore = TransformPtr::dcast(tmp->getCore());
if (tcore != NullFC)
{
Matrix mm = tcore->getMatrix();
Matrix tm = Matrix::identity();
tm.setScale(1,2,1);
mm.mult(tm);
beginEditCP(tcore, Transform::MatrixFieldMask);
tcore->setMatrix(mm);
endEditCP(tcore, Transform::MatrixFieldMask);
mm = tcore->getMatrix();
break;
}
tmp = tmp->getParent();
}
break;
}
default:
break;
}
if (osgdam != 0)
{
switch(k)
{
case '4':
{
all = !all;
osgdam->setShowAll(model, all);
break;
}
case 'e':
{
doExecute = !doExecute;
示例7: enter
//.........这里部分代码省略.........
SWARNING <<
"More than 4 vertices in face!" <<
endl <<
endLog;
return Action::Continue;
// exit(1);
}
++fit;
}
if(numQuads > 0)
{
SWARNING << "Quad encountered" << endl << endLog;
}
if(gl_sga->nodeDepth_ > 0)
{
for(i = 0; i < gl_sga->nodeDepth_; i++)
{
meshInfo.transf = meshInfo.transf * gl_sga->transf_[i];
}
}
else
meshInfo.transf.identity();
/* access to vertices */
GeoPositions3fPtr pPos = GeoPositions3fPtr::dcast(geo->getPositions());
GeoPositions3f::StoredFieldType * pPosField = pPos->getFieldPtr();
/* access to faces */
numFaces = 0;
fit = geo->beginFaces();
for(fit = geo->beginFaces(); fit != geo->endFaces(); ++fit)
{
numFaceVertices = fit.getLength();
for(j = 0; j < numFaceVertices; j++)
{
vId = fit.getPositionIndex(j);
}
numFaces++;
} /* for fit */
/* set other mesh attributes */
meshInfo.numQuads = numQuads;
meshInfo.geoPtr = geo;
meshInfo.vPtr = pPosField;
meshInfo.triangularFaces = (numQuads == 0);
meshInfo.numVertices = pPosField->size();
meshInfo.numFaces = numFaces;
gl_sga->meshInfo_.push_back(meshInfo);
gl_sga->numGeometryNodes_++;
}
else
{
// SWARNING << "Neither triangle nor quad. Field type = " <<
// (*pTypeField)[h] << endl << endLog;
}
} /* for h */
} /* if pLength!=NullFC */
}
else if(node->getCore()->getType().isDerivedFrom(Transform::getClassType()))
{
TransformPtr t = TransformPtr::dcast(node->getCore());
Matrix ma;
ma = t->getMatrix();
SINFO <<
"Node type derived from transform, skipping children" <<
endl <<
endLog;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
transf[i][j] = ma[j][i]; /* the matrix is stored as columns/rows ? */
}
}
if(gl_sga->nodeDepth_ > gl_sga->maxNodeDepth_)
{
gl_sga->maxNodeDepth_ = gl_sga->nodeDepth_;
gl_sga->transf_.push_back(transf);
}
else
{
gl_sga->transf_[gl_sga->nodeDepth_] = transf;
}
gl_sga->nodeDepth_++;
}
return Action::Continue;
}
示例8: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin = GLUTWindow::create();
beginEditCP(gwin);
gwin->setId(winid);
gwin->setSize( 800, 800 );
gwin->init();
endEditCP(gwin);
// create root node
_scene = makeCoredNode<Group>();
GeometryPtr geo = makeBoxGeo(0.5, 0.5, 0.5, 1, 1, 1);
// share the chunk
CGChunkPtr cg = CGChunk::create();
beginEditCP(cg);
cg->setVertexProfile(CG_PROFILE_ARBVP1);
cg->setVertexProgram(_vp_program);
cg->setFragmentProfile(CG_PROFILE_ARBFP1);
cg->setFragmentProgram(_fp_program);
endEditCP(cg);
Int32 size = 4;
// start color
Vec3f sc(0.0, 0.0, 0.0);
// end color
Vec3f ec(1.0, 1.0, 1.0);
Real32 sr = (ec[0] - sc[0]) / Real32((size*2));
Real32 sg = (ec[1] - sc[1]) / Real32((size*2));
Real32 sb = (ec[2] - sc[2]) / Real32((size*2));
Vec3f color(sc);
Int32 x = - size;
Int32 y = - size;
Int32 z = - size;
UInt32 iterations = size*2 * size*2 * size*2;
printf("Creating %u cubes ...\n", iterations);
for(UInt32 i=0;i<iterations;++i)
{
ChunkMaterialPtr cmat = ChunkMaterial::create();
// ok use one CGChunk and n CGParameterChunks
CGParameterChunkPtr cgparameter = CGParameterChunk::create();
beginEditCP(cgparameter);
cgparameter->setCGChunk(cg);
cgparameter->setUniformParameter("SurfaceColor", color);
endEditCP(cgparameter);
_cgparameter = cgparameter;
beginEditCP(cmat);
cmat->addChunk(cg);
cmat->addChunk(cgparameter);
endEditCP(cmat);
TransformPtr trans;
NodePtr trans_node = makeCoredNode<Transform>(&trans);
beginEditCP(trans);
trans->getMatrix().setTranslate(Real32(x), Real32(y), Real32(z));
endEditCP(trans);
MaterialGroupPtr mg;
NodePtr mg_node = makeCoredNode<MaterialGroup>(&mg);
beginEditCP(mg, MaterialGroup::MaterialFieldMask);
mg->setMaterial(cmat);
endEditCP(mg, MaterialGroup::MaterialFieldMask);
NodePtr geonode = Node::create();
beginEditCP(geonode, Node::CoreFieldMask);
geonode->setCore(geo);
endEditCP(geonode, Node::CoreFieldMask);
beginEditCP(mg_node);
mg_node->addChild(geonode);
endEditCP(mg_node);
beginEditCP(trans_node);
trans_node->addChild(mg_node);
endEditCP(trans_node);
// add to scene
beginEditCP(_scene);
_scene->addChild(trans_node);
endEditCP(_scene);
// ----
//.........这里部分代码省略.........
示例9: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
// create the scene
first = Node::create ();
beginEditCP(first);
first->setCore(Group::create());
unsigned i;
for (i=0; i<numFirst; ++i) {
first->addChild(makePerturbedAll(4, 1.0f));
//makeTransformedCube(1.0f,1.0f,1.0f,1,1,1, Color3f(1,0,0)));
}
endEditCP(first);
second = Node::create ();
beginEditCP(second);
second->setCore(Group::create());
for (i=0; i<numSecond; ++i) {
second->addChild(makePerturbedAll(4, 1.0f, 0.0f));
//makeTransformedCube(1.0f,1.0f,1.0f,1,1,1, Color3f(0,1,0)));
}
endEditCP(second);
for (i=0; i<numFirst; ++i) {
TransformPtr trf = TransformPtr::dcast(first->getChild(i)->getCore());
beginEditCP(trf);
randomTransform(trf->getMatrix());
endEditCP(trf);
}
for (i=0; i<numSecond; ++i) {
TransformPtr trf = TransformPtr::dcast(second->getChild(i)->getCore());
beginEditCP(trf);
randomTransform(trf->getMatrix());
endEditCP(trf);
}
scene = Node::create ();
beginEditCP(scene);
scene->setCore(Group::create());
scene->addChild(first);
scene->addChild(second);
endEditCP(scene);
addRefCP(scene);
SLOG << "scene created" << std::endl;
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
// prepare for collision detection
// * fill cache
OSGCache::the().setHierarchy(NULL);
OSGCache::the().apply(scene);
SLOG << "cache filled." << std::endl;
// * build hierarchy
OSGCache::the().setHierarchy(&hier);
OSGCache::the().apply(scene);
SLOG << "adapters created.." << std::endl;
// * create double traverser for collision detection
traverser = new Traverser();
traverser->setUseCoherency(false); // do not use generalized front cache for frame coherency
traverser->getDataTyped().setStopFirst(false);
#ifndef GV_WITH_RAPID
SWARNING << "For RAPID support you have to define GV_WITH_RAPID (see Kernel/OSGGVBase.h)"
<< std::endl;
#endif
// * create all traverser
all = new AllTraverser<OpenSGTraits>();
all->setDoubleTraverser(traverser);
// GLUT main loop
Profiler::the().Reset();
glutMainLoop();
return 0;
}
示例10: main
//.........这里部分代码省略.........
{
if(argv[i][0] >='0' &&
argv[i][0] <='9')
{
if(ca==-1)
ca=atoi(argv[i]);
else
if(cb==-1)
cb=atoi(argv[i]);
else
if(cc==-1)
cc=atoi(argv[i]);
}
else
{
filename=argv[1];
}
}
}
if(ca == -1 && filename)
{
file = OSG::SceneFileHandler::the().read(filename);
beginEditCP(scene);
scene->addChild(file);
endEditCP(scene);
}
else
{
if(ca==-1)
ca=4;
if(cb==-1)
cb=ca;
if(cc==-1)
cc=cb;
if(file == NullFC)
{
GeometryPtr geo=makeBoxGeo(.6,.6,.6,20,20,20);
beginEditCP(geo);
SimpleMaterialPtr mat=SimpleMaterial::create();
beginEditCP(mat);
mat->setAmbient(Color3f(.4,.4,.4));
mat->setSpecular(Color3f(0,0,0));
mat->setDiffuse(Color3f(1,1,1));
endEditCP(mat);
geo->setMaterial(mat);
endEditCP(geo);
NodePtr node;
NodePtr geoNode;
TransformPtr trans;
for(x=-ca/2 ; x<ca/2 ; x++)
for(y=-cb/2 ; y<cb/2 ; y++)
for(z=-cc/2 ; z<cc/2 ; z++)
{
trans=Transform::create();
node=Node::create();
geoNode=Node::create();
beginEditCP(geoNode);
beginEditCP(trans);
beginEditCP(node);
node->setCore(trans);
trans->getMatrix().setTranslate(x,y,z);
if(!filename)
{
geoNode=Node::create();
geoNode->setCore(geo);
}
else
{
geoNode = OSG::SceneFileHandler::the().read(filename);
}
node->addChild( geoNode );
beginEditCP(scene);
scene->addChild(node);
endEditCP(geoNode);
endEditCP(scene);
endEditCP(trans);
endEditCP(node);
}
}
}
// create the SimpleSceneManager helper
mgr = new MySceneManager;
mgr->setWindow( gwin );
mgr->setRoot( scene );
mgr->showAll();
// GLUT main loop
if(loop)
glutIdleFunc(display);
// glutReshapeWindow(720,576);
glutReshapeWindow(1152,864);
glutMainLoop();
return 0;
}