MyExaminerViewer::MyExaminerViewer(QWidget * parent) : SoQtExaminerViewer(parent) { // Coin should not clear the pixel-buffer, so the background image // is not removed. this->setClearBeforeRender(FALSE, TRUE); // Set up background scenegraph with image in it. this->bckgroundroot = new SoSeparator; this->bckgroundroot->ref(); SoOrthographicCamera * cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 1); cam->height = 1; // SoImage will be at z==0.0. cam->nearDistance = 0.5; cam->farDistance = 1.5; this->bckgroundroot->addChild(cam); // Set up foreground, overlayed scenegraph. this->foregroundroot = new SoSeparator; this->foregroundroot->ref(); SoLightModel * lm = new SoLightModel; lm->model = SoLightModel::BASE_COLOR; SoBaseColor * bc = new SoBaseColor; bc->rgb = SbColor(1, 1, 0); cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 5); cam->height = 10; cam->nearDistance = 0; cam->farDistance = 10; // const double ARROWSIZE = 2.0; // SoTranslation * posit = new SoTranslation; // posit->translation = SbVec3f(-2.5 * ARROWSIZE, 1.5 * ARROWSIZE, 0); // arrowrotation = new SoRotationXYZ; // arrowrotation->axis = SoRotationXYZ::Z; // SoTranslation * offset = new SoTranslation; // offset->translation = SbVec3f(ARROWSIZE/2.0, 0, 0); this->foregroundroot->addChild(cam); this->foregroundroot->addChild(lm); this->foregroundroot->addChild(bc); // this->foregroundroot->addChild(posit); // this->foregroundroot->addChild(arrowrotation); // this->foregroundroot->addChild(offset); Draw(); this->setSceneGraph(sp); }
//////////////////////////////////////////////////////////////////////// // // Description: // Rotate the rotateDiscDragger based on mouse motion. // // Use: private // void SoRotateDiscDragger::drag() // //////////////////////////////////////////////////////////////////////// { // Set up the projector space and view. // Working space is space at end of motion matrix. planeProj->setViewVolume( getViewVolume() ); planeProj->setWorkingSpace( getLocalToWorldMatrix() ); // Get newHitPt and startHitPt in workspace. SbVec3f newHitPt = planeProj->project( getNormalizedLocaterPosition()); SbVec3f startHitPt = getLocalStartingPoint(); // Find the amount of rotation SbVec3f oldVec = startHitPt; SbVec3f newVec = newHitPt; // Remove the part of these vectors that is parallel to the normal oldVec -= SbVec3f( 0, 0, oldVec[2] ); newVec -= SbVec3f( 0, 0, newVec[2] ); // deltaRot is how much we rotated since the mouse button went down. SbRotation deltaRot = SbRotation( oldVec, newVec ); // Append this to the startMotionMatrix, which we saved at the beginning // of the drag, to find the current motion matrix. setMotionMatrix( appendRotation( getStartMotionMatrix(), deltaRot, SbVec3f(0,0,0))); }
void SoXipPlot2Columns::setVertices() { SoCoordinate3* vertices = SO_GET_ANY_PART( this, "mVertices", SoCoordinate3 ); SoFaceSet* faces = SO_GET_ANY_PART( this, "mFaces", SoFaceSet ); SoLineSet* lines = SO_GET_ANY_PART( this, "mBorderLines", SoLineSet ); if( vertices && faces && lines ) { int numData = data.getNum(); vertices->point.setNum( 4 * numData ); faces->numVertices.setNum( numData ); lines->numVertices.setNum( numData ); SbVec3f* verticesPtr = vertices->point.startEditing(); for( int i = 0; i < numData; ++ i ) { verticesPtr[4*i ] = SbVec3f( i + .9, 0, 0 ); verticesPtr[4*i + 1] = SbVec3f( i + .9, data[i], 0 ); verticesPtr[4*i + 2] = SbVec3f( i + .1, data[i], 0 ); verticesPtr[4*i + 3] = SbVec3f( i + .1, 0, 0 ); faces->numVertices.set1Value( i, 4 ); lines->numVertices.set1Value( i, 4 ); } vertices->point.finishEditing(); } }
// Update the dragger based on the skeleton. void IvJointDragger::UpdateDragger() { ItemPtr selectedItem = GetSelectedItem(); if( !selectedItem ) { return; } KinBodyItemPtr pbody = boost::dynamic_pointer_cast<KinBodyItem>(selectedItem); if( !pbody ) { return; } vector<dReal> vjoints; pbody->GetDOFValues(vjoints); if( _jointtype == KinBody::JointSpherical ) { Vector vaxis(vjoints[_dofindex+0],vjoints[_dofindex+1],vjoints[_dofindex+2]); dReal fang = RaveSqrt(vaxis.lengthsqr3())-_jointoffset; _trackball->rotation = SbRotation(fang > 0 ? SbVec3f(vaxis.x/fang,vaxis.y/fang,vaxis.z/fang) : SbVec3f(1,0,0), fang); } else { float fang = vjoints[_dofindex]-_jointoffset; if( _jointtype == KinBody::JointSlider ) { if( _vupper[0] > _vlower[0] ) { fang = (fang-_vlower[0])/(_vupper[0]-_vlower[0]); } else { fang = 0; } } _trackball->rotation = SbRotation(SbVec3f(1,0,0), fang); } }
void loadLevel(SoSeparator*root) { FILE*f=fopen("level.dat", "r"); if(!f) { printf("Couldn't open menu\n"); exit(0); } fscanf(f, "%i %i\n", &mapX, &mapY); DEBUG("Loaded map"); map=new (char*)[mapY]; for(int i=0; i<mapY; i++) { map[i]=new char[mapX]; for(int j=0; j<mapX; j++) { map[i][j]=fgetc(f)-'0'; if(map[i][j]) { SoTranslation*position=new SoTranslation; SoCube*cube=new SoCube; SoSeparator*separator=new SoSeparator; SoScale *scale=new SoScale; scale->scaleFactor.setValue(SbVec3f(1, 0.5, 1)); position->translation.setValue(SbVec3f((j-mapX/2)*2, map[i][j], -i*2)); separator->addChild(scale); separator->addChild(position); separator->addChild(cube); root->addChild(separator); } } fgetc(f); } DEBUG("Done reading\n"); fclose(f); }
int QilexDoc::doc_new_kinematic_hand(ct_new_kinematic_chain *data) { int error = 0; int tipus = 0; void * buffer ; //char *buffer; char *buftemp = (char*)malloc(1024); SoOutput out; size_t sizeModel = 0; SoSeparator *kinechain = new SoSeparator; SoSeparator *kinetest = new SoSeparator; Rchain_hand *kineengine = new Rchain_hand(); SoTransform *pos_rot = new SoTransform; SbVec3f joinax; joinax.setValue(SbVec3f(data->x,data->y,data->z)); pos_rot->translation.setValue(joinax); pos_rot->rotation.setValue(SbVec3f(data->axeX, data->axeY, data->axeZ), (float) rad((double) data->angle)); kinechain = readFile(data->QsModelFile.latin1(), tipus); if (kinechain == NULL) // no object read { return 1; } else // ok, there's no object with the same name { error = kineengine->init_dat(data->QsDatFile.latin1()); // if (error == 0) { kinechain->ref(); kinetest = (SoSeparator*)SoNode::getByName(data->QsName.latin1()); if (kinetest==NULL) { //we need to put it in a buffer to write the xml file // if is Ok SoOutput out; out.setBuffer(buftemp, 1024, reallocCB); SoWriteAction wa1(&out); wa1.apply(kinechain); out.getBuffer(buffer, sizeModel); kinechain->insertChild(pos_rot, 0); } error = doc_insert_kinematic_hand(kineengine, kinechain); } } if (error==0) { writeXML_kineelement((char *)buffer, sizeModel, tipus, data, kineengine); } return error; }
//////////////////////////////////////////////////////////////////////// // // Constructor // SoMotion3Event::SoMotion3Event() // //////////////////////////////////////////////////////////////////////// { translation = SbVec3f(0, 0, 0); rotation = SbRotation(SbVec3f(1, 0, 0), 0); }
void XipPrimitiveDraw::quad( SoGLRenderAction* action, const SbVec3f& origin, const SbVec2f& size, const SbColor& color, const float alpha ) { action->getState()->push(); { GLboolean depthTest; glGetBooleanv( GL_DEPTH_TEST, &depthTest ); if( depthTest ) glDisable( GL_DEPTH_TEST ); m_Material->diffuseColor.setValue( color ); m_Material->transparency.setValue( alpha ); action->traverse( m_Material ); m_Coords->point.setNum(4); m_Coords->point.set1Value( 0, origin ); m_Coords->point.set1Value( 1, origin + SbVec3f( size[0], 0, 0 ) ); m_Coords->point.set1Value( 2, origin + SbVec3f( size[0], size[1], 0 ) ); m_Coords->point.set1Value( 3, origin + SbVec3f( 0, size[1], 0 ) ); action->traverse( m_Coords ); m_FaceSet->numVertices.setValue(4); action->traverse( m_FaceSet ); if( depthTest ) glEnable( GL_DEPTH_TEST ); } action->getState()->pop(); }
void vpSimulator::moveInternalCamera(vpHomogeneousMatrix &cMf) { SbMatrix matrix; SbRotation rotCam; SbMatrix rotX; rotX.setRotate (SbRotation (SbVec3f(1.0f, 0.0f, 0.0f), (float)M_PI)); for(unsigned int i=0;i<4;i++) for(unsigned int j=0;j<4;j++) matrix[(int)j][(int)i]=(float)cMf[i][j]; matrix= matrix.inverse(); matrix.multLeft (rotX); rotCam.setValue(matrix); internalCamera->ref() ; internalCamera->orientation.setValue(rotCam); internalCamera->position.setValue(matrix[3][0],matrix[3][1],matrix[3][2]); internalCamera->unref() ; rotX.setRotate (SbRotation (SbVec3f(-1.0f, 0.0f, 0.0f), (float)M_PI)); matrix.multLeft (rotX); rotCam.setValue(matrix); internalCameraPosition->ref() ; internalCameraPosition->rotation.setValue(rotCam); internalCameraPosition->translation.setValue(matrix[3][0],matrix[3][1],matrix[3][2]); internalCameraPosition->unref() ; }
SoXipGetCameraProperties::SoXipGetCameraProperties() { SO_NODE_CONSTRUCTOR(SoXipGetCameraProperties); SO_NODE_ADD_FIELD(camPos, (SbVec3f(0.0,0.0,0.0))); SO_NODE_ADD_FIELD(camDir, (SbVec3f(0.0,0.0,0.0))); SO_NODE_ADD_FIELD(viewport, (SbVec4f(0.0,0.0,0.0,0.0))); }
/*! Constructor. */ SoShuttle::SoShuttle(void) { SO_NODE_INTERNAL_CONSTRUCTOR(SoShuttle); SO_NODE_ADD_FIELD(translation0, (SbVec3f(0.0f, 0.0f, 0.0f))); SO_NODE_ADD_FIELD(translation1, (SbVec3f(0.0f, 0.0f, 0.0f))); SO_NODE_ADD_FIELD(speed, (1.0f)); SO_NODE_ADD_FIELD(on, (TRUE)); this->interpolator = new SoInterpolateVec3f; this->interpolator->ref(); this->calculator = new SoCalculator; this->calculator->ref(); this->timer = new SoElapsedTime; this->timer->ref(); this->calculator->expression = "oa = (1.0 - cos(a*b*2*M_PI)) * 0.5"; this->calculator->a.connectFrom(&this->timer->timeOut); this->timer->on.connectFrom(&this->on); this->calculator->b.connectFrom(&this->speed); this->interpolator->input0.connectFrom(&this->translation0); this->interpolator->input1.connectFrom(&this->translation1); this->interpolator->alpha.connectFrom(&this->calculator->oa); this->translation.connectFrom(&this->interpolator->output, TRUE); }
void TTracker::SetEngineOutputRotation(SbRotation rotation) { SO_ENGINE_OUTPUT( outputTranslation, SoSFVec3f, setValue( SbVec3f( 0.0, 0.0, 0.0 ) ) ); SO_ENGINE_OUTPUT( outputRotation, SoSFRotation, setValue( rotation ) ); SO_ENGINE_OUTPUT( outputScaleFactor, SoSFVec3f, setValue( SbVec3f( 1.0, 1.0, 1.0 ) ) ); SO_ENGINE_OUTPUT( outputScaleOrientation, SoSFRotation, setValue( SbRotation() ) ); SO_ENGINE_OUTPUT( outputCenter, SoSFVec3f, setValue( SbVec3f( 0.0, 0.0, 0.0 ) ) ); }
SoSeparator* HorizontalWidget::Text(){ SoSeparator* text = new SoSeparator; SoMaterial* myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue( 1.0, 0.0, 0.0 ); // Red text->addChild( myMaterial ); SoSeparator* norte = new SoSeparator; SoTransform* norteTransf = new SoTransform; norteTransf->translation.setValue( SbVec3f( 0, 0, -( sphereRadio+30) ) ); norte->addChild( norteTransf ); SoText3* northText= new SoText3(); northText->string.setValue("N"); northText->justification = SoText3::CENTER; northText->parts = SoText3::ALL; norte->addChild( northText ); text->addChild( norte ); SoSeparator* south = new SoSeparator; SoTransform* southTransf = new SoTransform; southTransf->translation.setValue( SbVec3f( 0, 0, ( sphereRadio+30 ) ) ); south->addChild( southTransf ); SoText3* southText = new SoText3(); southText->string.setValue("S"); southText->justification = SoText3::CENTER; southText->parts = SoText3::ALL; south->addChild( southText ); text->addChild( south ); SoSeparator* east = new SoSeparator; SoTransform* eastTransf = new SoTransform; eastTransf->translation.setValue( SbVec3f( ( sphereRadio+30 ), 0.0, 0.0 ) ); east->addChild( eastTransf ); SoText3* eastText = new SoText3(); eastText->string.setValue("E"); eastText->justification = SoText3::CENTER; eastText->parts = SoText3::ALL; east->addChild( eastText ); text->addChild( east ); SoSeparator* west = new SoSeparator; SoTransform* westTransf = new SoTransform; westTransf->translation.setValue( SbVec3f( -( sphereRadio+30 ), 0.0, 0.0 ) ); west->addChild( westTransf ); SoText3* westText = new SoText3(); westText->string.setValue("W"); westText->justification = SoText3::CENTER; westText->parts = SoText3::ALL; west->addChild( westText ); text->addChild( west ); return text; }
SoSeparator* createScene(void) { SoSeparator *root = new SoSeparator ; player.light=new SoPointLight; player.light->location.setValue(SbVec3f(0,5,0)); player.light->intensity.setValue(1); root->addChild(player.light); SoDirectionalLight*dl1=new SoDirectionalLight; // -1 right, 1 left : -1 top, 1 bottom : -1 back, 1 front dl1->direction.setValue(SbVec3f(0, -1, -0.5)); dl1->intensity.setValue(1); root->addChild(dl1); SoMaterial *mat2 = new SoMaterial ; mat2->diffuseColor.setValue(0.0,0.7,0.7) ; mat2->ambientColor.setValue(0.0,0.0,0.7) ; mat2->specularColor.setValue(0.0,1.0,0.0) ; root->addChild(mat2) ; SoDrawStyle * drawstyle2 = new SoDrawStyle; drawstyle2->style.setValue(SoDrawStyleElement::FILLED); root->addChild(drawstyle2); SoSeparator *ballSep=new SoSeparator; SoSphere *ball=new SoSphere; player.position=new SoTranslation; player.position->translation.setValue(SbVec3f(0,1.5,0)); ball->radius.setValue(0.5); ballSep->addChild(player.position); ballSep->addChild(ball); root->addChild(ballSep); //FILLED, LINES, POINTS, INVISIBLE SoDrawStyle * drawstyle = new SoDrawStyle; drawstyle->style.setValue(SoDrawStyleElement::FILLED); //drawstyle->style.setValue(SoDrawStyleElement::LINES); root->addChild(drawstyle); SoMaterial *mat = new SoMaterial ; mat->diffuseColor.setValue(0.7,0.7,0.0) ; mat->ambientColor.setValue(0.7,0.0,0.0) ; mat->specularColor.setValue(0.0,1.0,0.0) ; mat->shininess.setValue(1.0) ; root->addChild(mat) ; loadLevel(root); SoTimerSensor *ts=new SoTimerSensor(increment, (void*)0); ts->schedule(); SoEventCallback*cb=new SoEventCallback; cb->addEventCallback(SoKeyboardEvent::getClassTypeId(), keyboardCB, NULL); root->addChild(cb); return root ; }
SbRotation SoBillboard::calculateRotation(SoState *state) { SbRotation rot; #ifdef INVENTORRENDERER const SbViewVolume &viewVolume = SoViewVolumeElement::get(state); if (SbVec3f(0.0f, 0.0f, 0.0f) == axis.getValue()) { rot = viewVolume.getAlignRotation(); } #else const SbMatrix &mm = SoModelMatrixElement::get(state); SbMatrix imm = mm.inverse(); SbVec3f toviewer; SbVec3f cameray(0.0f, 1.0f, 0.0f); const SbViewVolume &vv = SoViewVolumeElement::get(state); toviewer = -vv.getProjectionDirection(); imm.multDirMatrix(toviewer, toviewer); (void)toviewer.normalize(); SbVec3f rotaxis = this->axis.getValue(); if (rotaxis == SbVec3f(0.0f, 0.0f, 0.0f)) { // 1. Compute the billboard-to-viewer vector. // 2. Rotate the Z-axis of the billboard to be collinear with the // billboard-to-viewer vector and pointing towards the viewer's position. // 3. Rotate the Y-axis of the billboard to be parallel and oriented in the // same direction as the Y-axis of the viewer. rot.setValue(SbVec3f(0.f, 0.0f, 1.0f), toviewer); SbVec3f viewup = vv.getViewUp(); imm.multDirMatrix(viewup, viewup); SbVec3f yaxis(0.0f, 1.0f, 0.0f); rot.multVec(yaxis, yaxis); SbRotation rot2(yaxis, viewup); SbVec3f axis; float angle; rot.getValue(axis, angle); rot2.getValue(axis, angle); rot = rot * rot2; //SoModelMatrixElement::rotateBy(state, (SoNode*) this, rot); } #endif else { fprintf(stderr, "SoBillboard: axis != (0.0, 0.0, 0.0) not implemented\n"); } return rot; }
void ScaleAxisArrow::setAntiScale(SbVec3f ¤t) { if (whichAxis == AXIS_X) { antiScale->scaleFactor = SbVec3f(1.0 / current[1], 1.0 / current[0], 1.0 / current[2]); } else if (whichAxis == AXIS_Y) { antiScale->scaleFactor = SbVec3f(1.0 / current[0], 1.0 / current[1], 1.0 / current[2]); } else { // AXIS_Z antiScale->scaleFactor = SbVec3f(1.0 / current[0], 1.0 / current[2], 1.0 / current[1]); } }
ObjectViewer:: ObjectViewer( ObjectViewerModel *objectViewerModel, bool is3D, bool isBlending): ObjectSimpleViewer(is3D, isBlending), m_camera(NULL), m_sensor(NULL), m_linkedTo(NULL), m_linkedPlaneTo(NULL), m_ID(-1), m_linkedViewerID(-1), m_linkedPlaneID(-1) { if(is3D) { m_camera = new SoPerspectiveCamera; } else { m_camera = new Camera2D; } // set camera viewpoint to match Woolz viewing point m_camera->position = SbVec3f(0, 0, -1); m_camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, -1, 0)); m_camera->ref(); root->insertChild(m_camera, 1);// has to be added before view root m_viewer->setCamera(m_camera); if(m_sensor) //make sure no sensor was allocated { m_sensor->detach(); delete m_sensor; m_sensor = NULL; } m_sensor = new SoNodeSensor(cameraCB, this); m_sensor->attach(m_camera); //this has to go in the Editor connect(this, SIGNAL(removedViewerStart()), objectViewerModel, SLOT(removedViewerStart())); connect(this, SIGNAL(removedViewerFinished()), objectViewerModel, SLOT(removedViewerFinished())); connect(this, SIGNAL(addedView(ObjectView *)), objectViewerModel, SLOT(addedView(ObjectView *))); connect(this, SIGNAL(changedViewer()), objectViewerModel, SLOT(changedViewer())); connect(objectViewerModel, SIGNAL(setBackgroundColour()), this, SLOT(setBackgroundColour())); m_blinkButton->setVisible(true); }
void increment(void *, SoSensor *) { player.x+=player.dx; player.y+=player.dy; player.z+=player.dz; player.ix=int(player.x+101)/2+mapX/2-50; player.iy=int(-player.y+101)/2-50; player.dz-=0.1; if(player.z<0) { // if((player.ix>=0)&&(player.iy>=0)&&(map[player.iy][player.ix])) { if((player.ix>=0)&&(player.iy>=0)&&(mapAt(player.ix,player.iy))) { player.dz=0; player.z=0; } else { player.x=player.dz=player.dy=player.dx=player.y=player.z=0; } } player.position->translation.setValue(SbVec3f(0+player.x, 1.5+player.z, 0+player.y)); player.light->location.setValue(SbVec3f(0+player.x,5+player.z,0+player.y)); player.camera->position=SbVec3f(0+player.x, 5+player.z, 20+player.y); //printf("%f %f %i %i\n",player.x, player.y,player.ix, player.iy); // Update acceleration based on whether player is holding arrow key down // Math used to set maximum speed of 2, and higher acceleration when away // from max speed. // Also, if speed is near zero, and player is trying to stop, ball stops, // rather than taking on pathetically slow velocities. if(player.left) if((player.dx<=0)||(player.dx>.2)) player.dx-=.1*(2+player.dx); else player.dx=0; if(player.right) if((player.dx>=0)||(player.dx<-.2)) player.dx+=.1*(2-player.dx); else player.dx=0; if((!player.left)&&(!player.right)) { if(fabs(player.dx<0.01)) player.dx=0; else player.dx*=0.8; } if(player.up) player.dy-=.1*(2+player.dy); if(player.down) player.dy+=.1*(2-player.dy); }
void SoRing::generatePrimitives(SoAction* action) { SoPrimitiveVertex pv; int nbSlices = (int)((float)NbTrianglesPerRing*sweepAngle.getValue()/360.F); if ( nbSlices < 3 ) nbSlices = 3; float angleInc = (sweepAngle.getValue())*M_PI/180.F/float(nbSlices); float R1 = innerRadius.getValue(); float R2 = outerRadius.getValue(); float radiiRatio = R1/R2; float Xc, Yc; center.getValue().getValue(Xc,Yc); beginShape(action, SoShape::TRIANGLE_STRIP); float angle = sweepAngle.getValue()*M_PI/180.F; // point at outer radius pv.setPoint(SbVec3f(R2*cos(angle)+Xc,R2*sin(angle)+Yc,0)); pv.setNormal(normal); pv.setTextureCoords(SbVec4f(0.5f*(1+cos(angle)), 0.5f*(1+sin(angle)), 0, 1)); shapeVertex(&pv); // point at inner radius pv.setPoint(SbVec3f(R1*cos(angle)+Xc,R1*sin(angle)+Yc,0)); pv.setNormal(normal); pv.setTextureCoords(SbVec4f(0.5f*(1+radiiRatio*cos(angle)), 0.5f*(1+radiiRatio*sin(angle)), 0, 1)); shapeVertex(&pv); for ( int i = 0; i < nbSlices; i++ ) { angle -= angleInc; // outer radius pv.setPoint(SbVec3f((float)(R2*cos(angle))+Xc,(float)(R2*sin(angle))+Yc,0)); pv.setNormal(normal); pv.setTextureCoords(SbVec4f(0.5f*(1+cos(angle)), 0.5f*(1+sin(angle)), 0, 1)); shapeVertex(&pv); // inner radius pv.setPoint(SbVec3f((float)(R1*cos(angle))+Xc,(float)(R1*sin(angle)+Yc),0)); pv.setNormal(normal); pv.setTextureCoords(SbVec4f(0.5f*(1+radiiRatio*cos(angle)), 0.5f*(1+radiiRatio*sin(angle)), 0, 1)); shapeVertex(&pv); } endShape(); }
SbVec3f AxisArrow::getDirVector(void) { if (whichAxis == AxisArrow::AXIS_X) { return SbVec3f(1, 0, 0); } else if (whichAxis == AxisArrow::AXIS_Y) { return SbVec3f(0, 1, 0); } else if (whichAxis == AxisArrow::AXIS_Z) { return SbVec3f(0, 0, 1); } // throw "bad enum"; }
// This is a helper function for debugging purposes: it sets up an // SoCoordinate3 + SoIndexedLineSet pair of nodes exposing the // geometry of the SbBox3f input argument. static void make_scene_graph(const SbBox3f & box, SoCoordinate3 *& coord3, SoIndexedLineSet *& ils) { const SbVec3f & vmin = box.getMin(); const SbVec3f & vmax = box.getMax(); const SbVec3f corners[] = { // back face SbVec3f(vmin[0], vmin[1], vmin[2]), SbVec3f(vmax[0], vmin[1], vmin[2]), SbVec3f(vmax[0], vmax[1], vmin[2]), SbVec3f(vmin[0], vmax[1], vmin[2]), // front face SbVec3f(vmin[0], vmin[1], vmax[2]), SbVec3f(vmax[0], vmin[1], vmax[2]), SbVec3f(vmax[0], vmax[1], vmax[2]), SbVec3f(vmin[0], vmax[1], vmax[2]) }; const int32_t indices[] = { 0, 1, 2, 3, 0, -1, // back face 4, 5, 6, 7, 4, -1, // front face 0, 4, -1, 1, 5, -1, 2, 6, -1, 3, 7, -1 // "crossover" lines }; coord3 = new SoCoordinate3; coord3->point.setValues(0, sizeof(corners) / sizeof(corners[0]), corners); ils = new SoIndexedLineSet; ils->coordIndex.setValues(0, sizeof(indices) / sizeof(indices[0]), indices); }
SoDoubleCalculator::SoDoubleCalculator() // //////////////////////////////////////////////////////////////////////// { SO_ENGINE_CONSTRUCTOR(SoDoubleCalculator); SO_ENGINE_ADD_INPUT(a, (0)); SO_ENGINE_ADD_INPUT(b, (0)); SO_ENGINE_ADD_INPUT(c, (0)); SO_ENGINE_ADD_INPUT(d, (0)); SO_ENGINE_ADD_INPUT(e, (0)); SO_ENGINE_ADD_INPUT(f, (0)); SO_ENGINE_ADD_INPUT(g, (0)); SO_ENGINE_ADD_INPUT(h, (0)); SO_ENGINE_ADD_INPUT(A, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(B, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(C, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(D, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(E, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(F, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(G, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(H, (SbVec3f(0,0,0))); SO_ENGINE_ADD_INPUT(expression, ("")); SO_ENGINE_ADD_OUTPUT(oa, SoMFDouble); SO_ENGINE_ADD_OUTPUT(ob, SoMFDouble); SO_ENGINE_ADD_OUTPUT(oc, SoMFDouble); SO_ENGINE_ADD_OUTPUT(od, SoMFDouble); SO_ENGINE_ADD_OUTPUT(oA, SoMFVec3f); SO_ENGINE_ADD_OUTPUT(oB, SoMFVec3f); SO_ENGINE_ADD_OUTPUT(oC, SoMFVec3f); SO_ENGINE_ADD_OUTPUT(oD, SoMFVec3f); parser = new SoCalcParser(lookupDouble, lookupVec3f, this); reparse = FALSE; isBuiltIn = TRUE; }
void rotateCamera(const SbRotation &rot) { SoCamera * camera = viewer->getCamera(); // get center of rotation const float radius = camera->focalDistance.getValue(); SbVec3f forward; camera->orientation.getValue().multVec(SbVec3f(0,0,-1), forward); const SbVec3f center = camera->position.getValue() + radius * forward; // apply new rotation to the camera camera->orientation = rot * camera->orientation.getValue(); // reposition camera to look at pt of interest camera->orientation.getValue().multVec(SbVec3f(0,0,-1), forward); camera->position = center - radius * forward; headlightRot->rotation = camera->orientation.getValue(); // Adjust clipping planes SoGetBoundingBoxAction clipbox_action(getViewportRegion()); clipbox_action.apply(viewer->getSceneRoot()); SbBox3f bbox = clipbox_action.getBoundingBox(); if (bbox.isEmpty()) return; SbSphere bSphere; bSphere.circumscribe(bbox); float denumerator = forward.length(); float numerator = (bSphere.getCenter() - camera->position.getValue()).dot(forward); float distToCenter = (forward * (numerator / denumerator)).length(); float farplane = distToCenter + bSphere.getRadius(); // if scene is behind the camera, don't change the planes if (farplane < 0) return; float nearplane = distToCenter - bSphere.getRadius(); if (nearplane < (0.001 * farplane)) nearplane = 0.001 * farplane; camera->nearDistance = nearplane; camera->farDistance = farplane; }
SbVec3f SoHandleBoxDragger::getDraggerCenter(void) { SbMatrix mat, inv; this->getSurroundScaleMatrices(mat, inv); return SbVec3f(mat[3][0], mat[3][1], mat[3][2]); }
void SoToVRMLActionP::triangle_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoPrimitiveVertex * v1, const SoPrimitiveVertex * v2, const SoPrimitiveVertex * v3) { SoToVRMLActionP * thisp = THISP(closure); assert(thisp->bsptree); assert(thisp->bsptreenormal); SoPrimitiveVertex const * const arr[3] = {v1, v2, v3}; for (int i = 0; i < 3; i++) { const SoPrimitiveVertex * v = arr[i]; thisp->coordidx->append(thisp->bsptree->addPoint(v->getPoint())); thisp->normalidx->append(thisp->bsptreenormal->addPoint(v->getNormal())); if (thisp->texidx) { assert(thisp->bsptreetex); const SbVec4f & tc = v->getTextureCoords(); thisp->texidx->append(thisp->bsptreetex->addPoint(SbVec3f(tc[0], tc[1], 0.0f))); } if (thisp->coloridx) thisp->coloridx->append(v->getMaterialIndex()); } thisp->coordidx->append(-1); thisp->normalidx->append(-1); if (thisp->texidx) thisp->texidx->append(-1); if (thisp->coloridx) thisp->coloridx->append(-1); }
/*! \COININTERNAL Called when user drags the mouse after picking the dragger. */ void SoScale2Dragger::drag(void) { this->planeProj->setViewVolume(this->getViewVolume()); this->planeProj->setWorkingSpace(this->getLocalToWorldMatrix()); SbVec3f projPt = this->planeProj->project(this->getNormalizedLocaterPosition()); SbVec3f startPt = this->getLocalStartingPoint(); SbVec3f scale = projPt; scale[2] = 1.0f; if (startPt[0] != 0.0f) scale[0] /= startPt[0]; else scale[0] = 0.0f; if (startPt[1] != 0.0f) scale[1] /= startPt[1]; else scale[1] = 0.0f; this->setMotionMatrix(this->appendScale(this->getStartMotionMatrix(), scale, SbVec3f(0.0f, 0.0f, 0.0f))); }
SoXipDrawClipPlane::SoXipDrawClipPlane() { SO_NODE_CONSTRUCTOR(SoXipDrawClipPlane); SO_NODE_ADD_FIELD(plane, (SbPlane(SbVec3f(0, 0, 1), 0))); SO_NODE_ADD_FIELD(on, (TRUE)); SO_NODE_ADD_FIELD(boundingBox, (SbMatrix::identity())); }
void SoXipDicomExaminer::updateCamera() { SoXipDataImage* xipImage = ((SoXipSFDataImage *)mImage->getField(SbName("image")))->getValue(); if( !xipImage ) return ; SbXipImage* image = xipImage->get(); if( image ) { SbVec3f newImagePos = image->getModelMatrix()[3]; SbVec3f oldImagePos = mImageModelMatrix[3]; SbVec3f cameraTranslation = (newImagePos - oldImagePos); getCamera()->position.setValue( getCamera()->position.getValue() + cameraTranslation ); mImageModelMatrix = image->getModelMatrix(); SbVec3f t, s, normal; SbRotation r, so; mImageModelMatrix.getTransform(t, r, s, so); normal = SbVec3f(mImageModelMatrix[2][0], mImageModelMatrix[2][1], mImageModelMatrix[2][2]); normal.normalize(); SbPlane plane ( normal, t ); planeSlice.setValue ( plane ) ; } }
//////////////////////////////////////////////////////////////////////// // // Description: // Set up the highlighting, projector, and the initial hit on // the dragger // // Use: private // void SoTranslate2Dragger::dragStart() // //////////////////////////////////////////////////////////////////////// { // Set the switches to 1... setSwitchValue( translatorSwitch.getValue(), 1 ); setSwitchValue( feedbackSwitch.getValue(), 1 ); // Set the axis feedback switch to display both. // They're displayed while dragging setSwitchValue( axisFeedbackSwitch.getValue(), SO_SWITCH_ALL ); // There is no constrained direction... translateDir = -1; // Make a note of which modifier keys are down. shftDown = getEvent()->wasShiftDown(); // This is the point we'll use if a metaKey callback makes us re-start. worldRestartPt = getWorldStartingPoint(); // Establish the projector plane in working space. // Working space is space at end of motion matrix. // Plane normal is defined relative to the translatorPart, so // use z-axis to construct the projector plane. SbVec3f startLocalHitPt = getLocalStartingPoint(); planeProj->setPlane( SbPlane(SbVec3f(0,0,1), startLocalHitPt ) ); }
void SoXipDicomExaminer::adjustCamera( SoGLRenderAction* action, const SbMatrix& model ) { SbVec3f imageAxis[3]; imageAxis[0] = model[0]; imageAxis[1] = model[1]; imageAxis[1].negate(); imageAxis[2] = imageAxis[0].cross( imageAxis[1] ); float width = imageAxis[0].length(); float height = imageAxis[1].length(); SbRotation rotation = SbRotation( SbVec3f(0, 0, -1), -imageAxis[2] ); getCamera()->orientation.setValue( rotation ); SbMatrix orientationMatrix; orientationMatrix = getCamera()->orientation.getValue(); tiltCamera( SbRotation( orientationMatrix[1], imageAxis[1] ) ); getCamera()->viewAll( mImage, mViewport ); getCamera()->height = ( width > height ? width : height ) / viewAllScale.getValue(); const float d = 2.0; SbVec3f imageCenter = model[3] + imageAxis[0] / d - imageAxis[1] / d; float focalDistance = (getCamera()->position.getValue() - imageCenter).length(); SbVec3f diff = (getCamera()->position.getValue() - imageCenter) / focalDistance; getCamera()->position.setValue( imageCenter ); getCamera()->focalDistance.setValue( 0 ); getCamera()->nearDistance.setValue( -1 ); getCamera()->farDistance.setValue( 1. ); //getCamera()->nearDistance.setValue( -0.1 ); //getCamera()->farDistance.setValue( 0.1 ); }