void ColladaNode::handleTranslate(domTranslate *translate) { if(translate == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->editMatrix().setTranslate(translate->getValue()[0], translate->getValue()[1], translate->getValue()[2] ); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(translate->getSid() != NULL) { nodeName.append("." ); nodeName.append(translate->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); }
void ColladaNode::handleMatrix(domMatrix *matrix) { if(matrix == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Matrix m(matrix->getValue()[0], // rVal00 matrix->getValue()[1], // rVal10 matrix->getValue()[2], // rVal20 matrix->getValue()[3], // rVal30 matrix->getValue()[4], // rVal01 matrix->getValue()[5], // rVal11 matrix->getValue()[6], // rVal21 matrix->getValue()[7], // rVal31 matrix->getValue()[8], // rVal02 matrix->getValue()[9], // rVal12 matrix->getValue()[10], // rVal22 matrix->getValue()[11], // rVal32 matrix->getValue()[12], // rVal03 matrix->getValue()[13], // rVal13 matrix->getValue()[14], // rVal23 matrix->getValue()[15] ); // rVal33 if(getGlobal()->getOptions()->getFlattenNodeXForms()) { MatrixTransformationElementUnrecPtr MatrixElement = MatrixTransformationElement::create(); MatrixElement->setMatrix(m); setName(MatrixElement, matrix->getSid()); appendStackedXForm(MatrixElement, node); } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->setMatrix(m); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(matrix->getSid() != NULL&& getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(matrix->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
void ColladaNode::handleSkew(domSkew *skew) { if(skew == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Vec3f rotationAxis(skew->getValue()[1],skew->getValue()[2],skew->getValue()[3]), translationAxis(skew->getValue()[4],skew->getValue()[5],skew->getValue()[6]); Real32 angle(skew->getValue()[0]); if(getGlobal()->getOptions()->getFlattenNodeXForms()) { SkewTransformationElementUnrecPtr SkewElement = SkewTransformationElement::create(); SkewElement->setRotationAxis(rotationAxis); SkewElement->setTranslationAxis(translationAxis); SkewElement->setAngle(angle); setName(SkewElement, skew->getSid()); appendStackedXForm(SkewElement, node); } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); Matrix skewMatrix; MatrixSkew(skewMatrix,rotationAxis, translationAxis, angle); xform->setMatrix(skewMatrix); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(skew->getSid() != NULL && getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(skew->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
void ColladaNode::handleRotate(domRotate *rotate) { if(rotate == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Vec3f axis(rotate->getValue()[0], rotate->getValue()[1], rotate->getValue()[2]); Real32 angle(rotate->getValue()[3]); if(getGlobal()->getOptions()->getFlattenNodeXForms()) { RotationTransformationElementUnrecPtr RotationElement = RotationTransformationElement::create(); RotationElement->setAxis(axis); RotationElement->setAngle(angle); setName(RotationElement, rotate->getSid()); appendStackedXForm(RotationElement, node); if(getGlobal()->editAnimationMap()[rotate] != NULL) { SLOG << "Found Rotation Animation" << std::endl; getGlobal()->editAnimationMap()[rotate]->getAnimation()->setAnimatedField(RotationElement,std::string("Angle")); } } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->editMatrix().setRotate(Quaternion(axis, osgDegree2Rad(angle))); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(rotate->getSid() != NULL&& getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(rotate->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
void ColladaNode::handleLookAt(domLookat *lookat) { if(lookat == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Pnt3f eyePosition(lookat->getValue()[0],lookat->getValue()[1],lookat->getValue()[2]), lookAtPoint(lookat->getValue()[3],lookat->getValue()[4],lookat->getValue()[5]); Vec3f upDirection(lookat->getValue()[7],lookat->getValue()[8],lookat->getValue()[9]); if(getGlobal()->getOptions()->getFlattenNodeXForms()) { LookAtTransformationElementUnrecPtr LookAtElement = LookAtTransformationElement::create(); LookAtElement->setEyePosition(eyePosition); LookAtElement->setLookAtPosition(lookAtPoint); LookAtElement->setUpDirection(upDirection); setName(LookAtElement, lookat->getSid()); appendStackedXForm(LookAtElement, node); } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); Matrix lookAtMatrix; MatrixLookAt(lookAtMatrix,eyePosition, lookAtPoint, upDirection); xform->setMatrix(lookAtMatrix); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(lookat->getSid() != NULL && getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(lookat->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
void ColladaNode::handleTranslate(domTranslate *translate) { if(translate == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Vec3f translation(translate->getValue()[0], translate->getValue()[1], translate->getValue()[2]); if(getGlobal()->getOptions()->getFlattenNodeXForms()) { TranslationTransformationElementUnrecPtr TranslateElement = TranslationTransformationElement::create(); TranslateElement->setTranslation(translation); setName(TranslateElement, translate->getSid()); appendStackedXForm(TranslateElement, node); if(getGlobal()->editAnimationMap()[translate] != NULL) { SLOG << "Found Translation Animation" << std::endl; getGlobal()->editAnimationMap()[translate]->getAnimation()->setAnimatedField(TranslateElement,std::string("Translation")) ; } } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->editMatrix().setTranslate(translation); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(translate->getSid() != NULL && getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(translate->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
/* virtual */ NodeTransitPtr OFMatrixRecord::convert(Node *pNode) { NodeUnrecPtr returnValue(NULL); if(pNode != NULL) { TransformUnrecPtr pXform = Transform::create(); pXform->setMatrix(matrix); returnValue = makeNodeFor(pXform); returnValue->addChild(pNode); } return NodeTransitPtr(returnValue); }
void display(void) { m1c = tball.getFullTrackballMatrix(); if(move_obj == true) { scene_trans->editSFMatrix()->setValue( m1c ); } else { cam_trans->editSFMatrix()->setValue( m1c ); } commitChanges(); win->render(rentravact); }
// // create an arbitrarly complex render scene // static NodeTransitPtr createStaticScene() { NodeUnrecPtr root = makeCoredNode<Group>(); typedef boost::mt19937 base_generator_type; static base_generator_type generator(0); static boost::uniform_01<float> value; static boost::variate_generator< base_generator_type, boost::uniform_01<float> > die(generator, value); for (int i = 0; i < max_tori; ++i) { NodeUnrecPtr scene = makeTorus(.5, 2, 32, 32); TransformUnrecPtr transformCore = Transform::create(); Matrix mat; mat.setIdentity(); float x = 500.f * die(); float y = 500.f * die(); float z = 500.f * die(); float e1 = die(); float e2 = die(); float e3 = die(); Vec3f v(e1,e2,e3); v.normalize(); float a = TwoPi * die(); Quaternion q(v, a); mat.setTranslate(x,y,z); mat.setRotate(q); transformCore->setMatrix(mat); NodeUnrecPtr trafo = makeNodeFor(transformCore); trafo->addChild(scene); root->addChild(trafo); } return NodeTransitPtr(root); }
OSG_BEGIN_NAMESPACE // Documentation for this class is emitted in the // OSGPhysicsHandlerBase.cpp file. // To modify it, please change the .fcd file (OSGPhysicsHandler.fcd) and // regenerate the base file. ////////////////////////////////////////////////////////////////////////// //! this action traverses the graph to match the OpenSG representation //! to ODE ////////////////////////////////////////////////////////////////////////// Action::ResultE updateOsgOde(Node* const node) { //SLOG << "entering " << node << endLog; TransformUnrecPtr t = dynamic_cast<Transform*>(node->getCore()); if(t!=NULL) { //SLOG << "found a TransformNode " << endLog; AttachmentUnrecPtr a = node->findAttachment(PhysicsBody::getClassType()); if(a!=NULL) { Matrix m; PhysicsBodyUnrecPtr body = dynamic_pointer_cast<PhysicsBody>(a); body->updateToODEState(); //update the position and rotation, but keep the scaling Vec3f Translation, Scale; Quaternion Rotation, ScaleOrientation; t->getMatrix().getTransform(Translation,Rotation,Scale,ScaleOrientation); Translation = body->getPosition(); Rotation = body->getQuaternion(); m.setTransform(Translation,Rotation,Scale,ScaleOrientation); t->setMatrix(m); //update BB node->updateVolume(); } } return Action::Continue; }
PhysicsBodyUnrecPtr buildBox(const Pnt3f& Position, const Vec3f& Dimensions, const Color3f& Color, Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace) { Matrix m; //create OpenSG mesh GeometryUnrecPtr box; NodeUnrecPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1); box = dynamic_cast<Geometry*>(boxNode->getCore()); SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create(); box_mat->setAmbient(Color3f(0.0,0.0,0.0)); box_mat->setDiffuse(Color); box->setMaterial(box_mat); TransformUnrecPtr boxTrans; NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); m.setTranslate(Position); boxTrans->setMatrix(m); //create ODE data PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld); boxBody->setPosition(Vec3f(Position)); boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z()); boxBody->setLinearDamping(0.0001); boxBody->setAngularDamping(0.0001); PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create(); boxGeom->setBody(boxBody); boxGeom->setSpace(physicsSpace); boxGeom->setLengths(Dimensions); //add attachments boxNode->addAttachment(boxGeom); boxTransNode->addAttachment(boxBody); boxTransNode->addChild(boxNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); return boxBody; }
////////////////////////////////////////////////////////////////////////// //! build a sphere ////////////////////////////////////////////////////////////////////////// PhysicsBodyUnrecPtr buildSphere(void) { Real32 Radius((Real32)(rand()%2)*0.5+0.5); Matrix m; //create OpenSG mesh GeometryUnrecPtr sphere; NodeUnrecPtr sphereNode = makeSphere(2, Radius); sphere = dynamic_cast<Geometry*>(sphereNode->getCore()); SimpleMaterialUnrecPtr sphere_mat = SimpleMaterial::create(); sphere_mat->setAmbient(Color3f(0.0,0.0,0.0)); sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0)); sphere->setMaterial(sphere_mat); TransformUnrecPtr sphereTrans; NodeUnrecPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 10.0); sphereTrans->setMatrix(m); //create ODE data PhysicsBodyUnrecPtr sphereBody = PhysicsBody::create(physicsWorld); sphereBody->setPosition(Vec3f(randX, randY, 10.0)); sphereBody->setLinearDamping(0.0001); sphereBody->setAngularDamping(0.0001); sphereBody->setSphereMass(1.0,Radius); PhysicsSphereGeomUnrecPtr sphereGeom = PhysicsSphereGeom::create(); sphereGeom->setBody(sphereBody); sphereGeom->setSpace(physicsSpace); sphereGeom->setRadius(Radius); //add attachments sphereNode->addAttachment(sphereGeom); sphereTransNode->addAttachment(sphereBody); sphereTransNode->addChild(sphereNode); //add to SceneGraph spaceGroupNode->addChild(sphereTransNode); commitChanges(); return sphereBody; }
////////////////////////////////////////////////////////////////////////// //! build a box ////////////////////////////////////////////////////////////////////////// PhysicsBodyUnrecPtr buildBox(void) { Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0); Matrix m; //create OpenSG mesh GeometryUnrecPtr box; NodeUnrecPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1); box = dynamic_cast<Geometry*>(boxNode->getCore()); SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create(); box_mat->setAmbient(Color3f(0.0,0.0,0.0)); box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0)); box->setMaterial(box_mat); TransformUnrecPtr boxTrans; NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 10.0); boxTrans->setMatrix(m); //create ODE data PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld); boxBody->setPosition(Vec3f(randX, randY, 10.0)); boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z()); PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create(); boxGeom->setBody(boxBody); boxGeom->setSpace(physicsSpace); boxGeom->setLengths(Lengths); //add attachments boxNode->addAttachment(boxGeom); boxTransNode->addAttachment(boxBody); boxTransNode->addChild(boxNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); commitChanges(); return boxBody; }
void ColladaNode::appendXForm(const Matrix &m, const std::string &xformSID, InstData &instData ) { domNodeRef node = getDOMElementAs<domNode>(); NodeLoaderState *state = getGlobal()->getLoaderStateAs<NodeLoaderState>(_loaderStateName); OSG_ASSERT(state != NULL); if(getGlobal()->getOptions()->getMergeTransforms() == true) { if(instData._bottomN == NULL) { if(node->getType() == NODETYPE_JOINT) { SkeletonJointUnrecPtr joint = SkeletonJoint::create(); instData._bottomN = makeNodeFor(joint); joint->setMatrix(m); joint->setJointId(state->getJointId()); } else { TransformUnrecPtr xform = Transform::create(); instData._bottomN = makeNodeFor(xform); xform->setMatrix(m); } instData._localMatrix = m; } else { if(node->getType() == NODETYPE_JOINT) { SkeletonJoint *joint = dynamic_cast<SkeletonJoint *>(instData._bottomN->getCore()); OSG_ASSERT(joint != NULL); joint->editMatrix().mult(m); } else { Transform *xform = dynamic_cast<Transform *>(instData._bottomN->getCore()); OSG_ASSERT(xform != NULL); xform->editMatrix().mult(m); } instData._localMatrix.mult(m); } if(instData._topN == NULL) instData._topN = instData._bottomN; if(xformSID.empty() == false) instData._sidMap[xformSID] = instData._bottomN; if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL && getName(instData._bottomN) == NULL ) { std::string nodeName = node->getName(); setName(instData._bottomN, nodeName); } } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); if(instData._bottomN != NULL) instData._bottomN->addChild(xformN); xform->setMatrix(m); instData._localMatrix.mult(m); instData._bottomN = xformN; if(instData._topN == NULL) instData._topN = instData._bottomN; if(xformSID.empty() == false) instData._sidMap[xformSID] = xformN; if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(xformSID.empty() == false) { nodeName.append("." ); nodeName.append(xformSID); } setName(instData._bottomN, nodeName); } } }
Node * ColladaNode::createInstanceJoint(ColladaInstInfo *colInstInfo, domNode *node) { NodeUnrecPtr retVal = NULL; bool startSkel = false; // if there is a ColladaInstanceElement someone tried to use <instance_node> // with this joint as target - this is currently not supported if(colInstInfo->getColInst() != NULL) { SWARNING << "ColladaNode::createInstanceJoint: <instance_node> with " << "target <node> of type JOINT not supported." << std::endl; return retVal; } NodeLoaderState *state = getGlobal()->getLoaderStateAs<NodeLoaderState>(_loaderStateName); OSG_ASSERT(state != NULL); state->pushNodePath(node->getId() != NULL ? node->getId() : ""); state->dumpNodePath(); InstData instData; instData._nodePath = state->getNodePath(); instData._skel = state->getSkeleton(); if(instData._skel == NULL) { startSkel = true; instData._skel = Skeleton::create(); state->setSkeleton(instData._skel); state->setJointId (0 ); OSG_COLLADA_LOG(("ColladaNode::createInstanceJoint: id [%s] " "root joint\n", node->getId())); } else { state->setJointId(state->getJointId() + 1); OSG_COLLADA_LOG(("ColladaNode::createInstanceJoint: id [%s] " "joint [%d]\n", node->getId(), state->getJointId())); } const daeElementRefArray &contents = node->getContents(); for(UInt32 i = 0; i < contents.getCount(); ++i) { switch(contents[i]->getElementType()) { case COLLADA_TYPE::LOOKAT: handleLookAt(daeSafeCast<domLookat>(contents[i]), instData); break; case COLLADA_TYPE::MATRIX: handleMatrix(daeSafeCast<domMatrix>(contents[i]), instData); break; case COLLADA_TYPE::ROTATE: handleRotate(daeSafeCast<domRotate>(contents[i]), instData); break; case COLLADA_TYPE::SCALE: handleScale(daeSafeCast<domScale>(contents[i]), instData); break; case COLLADA_TYPE::SKEW: handleSkew(daeSafeCast<domSkew>(contents[i]), instData); break; case COLLADA_TYPE::TRANSLATE: handleTranslate(daeSafeCast<domTranslate>(contents[i]), instData); break; } } // assert top and bottom are both set or both unset OSG_ASSERT((instData._topN != NULL && instData._bottomN != NULL) || (instData._topN == NULL && instData._bottomN == NULL) ); if(instData._topN == NULL && instData._bottomN == NULL) { // no xforms were created, make a SkeletonJoint for this <node> SkeletonJointUnrecPtr joint = SkeletonJoint::create(); joint->setJointId(state->getJointId()); instData._topN = makeNodeFor(joint); instData._bottomN = instData._topN; if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { setName(instData._topN, node->getName()); } } else if(getGlobal()->getOptions()->getMergeTransforms() == false) { // when not merging transforms add SkeletonJoint core now SkeletonJointUnrecPtr joint = SkeletonJoint::create(); NodeUnrecPtr jointN = makeNodeFor(joint); joint->setJointId(state->getJointId()); instData._bottomN->addChild(jointN); instData._bottomN = jointN; } if(startSkel == true) { // add a transform for the world matrix up to this node to put // the Skeleton in the correct coordinate system TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->setMatrix(state->getWorldMatrix()); xformN->addChild(instData._topN); instData._topN = xformN; if(getGlobal()->getOptions()->getCreateNameAttachments() == true) setName(xformN, "SkeletonWorldMatrix"); } // update world matrix before we instantiate child nodes, etc. state->pushMatrix(instData._localMatrix); // add <node> child elements const domNode_Array &nodes = node->getNode_array(); for(UInt32 i = 0; i < nodes.getCount(); ++i) handleNode(nodes[i], instData); // add <instance_node> child elements const domInstance_node_Array &instNodes = node->getInstance_node_array(); for(UInt32 i = 0; i < instNodes.getCount(); ++i) handleInstanceNode(instNodes[i], instData); // we don't handle other <instance_*> tags here, it does not // make sense to have them inside a skeleton editInstStore().push_back(instData._topN); _instDataStore .push_back(instData ); retVal = instData._topN; if(startSkel == true) { instData._skel->pushToRoots(instData._topN); state->setSkeleton(NULL); state->setJointId (SkeletonJoint::INVALID_JOINT_ID); } state->popMatrix (); state->popNodePath(); return retVal; }
void display(void) { Matrix m1, m2, m3; Quaternion q1; tball.getRotation().getValue(m3); q1.setValue(m3); m1.setRotate(q1); m2.setTranslate( tball.getPosition() ); m1.mult( m2 ); cam_trans->editSFMatrix()->setValue(m1); #if 0 m1c.setIdentity(); Matrix m2c, m3c; Quaternion q1c; tcamball.getRotation().getValue(m3c); q1c.setValue(m3c); m1c.setRotate(q1c); m2c.setTranslate( tcamball.getPosition() ); m1c.mult( m2c ); #else m1c.setIdentity(); float fLat = xPoints[0][1] + (xPoints[1][1] - xPoints[0][1]) * t; float fLong = xPoints[0][0] + (xPoints[1][0] - xPoints[0][0]) * t; // fprintf(stderr, "%f %f\n", fLat, fLong); if(bAnimate == true) { t += tStep; if(t > 1) { tStep = -tStep; t = 1; } else if(t < 0) { tStep = -tStep; t = 0; } } Pnt3f p1; projectPnt(p1, fLat, fLong, 50); m1c[3][0] = p1[0]; m1c[3][1] = p1[1]; m1c[3][2] = p1[2]; #endif scene_trans->editSFMatrix()->setValue(m1c); Vec3f x1(m1c[3][0], m1c[3][1], m1c[3][2]); Vec3f x2; backProjectPnt(x2, x1); /* fprintf(stderr, "%f %f %f\n", osgRad2Degree(x2[0]), x2[2], osgRad2Degree(x2[1])); */ /* -285.728333 -285.728333 | 494.500488 494.500488 */ const BbqDataSourceInformation &tInfo = pSource->getInformation(); m4c.setIdentity(); m4c[3][0] = osgRad2Degree(x2[0]); m4c[3][1] = 0; //x2[2]; // m4c[3][2] = -45.f - (osgRad2Degree(x2[1]) + 40.f); // m4c[3][2] = -(osgRad2Degree(x2[1]) + 40.f); m4c[3][2] = osgRad2Degree(x2[1]); // fprintf(stderr, "%f %f\n", // -(osgRad2Degree(x2[1]) + 40.f), // -45.f - (osgRad2Degree(x2[1]) + 40.f)); // (571.45666/ 5.f) // (- 285.728333 - (170.f * fUnitScale)) // m4c[3][0] = m4c[3][0] * fUnitScale + vUnitOffset[0]; m4c[3][0] = m4c[3][0] * tInfo.vScale[0] + tInfo.vOffset[0]; // m4c[3][2] = (-m4c[3][2] - 40.f) * fUnitScale - 285.728333; // m4c[3][2] = m4c[3][2] * fUnitScale1 + vUnitOffset[1]; m4c[3][2] = m4c[3][2] * tInfo.vScale[1] + tInfo.vOffset[1]; ref_trans->editSFMatrix()->setValue(m4c); commitChanges(); // win->render(rentravact); // fprintf(stderr, "Frame\n==========================================\n"); win->activate (); win->frameInit(); // query recently registered GL extensions win->renderAllViewports(rentravact); win->swap (); win->frameExit(); // after frame cleanup: delete GL objects, if needed }
/* Insert one or more shallow copies of a block (created by DXFBlock as * Transform Group) into a layer (created by DXFLayer as MaterialGroup) or * another block. * \todo * Could there be a INSERT inside a block referring to another block which has * not been read yet? We then have to find a solution to enable deferred * instantiation of INSERT entities :-( */ DXFResult DXFInsert::endEntity(void) { NodeUnrecPtr ctrafoNodeP = NULL; // ComponentTransformUnrecPtr ctrafoCoreP = NULL; TransformUnrecPtr ctrafoCoreP = NULL; NodeUnrecPtr blockNodeP = NULL; Node *parentNodeP = getParentNode(); StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName); if (itr != _blocksMapP->end() && parentNodeP != NULL) { blockNodeP = itr->second; // TODO: check fetched INSERT Data for consistency! // Insert multiple times in a grid... Vec3f offset(0.0, 0.0, 0.0); for(Int16 column = 0; column < _columnCount; ++ column) { offset[0] = column * _columnSpacing; for(Int16 row = 0; row < _rowCount; ++ row) { offset[1] = row * _rowSpacing; // TODO: find out about DXF insert semantics! ctrafoNodeP = Node::create(); ctrafoCoreP = Transform::create(); #if 0 beginEditCP(ctrafoCoreP); #endif { if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1")) { std::cout << blockNodeP->getNChildren() << std::endl; } OSG::TransformationMatrix<Real32> transMat; transMat.setIdentity(); transMat.setTranslate(_insertionPoint + offset); OSG::TransformationMatrix<Real32> rotMat; rotMat.setIdentity(); OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle)); rotMat.setRotate(rot); OSG::TransformationMatrix<Real32> scaleMat; scaleMat.setIdentity(); scaleMat.setScale(_scaleFactor); OSG::Vec3f vin(-40, 65, 0); OSG::Vec3f vout; transMat.mult(rotMat); transMat.mult(scaleMat); if(_extrusionDirection[2]<0) { transMat[0][0] *= -1.0; transMat[1][0] *= -1.0; transMat[2][0] *= -1.0; transMat[3][0] *= -1.0; } ctrafoCoreP->setMatrix(transMat); } #if 0 endEditCP(ctrafoCoreP); #endif #if 0 beginEditCP(ctrafoNodeP); #endif { ctrafoNodeP->setCore(ctrafoCoreP); #if 0 ctrafoNodeP->addChild(blockNodeP->clone()); #endif NodeUnrecPtr pClone = cloneTree(blockNodeP); ctrafoNodeP->addChild(pClone); } #if 0 endEditCP(ctrafoNodeP); #endif #if 0 beginEditCP(parentNodeP); #endif { parentNodeP->addChild(ctrafoNodeP); } #if 0 endEditCP(parentNodeP); #endif } } // Warn for details not implemented or assured yet! TODO: better // implement missing features! /*if(fabs(_rotationAngle) > Eps) FWARNING(("DXF Loader: before line %d: " "DXFInsert does not yet support ROTATION " "(group code 50). " "Most likely the graphics are incorrect!\n", DXFRecord::getLineNumber() ));*/ /*if(_scaleFactor != Vec3f(1.0,1.0,1.0)) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret SCALING " "(group codes 41, 42, 43) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() ));*/ if(_columnCount != 1 || _rowCount != 1) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret REPEATED INSERTION " "(group codes 70, 71, 44, 45) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() )); } else { if(itr == _blocksMapP->end()) FWARNING(("DXF Loader: before line %d (inside %s section): " "BLOCK '%s' to be inserted not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _blockName.c_str() )); if(parentNodeP == NULL) FWARNING(("DXF Loader: before line %d (inside %s section): " "layer %s to be inserted to not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _layerName.c_str() )); } //set back to default value; _insertionPoint.setNull(), _scaleFactor[0]=_scaleFactor[1]=_scaleFactor[2]=1.0; _rotationAngle=0.0; _columnCount=1; _rowCount=1; _columnSpacing=0.0; _rowSpacing=0.0; _extrusionDirection[0]=0; _extrusionDirection[1]=0; _extrusionDirection[2]=1; return DXFStateContinue; }