void RenderManager::centerObjects() { glm::vec3 minPt((std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)()); glm::vec3 maxPt = -minPt; // もとのサイズを計算 for (auto it = objects.begin(); it != objects.end(); ++it) { for (auto it2 = it.value().begin(); it2 != it.value().end(); ++it2) { for (int k = 0; k < it2->vertices.size(); ++k) { minPt.x = (std::min)(minPt.x, it2->vertices[k].position.x); minPt.y = (std::min)(minPt.y, it2->vertices[k].position.y); minPt.z = (std::min)(minPt.z, it2->vertices[k].position.z); maxPt.x = (std::max)(maxPt.x, it2->vertices[k].position.x); maxPt.y = (std::max)(maxPt.y, it2->vertices[k].position.y); maxPt.z = (std::max)(maxPt.z, it2->vertices[k].position.z); } } } glm::vec3 center = (maxPt + minPt) * 0.5f; float size = (std::max)(maxPt.x - minPt.x, (std::max)(maxPt.y - minPt.y, maxPt.z - minPt.z)); float scale = 1.0f / size; // 単位立方体に入るよう、縮尺・移動 for (auto it = objects.begin(); it != objects.end(); ++it) { for (auto it2 = it.value().begin(); it2 != it.value().end(); ++it2) { for (int k = 0; k < it2->vertices.size(); ++k) { it2->vertices[k].position = (it2->vertices[k].position - center) * scale; } } } }
void MkLineShape::__Update(const MkSceneTransform* parentTransform) { m_WorldVertices.Clear(); m_WorldDepth = m_LocalDepth; m_AABR.Clear(); if (!m_LocalVertices.Empty()) { // transform if (parentTransform == NULL) // 부모 노드가 없음 { m_WorldVertices = m_LocalVertices; } else // 자체 transform이 없으므로 부모 노드의 것을 그대로 사용 { parentTransform->GetWorldVertices(m_LocalVertices, m_WorldVertices); m_WorldDepth += parentTransform->GetWorldDepth(); } // aabb MkFloat2 minPt(m_WorldVertices[0]); MkFloat2 maxPt(m_WorldVertices[0]); MK_INDEXING_LOOP(m_WorldVertices, i) { const MkFloat2& vertex = m_WorldVertices[i]; minPt.CompareAndKeepMin(vertex); maxPt.CompareAndKeepMax(vertex); } m_AABR.position = minPt; m_AABR.size = maxPt - minPt; } }
void GroundPlane::projectFrustum( const Frustum& frustum, F32 squareSize, Point2F& outMin, Point2F& outMax ) { // Get the frustum's min and max XY coordinates. const Box3F bounds = frustum.getBounds(); Point2F minPt( bounds.minExtents.x, bounds.minExtents.y ); Point2F maxPt( bounds.maxExtents.x, bounds.maxExtents.y ); // Round the min and max coordinates so they align on the grid. minPt.x -= mFmod( minPt.x, squareSize ); minPt.y -= mFmod( minPt.y, squareSize ); F32 maxDeltaX = mFmod( maxPt.x, squareSize ); F32 maxDeltaY = mFmod( maxPt.y, squareSize ); if( maxDeltaX != 0.0f ) maxPt.x += ( squareSize - maxDeltaX ); if( maxDeltaY != 0.0f ) maxPt.y += ( squareSize - maxDeltaY ); // Add a safezone, so we don't touch the clipping planes. minPt.x -= squareSize; minPt.y -= squareSize; maxPt.x += squareSize; maxPt.y += squareSize; outMin = minPt; outMax = maxPt; }
void Enemies::CreateBoundingBox() { // // Compute scene bounding box. // XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity); XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity); for (UINT i = 0; i < mEnemyInstances.size(); ++i) { minPt.x = 0.0f; minPt.y = 0.0f; minPt.z = 0.0f; maxPt.x = 0.0f; maxPt.y = 0.0f; maxPt.z = 0.0f; for (UINT j = 0; j < mEnemyInstances[i].Model->BasicVertices.size(); ++j) { XMFLOAT3 P = mEnemyInstances[i].Model->BasicVertices[j].Pos; //////multiply all these by 7 minPt.x = MathHelper::Min(minPt.x, P.x); minPt.y = MathHelper::Min(minPt.y, P.y); minPt.z = MathHelper::Min(minPt.z, P.z); maxPt.x = MathHelper::Max(maxPt.x, P.x); maxPt.y = MathHelper::Max(maxPt.y, P.y); maxPt.z = MathHelper::Max(maxPt.z, P.z); } XMMATRIX temp = XMLoadFloat4x4(&mEnemyInstances[i].World); enemyclass[i]->setWorld(mEnemyInstances[i].World); XMVECTOR Scale; XMVECTOR Position; XMVECTOR Rotation; XMMatrixDecompose(&Scale, &Rotation, &Position, temp); XMFLOAT3 tempPos; XMStoreFloat3(&tempPos, Position); LevelCollisions[i].Center = tempPos; LevelCollisions[i].Extents = XMFLOAT3(0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); LevelCollisions[i].collisionType = enemyclass[i]->getcollisiontype(); FLOAT scale = enemyclass[i]->getScale(); LevelCollisions[i].Extents.x = LevelCollisions[i].Extents.x * scale; LevelCollisions[i].Extents.y = LevelCollisions[i].Extents.y * scale; LevelCollisions[i].Extents.z = LevelCollisions[i].Extents.z * scale; EnemyBox.collisionType = 1; enemyclass[i]->setAABB(&LevelCollisions[i]); } }
box2f GraphPane::updateGraphBounds() { float2 minPt(std::numeric_limits<float>::max()); float2 maxPt(std::numeric_limits<float>::min()); for (GraphDataPtr& curve : curves) { for (float2& pt : curve->points) { minPt = aly::min(pt, minPt); maxPt = aly::max(pt, maxPt); } } graphBounds = box2f(minPt, maxPt - minPt); return graphBounds; }
void GroundPlane::projectFrustum( const Frustum& _frustum, F32 squareSize, Point2F& outMin, Point2F& outMax ) { // Go through all the frustum's corner points and mark // the min and max XY coordinates. // transform the frustum to plane object space Frustum frustum = _frustum; frustum.mulL( mWorldToObj ); Point2F minPt( F32_MAX, F32_MAX ); Point2F maxPt( F32_MIN, F32_MIN ); for( U32 i = 0; i < Frustum::CornerPointCount; ++ i ) { const Point3F& point = frustum.getPoint( i ); if( point.x < minPt.x ) minPt.x = point.x; if( point.y < minPt.y ) minPt.y = point.y; if( point.x > maxPt.x ) maxPt.x = point.x; if( point.y > maxPt.y ) maxPt.y = point.y; } // Round the min and max coordinates so they align on the grid. minPt.x -= mFmod( minPt.x, squareSize ); minPt.y -= mFmod( minPt.y, squareSize ); F32 maxDeltaX = mFmod( maxPt.x, squareSize ); F32 maxDeltaY = mFmod( maxPt.y, squareSize ); if( maxDeltaX != 0.0f ) maxPt.x += ( squareSize - maxDeltaX ); if( maxDeltaY != 0.0f ) maxPt.y += ( squareSize - maxDeltaY ); // Add a safezone, so we don't touch the clipping planes. minPt.x -= squareSize; minPt.y -= squareSize; maxPt.x += squareSize; maxPt.y += squareSize; outMin = minPt; outMax = maxPt; }
AABB DBVH::createAABBFromObjList( const ObjectList& objList ) { AABB box; float minX, minY, minZ, maxX, maxY, maxZ; minX = minY = minZ = FLT_MAX; maxX = maxY = maxZ = -FLT_MAX; //Find the minimum and maximum x y and z points for(unsigned i = 0; i < objList.size(); ++i) { const Object& obj = objList[i]; Pt minPt = obj.boundingBox.center - obj.boundingBox.extents; Pt maxPt = obj.boundingBox.center + obj.boundingBox.extents; if(minPt.x < minX) minX = minPt.x; if(maxPt.x > maxX) maxX = maxPt.x; if(minPt.y < minY) minY = minPt.y; if(maxPt.y > maxY) maxY = maxPt.y; if(minPt.z < minZ) minZ = minPt.z; if(maxPt.z > maxZ) maxZ = maxPt.z; } //Extents are just width/height/depth / 2 box.extents.x = abs(maxX - minX) * 0.5f; box.extents.y = abs(maxY - minY) * 0.5f; box.extents.z = abs(maxZ - minZ) * 0.5f; //Center is just the min point plus the extents Pt minPt(minX, minY, minZ); box.center = minPt + box.extents; return box; }
void Bvh::update(std::list<IModel*> &modelList) { if(!bTree) return; primList.clear(); Point3 minPt(POS_INF, POS_INF,POS_INF); Point3 maxPt(-POS_INF,-POS_INF,-POS_INF); myTriSize = 0; std::list<IModel*>::iterator model; std::list<IPrimitive*>::iterator p; for( model = modelList.begin(); model != modelList.end(); model++ ) { myTriSize += (*model)->GetPrimitiveCount(); // update uniform grids min and max values; minPt.X() = min((*model)->MinPoint().X(), minPt.X()); minPt.Y() = min((*model)->MinPoint().Y(), minPt.Y()); minPt.Z() = min((*model)->MinPoint().Z(), minPt.Z()); maxPt.X() = max((*model)->MaxPoint().X(), maxPt.X()); maxPt.Y() = max((*model)->MaxPoint().Y(), maxPt.Y()); maxPt.Z() = max((*model)->MaxPoint().Z(), maxPt.Z()); std::list<IPrimitive*>* pl = &(*model)->getPrimitiveList(); for ( p = pl->begin(); p != pl->end(); p++ ) { primList.push_back( (*p) ); } } myBound = AABB( minPt, maxPt ); unsigned int *temp = new unsigned int[myTriSize]; // check as we go trace(0, temp, 0); delete [] temp; bTree[0].bound = myBound; }
/* Function: UpdateHapticMapping Usage: UpdateHapticMapping(); --------------------------------------------------------------------------- Use the current OpenGL viewing transforms to initialize a transform for the haptic device workspace so that it's properly mapped to world coordinates. */ void UpdateHapticMapping(void) { GLdouble modelview[16]; GLdouble projection[16]; GLint viewport[4]; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); hlMatrixMode(HL_TOUCHWORKSPACE); hlLoadIdentity(); /* fit haptic workspace to the bound of the deformable surface */ hduVector3Dd minPt(-kSurfaceSize / 2.0, -kSurfaceSize / 2.0, -kSurfaceSize / 2.0); hduVector3Dd maxPt(kSurfaceSize / 2.0, kSurfaceSize / 2.0, kSurfaceSize / 2.0); hluFitWorkspaceBox(modelview, minPt, maxPt); /* compute cursor scale */ mCursorScale = hluScreenToModelScale(modelview, projection, viewport); const int CURSOR_SIZE_PIXELS = 20; mCursorScale *= CURSOR_SIZE_PIXELS; }
void srs_env_model::CCollisionGridPlugin::newMapDataCB(SMapWithParameters & par) { // init projected 2D map: m_data->header.frame_id = par.frameId; m_data->header.stamp = par.currentTime; m_crawlDepth = par.treeDepth; bool sizeChanged(false); // TODO: move most of this stuff into c'tor and init map only once (adjust if size changes) double minX, minY, minZ, maxX, maxY, maxZ; par.map->getTree().getMetricMin(minX, minY, minZ); par.map->getTree().getMetricMax(maxX, maxY, maxZ); octomap::point3d minPt(minX, minY, minZ); octomap::point3d maxPt(maxX, maxY, maxZ); octomap::OcTreeKey minKey, maxKey, curKey; if (!par.map->getTree().genKey(minPt, minKey)){ ROS_ERROR("Could not create min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z()); return; } if (!par.map->getTree().genKey(maxPt, maxKey)){ ROS_ERROR("Could not create max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z()); return; } par.map->getTree().genKeyAtDepth(minKey, par.treeDepth, minKey); par.map->getTree().genKeyAtDepth(maxKey, par.treeDepth, maxKey); ROS_DEBUG("MinKey: %d %d %d / MaxKey: %d %d %d", minKey[0], minKey[1], minKey[2], maxKey[0], maxKey[1], maxKey[2]); // add padding if requested (= new min/maxPts in x&y): double halfPaddedX = 0.5*m_minSizeX; double halfPaddedY = 0.5*m_minSizeY; minX = std::min(minX, -halfPaddedX); maxX = std::max(maxX, halfPaddedX); minY = std::min(minY, -halfPaddedY); maxY = std::max(maxY, halfPaddedY); minPt = octomap::point3d(minX, minY, minZ); maxPt = octomap::point3d(maxX, maxY, maxZ); octomap::OcTreeKey paddedMaxKey; if (!par.map->getTree().genKey(minPt, m_paddedMinKey)){ ROS_ERROR("Could not create padded min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z()); return; } if (!par.map->getTree().genKey(maxPt, paddedMaxKey)){ ROS_ERROR("Could not create padded max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z()); return; } par.map->getTree().genKeyAtDepth(m_paddedMinKey, par.treeDepth, m_paddedMinKey); par.map->getTree().genKeyAtDepth(paddedMaxKey, par.treeDepth, paddedMaxKey); ROS_DEBUG("Padded MinKey: %d %d %d / padded MaxKey: %d %d %d", m_paddedMinKey[0], m_paddedMinKey[1], m_paddedMinKey[2], paddedMaxKey[0], paddedMaxKey[1], paddedMaxKey[2]); assert(paddedMaxKey[0] >= maxKey[0] && paddedMaxKey[1] >= maxKey[1]); m_multires2DScale = 1 << (par.treeDepth - m_crawlDepth); unsigned int newWidth = (paddedMaxKey[0] - m_paddedMinKey[0])/m_multires2DScale +1; unsigned int newHeight = (paddedMaxKey[1] - m_paddedMinKey[1])/m_multires2DScale +1; if (newWidth != m_data->info.width || newHeight != m_data->info.height) sizeChanged = true; m_data->info.width = newWidth; m_data->info.height = newHeight; int mapOriginX = minKey[0] - m_paddedMinKey[0]; int mapOriginY = minKey[1] - m_paddedMinKey[1]; assert(mapOriginX >= 0 && mapOriginY >= 0); // might not exactly be min / max of octree: octomap::point3d origin; par.map->getTree().genCoords(m_paddedMinKey, m_crawlDepth, origin); double gridRes = par.map->getTree().getNodeSize(par.treeDepth); m_data->info.resolution = gridRes; m_data->info.origin.position.x = origin.x() - gridRes*0.5; m_data->info.origin.position.y = origin.y() - gridRes*0.5; // std::cerr << "Origin: " << origin << ", grid resolution: " << gridRes << ", computed origin: "<< mapOriginX << ".." << mapOriginY << std::endl; if (par.treeDepth != m_crawlDepth){ m_data->info.origin.position.x -= par.resolution/2.0; m_data->info.origin.position.y -= par.resolution/2.0; } if (sizeChanged){ ROS_INFO("2D grid map size changed to %d x %d", m_data->info.width, m_data->info.height); m_data->data.clear(); // init to unknown: m_data->data.resize(m_data->info.width * m_data->info.height, -1); } tButServerOcTree & tree( par.map->getTree() ); srs_env_model::tButServerOcTree::leaf_iterator it, itEnd( tree.end_leafs() ); // Crawl through nodes for ( it = tree.begin_leafs(m_crawlDepth); it != itEnd; ++it) { // Node is occupied? if (tree.isNodeOccupied(*it)) { handleOccupiedNode(it, par); }// Node is occupied? else { handleFreeNode( it, par ); } } // Iterate through octree m_DataTimeStamp = par.currentTime; invalidate(); }
bool DuckHuntMain::Init() { if (!D3DApp::Init()) return false; // Must init Effects first since InputLayouts depend on shader signatures. Effects::InitAll(md3dDevice); InputLayouts::InitAll(md3dDevice); RenderStates::InitAll(md3dDevice); mCrosshair = new Crosshair(md3dDevice); mTexMgr.Init(md3dDevice); DuckHuntMain::ShowCursors(false); mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f); mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize); Terrain::InitInfo tii; tii.HeightMapFilename = L"Textures/myT5.raw"; tii.LayerMapFilename0 = L"Textures/grass.dds"; tii.LayerMapFilename1 = L"Textures/darkdirt.dds"; tii.LayerMapFilename2 = L"Textures/stone.dds"; tii.LayerMapFilename3 = L"Textures/lightdirt.dds"; tii.LayerMapFilename4 = L"Textures/snow.dds"; tii.BlendMapFilename = L"Textures/blend.dds"; tii.HeightScale = 50.0f; tii.HeightmapWidth = 2049; tii.HeightmapHeight = 2049; tii.CellSpacing = 0.5f; mTerrain.Init(md3dDevice, md3dImmediateContext, tii); //Sound result = FMOD::System_Create(&mSystem); result = mSystem->init(32, FMOD_INIT_NORMAL, 0); result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire); result = mGunFire->setMode(FMOD_LOOP_OFF); mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f); mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ()); BuildScreenQuadGeometryBuffers(); testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg"); BasicModelInstance testInstanceDuck; BasicModelInstance testInstanceDuck2; BasicModelInstance testInstanceDuck3; BasicModelInstance testInstanceDuck4; testInstanceDuck.Model = testModelDuck; testInstanceDuck2.Model = testModelDuck; testInstanceDuck3.Model = testModelDuck; testInstanceDuck4.Model = testModelDuck; //Duck 1 XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //Duck 2 XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f); XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f); XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f); //Duck3 XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f); XMMATRIX modelRot3 = XMMatrixRotationY(0.5f); XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f); //Duck4 XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f); XMMATRIX modelRot4 = XMMatrixRotationY(1.0f); XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f); //Duck 1 XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset); mModelInstances.push_back(testInstanceDuck); //Duck 2 XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2); mModelInstances.push_back(testInstanceDuck2); //Duck 3 XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3); mModelInstances.push_back(testInstanceDuck3); //Duck 4 XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4); mModelInstances.push_back(testInstanceDuck4); //create collision box for (unsigned i = 0; i < mModelInstances.size(); i++) { mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices); } // // Compute scene bounding box. // XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity); XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity); for (UINT i = 0; i < mModelInstances.size(); ++i) { for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j) { XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos; minPt.x = MathHelper::Min(minPt.x, P.x); minPt.y = MathHelper::Min(minPt.x, P.x); minPt.z = MathHelper::Min(minPt.x, P.x); maxPt.x = MathHelper::Max(maxPt.x, P.x); maxPt.y = MathHelper::Max(maxPt.x, P.x); maxPt.z = MathHelper::Max(maxPt.x, P.x); } } // // Derive scene bounding sphere from bounding box. // mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); XMFLOAT3 extent( 0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); return true; }
void srs_env_model::CMap2DPlugin::newMapDataCB(SMapWithParameters & par) { m_data->header.frame_id = m_map2DFrameId; m_data->header.stamp = par.currentTime; m_data->info.resolution = par.resolution; m_ocFrameId = par.frameId; ros::Time timestamp( par.currentTime ); tf::StampedTransform ocToMap2DTf; m_bConvert = m_ocFrameId != m_map2DFrameId; // Get transform try { // Transformation - to, from, time, waiting time m_tfListener.waitForTransform(m_map2DFrameId, m_ocFrameId, timestamp, ros::Duration(5)); m_tfListener.lookupTransform(m_map2DFrameId, m_ocFrameId, timestamp, ocToMap2DTf); } catch (tf::TransformException& ex) { ROS_ERROR_STREAM("Transform error: " << ex.what() << ", quitting callback"); PERROR( "Transform error."); return; } Eigen::Matrix4f ocToMap2DTM; // Get transformation matrix pcl_ros::transformAsMatrix(ocToMap2DTf, ocToMap2DTM); const tButServerOcMap &map(*par.map); // Disassemble translation and rotation m_ocToMap2DRot = ocToMap2DTM.block<3, 3> (0, 0); m_ocToMap2DTrans = ocToMap2DTM.block<3, 1> (0, 3); double minX, minY, minZ, maxX, maxY, maxZ; map.getTree().getMetricMin(minX, minY, minZ); map.getTree().getMetricMax(maxX, maxY, maxZ); octomap::point3d minPt(minX, minY, minZ); octomap::point3d maxPt(maxX, maxY, maxZ); octomap::OcTreeKey minKey, maxKey, curKey; // Try to create key if (!map.getTree().genKey(minPt, minKey)) { ROS_ERROR("Could not create min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z()); return; } if (!map.getTree().genKey(maxPt, maxKey)) { ROS_ERROR("Could not create max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z()); return; } ROS_DEBUG("MinKey: %d %d %d / MaxKey: %d %d %d", minKey[0], minKey[1], minKey[2], maxKey[0], maxKey[1], maxKey[2]); // add padding if requested (= new min/maxPts in x&y): double halfPaddedX = 0.5 * m_minSizeX; double halfPaddedY = 0.5 * m_minSizeY; minX = std::min(minX, -halfPaddedX); maxX = std::max(maxX, halfPaddedX); minY = std::min(minY, -halfPaddedY); maxY = std::max(maxY, halfPaddedY); minPt = octomap::point3d(minX, minY, minZ); maxPt = octomap::point3d(maxX, maxY, maxZ); octomap::OcTreeKey paddedMaxKey; if (!map.getTree().genKey(minPt, m_paddedMinKey)) { ROS_ERROR("Could not create padded min OcTree key at %f %f %f", minPt.x(), minPt.y(), minPt.z()); return; } if (!map.getTree().genKey(maxPt, paddedMaxKey)) { ROS_ERROR("Could not create padded max OcTree key at %f %f %f", maxPt.x(), maxPt.y(), maxPt.z()); return; } ROS_DEBUG("Padded MinKey: %d %d %d / padded MaxKey: %d %d %d", m_paddedMinKey[0], m_paddedMinKey[1], m_paddedMinKey[2], paddedMaxKey[0], paddedMaxKey[1], paddedMaxKey[2]); assert(paddedMaxKey[0] >= maxKey[0] && paddedMaxKey[1] >= maxKey[1]); m_data->info.width = paddedMaxKey[0] - m_paddedMinKey[0] + 1; m_data->info.height = paddedMaxKey[1] - m_paddedMinKey[1] + 1; int mapOriginX = minKey[0] - m_paddedMinKey[0]; int mapOriginY = minKey[1] - m_paddedMinKey[1]; assert(mapOriginX >= 0 && mapOriginY >= 0); // might not exactly be min / max of octree: octomap::point3d origin; map.getTree().genCoords(m_paddedMinKey, par.treeDepth, origin); m_data->info.origin.position.x = origin.x() - par.resolution* 0.5; m_data->info.origin.position.y = origin.y() - par.resolution * 0.5; // Allocate space to hold the data (init to unknown) m_data->data.resize(m_data->info.width * m_data->info.height, -1); tButServerOcTree & tree( par.map->getTree() ); srs_env_model::tButServerOcTree::leaf_iterator it, itEnd( tree.end_leafs() ); // Crawl through nodes for ( it = tree.begin_leafs(m_crawlDepth); it != itEnd; ++it) { // Node is occupied? if (tree.isNodeOccupied(*it)) { handleOccupiedNode(it, par); }// Node is occupied? else { handleFreeNode( it, par ); } } // Iterate through octree invalidate(); }
void Bvh::build(std::list<IModel*> &modelList) { DWORD dwBuildTime = EncoreGetTime(); primList.clear(); // destory the old information regardless deleteTree(); rightBOX.reserve(maxReserve); Point3 minPt(POS_INF, POS_INF,POS_INF); Point3 maxPt(-POS_INF,-POS_INF,-POS_INF); myTriSize = 0; std::list<IModel*>::iterator model; std::list<IPrimitive*>::iterator p; for( model = modelList.begin(); model != modelList.end(); model++ ) { myTriSize += (*model)->GetPrimitiveCount(); // update uniform grids min and max values; minPt.X() = min((*model)->MinPoint().X(), minPt.X()); minPt.Y() = min((*model)->MinPoint().Y(), minPt.Y()); minPt.Z() = min((*model)->MinPoint().Z(), minPt.Z()); maxPt.X() = max((*model)->MaxPoint().X(), maxPt.X()); maxPt.Y() = max((*model)->MaxPoint().Y(), maxPt.Y()); maxPt.Z() = max((*model)->MaxPoint().Z(), maxPt.Z()); std::list<IPrimitive*>* pl = &(*model)->getPrimitiveList(); for ( p = pl->begin(); p != pl->end(); p++ ) { primList.push_back( (*p) ); } } myBound = AABB( minPt, maxPt ); // bvh size is always 2n-1 maxSize = 2*myTriSize-1; bTree = new bvhNode[maxSize];//(bvhNode*)malloc((maxSize)*sizeof(bvhNode)); if(bTree == NULL) { printf("no memory to make bvh\n"); return; } try { leftBOX = new IPrimitive*[myTriSize]; } catch(std::bad_alloc&) { printf("no memory"); return; } m_NodeUsed = 1; construct(0, 1, myTriSize, myBound, 0, 0); // clear junk //if(leftBOX) // free(leftBOX); //leftBOX = 0; //rightBOX.clear(); maxReserve = rightBOX.size(); dwBuildTime = EncoreGetTime() - dwBuildTime; }
void LevelBuilder::CreateBoundingBox() { // // Compute scene bounding box. // XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity); XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity); for (UINT i = 0; i < mLevelPartsInstances.size(); ++i) { minPt.x = 0.0f; minPt.y = 0.0f; minPt.z = 0.0f; maxPt.x = 0.0f; maxPt.y = 0.0f; maxPt.z = 0.0f; for (UINT j = 0; j < mLevelPartsInstances[i].Model->BasicVertices.size(); ++j) { XMFLOAT3 P = mLevelPartsInstances[i].Model->BasicVertices[j].Pos; minPt.x = MathHelper::Min(minPt.x, P.x); minPt.y = MathHelper::Min(minPt.y, P.y); minPt.z = MathHelper::Min(minPt.z, P.z); maxPt.x = MathHelper::Max(maxPt.x, P.x); maxPt.y = MathHelper::Max(maxPt.y, P.y); maxPt.z = MathHelper::Max(maxPt.z, P.z); } XMMATRIX temp = XMLoadFloat4x4(&mLevelPartsInstances[i].World); LevelPartsclass[i]->setWorld(mLevelPartsInstances[i].World); XMVECTOR Scale; XMVECTOR Position; XMVECTOR Rotation; XMMatrixDecompose(&Scale, &Rotation, &Position, temp); XMFLOAT3 tempPos; XMStoreFloat3(&tempPos, Position); LevelCollisions[i].Center = tempPos; LevelCollisions[i].Extents = XMFLOAT3(0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); LevelCollisions[i].collisionType = LevelPartsclass[i]->getCollisionType(); // sets the scale of the collision box int scale = LevelPartsclass[i]->getScale(); LevelCollisions[i].Extents.x = LevelCollisions[i].Extents.x * scale; LevelCollisions[i].Extents.y = LevelCollisions[i].Extents.y * scale; LevelCollisions[i].Extents.z = LevelCollisions[i].Extents.z * scale; if (LevelPartsclass[i]->getRotationY() != 0) { FLOAT tempX = LevelCollisions[i].Extents.x; FLOAT tempZ = LevelCollisions[i].Extents.z; LevelCollisions[i].Extents.x = tempZ; LevelCollisions[i].Extents.z = tempX; } //// this doesn't work, useless atm //LevelPartsBox[i]->setCollisionType(); LevelPartsclass[i]->setAABB(&LevelCollisions[i]); } }
bool Projekt::Init() { if (!D3D11App::Init()) return false; // Initialize effects, input layouts and texture manager Effects::InitAll(mDirect3D->GetDevice()); InputLayouts::InitAll(mDirect3D->GetDevice()); mTextureMgr.init(mDirect3D->GetDevice()); // Initialize wireframe render state D3D11_RASTERIZER_DESC wireFrameDesc; ZeroMemory(&wireFrameDesc, sizeof(D3D11_RASTERIZER_DESC)); wireFrameDesc.FillMode = D3D11_FILL_WIREFRAME; wireFrameDesc.CullMode = D3D11_CULL_BACK; wireFrameDesc.FrontCounterClockwise = false; wireFrameDesc.DepthClipEnable = true; HR(mDirect3D->GetDevice()->CreateRasterizerState(&wireFrameDesc, &WireFrameRS)); //-------------------------------------------------------- // Create sky //-------------------------------------------------------- mSky = new Sky(mDirect3D->GetDevice(), L"Data/Textures/snowcube1024.dds", 5000.0f); //-------------------------------------------------------- // Create terrain //-------------------------------------------------------- // Describe terrain Terrain::InitInfo tInitInfo; tInitInfo.HeightMapFilename = L"Data/Textures/Heightmaps/terrain.raw"; tInitInfo.LayerMapFilename0 = L"Data/Textures/grass.dds"; tInitInfo.LayerMapFilename1 = L"Data/Textures/darkdirt.dds"; tInitInfo.LayerMapFilename2 = L"Data/Textures/stone.dds"; tInitInfo.LayerMapFilename3 = L"Data/Textures/lightdirt.dds"; tInitInfo.LayerMapFilename4 = L"Data/Textures/snow.dds"; tInitInfo.BlendMapFilename = L"Data/Textures/blend.dds"; tInitInfo.HeightScale = 50.0f; tInitInfo.HeightmapWidth = 2049; tInitInfo.HeightmapHeight = 2049; tInitInfo.CellSpacing = 0.5f; // Initialize terrain mTerrain.Init(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), tInitInfo); //-------------------------------------------------------- // Particle systems //-------------------------------------------------------- mRandomTexSRV = d3dHelper::CreateRandomTexture1DSRV(mDirect3D->GetDevice()); std::vector<std::wstring> flares; flares.push_back(L"Data\\Textures\\flare0.dds"); mFlareTexSRV = d3dHelper::CreateTexture2DArraySRV(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), flares); mFire.init(mDirect3D->GetDevice(), Effects::FireFX, mFlareTexSRV, mRandomTexSRV, 500); mFire.setEmitPos(XMFLOAT3(65.0f, 5.0f, 0.0f)); //-------------------------------------------------------- // Create shadow map //-------------------------------------------------------- mShadowMapSize = 2048; mShadowMap = new ShadowMap(mDirect3D->GetDevice(), mShadowMapSize, mShadowMapSize); //-------------------------------------------------------- // Load models //-------------------------------------------------------- mGenericModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\duck.dae", L"Data\\Models\\Collada\\"); //mSkinnedModel = new GenericSkinnedModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\AnimTest\\test_Collada_DAE.dae", L"Data\\Models\\Collada\\AnimTest\\"); mPlayerModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\OBJ\\Cop\\cop.obj", L"Data\\Models\\OBJ\\Cop\\"); Player::InitProperties playerProp; playerProp.PlayerID = 0; playerProp.Nickname = "Hyzor"; playerProp.Speed = 1.0f; playerProp.Health = 1.0f; playerProp.Position = XMFLOAT3(0.0f, 0.0f, 0.0f); playerProp.Scale = XMFLOAT3(1.0f, 1.0f, 1.0f); playerProp.Angle = 0.0f; playerProp.Model = mPlayerModel; mPlayer.Init(playerProp); //-------------------------------------------------------- // Create model instances //-------------------------------------------------------- GenericModelInstance genericInstance; genericInstance.model = mGenericModel; // GenericSkinnedModelInstance genSkinnedInstance; // genSkinnedInstance.model = mSkinnedModel; // genSkinnedInstance.FinalTransforms.resize(mSkinnedModel->skinnedData.getBoneCount()); // genSkinnedInstance.ClipName = "animation"; // genSkinnedInstance.TimePos = 0.0f; //-------------------------------------------------------- // Scale, rotate and move model instances //-------------------------------------------------------- XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, 1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //modelScale = XMMatrixScaling(0.1f, 0.1f, 0.1f); modelOffset = XMMatrixTranslation(-30.0f, 15.0f, -110.0f); XMStoreFloat4x4(&genericInstance.world, modelScale*modelRot*modelOffset); // modelOffset = XMMatrixTranslation(50.0f, 15.0f, -110.0f); // XMStoreFloat4x4(&genSkinnedInstance.world, modelScale*modelRot*modelOffset); //-------------------------------------------------------- // Insert model instances to the vector //-------------------------------------------------------- mGenericInstances.push_back(genericInstance); /* mGenSkinnedInstances.push_back(genSkinnedInstance);*/ //-------------------------------------------------------- // Compute scene bounding box //-------------------------------------------------------- XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity); XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity); // Get vertex positions from all models for (UINT i = 0; i < mGenericInstances.size(); ++i) { for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j) { XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } } // Get vertex positions from all skinned models // for (UINT i = 0; i < mGenSkinnedInstances.size(); ++i) // { // for (UINT j = 0; j < mGenSkinnedInstances[i].model->vertices.size(); ++j) // { // XMFLOAT3 vPos = mGenSkinnedInstances[i].model->vertices[j]->position; // // minPt.x = MathHelper::getMin(minPt.x, vPos.x); // minPt.y = MathHelper::getMin(minPt.x, vPos.x); // minPt.z = MathHelper::getMin(minPt.x, vPos.x); // // maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); // } // } // Now continue with terrain vertex positions for (UINT i = 0; i < mTerrain.getPatchVertices().size(); ++i) { XMFLOAT3 vPos = mTerrain.getPatchVertices()[i].position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } // Sphere center is at half of these new dimensions mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); // Calculate the sphere radius XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); OnResize(); return true; }