// //Set the color of the text // void TextRegion::SetTextColor(const osg::Vec4& color) { _textColor.r() = color.x(); _textColor.g() = color.y(); _textColor.b() = color.z(); _textColor.a() = this->GetAlpha(); _text->setColor(_textColor); this->SetColor(osg::Vec3(color.x(),color.y(),color.z())); _dirtyRenderState = true; }
/** * Calculate what the section is and return as string */ std::string ConicSectionPlugin::calculateSection(osg::Vec4 eq) { double a, b, h; if (!isNull(eq.z())) { double z2 = eq.z() * eq.z(); a = 1 - (eq.x() * eq.x() / z2); b = 1 - (eq.y() * eq.y() / z2); h = eq.x() * eq.y() / z2; } else if (!isNull(eq.y())) { double y2 = eq.y() * eq.y(); a = 1 - (eq.x() * eq.x() / y2); b = 1 - (eq.z() * eq.z() / y2); h = eq.x() * eq.z() / y2; } else if (!isNull(eq.x())) { double x2 = eq.x() * eq.x(); a = 1 - (eq.y() * eq.y() / x2); b = 1 - (eq.z() * eq.z() / x2); h = eq.y() * eq.z() / x2; } else { return coTranslator::coTranslate("Kegelschnitt: --- "); } double ab = a * b; double h2 = h * h; if (a == b && h == 0) { return coTranslator::coTranslate("Kegelschnitt: Kreis "); } if ((a == 0 && b != 0) || (a != 0 && b == 0)) { return coTranslator::coTranslate("Kegelschnitt: Parabel / Hyperbel"); } if (h2 < ab) { return coTranslator::coTranslate("Kegelschnitt: Ellipse"); } if (h2 > ab) { // check if it only intersects one cone // if (numIntersectTop <= 3 || numIntersectBottom <= 3) // return "Section: Parabola"; return coTranslator::coTranslate("Kegelschnitt: Parabel / Hyperbel"); } return coTranslator::coTranslate("Kegelschnitt: --- "); }
osg::Vec4 ConfigManager::getVec4(std::string attributeX, std::string attributeY, std::string attributeZ, std::string attributeW, std::string path, osg::Vec4 def, bool * found) { bool hasEntry = false; bool isFound; osg::Vec4 result; result.x() = getFloat(attributeX,path,def.x(),&isFound); if(isFound) { hasEntry = true; } result.y() = getFloat(attributeY,path,def.y(),&isFound); if(isFound) { hasEntry = true; } result.z() = getFloat(attributeZ,path,def.z(),&isFound); if(isFound) { hasEntry = true; } result.w() = getFloat(attributeW,path,def.w(),&isFound); if(isFound) { hasEntry = true; } if(found) { *found = hasEntry; } return result; }
osg::Vec2 calcCoordReprojTrans(const osg::Vec3 &vert,const osg::Matrix &trans,const osg::Matrix &viewProj,const osg::Vec2 &size,const osg::Vec4 &ratio){ osg::Vec4 v(vert.x(),vert.y(),vert.z(),1.0); v=v*trans; v=v*viewProj; v.x() /= v.w(); v.y() /= v.w(); v.z() /= v.w(); v.w() /= v.w(); //std::cout << "Pre shift " << v << std::endl; v.x() /= size.x();; v.y() /= size.y(); v.x() -= (ratio.x()/size.x()); v.y() -= (ratio.y()/size.y()); //std::cout << "Post shift " << v << std::endl; // std::cout << "PP shift " << v << std::endl; osg::Vec2 tc(v.x(),v.y()); tc.x() *= ratio.z(); tc.y() *=ratio.w(); //tc.x()*=ratio.x(); //tc.y()*=ratio.y(); tc.x()/=(ratio.z()); tc.y()/=(ratio.w()); return tc; }
void ConicSectionPlugin::drawPlane(osg::Vec4 eq) { //if (showClipplane_->getState()) //{ //helper plane Vec3 normal = Vec3(eq.x(), eq.y(), eq.z()); normal.normalize(); Vec3 point = normal * -eq.w(); point = point + normal * 0.003; helperPlane_->update(normal, point); Vec3 intersect[6]; osg::BoundingBox bboxCompl = cover->getBBox(Cone_.get()); int numIntersect = helperPlane_->getBoxIntersectionPoints(bboxCompl, intersect); if (numIntersect > 0) { for (int i = 0; i < numIntersect; i++) { (*polyCoords_)[i] = intersect[i]; } for (int i = numIntersect; i < 6; i++) { (*polyCoords_)[i] = (*polyCoords_)[numIntersect - 1]; } } (*polyNormal_)[0].set(normal[0], normal[1], normal[2]); plane_->dirtyBound(); //} }
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec4& value) const { value.x() = _heightField->getHeight(i,j); value.y() = _defaultValue.y(); value.z() = _defaultValue.z(); value.w() = _defaultValue.w(); return true; }
void DataOutputStream::writeVec4(const osg::Vec4& v){ writeFloat(v.x()); writeFloat(v.y()); writeFloat(v.z()); writeFloat(v.w()); if (_verboseOutput) std::cout<<"read/writeVec4() ["<<v<<"]"<<std::endl; }
bool Uniform::getElement( unsigned int index, osg::Vec4& v4 ) const { if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC4) ) return false; unsigned int j = index * getTypeNumComponents(getType()); v4.x() = (*_floatArray)[j]; v4.y() = (*_floatArray)[j+1]; v4.z() = (*_floatArray)[j+2]; v4.w() = (*_floatArray)[j+3]; return true; }
void OrbitalBodyImposter::updateTint(osg::Vec4 const &color, double flare_alpha) { osg::Vec4Array *colors = dynamic_cast<osg::Vec4Array*>(m_CoreImposter->getColorArray()); assert(colors); (*colors)[0] = color; m_CoreImposter->dirtyDisplayList(); if (m_FlareImposter.valid()) { osg::Vec4Array *colors = dynamic_cast<osg::Vec4Array*>(m_FlareImposter->getColorArray()); assert(colors); (*colors)[0] = osg::Vec4(color.x(), color.y(), color.z(), flare_alpha); m_FlareImposter->dirtyDisplayList(); } }
void StandardShadowMap::ViewData::aimShadowCastingCamera( const osg::BoundingSphere &bs, const osg::Light *light, const osg::Vec4 &lightPos, const osg::Vec3 &lightDir, const osg::Vec3 &lightUpVector /* by default = osg::Vec3( 0, 1 0 )*/ ) { osg::Matrixd & view = _camera->getViewMatrix(); osg::Matrixd & projection = _camera->getProjectionMatrix(); osg::Vec3 up = lightUpVector; if( up.length2() <= 0 ) up.set( 0,1,0 ); osg::Vec3d position(lightPos.x(), lightPos.y(), lightPos.z()); if (lightPos[3]==0.0) // infinite directional light { // make an orthographic projection // set the position far away along the light direction position = bs.center() - lightDir * bs.radius() * 2; } float centerDistance = (position-bs.center()).length(); float znear = centerDistance-bs.radius(); float zfar = centerDistance+bs.radius(); float zNearRatio = 0.001f; if (znear<zfar*zNearRatio) znear = zfar*zNearRatio; if ( lightPos[3]!=0.0 ) { // positional light if( light->getSpotCutoff() < 180.0f) // also needs znear zfar estimates { float spotAngle = light->getSpotCutoff(); projection.makePerspective( spotAngle * 2, 1.0, znear, zfar); view.makeLookAt(position,position+lightDir,up); } else { // standard omnidirectional positional light float top = (bs.radius()/centerDistance)*znear; float right = top; projection.makeFrustum(-right,right,-top,top,znear,zfar); view.makeLookAt(position,bs.center(),up ); } } else // directional light { float top = bs.radius(); float right = top; projection.makeOrtho(-right, right, -top, top, znear, zfar); view.makeLookAt(position,bs.center(),up); } }
btVector4 osgbCollision::asBtVector4( const osg::Vec4& v ) { return btVector4( v.x(), v.y(), v.z(), v.w() ); }
Eigen::Vector4f toE(const osg::Vec4 &v) const { return Eigen::Vector4f(v.x(), v.y(), v.z(), v.w()); }
std::string ConicSectionPlugin::sectionString(osg::Vec4 eq) { stringstream equation; equation << coTranslator::coTranslate("Gleichung: "); equation << std::fixed << std::setprecision(2); double ax, bx, cx, dx, ex, fx; if (!isNull(eq.z())) { double z2 = eq.z() * eq.z(); ax = 1 - ((eq.x() * eq.x()) / z2); bx = 1 - (eq.y() * eq.y() / z2); cx = 2 * eq.x() * eq.y() / z2; dx = 2 * eq.x() * eq.w() / z2; ex = 2 * eq.y() * eq.w() / z2; fx = eq.w() * eq.w() / z2; if (!isNull(ax)) equation << ax << "x^2 "; if (bx > 0) equation << "+" << bx << "y^2 "; else if (bx < 0) equation << bx << "y^2 "; if (cx > 0) equation << "+" << cx << "xy "; else if (cx < 0) equation << cx << "xy "; if (dx > 0) equation << "+" << dx << "x "; else if (dx < 0) equation << dx << "x "; if (ex > 0) equation << "+" << ex << "y "; else if (ex < 0) equation << ex << "y "; if (fx > 0) equation << "+" << fx << " = 0"; else if (fx < 0) equation << fx << " = 0 "; else equation << " = 0 "; } else if (!isNull(eq.x())) { double a2 = eq.x() * eq.x(); ax = 1 + ((eq.y() * eq.y()) / a2); bx = (eq.z() * eq.z() / a2) - 1; cx = 2 * eq.y() * eq.z() / a2; dx = 2 * eq.y() * eq.w() / a2; ex = 2 * eq.z() * eq.w() / a2; fx = eq.w() * eq.w() / a2; if (!isNull(ax)) equation << ax << "y^2 "; if (bx > 0) equation << "+" << bx << "z^2 "; else if (bx < 0) equation << bx << "z^2 "; if (cx > 0) equation << "+" << cx << "yz "; else if (cx < 0) equation << cx << "yz "; if (dx > 0) equation << "+" << dx << "y "; else if (dx < 0) equation << dx << "y "; if (ex > 0) equation << "+" << ex << "z "; else if (ex < 0) equation << ex << "z "; if (fx > 0) equation << "+" << fx << " = 0"; else if (fx < 0) equation << fx << " = 0 "; else equation << " = 0 "; } else if (!isNull(eq.y())) { double b2 = eq.y() * eq.y(); ax = 1 + ((eq.x() * eq.x()) / b2); bx = (eq.z() * eq.z() / b2) - 1; cx = 2 * eq.x() * eq.z() / b2; dx = 2 * eq.x() * eq.w() / b2; ex = 2 * eq.z() * eq.w() / b2; fx = eq.w() * eq.w() / b2; if (!isNull(ax)) equation << ax << "x^2 "; if (bx > 0) equation << "+" << bx << "z^2 "; else if (bx < 0) equation << bx << "z^2 "; if (cx > 0) equation << "+" << cx << "xz "; else if (cx < 0) equation << cx << "xz "; if (dx > 0) equation << "+" << dx << "x "; else if (dx < 0) equation << dx << "x "; if (ex > 0) equation << "+" << ex << "z "; else if (ex < 0) equation << ex << "z "; if (fx > 0) equation << "+" << fx << " = 0"; else if (fx < 0) equation << fx << " = 0 "; else equation << " = 0 "; } return equation.str(); }
void print(osg::Vec4 & v, std::string label) { std::cerr << label << " x: " << v.x() << " y: " << v.y() << " z: " << v.z() << " w: " << v.w() << std::endl; }