bool RayIntersectorKDTreeNode::FindBestSplit(const Vector<UINT> &TriangleIndices, const RayIntersectorKDTree &Root, UINT &Axis, float &SplitValue) const { Rectangle3f BBox = ComputeBBox(TriangleIndices, Root); int BestAxis = -1; UINT BestChildImprovement = 8; for(UINT CurAxis = 0; CurAxis < 3; CurAxis++) { UINT LeftCount, RightCount; TestSplit(TriangleIndices, Root, CurAxis, BBox, LeftCount, RightCount); /*const UINT BestChildCost = TriangleIndices.Length(); const UINT WorstChildCost = TriangleIndices.Length() * 2; const UINT ActualChildCost = LeftCount + RightCount; const float CurAxisValue = float(ActualChildCost) / float(WorstChildCost);*/ const UINT CurChildImprovement = Math::Min(TriangleIndices.Length() - LeftCount, TriangleIndices.Length() - RightCount); if(CurChildImprovement > BestChildImprovement && LeftCount > 0 && RightCount > 0) { BestAxis = CurAxis; BestChildImprovement = CurChildImprovement; } } if(BestAxis == -1) { return false; } else { Axis = BestAxis; SplitValue = BBox.Center()[Axis]; return true; } }
HRESULT KG3DModelPointLight::LoadFromFile(const char cszFileName[], unsigned uFileNameHash, unsigned uOption) { m_scName = cszFileName; m_bMeshPostLoadProcessed = TRUE; ComputeBBox(); return S_OK; }
// translating a robot item // doesnt just translate the matrix // but also translates the slot maps by discrete amounts // the children slot maps are translate recusivley void VDSBuildingBlock::TranslateBlock( int x, int y ) { // detach the block if it is linked Detach(); // translate pivots of all the tree TranslateRec( x, y ); // recompute the bounding box here ComputeBBox(); }
// robot block constructor // some paramegters should be passed from child classes // which are the slots width and height, the thickness // and the type ID of the block // each block type SHOULD have a unique type id block VDSBuildingBlock::VDSBuildingBlock( int SlotsWidth, int SlotsHeight, eBlockType TypeID ) { // return; // save number of rows and columns m_uiRowsCount = SlotsWidth; m_uiColumnsCount = SlotsHeight; // allocate the slots with the specified width and height m_UpSlots.Create( SlotsWidth, SlotsHeight ); m_DownSlots.Create( SlotsWidth, SlotsHeight ); m_pParent = NULL; // parent is NULL initially, until it is linked to another m_PivotX = 0; m_PivotY = 0; m_RotationCount = 0; // the upper and lower boxes.. // they are in the simple case both the same .. // those will be used later in child blocks // like the rotbase and the pyramid and the arms // putting any of those on or below their parent changes this m_pUpperBox = &m_BoundBox; m_pLowerBox = &m_BoundBox; // set the bounding box dimensions m_Density = 1.0f; m_BoundBox.SetBox( m_Density, ( float ) m_uiRowsCount, 0.5f, ( float ) m_uiColumnsCount ); // compute the bounding box matrix ComputeBBox(); // set a default name memset( m_Name, 0, sizeof( m_Name ) ); strcpy( m_Name, "No Name" ); // set the name id // and the type id m_Type = TypeID; // any block is a root initially .. // until it is linked, // any puton/putbelow/detach should modify this value m_ParentIndex = -1; // parent is down initially m_bParentIsUp = false; // set the initial basic response m_SystemResponse.SetParams( 200, 0.9f ); m_BoundBox.m_bLinkable = true; m_Material.m_Diffuse.Assign( 1.0f, 1.0f, 1.0f, 1.0f ); }
// this will rotate the item 90 degrees around it reference plate(0,0) void VDSBuildingBlock::RotateBlock() { m_RotationCount++; // detach the block if it is linked Detach(); // rotate everything in its tree(the slot maps) RotateRec( m_PivotX, m_PivotY ); // rotate the slot maps around the pivot // rotate its boudbing box matrix too.. m_BoundBox.m_Transform.Rotate( 0.0f, -PI / 2.0f, 0.0f ); // rotate the box matrix; // recompute its bounding box ComputeBBox(); }
RayIntersectorKDTreeNode::RayIntersectorKDTreeNode(const Vector<UINT> &TriangleIndices, const RayIntersectorKDTree &Root, UINT Depth, Vector<UINT> &LeafTriangles) { Assert(Depth < 60, "Tree unexpectedly deep"); _BBox = ComputeBBox(TriangleIndices, Root); const UINT MinTriCount = 8; if(TriangleIndices.Length() <= MinTriCount) { MakeLeafNode(TriangleIndices, LeafTriangles); } else { MakeInteriorNode(TriangleIndices, Root, Depth, LeafTriangles); } }
// this unlinks the part from its parent..it will do so by calling // sSlotMap unlink in the 2 slot maps, and by removing itself from the parent // array of pointer void VDSBuildingBlock::Detach() { // if there is no parent..return if ( !m_pParent ) { return; } // unlink upper slots here from lower slots of parent // and unlink lower slots her from upper slots of parent // if the parent is up.. // unlink the upper slots here, and the down slots in the parent if ( m_bParentIsUp ) { m_pParent->m_DownSlots.UnLink( m_UpSlots ); } else { m_pParent->m_UpSlots.UnLink( m_DownSlots ); } // get the parent matrix and remove the translation data and invert it TSRMatrix4 parentmat; m_pParent->m_BoundBox.GetWorldMatrix( parentmat ); parentmat._41 = 0.0f; parentmat._42 = 0.0f; parentmat._43 = 0.0f; m_BoundBox.m_Transform.Multiply( m_BoundBox.m_Transform, parentmat ); // and remove yourself from parent as well DetachFromParent(); // now remove the bounding box here from its parent m_BoundBox.DetachFromParent(); // the new pivot it the same start m_PivotX = m_UpSlots.m_StartX; m_PivotY = m_UpSlots.m_StartY; // recompute the bounding box ComputeBBox(); }
// linking objects.. the caller object will be child // the called object is the parent // the caller will be put on top of the called bool VDSBuildingBlock::PutOn( VDSBuildingBlock& _parent ) { // detach if linked somewhere else Detach(); // return if linking is not possible if ( !_parent.m_UpSlots.CanLink( m_DownSlots ) ) { return false; } // make the proximity check if ( ProximityCheck( _parent, true ) != true ) { return false; } // linking sets the slot maps in both places _parent.m_UpSlots.Link( m_DownSlots ); // now we will adjust the matrix of us according to data in the parent // usually this is in the y direction _parent.AddChild( this ); //AttachTo(); // attach the bounding box tree to the other tree in the parent //m_pLowerBox->AttachTo(*Parent.m_pUpperBox); _parent.m_pUpperBox->AddChild( m_pLowerBox ); // compute the new bounding boxe translation on Y m_pLowerBox->m_Transform._42 = ( m_pLowerBox->m_Dimensions.y + _parent.m_pUpperBox->m_Dimensions.y ) / 2.0f; // the parent is down m_bParentIsUp = false; // compute the new bounding box after linking ComputeBBox(); _parent.RecreateMesh(); // return success ! return true; }
// linking objects.. the caller object will be child // the called object is the parent // the caller will be put on top of the called bool VDSBuildingBlock::PutBelow( VDSBuildingBlock& Parent ) { // detach if linked Detach(); // return if linking is not possible if ( !Parent.m_DownSlots.CanLink( m_UpSlots ) ) { return false; } // make the proximity check if ( ProximityCheck( Parent, false ) != true ) { return false; } // linking sets the slot maps in both places Parent.m_DownSlots.Link( m_UpSlots ); Parent.AddChild( this ); // attach the bounding box tree to the other tree in the parent //m_pUpperBox->AttachTo(*Parent.m_pLowerBox); Parent.m_pLowerBox->AddChild( m_pUpperBox ); // compute the new bounding box translation on Y m_pUpperBox->m_Transform._42 = - ( m_pUpperBox->m_Dimensions.y + Parent.m_pLowerBox->m_Dimensions.y ) / 2.0f; // the parent is now up m_bParentIsUp = true; // compute the new bounding box after linking ComputeBBox(); RecreateMesh(); // return success ! return true; }
//_____________________________________________________________________________ TGeoArb8::TGeoArb8(Double_t dz, Double_t *vertices) :TGeoBBox(0,0,0) { // constructor. If the array of vertices is not null, this should be // in the format : (x0, y0, x1, y1, ... , x7, y7) fDz = dz; fTwist = 0; SetShapeBit(kGeoArb8); if (vertices) { for (Int_t i=0; i<8; i++) { fXY[i][0] = vertices[2*i]; fXY[i][1] = vertices[2*i+1]; } ComputeTwist(); ComputeBBox(); } else { for (Int_t i=0; i<8; i++) { fXY[i][0] = 0.0; fXY[i][1] = 0.0; } } }
/// \brief /// Generates a bounding box encompassing all position vertices in this list - note that this /// will compute the unanimated bounding box, vertex animations won't influence the result /// /// \param bbox /// Bounding box to be generated/filled in /// /// \return /// Returns false if there are no position vertices inline bool ComputeBBox(hkvAlignedBBox& bbox) const { return ComputeBBox(bbox, 0, GetNumVertices()); }//@@@ write version that will compute bbox respecting vertex anims?