// ----------------------------- // QtImage_IO::getVolumeFileInfo // ----------------------------- // Purpose: // Nothing yet. // ---- Change History ---- // 04/24/2010 -- Joe R. -- Initial implementation. void QtImage_IO::getVolumeFileInfo(VolumeFileInfo::Data& data, const std::string& filename) const { CVC::ThreadInfo ti(BOOST_CURRENT_FUNCTION); QImage img(filename.c_str()); if(img.isNull()) throw ReadError( boost::str( boost::format("QImage could not read %1%") % filename ) ); data._filename = filename; data._dimension = Dimension(img.width(),img.height(),1); data._boundingBox = BoundingBox(0.0,0.0,0.0, img.width()+1, img.height()+1, 0.0); data._numVariables = 1; //just using grayscale for now, so 1 var data._numTimesteps = 1; data._voxelTypes = std::vector<VoxelType>(1,UChar); data._names.clear(); data._names.push_back("QImage"); data._tmin = 0.0; data._tmax = 0.0; data._minIsSet.clear(); data._minIsSet.resize(data._numVariables); for(int i=0; i<data._minIsSet.size(); i++) data._minIsSet[i].resize(data._numTimesteps); data._min.clear(); data._min.resize(data._numVariables); for(int i=0; i<data._min.size(); i++) data._min[i].resize(data._numTimesteps); data._maxIsSet.clear(); data._maxIsSet.resize(data._numVariables); for(int i=0; i<data._maxIsSet.size(); i++) data._maxIsSet[i].resize(data._numTimesteps); data._max.clear(); data._max.resize(data._numVariables); for(int i=0; i<data._max.size(); i++) data._max[i].resize(data._numTimesteps); }
World::World(double _width, double _height) : BoundedObject(Pd(), Qd(), BoundingBox(Pd(-_width/2, -_height/2, 0), Pd(_width,0,0), Pd(0,_height,0), Pd(_width,_height,0), Pd(), Pd(), Pd(), Pd(_width/2, _height/2, HIGH)), Assets::WorldMaterial) { ObjectHandle tHandle; tHandle = Terrain(_width, _height); terrain = TO(Terrain, tHandle); children.insert(tHandle); ObjectHandle hudHandle; hudHandle = HUD(640, 480); hud = TO(HUD, hudHandle); children.insert(hudHandle); children.insert(Sky((int) _width, (int) _height)); width = _width; height = _height; }
void ImagePane::deleteCurrentBox() //if an inscription or surface box is deleted //all boxes below it in the hierarchy (graphs, or graphs and inscriptions) //are deleted too { if(locked || currentBoxIndex == -1) return; switch(mode) { case SURFACE: if(surf->inscriptionCount() == 0 || confirmDelete("inscription")) { *surf = BoundingBox(QPoint(0,0), QPoint(0,0), 0); surf->deleteAllInscriptions(); emit inscrImgListModified(); //signal picked up by TranscriptionWindow currentBoxIndex = -1; } break; case INSCRIPTION: if(surf->ptrInscrAt(currentBoxIndex)->boxCount() == 0 || confirmDelete("graph")) { surf->deleteInscr(currentBoxIndex); emit inscrImgListModified(); //signal picked up by TranscriptionWindow currentBoxIndex--; if(currentBoxIndex == -1) currentBoxIndex = surf->inscriptionCount() - 1; } break; case GRAPH: surf->ptrInscrAt(currentInscrIndex)->deleteBox(currentBoxIndex); currentBoxIndex--; if(currentBoxIndex == -1) currentBoxIndex = surf->ptrInscrAt(currentInscrIndex)->count() - 1; break; default: break; } update(); }
void PhotonMapping::TracePhotons() { std::cout << "trace photons" << std::endl; // first, throw away any existing photons delete kdtree; // consruct a kdtree to store the photons BoundingBox *bb = mesh->getBoundingBox(); Vec3f min = bb->getMin(); Vec3f max = bb->getMax(); Vec3f diff = max-min; min -= 0.001*diff; max += 0.001*diff; kdtree = new KDTree(BoundingBox(min,max)); // photons emanate from the light sources const std::vector<Face*>& lights = mesh->getLights(); // compute the total area of the lights double total_lights_area = 0; for (unsigned int i = 0; i < lights.size(); i++) { total_lights_area += lights[i]->getArea(); } // shoot a constant number of photons per unit area of light source // (alternatively, this could be based on the total energy of each light) for (unsigned int i = 0; i < lights.size(); i++) { double my_area = lights[i]->getArea(); int num = args->num_photons_to_shoot * my_area / total_lights_area; // the initial energy for this photon Vec3f energy = my_area/double(num) * lights[i]->getMaterial()->getEmittedColor(); Vec3f normal = lights[i]->computeNormal(); for (int j = 0; j < num; j++) { Vec3f start = lights[i]->RandomPoint(); // the initial direction for this photon (for diffuse light sources) Vec3f direction = RandomDiffuseDirection(normal); TracePhoton(start,direction,energy,0); } } }
BraunnerTree::BraunnerTree(int _depth,vec3 _halfDimension, vec3 _center){ if (_depth>=0) { this->nodeObjects = new BraunnerPoint(); this->depth = depth; this->origin = _center; this->halfDimension = _halfDimension; myBox = BoundingBox(origin-halfDimension,origin+halfDimension); for(int i=0; i<8; ++i) { // Calcular a nova bounding box das folhas (ou ramos) vec3 newOrigin = origin; newOrigin.x += _halfDimension.x * (i&4 ? .5f : -.5f);//SImplificação de If (i==4) .5; else -.5; newOrigin.y += _halfDimension.y * (i&2 ? .5f : -.5f); newOrigin.z += _halfDimension.z * (i&1 ? .5f : -.5f); this->daughters[i] = new BraunnerTree(_depth-1,_halfDimension*0.5f,newOrigin); } } }
void the::object::recalculateBoundingBox() { float xMax = std::numeric_limits<float>::min(); float yMax = std::numeric_limits<float>::min(); float zMax = std::numeric_limits<float>::min(); float xMin = std::numeric_limits<float>::max(); float yMin = std::numeric_limits<float>::max(); float zMin = std::numeric_limits<float>::max(); for (auto & v : vertexes) { if (v.position.x > xMax) xMax = v.position.x; if (v.position.y > yMax) yMax = v.position.y; if (v.position.z > zMax) zMax = v.position.z; if (v.position.x < xMin) xMin = v.position.x; if (v.position.y < yMin) yMin = v.position.y; if (v.position.z < zMin) zMin = v.position.z; } boundingBox = BoundingBox(vec3(xMin, yMin, zMin), vec3(xMax, yMax, zMax)); }
Player::Player(int16_t playerId, sf::Vector2f position, OutputSocket socket, char * nick) : playerId(playerId), timeSinceLastShot(sf::Time::Zero), speed(500), rotation(0), cross_thickness(5), socket(socket), health(100), playerInfo(0), ip(socket.ip), nick(nick), ammo(10), invisibleTime(sf::Time::Zero) { boundingBox = BoundingBox(position.x, position.y, 50, 50); updateCross(); horz_rect.width = boundingBox.width; vert_rect.height = boundingBox.height; type = EntityType::Player_T; setTeam(0); setValid(0); }
TEST(GridTest, UniformGridSamplerTest) { glm::ivec3 size(8, 8, 8); UniformGridSampler s(size, BoundingBox(glm::vec3(0.0f), glm::vec3(1.0f))); glm::ivec3 index = glm::ivec3(0); glm::ivec3 check = glm::ivec3(0); glm::vec3 point = glm::vec3(0.0f); for (int i = 0; i < s.num_cells(); ++i) { point = (0.5f / (size - 1)) + (1.0f / (size - 1)) * index; s.PointToCellIndex(point, check); if (index != check) std::cout << "point = " << point << " index = " << index << " value = " << check << std::endl; EXPECT_EQ(index, check); index = s.StepCell(index); } index = glm::ivec3(0); for (int i = 0; i < s.num_cells(); ++i) { point = (1.0f / (size - 1)) * index; s.PointToCellIndex(point, check); if (index != check) std::cout << "point = " << point << " index = " << index << " value = " << check << std::endl; EXPECT_EQ(index, check); index = s.StepCell(index); } index = glm::ivec3(0); glm::ivec3 expected = glm::ivec3(0); for (int i = 0; i < s.num_vertices(); ++i) { point = (1.0f / (size - 1)) * index; s.PointToCellIndex(point, check); expected = glm::min(size - 2, index); if (expected != check) std::cout << "point = " << point << " index = " << expected << " value = " << check << std::endl; EXPECT_EQ(expected, check); index = s.StepVertex(index); } }
bool Flash::Init(HandleOrRid movieId) { FrameworkManagers *res = FrameworkManagers::Get(); if(movieId.isHandle && movieId.handle != HANDLE_NONE) { FlashMovieManager::AddRef(movieId.handle); movie = movieId.handle; } else if(movieId.rid != RID_NONE) { movie = res->flashMovieManager->Load(movieId.rid); } else { Console::Error("Invalid flash movie handle or rid"); return false; } if(!state.Init(movie)) { Console::Error("Flash movie state init failed"); return false; } FlashMovie *mov = res->flashMovieManager->Get(movie); bounds = BoundingBox(Vector4(mov->size.x / 2.0f, mov->size.y / 2.0f, 0.0f, 1.0f), Vector4(mov->size.x / 2.0f, mov->size.y / 2.0f, 0.0f, 1.0f)); return true; }
//============================================================ void GlBox::setWithXML(xmlNodePtr rootNode) { xmlNodePtr dataNode=NULL; GlXMLTools::getDataNode(rootNode,dataNode); // Parse Data if(dataNode) { GlXMLTools::setWithXML(dataNode,"position",position); GlXMLTools::setWithXML(dataNode,"size",size); fillColors.clear(); GlXMLTools::setWithXML(dataNode,"fillColors",fillColors); outlineColors.clear(); GlXMLTools::setWithXML(dataNode,"outlineColors",outlineColors); GlXMLTools::setWithXML(dataNode,"filled",filled); GlXMLTools::setWithXML(dataNode,"outlined",outlined); GlXMLTools::setWithXML(dataNode,"textureName",textureName); GlXMLTools::setWithXML(dataNode,"outlineSize",outlineSize); boundingBox = BoundingBox(); boundingBox.expand(position-size/2.f); boundingBox.expand(position+size/2.f); } }
BoundingBox Rect::getBoundingBox()const { glm::vec3 p0(kHugeValue),p1(-kHugeValue); p0.x = corner.x + v0.x + v1.x; p0.y = corner.y + v0.y + v1.y; p0.z = corner.z + v0.z + v1.z; p1.x = corner.x + v0.x + v1.x; p1.y = corner.y + v0.y + v1.y; p1.z = corner.z + v0.z + v1.z; p0.x = p0.x<corner.x? p0.x : corner.x; p0.y = p0.y<corner.y? p0.y : corner.y; p0.z = p0.z<corner.z? p0.z : corner.z; p1.x = p1.x>corner.x? p1.x : corner.x; p1.y = p1.y>corner.y? p1.y : corner.y; p1.z = p1.z>corner.z? p1.z : corner.z; p0 -= glm::vec3(KEpsilon); p1 += glm::vec3(KEpsilon); return BoundingBox(p1,p0); }
/** * Creates a new TextGlyph from the given XMLNode */ TextGlyph::TextGlyph(const XMLNode& node, unsigned int l2version) : GraphicalObject(2, l2version) ,mText("") ,mGraphicalObject("") ,mOriginOfText("") { const XMLAttributes& attributes=node.getAttributes(); const XMLNode* child; //ExpectedAttributes ea(getElementName()); ExpectedAttributes ea; addExpectedAttributes(ea); this->readAttributes(attributes,ea); unsigned int n=0,nMax = node.getNumChildren(); while(n<nMax) { child=&node.getChild(n); const std::string& childName=child->getName(); if(childName=="boundingBox") { this->mBoundingBox=BoundingBox(*child); } else if(childName=="annotation") { this->mAnnotation=new XMLNode(*child); } else if(childName=="notes") { this->mNotes=new XMLNode(*child); } else { //throw; } ++n; } }
void NavigationMesh::CollectGeometries(Vector<NavigationGeometryInfo>& geometryList) { PROFILE(CollectNavigationGeometry); // Get Navigable components from child nodes, not from whole scene. This makes it possible to partition // the scene into several navigation meshes PODVector<Navigable*> navigables; node_->GetComponents<Navigable>(navigables, true); HashSet<Node*> processedNodes; for (unsigned i = 0; i < navigables.Size(); ++i) { if (navigables[i]->IsEnabledEffective()) CollectGeometries(geometryList, navigables[i]->GetNode(), processedNodes, navigables[i]->IsRecursive()); } // Get offmesh connections Matrix3x4 inverse = node_->GetWorldTransform().Inverse(); PODVector<OffMeshConnection*> connections; node_->GetComponents<OffMeshConnection>(connections, true); for (unsigned i = 0; i < connections.Size(); ++i) { OffMeshConnection* connection = connections[i]; if (connection->IsEnabledEffective() && connection->GetEndPoint()) { const Matrix3x4& transform = connection->GetNode()->GetWorldTransform(); NavigationGeometryInfo info; info.component_ = connection; info.boundingBox_ = BoundingBox(Sphere(transform.Translation(), connection->GetRadius())).Transformed(inverse); geometryList.Push(info); } } }
BoundingBox BoundingBox::join(const std::vector<BoundingBox>& boxes) { if (boxes.empty()) { throw EmptyBoundingBoxException(); } double minX = boxes.front().minX, maxX = boxes.front().maxX, minY = boxes.front().minY, maxY = boxes.front().maxY, minZ = boxes.front().minZ, maxZ = boxes.front().maxZ; for (std::vector<BoundingBox>::const_iterator i = (boxes.begin()+1); i != boxes.end(); ++i) { minX = fmin(minX, i->minX); maxX = fmax(maxX, i->maxX); minY = fmin(minY, i->minY); maxY = fmax(maxY, i->maxY); minZ = fmin(minZ, i->minZ); maxZ = fmax(maxZ, i->maxZ); } return BoundingBox(minX, maxX, minY, maxY, minZ, maxZ); }
BoundingBox BoundingBoxHierarchy::_build( vector<RTShape*>::iterator first, vector<RTShape*>::iterator last, int axis) { if (first+1 < last) { sort(first, last, axis); vector<RTShape*>::iterator middle = first + ((last - first) / 2); left = new BoundingBoxHierarchy(); right = new BoundingBoxHierarchy(); BoundingBox leftBox = left->_build(first, middle, (axis+1)%3); BoundingBox rightBox = right->_build(middle, last, (axis+1)%3); return box = leftBox.unionWith(rightBox); } else if (first != last) { shape = *first; return box = shape->getBoundingBox(); } else { return BoundingBox(Vector(0,0,0), Vector(0,0,0)); } }
/** * Creates a new ReactionGlyph from the given XMLNode */ ReactionGlyph::ReactionGlyph(const XMLNode& node, unsigned int l2version) : GraphicalObject(2,l2version) ,mReaction ("") ,mSpeciesReferenceGlyphs(2,l2version) ,mCurve(2,l2version) { const XMLAttributes& attributes=node.getAttributes(); const XMLNode* child; //ExpectedAttributes ea(getElementName()); ExpectedAttributes ea; addExpectedAttributes(ea); this->readAttributes(attributes,ea); unsigned int n=0,nMax = node.getNumChildren(); while(n<nMax) { child=&node.getChild(n); const std::string& childName=child->getName(); if(childName=="boundingBox") { this->mBoundingBox=BoundingBox(*child); } else if(childName=="annotation") { this->mAnnotation=new XMLNode(*child); } else if(childName=="notes") { this->mNotes=new XMLNode(*child); } else if(childName=="curve") { // since the copy constructor of ListOf does not make deep copies // of the objects, we have to add the individual curveSegments to the // curve instead of just copying the whole curve. Curve* pTmpCurve=new Curve(*child); unsigned int i,iMax=pTmpCurve->getNumCurveSegments(); for(i=0;i<iMax;++i) { this->mCurve.addCurveSegment(pTmpCurve->getCurveSegment(i)); } // we also have to copy mAnnotations, mNotes, mCVTerms and mHistory if(pTmpCurve->isSetNotes()) this->mCurve.setNotes(new XMLNode(*pTmpCurve->getNotes())); if(pTmpCurve->isSetAnnotation()) this->mCurve.setAnnotation(new XMLNode(*pTmpCurve->getAnnotation())); if(pTmpCurve->getCVTerms()!=NULL) { iMax=pTmpCurve->getCVTerms()->getSize(); for(i=0;i<iMax;++i) { this->mCurve.getCVTerms()->add(static_cast<CVTerm*>(pTmpCurve->getCVTerms()->get(i))->clone()); } } delete pTmpCurve; } else if(childName=="listOfSpeciesReferenceGlyphs") { const XMLNode* innerChild; unsigned int i=0,iMax=child->getNumChildren(); while(i<iMax) { innerChild=&child->getChild(i); const std::string innerChildName=innerChild->getName(); if(innerChildName=="speciesReferenceGlyph") { this->mSpeciesReferenceGlyphs.appendAndOwn(new SpeciesReferenceGlyph(*innerChild)); } else if(innerChildName=="annotation") { this->mSpeciesReferenceGlyphs.setAnnotation(new XMLNode(*innerChild)); } else if(innerChildName=="notes") { this->mSpeciesReferenceGlyphs.setNotes(new XMLNode(*innerChild)); } else { // throw } ++i; } } else { //throw; } ++n; } connectToChild(); }
// hifi // // Added by Brad Hefta-Gaub on 06/11/13. // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // #include "CoverageMap.h" #include <SharedUtil.h> #include <cstring> #include "Log.h" int CoverageMap::_mapCount = 0; int CoverageMap::_checkMapRootCalls = 0; bool CoverageMap::wantDebugging = false; const BoundingBox CoverageMap::ROOT_BOUNDING_BOX = BoundingBox(glm::vec2(-2.f,-2.f), glm::vec2(4.f,4.f)); // Coverage Map's polygon coordinates are from -1 to 1 in the following mapping to screen space. // // (0,0) (windowWidth, 0) // -1,1 1,1 // +-----------------------+ // | | | // | | | // | -1,0 | | // |-----------+-----------| // | 0,0 | // | | | // | | | // | | | // +-----------------------+
bool GenerateAirMeshes(const TArray<FVector>& Vertices, const TArray<int32>& Indices, TArray<TStaticArray<int32, 4u>>& OutTetrahedra) { check(Indices.Num() % 3 == 0); #if WITH_EDITOR namespace tw = tetgen_wrapper; // ================================================================ // Convert vertex positions to the format readable by tetgen // ================================================================ TArray<double> VerticesForTetgen; // 8 points are for bounding box VerticesForTetgen.Empty((Vertices.Num() + 8) * 3); for (const auto& Vertex : Vertices) { VerticesForTetgen.Add(Vertex.X); VerticesForTetgen.Add(Vertex.Y); VerticesForTetgen.Add(Vertex.Z); } // Generate bounding 8 points FBox BoundingBox(Vertices); float Extension = BoundingBox.GetExtent().GetAbsMax() * 0.02f; BoundingBox.Min -= FVector(Extension); BoundingBox.Max += FVector(Extension); VerticesForTetgen.Add(BoundingBox.Min.X); VerticesForTetgen.Add(BoundingBox.Min.Y); VerticesForTetgen.Add(BoundingBox.Min.Z); VerticesForTetgen.Add(BoundingBox.Max.X); VerticesForTetgen.Add(BoundingBox.Min.Y); VerticesForTetgen.Add(BoundingBox.Min.Z); VerticesForTetgen.Add(BoundingBox.Min.X); VerticesForTetgen.Add(BoundingBox.Max.Y); VerticesForTetgen.Add(BoundingBox.Min.Z); VerticesForTetgen.Add(BoundingBox.Max.X); VerticesForTetgen.Add(BoundingBox.Max.Y); VerticesForTetgen.Add(BoundingBox.Min.Z); VerticesForTetgen.Add(BoundingBox.Min.X); VerticesForTetgen.Add(BoundingBox.Min.Y); VerticesForTetgen.Add(BoundingBox.Max.Z); VerticesForTetgen.Add(BoundingBox.Max.X); VerticesForTetgen.Add(BoundingBox.Min.Y); VerticesForTetgen.Add(BoundingBox.Max.Z); VerticesForTetgen.Add(BoundingBox.Min.X); VerticesForTetgen.Add(BoundingBox.Max.Y); VerticesForTetgen.Add(BoundingBox.Max.Z); VerticesForTetgen.Add(BoundingBox.Max.X); VerticesForTetgen.Add(BoundingBox.Max.Y); VerticesForTetgen.Add(BoundingBox.Max.Z); // ================================================================ // Generate polygons for tetgen // ================================================================ int32 NumTriangles = Indices.Num() / 3; TArray<tw::polygon> PolygonsForTetgen; PolygonsForTetgen.Empty(NumTriangles + 6); // 6 are for bounding box faces for (int32 TriangleIndex = 0; TriangleIndex < NumTriangles; TriangleIndex++) { PolygonsForTetgen.AddUninitialized(); auto& Added = PolygonsForTetgen.Last(); Added.num_vertices = 3; Added.vertex_list = const_cast<tw::int32*>(&Indices[TriangleIndex * 3]); } // Indices for bounding box int32 BoundingBoxIndices[] = { 0, 1, 3, 2, 1, 5, 7, 3, 5, 4, 6, 7, 4, 0, 2, 6, 4, 5, 1, 0, 2, 3, 7, 6, }; check(ARRAYSIZE(BoundingBoxIndices) == 24); // add offset for (auto& BoundingBoxIndex : BoundingBoxIndices) { BoundingBoxIndex += Vertices.Num(); } for (int32 FaceIndex = 0; FaceIndex < ARRAYSIZE(BoundingBoxIndices) / 4; FaceIndex++) { PolygonsForTetgen.AddUninitialized(); auto& Added = PolygonsForTetgen.Last(); Added.num_vertices = 4; Added.vertex_list = &BoundingBoxIndices[FaceIndex * 4]; } // ================================================================ // Generate facets for tetgen // ================================================================ TArray<tw::facet> FacetsForTetgen; FacetsForTetgen.Empty(PolygonsForTetgen.Num()); for (auto& Polygon : PolygonsForTetgen) { FacetsForTetgen.AddUninitialized(); auto& Added = FacetsForTetgen.Last(); Added.hole_list = nullptr; Added.num_holes = 0; Added.polygon_list = &Polygon; Added.num_polygons = 1; } // ================================================================ // Build tetgen input // ================================================================ tw::input_output InTetgen, OutTetgen; InTetgen.automatic_deallocation = false; // pointers are on stack or managed by TArray InTetgen.point_list = VerticesForTetgen.GetData(); InTetgen.num_points = VerticesForTetgen.Num() / 3; InTetgen.facet_list = FacetsForTetgen.GetData(); InTetgen.num_facets = FacetsForTetgen.Num(); // ================================================================ // Tetrahedralize // ================================================================ if (0 != tw::tetrahedralize("", InTetgen, OutTetgen)) { return false; } // ================================================================ // Gather relevant tetrahedra // ================================================================ int32 NumTetrahedra = 0; // Count tetrahedra for (tw::int32 TetIndex = 0; TetIndex < OutTetgen.num_tetrahedra; TetIndex++) { if (OutTetgen.tetrahedron_list[TetIndex * 4 + 0] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 1] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 2] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 3] >= Vertices.Num()) { continue; } NumTetrahedra++; } // Gather tetrahedra OutTetrahedra.Empty(NumTetrahedra); for (tw::int32 TetIndex = 0; TetIndex < OutTetgen.num_tetrahedra; TetIndex++) { if (OutTetgen.tetrahedron_list[TetIndex * 4 + 0] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 1] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 2] >= Vertices.Num()) { continue; } if (OutTetgen.tetrahedron_list[TetIndex * 4 + 3] >= Vertices.Num()) { continue; } OutTetrahedra.AddUninitialized(); auto& Added = OutTetrahedra.Last(); FMemory::Memcpy(&Added[0], OutTetgen.tetrahedron_list + TetIndex * 4, sizeof(Added)); } for (auto& Tet : OutTetrahedra) { const auto& P3 = Vertices[Tet[3]]; const auto& P23 = Vertices[Tet[2]] - P3; const auto& P13 = Vertices[Tet[1]] - P3; const auto& P03 = Vertices[Tet[0]] - P3; float TetVolume = FVector::DotProduct(P03, FVector::CrossProduct(P13, P23)); if (TetVolume < 0.0f) { Swap(Tet[2], Tet[3]); } } return true; #else // On UE4Game, tetrahedra are deserialized UE_LOG(LogAirMeshCloth, Warning, TEXT("Tetrahedron generation is disabled on UE4Game.")); return false; #endif }
bool OBJ::read(const QString &path) { // Open the file QString obj = QString(path); QFile file(obj); if (!file.open(QFile::ReadOnly | QFile::Text)) return false; QTextStream f(&file); QString line; vertices.clear(); normals.clear(); vertexNormals.clear(); vertexNormalContributions.clear(); triangles.clear(); boundingBox = BoundingBox(); // Read the file QRegExp spaces("\\s+"); Vector3 currKA; Vector3 currKD; do { line = f.readLine().trimmed(); QStringList parts = line.split(spaces); if (parts.isEmpty()) continue; if (parts[0] == "ka" && parts.count() >= 4) { float x = parts[1].toFloat(); float y = parts[2].toFloat(); float z = parts[3].toFloat(); currKA = Vector3(x,y,z); } else if(parts[0] == "kd" && parts.count() >= 4) { float x = parts[1].toFloat(); float y = parts[2].toFloat(); float z = parts[3].toFloat(); currKD = Vector3(x,y,z); } else if (parts[0] == "v" && parts.count() >= 4) { float x = parts[1].toFloat(); float y = parts[2].toFloat(); float z = parts[3].toFloat(); vertices += Vertex(x,y,z,currKA,currKD); vertexNormals += Vector3(0,0,0); vertexNormalContributions += 0; //Bounding box info to position camera correctly boundingBox.maxX = max(x, boundingBox.maxX ); boundingBox.minX = min(x, boundingBox.minX ); boundingBox.maxY = max(y, boundingBox.maxY ); boundingBox.minY = min(y, boundingBox.minY ); boundingBox.maxZ = max(z, boundingBox.maxZ ); boundingBox.minZ = min(z, boundingBox.minZ ); } else if (parts[0] == "vn" && parts.count() >= 4) { normals += Vector3(parts[1].toFloat(), parts[2].toFloat(), parts[3].toFloat()); } else if (parts[0] == "f" && parts.count() >= 4) { // Convert polygons into triangle fans Index a = getIndex(parts[1]); Index b = getIndex(parts[2]); for (int i = 3; i < parts.count(); i++) { Index c = getIndex(parts[i]); triangles += Triangle(a, b, c); b = c; } } } while (!line.isNull()); boundingBox.center = Vector3((boundingBox.maxX + boundingBox.minX) / 2, (boundingBox.maxY + boundingBox.minY) / 2, (boundingBox.maxZ + boundingBox.minZ) / 2); computeNormals(); initVbo(); return true; }
void Mesh::SetBoundingBox(const Vector3& position, const Vector3& size) { SetBoundingBox(BoundingBox(position, size)); }
BoundingBox bounding_box() const { // since the object is aligned to origin, bounding box coincides with size return BoundingBox(Point(0,0), this->size); }
void TestWall::updateCollision() { this->setColideBox(BoundingBox(this->getLocation() - this->getCalculatedSize()/2, this->getLocation() + this->getCalculatedSize()/2)); }
BoundingBox BoundingBox::OfLineSegmnet(const LineSegment& line) { const Point3D p0(line.p0); const Point3D p1(line.p1); return BoundingBox(fmin(p0.x, p1.x), fmax(p0.x, p1.x), fmin(p0.y, p1.y), fmax(p0.y, p1.y), fmin(p0.z, p1.z), fmax(p0.z, p1.z)); }
#include <cstring> #include <QtCore/QDebug> #include <SharedUtil.h> #include "CoverageMap.h" int CoverageMap::_mapCount = 0; int CoverageMap::_checkMapRootCalls = 0; int CoverageMap::_notAllInView = 0; bool CoverageMap::wantDebugging = false; const int MAX_POLYGONS_PER_REGION = 50; const BoundingBox CoverageMap::ROOT_BOUNDING_BOX = BoundingBox(glm::vec2(-1.0f,-1.0f), glm::vec2(2.0f,2.0f)); // Coverage Map's polygon coordinates are from -1 to 1 in the following mapping to screen space. // // (0,0) (windowWidth, 0) // -1,1 1,1 // +-----------------------+ // | | | // | | | // | -1,0 | | // |-----------+-----------| // | 0,0 | // | | | // | | | // | | | // +-----------------------+
// Create scene and manage models Scene() { bbox = BoundingBox(); }
void Ragdolls::CreateScene() { ResourceCache* cache = GetContext()->m_ResourceCache.get(); scene_ = new Scene(GetContext()); // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000) // Create a physics simulation world with default parameters, which will update at 60fps. Like the Octree must // exist before creating drawable components, the PhysicsWorld must exist before creating physics components. // Finally, create a DebugRenderer component so that we can draw physics debug geometry scene_->CreateComponent<Octree>(); scene_->CreateComponent<PhysicsWorld>(); scene_->CreateComponent<DebugRenderer>(); // Create a Zone component for ambient lighting & fog control Node* zoneNode = scene_->CreateChild("Zone"); Zone* zone = zoneNode->CreateComponent<Zone>(); zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f)); zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f)); zone->SetFogColor(Color(0.5f, 0.5f, 0.7f)); zone->SetFogStart(100.0f); zone->SetFogEnd(300.0f); // Create a directional light to the world. Enable cascaded shadows on it Node* lightNode = scene_->CreateChild("DirectionalLight"); lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f)); Light* light = lightNode->CreateComponent<Light>(); light->SetLightType(LIGHT_DIRECTIONAL); light->SetCastShadows(true); light->SetShadowBias(BiasParameters(0.00025f, 0.5f)); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f)); { // Create a floor object, 500 x 500 world units. Adjust position so that the ground is at zero Y Node* floorNode = scene_->CreateChild("Floor"); floorNode->SetPosition(Vector3(0.0f, -0.5f, 0.0f)); floorNode->SetScale(Vector3(500.0f, 1.0f, 500.0f)); StaticModel* floorObject = floorNode->CreateComponent<StaticModel>(); floorObject->SetModel(cache->GetResource<Model>("Models/Box.mdl")); floorObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml")); // Make the floor physical by adding RigidBody and CollisionShape components RigidBody* body = floorNode->CreateComponent<RigidBody>(); // We will be spawning spherical objects in this sample. The ground also needs non-zero rolling friction so that // the spheres will eventually come to rest body->SetRollingFriction(0.15f); CollisionShape* shape = floorNode->CreateComponent<CollisionShape>(); // Set a box shape of size 1 x 1 x 1 for collision. The shape will be scaled with the scene node scale, so the // rendering and physics representation sizes should match (the box model is also 1 x 1 x 1.) shape->SetBox(Vector3::ONE); } // Create animated models for (int z = -1; z <= 1; ++z) { for (int x = -4; x <= 4; ++x) { Node* modelNode = scene_->CreateChild("Jack"); modelNode->SetPosition(Vector3(x * 5.0f, 0.0f, z * 5.0f)); modelNode->SetRotation(Quaternion(0.0f, 180.0f, 0.0f)); AnimatedModel* modelObject = modelNode->CreateComponent<AnimatedModel>(); modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl")); modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml")); modelObject->SetCastShadows(true); // Set the model to also update when invisible to avoid staying invisible when the model should come into // view, but does not as the bounding box is not updated modelObject->SetUpdateInvisible(true); // Create a rigid body and a collision shape. These will act as a trigger for transforming the // model into a ragdoll when hit by a moving object RigidBody* body = modelNode->CreateComponent<RigidBody>(); // The Trigger mode makes the rigid body only detect collisions, but impart no forces on the // colliding objects body->SetTrigger(true); CollisionShape* shape = modelNode->CreateComponent<CollisionShape>(); // Create the capsule shape with an offset so that it is correctly aligned with the model, which // has its origin at the feet shape->SetCapsule(0.7f, 2.0f, Vector3(0.0f, 1.0f, 0.0f)); // Create a custom component that reacts to collisions and creates the ragdoll modelNode->CreateComponent<CreateRagdoll>(); } } // Create the camera. Limit far clip distance to match the fog. Note: now we actually create the camera node outside // the scene, because we want it to be unaffected by scene load / save cameraNode_ = new Node(GetContext()); Camera* camera = cameraNode_->CreateComponent<Camera>(); camera->setFarClipDistance(300.0f); // Set an initial position for the camera scene node above the floor cameraNode_->SetPosition(Vector3(0.0f, 3.0f, -20.0f)); }
BoundingBox CLBoundingBox::getSBMLBoundingBox() const { return BoundingBox(new LayoutPkgNamespaces(), "", mPosition.getX(), mPosition.getY(), mDimensions.getWidth(), mDimensions.getHeight()); }
std::vector<BoundingBox> Player::getBoundingBoxes() { std::vector<BoundingBox> v; v.push_back(BoundingBox(x, y, w, h)); return v; }
HQWater::HQWater(f32 H) { m_waterY = H; m_shader = gEngine.shaderMgr->load("HQWater.fx"); if(!m_shader) { gEngine.kernel->log->prnEx(LT_ERROR, "HQWater", "Couldn't load shader for HQWater!"); m_shader = 0; } position = Vec3(0,H,0); rotation = Vec3(0,0,0); m_hmap = gEngine.resMgr->load<Texture>("water/hmap.jpg"); m_hmap2 = gEngine.resMgr->load<Texture>("water/hmap2.png"); m_dhmap = gEngine.resMgr->load<Texture>("water/hmap.png"); m_fresnel = gEngine.resMgr->load<Texture>("water/fresnel.bmp"); m_foam = gEngine.resMgr->load<Texture>("water/foam.jpg"); if(!m_hmap || !m_hmap2 || !m_dhmap || !m_fresnel || !m_foam) { gEngine.kernel->log->prnEx(LT_ERROR, "HQWater", "Couldn't create all textures for HQWater!"); m_hmap = m_hmap2 = m_dhmap = m_fresnel = m_foam = 0; } RenderTexture::CreationParams cp; cp.width = g_waterNormalMapSize; cp.height = g_waterNormalMapSize; cp.colorFormat = D3DFMT_A32B32G32R32F; cp.depthFormat = D3DFMT_D24S8; m_normalMap = new RenderTexture(); if(!m_normalMap->init(cp)) { gEngine.kernel->log->prnEx(LT_ERROR, "HQWater", "Couldn't create normalMap texture for HQWater!"); m_normalMap = 0; } m_detailNormalMap = new RenderTexture(); if(!m_detailNormalMap->init(cp)) { gEngine.kernel->log->prnEx(LT_ERROR, "HQWater", "Couldn't create detailNormalMap texture for HQWater!"); m_detailNormalMap = 0; } m_mustUpdateNormalMap = 1; m_mustUpdateDetailNormalMap = 1; m_updatedNormalMapType = 1000; mesh = gEngine.resMgr->load<Mesh>("%gm plane 1000 120"); meshMed = gEngine.resMgr->load<Mesh>("%gm plane 2000 80"); meshLow = gEngine.resMgr->load<Mesh>("%gm plane 6000 40"); if(!mesh || !meshMed || !meshLow) { gEngine.kernel->log->prnEx(LT_ERROR, "HQWater", "Couldn't create meshes for HQWater!"); mesh = meshMed = meshLow = 0; } Vec3 minbb = Vec3(-13000,0,-13000); Vec3 maxbb = Vec3(13000,20,13000); boundingBox = BoundingBox(minbb, maxbb); boundingBox.setTransform(Vec3(0,0,0)); }
virtual ON_BoundingBox BoundingBox(const CRhinoView* pView) const { return BoundingBox(); }