//---------------------------------------------------------------------------- bool Rope::OnInitialize () { if ( !Application::OnInitialize() ) return false; CreateScene(); // center-and-fit for camera viewing m_spkScene->UpdateGS(0.0f); Bound kWBound = m_spkScene->WorldBound(); m_spkTrnNode->Translate() = -kWBound.Center(); ms_spkCamera->SetFrustum(1.0f,100.0f,-0.55f,0.55f,0.4125f,-0.4125f); Vector3f kCLeft(1.0f,0.0f,0.0f); Vector3f kCUp(0.0f,0.0f,1.0f); Vector3f kCDir(0.0f,-1.0f,0.0f); Vector3f kCLoc = -3.0f*kWBound.Radius()*kCDir - 0.5f*kCUp; ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir); // initial update of objects ms_spkCamera->Update(); m_spkScene->UpdateGS(0.0f); m_spkScene->UpdateRS(); // camera turret and tumble mode m_spkMotionObject = m_spkScene; m_fTrnSpeed = 0.01f; m_fRotSpeed = 0.01f; m_bTurretActive = true; SetTurretAxes(); return true; }
void AnalysisForm::bindTo(Options *options, DataSet *dataSet) { if (_options != NULL) unbind(); _dataSet = dataSet; _options = options; for(const string &name : options->names) { Option *option = options->get(name); QString qsName = QString::fromUtf8(name.c_str(), name.length()); qsName.replace('/', '_'); QWidget *child = this->findChild<QWidget*>(qsName); Bound *boundChild = dynamic_cast<Bound*>(child); if (boundChild != NULL) { _bounds.push_back(boundChild); boundChild->bindTo(option); boundChild->illegalChanged.connect(boost::bind(&AnalysisForm::illegalValueHandler, this, _1)); } else qDebug() << "child not found : " << qsName << " in AnalysisForm::setOptions()"; } updateIllegalStatus(); }
bool Feedback::is_route_turned() const { std::vector<Cell> route_arr; std::vector<Bound> bounds; for(auto I=route.begin(); I!=route.end(); I++) { route_arr.push_back(*I); } for(int i=0; (i+1)<route_arr.size(); i++) { Cell current = route_arr[i]; Cell next = route_arr[i+1]; std::list<Bound> adjacents = current.get_adjacents(); for(auto J=adjacents.begin(); J!=adjacents.end(); J++) { if(J->get_target() == next) { bounds.push_back(*J); } // the corressponding bound } // for adjacents } // for i (index of arr) for(int i=0; (i+1)<bounds.size(); i++) { Bound current = bounds[i]; Bound next = bounds[i+1]; if(!next.is_linkable(current, false)) { // 不能轉向的話接不上 // 結論:轉向了 return true; } } return false; }
void AnalysisForm::unbind() { _bounds.clear(); updateIllegalStatus(); if (_options == NULL) return; BOOST_FOREACH(const string &name, _options->names) { Option *option = _options->get(name); QString qsName = QString::fromUtf8(name.c_str(), name.length()); qsName.replace('/', '_'); QWidget *child = this->findChild<QWidget*>(qsName); Bound *boundChild = dynamic_cast<Bound*>(child); if (boundChild != NULL) boundChild->unbind(); } _options = NULL; }
//---------------------------------------------------------------------------- bool EnvironmentMaps::OnInitialize () { if ( !Application::OnInitialize() ) return false; if ( !Setup() ) return true; m_spkScene->UpdateGS(0.0f); Bound kWBound = m_spkScene->WorldBound(); m_spkTrnNode->Translate() = -kWBound.Center(); ms_spkCamera->SetFrustum(1.0f,10000.0f,-0.55f,0.55f,0.4125f,-0.4125f); Vector3f kCLeft(0.0f,0.0f,-1.0f); Vector3f kCUp(0.0f,1.0f,0.0f); Vector3f kCDir(1.0f,0.0f,0.0f); Vector3f kCLoc = -3.0f*kWBound.Radius()*kCDir; ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir); // initial update of objects ms_spkCamera->Update(); m_spkScene->UpdateGS(0.0f); m_spkScene->UpdateRS(); m_spkMotionObject = m_spkScene; m_fTrnSpeed = 1.0f; m_fRotSpeed = 0.01f; m_bTurretActive = true; SetTurretAxes(); m_bInitialized = true; return true; }
VOID Bound::Merge( const Bound& Other ) { Sphere OtherSphere; OtherSphere.Center = Other.GetCenter(); OtherSphere.Radius = Other.GetMaxRadius(); if( m_Type == Bound::No_Bound ) { SetSphere( OtherSphere ); return; } Sphere ThisSphere; if( m_Type != Bound::Sphere_Bound ) { // convert this bound into a sphere ThisSphere.Center = GetCenter(); ThisSphere.Radius = GetMaxRadius(); } else { ThisSphere = GetSphere(); } XMVECTOR vThisCenter = XMLoadFloat3( &ThisSphere.Center ); XMVECTOR vOtherCenter = XMLoadFloat3( &OtherSphere.Center ); XMVECTOR vThisToOther = XMVectorSubtract( vOtherCenter, vThisCenter ); XMVECTOR vDistance = XMVector3LengthEst( vThisToOther ); FLOAT fCombinedDiameter = XMVectorGetX( vDistance ) + ThisSphere.Radius + OtherSphere.Radius; if( fCombinedDiameter <= ( ThisSphere.Radius * 2 ) ) { SetSphere( ThisSphere ); return; } if( fCombinedDiameter <= ( OtherSphere.Radius * 2 ) ) { SetSphere( OtherSphere ); return; } XMVECTOR vDirectionNorm = XMVector3Normalize( vThisToOther ); XMVECTOR vRadius = XMVectorSet( ThisSphere.Radius, OtherSphere.Radius, 0, 0 ); XMVECTOR vThisRadius = XMVectorSplatX( vRadius ); XMVECTOR vOtherRadius = XMVectorSplatY( vRadius ); XMVECTOR vCombinedDiameter = vThisRadius + vDistance + vOtherRadius; XMVECTOR vMaxDiameter = XMVectorMax( vCombinedDiameter, vThisRadius * 2 ); vMaxDiameter = XMVectorMax( vMaxDiameter, vOtherRadius * 2 ); XMVECTOR vMaxRadius = vMaxDiameter * 0.5f; ThisSphere.Radius = XMVectorGetX( vMaxRadius ); vMaxRadius -= vThisRadius; XMVECTOR vCombinedCenter = vThisCenter + vMaxRadius * vDirectionNorm; XMStoreFloat3( &ThisSphere.Center, vCombinedCenter ); SetSphere( ThisSphere ); }
// Reset right bound (must be to >= left bound.) void BiVector::set_right(const Bound &e) { assert(left.is_infinite() || e.is_infinite() || left.value() <= e.value()); if (!e.is_infinite() && (right.is_infinite() || e.value() < right.value())) { right = e; trim_bivector_at_right(); } else right = e; }
// Reset left bound (must be to <= right bound.) void BiVector::set_left(const Bound &e) { assert(e.is_infinite() || right.is_infinite() || e.value() <= right.value()); if (!e.is_infinite() && (left.is_infinite() || e.value() > left.value())) { left = e; trim_bivector_at_left(); } else left = e; }
//---------------------------------------------------------------------------- bool WaterDropFormation::OnInitialize () { if ( !Application::OnInitialize() ) return false; // create scene m_spkScene = new Node; m_spkTrnNode = new Node(3); m_spkScene->AttachChild(m_spkTrnNode); CreatePlane(); CreateWall(); CreateWaterRoot(); // wireframe m_spkWireframe = new WireframeState; m_spkScene->SetRenderState(m_spkWireframe); // depth buffer ZBufferState* pkZBuffer = new ZBufferState; pkZBuffer->Enabled() = true; pkZBuffer->Writeable() = true; pkZBuffer->Compare() = ZBufferState::CF_LEQUAL; m_spkScene->SetRenderState(pkZBuffer); Configuration0(); // center-and-fit for camera viewing m_spkScene->UpdateGS(0.0f); Bound kWBound = m_spkScene->WorldBound(); m_spkTrnNode->Translate() = -kWBound.Center(); ms_spkCamera->SetFrustum(0.1f,1000.0f,-0.055f,0.055f,0.04125f,-0.04125f); float fAngle = 0.01f*Mathf::PI; float fCos = Mathf::Cos(fAngle), fSin = Mathf::Sin(fAngle); Vector3f kCUp(fSin,0.0f,-fCos); Vector3f kCDir(-fCos,0.0f,-fSin); Vector3f kCLeft(0.0f,1.0f,0.0f); Vector3f kCLoc = -0.9f*kWBound.Radius()*kCDir; ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir); // initial update of objects ms_spkCamera->Update(); m_spkScene->UpdateGS(0.0f); m_spkScene->UpdateRS(); m_spkMotionObject = m_spkScene; m_bTurretActive = true; SetTurretAxes(); m_fTrnSpeed = 0.01f; m_fRotSpeed = 0.001f; m_fLastSeconds = GetTimeInSeconds(); return true; }
bool InStream::ReadAggregate (Bound& datum) { APoint center; float radius; if (!ReadAggregate(center) || !Read(radius)) { return false; } datum.SetCenter(center); datum.SetRadius(radius); return true; }
he::IntersectResult CameraPerspective::intersect( const Bound& bound ) const { HIERARCHICAL_PROFILE(__HE_FUNCTION__); const Sphere& camSphereBound(m_Bound.getSphere()); const Cone& camConeBound(m_Bound.getCone()); const Frustum& frustumBound(m_Bound.getFrustum()); const Sphere& otherSphereBound(bound.getSphere()); // Fast sphere - sphere test { HIERARCHICAL_PROFILE("Sphere Test"); if (camSphereBound.intersectTest(otherSphereBound) == false) return IntersectResult_Outside; } { HIERARCHICAL_PROFILE("Cone Test"); // Fast cone - sphere test if (camConeBound.intersectTest(otherSphereBound) == false) return IntersectResult_Outside; } // sphere frustum test { HIERARCHICAL_PROFILE("Frustum Test"); switch(frustumBound.intersect(otherSphereBound)) { case IntersectResult_Outside: return IntersectResult_Outside; case IntersectResult_Inside: return IntersectResult_Inside; case IntersectResult_Intersecting: { HIERARCHICAL_PROFILE("Slow Frustum Test"); switch(frustumBound.intersect(bound.getAABB())) { case IntersectResult_Outside: return IntersectResult_Outside; case IntersectResult_Inside: return IntersectResult_Inside; case IntersectResult_Intersecting: return IntersectResult_Intersecting; } } break; } } LOG(LogType_ProgrammerAssert, "Should never get here"); return IntersectResult_Outside; }
bool ZoneBox::in_interval (const double point, const Bound& from, const Bound& to) { if (from.type () == Bound::finite && point <= from.value ()) // Point before interval. return false; if (to.type () == Bound::finite && point > to.value ()) // Point after interval. return false; // Point in interval. return true; }
//================================================================== inline void bounds2DSweepR( Bound &out_bound, float r, float phiMin, float phiMax ) { out_bound.Expand( polar(r, phiMin) ); out_bound.Expand( polar(r, phiMax) ); for (int i=-3; i < 4; ++i) { float phi = i * FM_PI_2; if ( phiMin < phi && phiMax > phi ) out_bound.Expand( polar( r, phi ) ); } }
//---------------------------------------------------------------------------- bool Bound::TestIntersection (const Bound& bound, float tmax, const AVector& velocity0, const AVector& velocity1) const { if (bound.GetRadius() == 0.0f || GetRadius() == 0.0f) { return false; } AVector relVelocity = velocity1 - velocity0; // 相对速度 AVector cenDiff = bound.mCenter - mCenter; // 相对位移 float a = relVelocity.SquaredLength(); float c = cenDiff.SquaredLength(); float rSum = bound.mRadius + mRadius; float rSumSqr = rSum*rSum; if (a > 0.0f) { float b = cenDiff.Dot(relVelocity); if (b <= 0.0f) { if (-tmax*a <= b) { return a*c - b*b <= a*rSumSqr; } else { return tmax*(tmax*a + 2.0f*b) + c <= rSumSqr; } } } return c <= rSumSqr; }
void Sphere::MakeBound( Bound &out_bound ) const { float tuMin = mThetamaxRad * mURange[0]; float tuMax = mThetamaxRad * mURange[1]; float alphaMin = DASin( mZMin / mRadius ); float alphaMax = DASin( mZMax / mRadius ); float aVMin = DMix( alphaMin, alphaMax, mVRange[0] ); float aVMax = DMix( alphaMin, alphaMax, mVRange[1] ); float rVMin = DCos( aVMin ) * mRadius; float rVMax = DCos( aVMax ) * mRadius; float rMin = DMIN( rVMin, rVMax ); float rMax; if ( aVMin < 0 && aVMax > 0 ) rMax = mRadius; else rMax = DMAX( rVMin, rVMax ); out_bound.Reset(); bounds2DSweepL( out_bound, rMin, rMax, tuMin, tuMax ); out_bound.mBox[0].z() = DSin( aVMin ) * mRadius; out_bound.mBox[1].z() = DSin( aVMax ) * mRadius; }
// Trim arg1 to within bounds arg2 & arg3; should have arg2 <= arg3. Integer trim_to(const Integer &i, const Bound &lo, const Bound &hi) { assert(lo.is_infinite() || hi.is_infinite() || lo.value() <= hi.value()); if (!lo.is_le(i)) return lo.value(); else if (!hi.is_ge(i)) return hi.value(); else return i; }
//================================================================== void Cylinder::MakeBound( Bound &out_bound ) const { float tuMin = mThetamaxRad * mURange[0]; float tuMax = mThetamaxRad * mURange[1]; out_bound.Reset(); bounds2DSweepL( out_bound, mRadius, mRadius, tuMin, tuMax ); out_bound.mBox[0].z() = DMix( mZMin, mZMax, mVRange[0] ); out_bound.mBox[1].z() = DMix( mZMin, mZMax, mVRange[1] ); }
VOID DebugDraw::DrawBound( const Bound& bound, D3DCOLOR Color ) { switch( bound.GetType() ) { case Bound::Sphere_Bound: DrawSphere( bound.GetSphere(), Color ); return; case Bound::Frustum_Bound: DrawFrustum( bound.GetFrustum(), Color ); return; case Bound::AABB_Bound: DrawAabb( bound.GetAabb(), Color ); return; case Bound::OBB_Bound: DrawObb( bound.GetObb(), Color ); return; } }
//----------------------------------------------------------------------------- // Name: Bound::Collide // Desc: collides this bound with another bound //----------------------------------------------------------------------------- BOOL Bound::Collide( const Bound& Other ) const { switch( Other.m_Type ) { case Bound::Sphere_Bound: return Collide( Other.GetSphere() ); case Bound::Frustum_Bound: return Collide( Other.GetFrustum() ); case Bound::OBB_Bound: return Collide( Other.GetObb() ); case Bound::AABB_Bound: return Collide( Other.GetAabb() ); case Bound::No_Bound: return TRUE; } return FALSE; }
//---------------------------------------------------------------------------- bool WrigglingSnake::OnInitialize () { if ( !Application::OnInitialize() ) return false; m_spkScene = new Node(1); m_spkTrnNode = new Node(1); m_spkScene->AttachChild(m_spkTrnNode); m_spkWireframe = new WireframeState; m_spkScene->SetRenderState(m_spkWireframe); ZBufferState* pkZBuffer = new ZBufferState; pkZBuffer->Enabled() = true; pkZBuffer->Writeable() = true; pkZBuffer->Compare() = ZBufferState::CF_LEQUAL; m_spkScene->SetRenderState(pkZBuffer); CreateSnake(); // center-and-fit for camera viewing m_spkScene->UpdateGS(0.0f); Bound kWBound = m_spkScene->WorldBound(); m_spkTrnNode->Translate() = -kWBound.Center(); ms_spkCamera->SetFrustum(1.0f,100.0f,-0.55f,0.55f,0.4125f,-0.4125f); Vector3f kCLeft(1.0f,0.0f,0.0f); Vector3f kCUp(0.0f,0.0f,1.0f); Vector3f kCDir(0.0f,-1.0f,0.0f); Vector3f kCLoc = -3.0f*kWBound.Radius()*kCDir; ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir); // initial update of objects ms_spkCamera->Update(); m_spkScene->UpdateGS(0.0f); m_spkScene->UpdateRS(); // camera turret and tumble mode m_spkMotionObject = m_spkScene; m_fTrnSpeed = 0.01f; m_fRotSpeed = 0.001f; m_bTurretActive = true; SetTurretAxes(); return true; }
void Torus::MakeBound( Bound &out_bound ) const { float tuMin = mThetamaxRad * mURange[0]; float tuMax = mThetamaxRad * mURange[1]; float phiVMin = DMix( mPhiminRad, mPhimaxRad, mVRange[0] ); float phiVMax = DMix( mPhiminRad, mPhimaxRad, mVRange[1] ); Bound a; a.Reset(); bounds2DSweepR( a, mMinRadius, phiVMin, phiVMax ); float rMin = a.mBox[0].x() + mMaxRadius; float rMax = a.mBox[1].x() + mMaxRadius; out_bound.Reset(); bounds2DSweepL( out_bound, rMin, rMax, tuMin, tuMax ); out_bound.mBox[0].z() = a.mBox[0].y(); out_bound.mBox[1].z() = a.mBox[1].y(); }
void AnalysisForm::bindTo(Options *options, DataSet *dataSet) { if (_options != NULL) unbind(); _dataSet = dataSet; vector<string> columnNames; BOOST_FOREACH(Column &column, dataSet->columns()) columnNames.push_back(column.name()); _availableVariablesModel.setInfoProvider(this); _availableVariablesModel.setVariables(columnNames); _options = options; BOOST_FOREACH(const string &name, options->names) { Option *option = options->get(name); QString qsName = QString::fromUtf8(name.c_str(), name.length()); qsName.replace('/', '_'); QWidget *child = this->findChild<QWidget*>(qsName); Bound *boundChild = dynamic_cast<Bound*>(child); if (boundChild != NULL) { _bounds.push_back(boundChild); boundChild->bindTo(option); boundChild->illegalChanged.connect(boost::bind(&AnalysisForm::illegalValueHandler, this, _1)); } else { qDebug() << "child not found : " << qsName << " in AnalysisForm::setOptions()"; } } updateIllegalStatus(); }
// Trim all values in vector to be between LOW and HIGH, inclusive. // We should have LOW <= 0, HIGH >= 0. void BiVector::trim_values(const Bound &low, const Bound &high) { assert(low.is_le(0) && high.is_ge(0)); for (std::map<Integer, Integer>::iterator i = contents.begin(); i != contents.end(); i++) { if (!low.is_infinite() && i->second < low.value()) i->second = low.value(); if (!high.is_infinite() && i->second > high.value()) i->second = high.value(); } }
//---------------------------------------------------------------------------- bool Bound::TestIntersection (const Bound& bound) const { if (bound.GetRadius() == 0.0f || GetRadius() == 0.0f) { return false; } // 静态相交检测 AVector diff = mCenter - bound.mCenter; float rSum = mRadius + bound.mRadius; return diff.SquaredLength() <= rSum*rSum; }
void Cone::MakeBound( Bound &out_bound ) const { float tuMin = mThetamaxRad * mURange[0]; float tuMax = mThetamaxRad * mURange[1]; float rMin = mRadius * (1 - mVRange[1]); float rMax = mRadius * (1 - mVRange[0]); out_bound.Reset(); bounds2DSweepL( out_bound, rMin, rMax, tuMin, tuMax ); out_bound.mBox[0].z() = mVRange[0] * mHeight; out_bound.mBox[1].z() = mVRange[1] * mHeight; }
//================================================================== inline void bounds2DSweepL( Bound &out_bound, float rmin, float rmax, float tmin, float tmax ) { out_bound.Expand( polar(rmin,tmin) ); out_bound.Expand( polar(rmax,tmin) ); out_bound.Expand( polar(rmin,tmax) ); out_bound.Expand( polar(rmax,tmax) ); if ( tmin < FM_PI_2 && tmax > FM_PI_2 ) out_bound.Expand( polar( rmax, FM_PI_2 ) ); if ( tmin < FM_PI && tmax > FM_PI ) out_bound.Expand( polar( rmax, FM_PI ) ); if ( tmin < (FM_PI+FM_PI_2) && tmax > (FM_PI+FM_PI_2) ) out_bound.Expand( polar( rmax, (FM_PI+FM_PI_2) ) ); }
//---------------------------------------------------------------------------- void Bound::GrowToContain (const Bound& bound) { if (bound.GetRadius() == 0.0f) { // The node is a dummy node and cannot affect growth. return; } if (GetRadius() == 0.0f) { mCenter = bound.GetCenter(); mRadius = bound.GetRadius(); return; } AVector centerDiff = bound.mCenter - mCenter; float lengthSqr = centerDiff.SquaredLength(); float radiusDiff = bound.mRadius - mRadius; float radiusDiffSqr = radiusDiff*radiusDiff; if (radiusDiffSqr >= lengthSqr) { if (radiusDiff >= 0.0f) { mCenter = bound.mCenter; mRadius = bound.mRadius; } return; } float length = Mathf::Sqrt(lengthSqr); if (length > Mathf::ZERO_TOLERANCE) { float coeff = (length + radiusDiff)/(2.0f*length); mCenter += coeff*centerDiff; } mRadius = 0.5f*(length + mRadius + bound.mRadius); }
//---------------------------------------------------------------------------- void Selection::_UpdateSelect() { mCenter = APoint::ORIGIN; mBoundRadius = 0.0f; APoint pos; Bound bound; int firstBound = true; int numObjects = (int)mObjects.size(); for (int i = 0; i < numObjects; i++) { Object *obj = mObjects[i]; Movable *mov = DynamicCast<Movable>(obj); if (mov) { pos += mov->WorldTransform.GetTranslate(); if (0.0f != mov->WorldBound.GetRadius()) { if (firstBound) { bound = mov->WorldBound; firstBound = false; } else { bound.GrowToContain(mov->WorldBound); } } } } if (numObjects > 0) { mCenter = pos / (float)numObjects; mBoundRadius = bound.GetRadius(); } }
// TODO(jhuang). BUG(jhuang): this has memory issue. void RenderableBound::setupMeshWithBound(const string& meshName, Bound& bound) { mMesh = MeshManager::getInstance()->getAsset(meshName); if (!mMesh) { mMesh = MeshManager::getInstance()->loadFromShape(meshName, bound); SubMeshList& submeshes = mMesh->getSubMeshes(); assert(submeshes.size() == 1); mSubMesh = submeshes[0]; assert(mSubMesh != NULL && mSubMesh->getNumIndices() == 36); } else { bound.updateMesh(*mMesh); assert(mSubMesh->getNumIndices() == 36); } }
//---------------------------------------------------------------------------- bool Culler::IsVisible (const Bound& bound) { if (bound.GetRadius() == 0.0f) { // The node is a dummy node and cannot be visible. return false; } // Start with the last pushed plane, which is potentially the most // restrictive plane. int index = mPlaneQuantity - 1; unsigned int mask = (1 << index); for (int i = 0; i < mPlaneQuantity; ++i, --index, mask >>= 1) { if (mPlaneState & mask) { int side = bound.WhichSide(mPlane[index]); if (side < 0) { // The object is on the negative side of the plane, so // cull it. return false; } if (side > 0) { // The object is on the positive side of plane. There is // no need to compare subobjects against this plane, so // mark it as inactive. mPlaneState &= ~mask; } } } return true; }